### Eclipse Workspace Patch 1.0 #P org.jboss.tools.jsf.vpe.richfaces.test Index: resources/richFacesTest/WebContent/pages/components/messages.xhtml =================================================================== --- resources/richFacesTest/WebContent/pages/components/messages.xhtml (revision 20840) +++ resources/richFacesTest/WebContent/pages/components/messages.xhtml (working copy) @@ -7,9 +7,29 @@ xmlns:rich="http://richfaces.org/rich"> + + +

header

+ + some text + some text2 + some text2 + some text2 + + 0) - ) ||(child.getNodeType() == Node.ELEMENT_NODE)) { - VpeChildrenInfo childrenInfo = new VpeChildrenInfo(div); - childrenInfo.addSourceChild(child); - creationData.addChildrenInfo(childrenInfo); - jsfComponentFound = true; - break; + public VpeCreationData create(VpePageContext pageContext, Node sourceNode, + nsIDOMDocument visualDocument) { + Element sourceElement = (Element) sourceNode; + Node facetParent = null; + nsIDOMElement facetVisualTag = null; +// nsIDOMElement facetVisualTag2 = null; + + NodeList children = sourceNode.getChildNodes(); + boolean jsfComponentFound = false; + + /* + * https://jira.jboss.org/jira/browse/JBIDE-3373 + * By rendering facet to existed visual node + * we avoid unwarranted tag creation for facet element. + */ + facetParent = sourceNode.getParentNode(); +// Node column = sourceNode.getParentNode(); +// Node datatable = (column != null) ? column.getParentNode() : null; +// if (datatable != null) { +// List taglibs1 = XmlUtil.getTaglibsForNode(datatable, +// pageContext); +// TaglibData sourceNodeTaglib1 = XmlUtil.getTaglibForPrefix( +// datatable.getPrefix(), taglibs1); +// if (VisualDomUtil.JSF_HTML_URI.equalsIgnoreCase(sourceNodeTaglib1.getUri())) { +// facetParent = datatable; +// } +// } + nsIDOMNode facetParentVisualTag = pageContext.getDomMapping().getVisualNode(facetParent); + facetVisualTag = VisualDomUtil.findVisualTagWithFacetAttribute( + facetParentVisualTag, sourceElement.getAttribute(JSF.ATTR_NAME)); + /* + * When no tag found use 'SPAN' tag by default. + * So facet will be rendered in any case. + */ +// facetVisualTag = visualDocument.createElement(HTML.TAG_SPAN); + if (null == facetVisualTag) { + facetVisualTag = visualDocument.createElement(HTML.TAG_SPAN); } - //commented by Maksim Areshkau as fix for https://jira.jboss.org/jira/browse/JBIDE-5744 -// if ((child.getNodeType() == Node.ELEMENT_NODE)){ -//// && (VisualDomUtil.JSF_CORE_URI.equalsIgnoreCase(sourceNodeUri) -//// || VisualDomUtil.JSF_HTML_URI.equalsIgnoreCase(sourceNodeUri) -//// || VisualDomUtil.RICH_FACES_URI.equalsIgnoreCase(sourceNodeUri) -//// || VisualDomUtil.A4J_URI.equalsIgnoreCase(sourceNodeUri) -//// || VisualDomUtil.FACELETS_URI.equalsIgnoreCase(sourceNodeUri))) { -// VpeChildrenInfo childrenInfo = new VpeChildrenInfo(div); -// childrenInfo.addSourceChild(child); -// creationData.addChildrenInfo(childrenInfo); -// jsfComponentFound = true; -// break; -//// } -// } - } - - if (!jsfComponentFound) { - div.setAttribute(HTML.ATTR_STYLE, "display: none; "); //$NON-NLS-1$ - creationData.addChildrenInfo(new VpeChildrenInfo(div)); - } - - return creationData; + + VpeCreationData creationData = new VpeCreationData(facetVisualTag); + /* + * Only one JSF component may be present inside a facet tag, if more are + * present only the first one is rendered and the other ones are + * ignored. + */ + for (int i = children.getLength() - 1; i >= 0 ; i--) { + Node child = children.item(i); + String sourcePrefix = child.getPrefix(); + List taglibs = XmlUtil.getTaglibsForNode(sourceNode, + pageContext); + TaglibData sourceNodeTaglib = XmlUtil.getTaglibForPrefix( + sourcePrefix, taglibs); + if (null != sourceNodeTaglib) { + String sourceNodeUri = sourceNodeTaglib.getUri(); + if (VisualDomUtil.JSF_CORE_URI.equalsIgnoreCase(sourceNodeUri) + || VisualDomUtil.JSF_HTML_URI.equalsIgnoreCase(sourceNodeUri) + || VisualDomUtil.RICH_FACES_URI.equalsIgnoreCase(sourceNodeUri) + || VisualDomUtil.A4J_URI.equalsIgnoreCase(sourceNodeUri) + || VisualDomUtil.FACELETS_URI.equalsIgnoreCase(sourceNodeUri)) { + VpeChildrenInfo childrenInfo = new VpeChildrenInfo(facetVisualTag); + childrenInfo.addSourceChild(child); + creationData.addChildrenInfo(childrenInfo); + jsfComponentFound = true; + break; + } + } + } + if (!jsfComponentFound) { + facetVisualTag.setAttribute(HTML.ATTR_STYLE, "display: none; "); //$NON-NLS-1$ + creationData.addChildrenInfo(new VpeChildrenInfo(facetVisualTag)); + } + return creationData; } } #P org.jboss.tools.vpe Index: src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java =================================================================== --- src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java (revision 20840) +++ src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java (working copy) @@ -97,7 +97,12 @@ public static final String PARENT = "PARENT"; //$NON-NLS-1$ public static final String VPE_USER_TOGGLE_ID = "vpe-user-toggle-id"; //$NON-NLS-1$ public static final String VPE_USER_TOGGLE_LOOKUP_PARENT = "vpe-user-toggle-lookup-parent"; //$NON-NLS-1$ - + /* + * https://jira.jboss.org/jira/browse/JBIDE-3373 + * Attribute that specifies the place where JSF facet should be rendered. + */ + public static final String VPE_FACET = "VPE-FACET"; //$NON-NLS-1$ + private static final String PSEUDO_ELEMENT = "br"; //$NON-NLS-1$ private static final String PSEUDO_ELEMENT_ATTR = "vpe:pseudo-element"; //$NON-NLS-1$ private static final String INIT_ELEMENT_ATTR = "vpe:init-element"; //$NON-NLS-1$ @@ -298,11 +303,28 @@ // } catch (XPCOMException ex) { // // just ignore this exception // } + if (visualNewNode != null) { - if (visualNextNode == null) { - visualContainer.appendChild(visualNewNode); - } else { - visualContainer.insertBefore(visualNewNode, visualNextNode); + /* + * https://jira.jboss.org/jira/browse/JBIDE-3373 + * Do not add additional visual node for f:facet + * when it is inserted into existed one. + */ + nsIDOMElement element = null; + try { + element = (nsIDOMElement) visualNewNode.queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID); + } catch (org.mozilla.xpcom.XPCOMException e) { + /* + * Cannot parse node to element, + * do nothing + */ + } + if (!((null != element) && element.hasAttribute(VPE_FACET))) { + if (visualNextNode == null) { + visualContainer.appendChild(visualNewNode); + } else { + visualContainer.insertBefore(visualNewNode, visualNextNode); + } } return true; } Index: src/org/jboss/tools/vpe/editor/template/VpeDataTableColumnCreator.java =================================================================== --- src/org/jboss/tools/vpe/editor/template/VpeDataTableColumnCreator.java (revision 20840) +++ src/org/jboss/tools/vpe/editor/template/VpeDataTableColumnCreator.java (working copy) @@ -10,14 +10,17 @@ ******************************************************************************/ package org.jboss.tools.vpe.editor.template; +import java.util.List; import java.util.Map; +import org.jboss.tools.vpe.editor.VpeVisualDomBuilder; import org.jboss.tools.vpe.editor.context.VpePageContext; import org.jboss.tools.vpe.editor.template.VpeDataTableElements.SourceColumnElements; import org.jboss.tools.vpe.editor.template.VpeDataTableElements.SourceDataTableElements; import org.jboss.tools.vpe.editor.template.VpeDataTableElements.VisualColumnElements; import org.jboss.tools.vpe.editor.template.VpeDataTableElements.VisualDataTableElements; import org.jboss.tools.vpe.editor.util.HTML; +import org.jboss.tools.vpe.editor.util.VisualDomUtil; import org.mozilla.interfaces.nsIDOMDocument; import org.mozilla.interfaces.nsIDOMElement; import org.mozilla.interfaces.nsIDOMNode; @@ -90,8 +93,50 @@ } setCellClass(cell, styleClass); visualColumnElements.setFooterCell(cell); - + + /* + * Find elements from the f:facet + */ + Map> headerFacetChildren = null; + Map> footerFacetChildren = null; + headerFacetChildren = VisualDomUtil.findFacetElements(columnElements.getHeader(), pageContext); + footerFacetChildren = VisualDomUtil.findFacetElements(columnElements.getFooter(), pageContext); + boolean headerHtmlElementsPresents = ((null != headerFacetChildren) && (headerFacetChildren + .get(VisualDomUtil.FACET_HTML_TAGS).size() > 0)); + boolean footerHtmlElementsPresents = ((null != footerFacetChildren) && (footerFacetChildren + .get(VisualDomUtil.FACET_HTML_TAGS).size() > 0)); + + /* + * Create column body cell. (TD) + */ cell = VpeDataTableElements.makeCell(visualDataTableElements.getBodyRow(), index, HTML.TAG_TD, visualDocument); + + /* + * Add HTML elements to the body cell. + * Correct facet will be rendered while JsfFacet template creating. + */ + VpeChildrenInfo childrenInfo = new VpeChildrenInfo(cell); + if (headerHtmlElementsPresents) { + for (Node node : headerFacetChildren.get(VisualDomUtil.FACET_HTML_TAGS)) { +// childrenInfo = new VpeChildrenInfo(cell); + childrenInfo.addSourceChild(node); +// creatorInfo.addChildrenInfo(childrenInfo); + } +// creatorInfo.addChildrenInfo(childrenInfo); + } + if (footerHtmlElementsPresents) { + for (Node node : footerFacetChildren.get(VisualDomUtil.FACET_HTML_TAGS)) { +// childrenInfo = new VpeChildrenInfo(cell); + childrenInfo.addSourceChild(node); +// creatorInfo.addChildrenInfo(childrenInfo); + } + } + /* + * If any elements were added they will be shown + * otherwise empty childrenInfo will be added. + */ + creatorInfo.addChildrenInfo(childrenInfo); + NodeList list = sourceNode.getChildNodes(); int cnt = list != null ? list.getLength() : 0; if (cnt > 0) { Index: src/org/jboss/tools/vpe/editor/util/SourceDomUtil.java =================================================================== --- src/org/jboss/tools/vpe/editor/util/SourceDomUtil.java (revision 20840) +++ src/org/jboss/tools/vpe/editor/util/SourceDomUtil.java (working copy) @@ -20,6 +20,7 @@ import org.jboss.tools.vpe.editor.template.VpeTemplateManager; import org.w3c.dom.Element; import org.w3c.dom.Node; +import org.w3c.dom.NodeList; public class SourceDomUtil { private static final Set templatesNamespacesWithRendered=new HashSet(); @@ -91,4 +92,20 @@ } return result; } + + public static Element getFacetByName(Element sourceElement, String facetName) { + Element facetElement = null; + NodeList children = sourceElement.getChildNodes(); + for (int i = 0; i < children.getLength(); i++) { + Node node = children.item(i); + if ((facetName != null) + && (node instanceof Element) + && (node.getNodeName() != null) + && (node.getNodeName().indexOf(":facet") > 0) //$NON-NLS-1$ + && (facetName.equalsIgnoreCase((((Element) node)).getAttribute("name")))) { //$NON-NLS-1$ + facetElement = (Element) node; + } + } + return facetElement; + } } Index: src/org/jboss/tools/vpe/editor/template/VpeFacetCreator.java =================================================================== --- src/org/jboss/tools/vpe/editor/template/VpeFacetCreator.java (revision 20840) +++ src/org/jboss/tools/vpe/editor/template/VpeFacetCreator.java (working copy) @@ -30,7 +30,7 @@ @Override public VpeCreatorInfo create(VpePageContext pageContext, Node sourceNode, nsIDOMDocument visualDocument, nsIDOMElement visualElement, Map visualNodeMap) { VpeCreatorInfo creatorInfo = null; - +System.out.println(" ---------- FACET CRETOR ----------"); boolean isHeader = false; boolean isFooter = false; Index: src/org/jboss/tools/vpe/editor/util/VisualDomUtil.java =================================================================== --- src/org/jboss/tools/vpe/editor/util/VisualDomUtil.java (revision 20840) +++ src/org/jboss/tools/vpe/editor/util/VisualDomUtil.java (working copy) @@ -11,11 +11,16 @@ package org.jboss.tools.vpe.editor.util; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import org.eclipse.swt.graphics.Point; +import org.jboss.tools.jst.web.tld.TaglibData; +import org.jboss.tools.vpe.editor.VpeVisualDomBuilder; +import org.jboss.tools.vpe.editor.context.VpePageContext; import org.jboss.tools.vpe.editor.template.VpeChildrenInfo; import org.jboss.tools.vpe.editor.template.VpeCreationData; import org.mozilla.interfaces.nsIDOMDocument; @@ -42,6 +47,10 @@ public static String RICH_FACES_URI = "http://richfaces.org/rich"; //$NON-NLS-1$ public static String A4J_URI = "http://richfaces.org/a4j"; //$NON-NLS-1$ public static String FACELETS_URI = "http://java.sun.com/jsf/facelets"; //$NON-NLS-1$ + + public static String FACET_JSF_TAG = "FACET-JSF-TAG"; //$NON-NLS-1$ + public static String FACET_ODD_TAGS = "FACET-ODD-TAGS"; //$NON-NLS-1$ + public static String FACET_HTML_TAGS = "FACET-HTML-TAGS"; //$NON-NLS-1$ private static final String ACCESSIBILITY_SERVICE_CONTRACT_ID = "@mozilla.org/accessibilityService;1"; //$NON-NLS-1$ // private static Reference accessibilityServiceCache = null; @@ -381,4 +390,130 @@ } return creationData; } + + /** + * Finds visual tag with 'VPE-FACET' attribute in it. + * Facet element should be rendered into this tag. + * + * @param facetsParentNode node for which its facet should be rendered. + * @param facetName facet's name to compare to 'VPE-FACET' attribute value. + * @return found visual tag or 'null' otherwise. + */ + public static nsIDOMElement findVisualTagWithFacetAttribute(nsIDOMNode facetsParentNode, String facetName) { + nsIDOMElement tagForFacet = null; + nsIDOMNodeList nodeList = facetsParentNode.getChildNodes(); + for (int i = 0; i < nodeList.getLength(); i++) { + nsIDOMElement element = null; + try { + element = (nsIDOMElement) nodeList.item(i).queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID); + } catch (org.mozilla.xpcom.XPCOMException e) { + /* + * Cannot parse node to element, return null. + */ + return null; + } + /* + * If current tag has 'VPE-FACET' attribute + * with the corresponding facet name. + * Then return this tag. + */ + if (element.hasAttribute(VpeVisualDomBuilder.VPE_FACET)) { + String facetAttributeName = element.getAttribute(VpeVisualDomBuilder.VPE_FACET); + /* + * In some cases there could be several footer in one visual node. + * For instance, header and footer could be in single column cell. + * Thus VPE-FACET can contain several facet names + * separated by whitespace, i.e. "header footer". + */ + if (facetAttributeName.indexOf(facetName) >= 0) { + return element; + } + } + /* + * Else search in children + */ + tagForFacet = findVisualTagWithFacetAttribute(element, facetName); + /* + * When tag is found in children it will be returned + */ + if (null != tagForFacet) { + return tagForFacet; + } + } + /* + * If nothing matched return null + */ + return tagForFacet; + } + + /** + * Clarifies JSF facet element's children: JSF tags, other tags, HTML, text. + * (For JSF Facet cannot display more than one JSF component). + * Results are put into the map with keys: + *

'FACET-JSF-TAG' - for suitable JSF element + *

'FACET-ODD-TAGS' - for superfluous elements + *

'FACET-HTML-TAG' - for HTML elements and plain text + * + * @param facet the facet + * @param pageContext the page context + * @return map with arranged elements or empty map if nothing was found. + */ + public static Map> findFacetElements(Node facet, VpePageContext pageContext) { + Map> facetChildren = new HashMap>(); + List jsfTag = new ArrayList(); + List oddTags = new ArrayList(); + List htmlTags = new ArrayList(); + facetChildren.put(FACET_JSF_TAG, jsfTag); + facetChildren.put(FACET_ODD_TAGS, oddTags); + facetChildren.put(FACET_HTML_TAGS, htmlTags); + if (null != facet) { + NodeList children = facet.getChildNodes(); + Node lastJSFComponent = null; + for (int i = 0; i < children.getLength() ; i++) { + Node child = children.item(i); + String sourcePrefix = child.getPrefix(); + List taglibs = XmlUtil.getTaglibsForNode(child, + pageContext); + TaglibData sourceNodeTaglib = XmlUtil.getTaglibForPrefix( + sourcePrefix, taglibs); + /* + * Here will be nodes with taglibs + * Plain html tags and text - will not. + */ + if (null != sourceNodeTaglib) { + String sourceNodeUri = sourceNodeTaglib.getUri(); + if ((JSF_CORE_URI.equalsIgnoreCase(sourceNodeUri) + || JSF_HTML_URI.equalsIgnoreCase(sourceNodeUri) + || RICH_FACES_URI.equalsIgnoreCase(sourceNodeUri) + || A4J_URI.equalsIgnoreCase(sourceNodeUri) + || FACELETS_URI.equalsIgnoreCase(sourceNodeUri))) { + /* + * Mark the correct jsf component + * and add it to the odd list for further correction. + */ + lastJSFComponent = child; + oddTags.add(child); + } else { + /* + * All other tags: JSF or not. + */ + oddTags.add(child); + } + } else { + /* + * Plain html and text + */ + htmlTags.add(child); + } + /* + * Fill the correct JSF component: + * remove it from the odd list and add to the jsf list. + */ + oddTags.remove(lastJSFComponent); + jsfTag.add(lastJSFComponent); + } + } + return facetChildren; + } + } Index: src/org/jboss/tools/vpe/editor/template/VpeDataTableCreator.java =================================================================== --- src/org/jboss/tools/vpe/editor/template/VpeDataTableCreator.java (revision 20840) +++ src/org/jboss/tools/vpe/editor/template/VpeDataTableCreator.java (working copy) @@ -192,7 +192,7 @@ // div.appendChild(visualDocument.createTextNode(redundantText)); div.appendChild(outterTable); - if (true || sourceElements.hasTableCaption()) { + if (sourceElements.hasTableCaption()) { caption = visualDocument.createElement(HTML.TAG_CAPTION); if (sourceElements.getTableCaption() != null) { VpeChildrenInfo info = new VpeChildrenInfo(caption); Index: src/org/jboss/tools/vpe/editor/template/VpePanelGridCreator.java =================================================================== --- src/org/jboss/tools/vpe/editor/template/VpePanelGridCreator.java (revision 20840) +++ src/org/jboss/tools/vpe/editor/template/VpePanelGridCreator.java (working copy) @@ -15,6 +15,7 @@ import java.util.Map; import org.jboss.tools.vpe.VpePlugin; +import org.jboss.tools.vpe.editor.VpeVisualDomBuilder; import org.jboss.tools.vpe.editor.context.VpePageContext; import org.jboss.tools.vpe.editor.template.expression.VpeExpression; import org.jboss.tools.vpe.editor.template.expression.VpeExpressionBuilder; @@ -23,6 +24,7 @@ import org.jboss.tools.vpe.editor.template.expression.VpeExpressionInfo; import org.jboss.tools.vpe.editor.template.expression.VpeValue; import org.jboss.tools.vpe.editor.util.HTML; +import org.jboss.tools.vpe.editor.util.VisualDomUtil; import org.jboss.tools.vpe.editor.util.VpeClassUtil; import org.mozilla.interfaces.nsIDOMAttr; import org.mozilla.interfaces.nsIDOMDocument; @@ -265,6 +267,23 @@ if (tableSize == 0) { tableSize = childrenCount; } + Map> captionFacetChildren = null; + Map> headerFacetChildren = null; + Map> footerFacetChildren = null; + captionFacetChildren = VisualDomUtil.findFacetElements(caption, pageContext); + headerFacetChildren = VisualDomUtil.findFacetElements(header, pageContext); + footerFacetChildren = VisualDomUtil.findFacetElements(footer, pageContext); + /* + * Add additional table cell for odd facet's elements. + */ + boolean captionHtmlElementsPresents = ((null != captionFacetChildren) && (captionFacetChildren.get(VisualDomUtil.FACET_HTML_TAGS).size() > 0)); + boolean headerHtmlElementsPresents = ((null != headerFacetChildren) && (headerFacetChildren.get(VisualDomUtil.FACET_HTML_TAGS).size() > 0)); + boolean footerHtmlElementsPresents = ((null != footerFacetChildren) && (footerFacetChildren.get(VisualDomUtil.FACET_HTML_TAGS).size() > 0)); + boolean htmlFacetsElementsPresents = captionHtmlElementsPresents || headerHtmlElementsPresents || footerHtmlElementsPresents; + boolean htmlFacetsElementsRendered = false; + if (htmlFacetsElementsPresents) { + childrenCount++; + } int rowCount = (childrenCount + tableSize - 1) / tableSize; nsIDOMElement visualHead = null; @@ -275,8 +294,7 @@ visualCaption = visualDocument .createElement(HTML.TAG_CAPTION); visualTable.appendChild(visualCaption); - VpeChildrenInfo childrenInfo = new VpeChildrenInfo( - visualCaption); + VpeChildrenInfo childrenInfo = new VpeChildrenInfo(visualCaption); childrenInfo.addSourceChild(caption); creatorInfo.addChildrenInfo(childrenInfo); if (captionClassExpr != null @@ -317,8 +335,7 @@ for (int i = 0; i < rowCount; i++) { int cci = 0; // index of column class. Reset on every new row. - nsIDOMElement visualRow = visualDocument - .createElement(HTML.TAG_TR); + nsIDOMElement visualRow = visualDocument.createElement(HTML.TAG_TR); if (rowClasses.size() > 0) { visualRow.setAttribute(HTML.ATTR_CLASS, rowClasses.get(rci) .toString()); @@ -330,8 +347,7 @@ if (i*tableSize+j >= childrenCount) { break; } - nsIDOMElement visualCell = visualDocument - .createElement(HTML.TAG_TD); + nsIDOMElement visualCell = visualDocument.createElement(HTML.TAG_TD); if (columnClasses.size() > 0) { visualCell.setAttribute(HTML.ATTR_CLASS, columnClasses.get( cci).toString()); @@ -340,27 +356,64 @@ cci = 0; } visualRow.appendChild(visualCell); - int sourceIndex = tableSize * i + j; - if (sourceIndex < childrenCount) { - Node child = sourceChildren[sourceIndex]; - if (child != header && child != footer) { - VpeChildrenInfo childrenInfo = new VpeChildrenInfo( - visualCell); - childrenInfo.addSourceChild(child); - creatorInfo.addChildrenInfo(childrenInfo); - } - } + /* + * https://jira.jboss.org/jira/browse/JBIDE-3373 + * Add odd facets elements to the first table cell + */ + if (htmlFacetsElementsPresents && !htmlFacetsElementsRendered) { + VpeChildrenInfo childrenInfo = null; + if (captionHtmlElementsPresents) { + for (Node node : captionFacetChildren.get(VisualDomUtil.FACET_HTML_TAGS)) { + childrenInfo = new VpeChildrenInfo(visualCell); + childrenInfo.addSourceChild(node); + creatorInfo.addChildrenInfo(childrenInfo); + } + } + if (headerHtmlElementsPresents) { + for (Node node : headerFacetChildren.get(VisualDomUtil.FACET_HTML_TAGS)) { + childrenInfo = new VpeChildrenInfo(visualCell); + childrenInfo.addSourceChild(node); + creatorInfo.addChildrenInfo(childrenInfo); + } + } + if (footerHtmlElementsPresents) { + for (Node node : footerFacetChildren.get(VisualDomUtil.FACET_HTML_TAGS)) { + childrenInfo = new VpeChildrenInfo(visualCell); + childrenInfo.addSourceChild(node); + creatorInfo.addChildrenInfo(childrenInfo); + } + } + htmlFacetsElementsRendered = true; + } else { + + int sourceIndex = tableSize * i + j; + if (sourceIndex < childrenCount) { + /* + * https://jira.jboss.org/jira/browse/JBIDE-3373 + * Correct index when odd facets elements presents + */ + if (htmlFacetsElementsPresents) { + sourceIndex = sourceIndex-1; + } + Node child = sourceChildren[sourceIndex]; + if (child != header && child != footer) { + VpeChildrenInfo childrenInfo = new VpeChildrenInfo(visualCell); + childrenInfo.addSourceChild(child); + creatorInfo.addChildrenInfo(childrenInfo); + } + } } + } if (visualBody != null) { visualBody.appendChild(visualRow); } else { visualTable.appendChild(visualRow); } } - makeSpecial(header, visualHead, visualDocument, tableSize, - creatorInfo, HTML.TAG_TH, headerClassExpr, pageContext); - makeSpecial(footer, visualFoot, visualDocument, tableSize, - creatorInfo, HTML.TAG_TD, footerClassExpr, pageContext); + makeSpecial(header, "header", visualHead, visualDocument, tableSize, //$NON-NLS-1$ + creatorInfo, HTML.TAG_TH, headerClassExpr, pageContext); + makeSpecial(footer, "footer", visualFoot, visualDocument, tableSize, //$NON-NLS-1$ + creatorInfo, HTML.TAG_TD, footerClassExpr, pageContext); for (int i = 0; i < propertyCreators.size(); i++) { VpeCreator creator = (VpeCreator) propertyCreators.get(i); @@ -382,24 +435,25 @@ return creatorInfo; } - private void makeSpecial(Node header, nsIDOMElement visualHead, + private void makeSpecial(Node facet, String facetName, nsIDOMElement visualHead, nsIDOMDocument visualDocument, int tableSize, VpeCreatorInfo creatorInfo, String cellTag, VpeExpression headerClassExpr, VpePageContext pageContext) throws VpeExpressionException { - if (header != null && visualHead != null) { + if (facet != null && visualHead != null) { nsIDOMElement visualRow = visualDocument.createElement(HTML.TAG_TR); visualHead.appendChild(visualRow); nsIDOMElement visualCell = visualDocument.createElement(cellTag); visualCell.setAttribute(HTML.ATTR_COLSPAN, "" + tableSize); //$NON-NLS-1$ - if (headerClassExpr != null && header.getParentNode() != null) { + if (headerClassExpr != null && facet.getParentNode() != null) { String headerClass = headerClassExpr.exec(pageContext, - header.getParentNode()).stringValue(); + facet.getParentNode()).stringValue(); visualCell.setAttribute(HTML.ATTR_CLASS, headerClass); } visualRow.appendChild(visualCell); VpeChildrenInfo childrenInfo = new VpeChildrenInfo(visualCell); - childrenInfo.addSourceChild(header); + childrenInfo.addSourceChild(facet); creatorInfo.addChildrenInfo(childrenInfo); + visualCell.setAttribute(VpeVisualDomBuilder.VPE_FACET, facetName); } } #P org.jboss.tools.jsf.vpe.richfaces Index: src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesPanelTemplate.java =================================================================== --- src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesPanelTemplate.java (revision 20840) +++ src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesPanelTemplate.java (working copy) @@ -11,12 +11,18 @@ package org.jboss.tools.jsf.vpe.richfaces.template; import java.util.List; +import java.util.Map; import org.jboss.tools.jsf.vpe.richfaces.ComponentUtil; +import org.jboss.tools.jsf.vpe.richfaces.template.util.RichFaces; +import org.jboss.tools.vpe.editor.VpeVisualDomBuilder; import org.jboss.tools.vpe.editor.context.VpePageContext; import org.jboss.tools.vpe.editor.template.VpeAbstractTemplate; import org.jboss.tools.vpe.editor.template.VpeChildrenInfo; import org.jboss.tools.vpe.editor.template.VpeCreationData; +import org.jboss.tools.vpe.editor.util.HTML; +import org.jboss.tools.vpe.editor.util.SourceDomUtil; +import org.jboss.tools.vpe.editor.util.VisualDomUtil; import org.mozilla.interfaces.nsIDOMDocument; import org.mozilla.interfaces.nsIDOMElement; import org.w3c.dom.Element; @@ -43,28 +49,71 @@ div.setAttribute("style", style); //$NON-NLS-1$ } - // Encode Header - Node header = ComponentUtil.getFacet(sourceElement, "header", true); //$NON-NLS-1$ - if(header!=null) { - nsIDOMElement headerDiv = visualDocument.createElement("div"); //$NON-NLS-1$ + /* + * Encode the Header Facet + * Find elements from the f:facet + */ + Map> headerFacetChildren = null; + Element headerFacet = SourceDomUtil.getFacetByName(sourceElement, RichFaces.NAME_FACET_HEADER); + if (headerFacet != null) { + headerFacetChildren = VisualDomUtil.findFacetElements(headerFacet, pageContext); + nsIDOMElement headerDiv = visualDocument.createElement(HTML.TAG_DIV); + /* + * By adding attribute VPE-FACET to this visual node + * we force JsfFacet to be rendered inside it. + */ + headerDiv.setAttribute(VpeVisualDomBuilder.VPE_FACET, RichFaces.NAME_FACET_HEADER); div.appendChild(headerDiv); - String headerClass = sourceElement.getAttribute("headerClass"); //$NON-NLS-1$ - headerDiv.setAttribute("class", "dr-pnl-h rich-panel-header " + (headerClass==null?"":headerClass)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - headerDiv.setAttribute("style", ComponentUtil.getHeaderBackgoundImgStyle()); //$NON-NLS-1$ + String headerClass = sourceElement.getAttribute(RichFaces.ATTR_HEADER_CLASS); + headerDiv.setAttribute(HTML.ATTR_CLASS, + "dr-pnl-h rich-panel-header " + (headerClass == null ? "" : headerClass)); //$NON-NLS-1$ //$NON-NLS-2$ + headerDiv.setAttribute(HTML.ATTR_STYLE, + ComponentUtil.getHeaderBackgoundImgStyle()); VpeChildrenInfo headerInfo = new VpeChildrenInfo(headerDiv); - headerInfo.addSourceChild(header); + headerInfo.addSourceChild(headerFacet); creationData.addChildrenInfo(headerInfo); } + + // Encode Header +// Node header = ComponentUtil.getFacet(sourceElement, "header", true); //$NON-NLS-1$ +// if(header!=null) { +// nsIDOMElement headerDiv = visualDocument.createElement("div"); //$NON-NLS-1$ +// div.appendChild(headerDiv); +// String headerClass = sourceElement.getAttribute("headerClass"); //$NON-NLS-1$ +// headerDiv.setAttribute("class", "dr-pnl-h rich-panel-header " + (headerClass==null?"":headerClass)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ +// headerDiv.setAttribute("style", ComponentUtil.getHeaderBackgoundImgStyle()); //$NON-NLS-1$ +// +// VpeChildrenInfo headerInfo = new VpeChildrenInfo(headerDiv); +// headerInfo.addSourceChild(header); +// creationData.addChildrenInfo(headerInfo); +// } - // Encode Body - nsIDOMElement bodyDiv = visualDocument.createElement("div"); //$NON-NLS-1$ + /* + * Encode rich:panel content + */ + nsIDOMElement bodyDiv = visualDocument.createElement(HTML.TAG_DIV); div.appendChild(bodyDiv); - String bodyClass = sourceElement.getAttribute("bodyClass"); //$NON-NLS-1$ - bodyDiv.setAttribute("class", "dr-pnl-b rich-panel-body " + (bodyClass==null?"":bodyClass)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - + String bodyClass = sourceElement.getAttribute(RichFaces.ATTR_BODY_CLASS); + bodyDiv.setAttribute(HTML.ATTR_CLASS, + "dr-pnl-b rich-panel-body " + (bodyClass == null ? "" : bodyClass)); //$NON-NLS-1$ //$NON-NLS-2$ + /* + * If there are some odd HTML elements from facet + * add them to the panel body first. + */ + boolean headerHtmlElementsPresents = ((headerFacetChildren != null) && (headerFacetChildren + .get(VisualDomUtil.FACET_HTML_TAGS).size() > 0)); + VpeChildrenInfo bodyInfo = new VpeChildrenInfo(bodyDiv); + if (headerHtmlElementsPresents) { + for (Node node : headerFacetChildren.get(VisualDomUtil.FACET_HTML_TAGS)) { + bodyInfo.addSourceChild(node); + } + } + + /* + * Add the rest panel's content + */ List children = ComponentUtil.getChildren(sourceElement, true); - VpeChildrenInfo bodyInfo = new VpeChildrenInfo(bodyDiv); for (Node child : children) { bodyInfo.addSourceChild(child); } Index: src/org/jboss/tools/jsf/vpe/richfaces/template/util/RichFaces.java =================================================================== --- src/org/jboss/tools/jsf/vpe/richfaces/template/util/RichFaces.java (revision 20840) +++ src/org/jboss/tools/jsf/vpe/richfaces/template/util/RichFaces.java (working copy) @@ -46,8 +46,9 @@ public static final String ATTR_JOINT_POINT = "jointPoint"; //$NON-NLS-1$ public static final String ATTR_DISABLED = "disabled";//$NON-NLS-1$ public static final String ATTR_ELEMENTS = "elements"; //$NON-NLS-1$ + public static final String ATTR_HEADER_CLASS = "headerClass"; //$NON-NLS-1$ + public static final String ATTR_BODY_CLASS = "bodyClass"; //$NON-NLS-1$ public static final String ATTR_FOOTER_CLASS = "footerClass"; //$NON-NLS-1$ - public static final String ATTR_HEADER_CLASS = "headerClass"; //$NON-NLS-1$ public static final String ATTR_INPUT_CLASS = "inputClass"; //$NON-NLS-1$ public static final String ATTR_INPUT_SIZE = "inputSize"; //$NON-NLS-1$ public static final String ATTR_INPUT_STYLE = "inputStyle"; //$NON-NLS-1$ Index: src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesMessageTemplate.java =================================================================== --- src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesMessageTemplate.java (revision 20840) +++ src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesMessageTemplate.java (working copy) @@ -15,6 +15,7 @@ import org.jboss.tools.jsf.vpe.richfaces.ComponentUtil; import org.jboss.tools.jsf.vpe.richfaces.template.util.RichFaces; import org.jboss.tools.vpe.editor.VpeSourceDomBuilder; +import org.jboss.tools.vpe.editor.VpeVisualDomBuilder; import org.jboss.tools.vpe.editor.context.VpePageContext; import org.jboss.tools.vpe.editor.template.VpeAbstractTemplate; import org.jboss.tools.vpe.editor.template.VpeChildrenInfo; @@ -40,14 +41,11 @@ protected static String FATAL_MESSAGE = "Fatal message"; //$NON-NLS-1$ protected static String INFO_MESSAGE = "Info message"; //$NON-NLS-1$ protected static String WARNING_MESSAGE = "Warning message"; //$NON-NLS-1$ + protected static String FACET_TAG_NAME = ":facet"; //$NON-NLS-1$ protected static String[] markers = { "passedMarker", "errorMarker", //$NON-NLS-1$ //$NON-NLS-2$ "fatalMarker", "infoMarker", "warnMarker" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - protected static String FACET_TAG_NAME = "facet"; //$NON-NLS-1$ - - protected static String NAME_ATTRIBUTE_NAME = "name"; //$NON-NLS-1$ - private final static String MESSAGE_STYLE = "padding-left: 1px;padding-right: 1px;padding-top: 1px;padding-bottom: 1px"; //$NON-NLS-1$ public VpeCreationData create(VpePageContext pageContext, Node sourceNode, @@ -235,6 +233,7 @@ if (!(facets.get(markers[i]) instanceof Element)) continue; else { + td.setAttribute(VpeVisualDomBuilder.VPE_FACET, markers[i]); childrenInfo.addSourceChild(facets.get(markers[i])); } tr.appendChild(td); @@ -271,20 +270,15 @@ NodeList nodeList = sourceElement.getChildNodes(); HashMap facets = new HashMap(); - for (int i = 0; i < nodeList.getLength(); i++) { - - if (!(nodeList.item(i) instanceof Element)) - continue; - - String facetName = nodeList.item(i).getPrefix() + Constants.COLON - + FACET_TAG_NAME; - - if (nodeList.item(i).getNodeName().equalsIgnoreCase(facetName) + if (!(nodeList.item(i) instanceof Element)){ + continue; + } + if (nodeList.item(i).getNodeName().endsWith(FACET_TAG_NAME) && searchInMarker(((Element) nodeList.item(i)) - .getAttribute(NAME_ATTRIBUTE_NAME))) { + .getAttribute(RichFaces.ATTR_NAME))) { facets.put(((Element) nodeList.item(i)) - .getAttribute(NAME_ATTRIBUTE_NAME), nodeList.item(i)); + .getAttribute(RichFaces.ATTR_NAME), nodeList.item(i)); } } Index: src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesMessagesTemplate.java =================================================================== --- src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesMessagesTemplate.java (revision 20840) +++ src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesMessagesTemplate.java (working copy) @@ -13,6 +13,8 @@ import java.util.HashMap; import org.jboss.tools.jsf.vpe.richfaces.ComponentUtil; +import org.jboss.tools.jsf.vpe.richfaces.template.util.RichFaces; +import org.jboss.tools.vpe.editor.VpeVisualDomBuilder; import org.jboss.tools.vpe.editor.context.VpePageContext; import org.jboss.tools.vpe.editor.template.VpeChildrenInfo; import org.jboss.tools.vpe.editor.template.VpeCreationData; @@ -26,14 +28,11 @@ public class RichFacesMessagesTemplate extends RichFacesMessageTemplate { - private static final String LAYOUT = "layout"; //$NON-NLS-1$ - private static final String TABLE = "table"; //$NON-NLS-1$ - private static final String CSS_RICH_MESSAGES - = "rich-messages"; //$NON-NLS-1$ - private static final String CSS_RICH_MESSAGES_MARKER - = "rich-messages-marker"; //$NON-NLS-1$ - private static final String CSS_RICH_MESSAGES_LABEL - = "rich-messages-label"; //$NON-NLS-1$ + private static final String LAYOUT = "layout"; //$NON-NLS-1$ + private static final String TABLE = "table"; //$NON-NLS-1$ + private static final String CSS_RICH_MESSAGES = "rich-messages"; //$NON-NLS-1$ + private static final String CSS_RICH_MESSAGES_MARKER = "rich-messages-marker"; //$NON-NLS-1$ + private static final String CSS_RICH_MESSAGES_LABEL = "rich-messages-label"; //$NON-NLS-1$ @Override public VpeCreationData create(VpePageContext pageContext, Node sourceNode, @@ -127,6 +126,8 @@ if (facet != null) { final VpeChildrenInfo childrenInfo = new VpeChildrenInfo(marker); + marker.setAttribute(VpeVisualDomBuilder.VPE_FACET, facet + .getAttribute(RichFaces.ATTR_NAME)); creationData.addChildrenInfo(childrenInfo); childrenInfo.addSourceChild(facet); }