### Eclipse Workspace Patch 1.0 #P org.jboss.tools.jsf.vpe.jsf Index: src/org/jboss/tools/jsf/vpe/jsf/template/JsfFacet.java =================================================================== --- src/org/jboss/tools/jsf/vpe/jsf/template/JsfFacet.java (revision 21098) +++ src/org/jboss/tools/jsf/vpe/jsf/template/JsfFacet.java (working copy) @@ -10,13 +10,21 @@ ******************************************************************************/ package org.jboss.tools.jsf.vpe.jsf.template; +import java.util.List; + +import org.jboss.tools.jsf.vpe.jsf.template.util.JSF; +import org.jboss.tools.jst.web.tld.TaglibData; 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.VisualDomUtil; +import org.jboss.tools.vpe.editor.util.XmlUtil; import org.mozilla.interfaces.nsIDOMDocument; import org.mozilla.interfaces.nsIDOMElement; +import org.mozilla.interfaces.nsIDOMNode; +import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -34,53 +42,64 @@ * .vpe.editor.context.VpePageContext, org.w3c.dom.Node, * org.mozilla.interfaces.nsIDOMDocument) */ - public VpeCreationData create(VpePageContext pageContext, Node sourceNode, - nsIDOMDocument visualDocument) { - nsIDOMElement div = visualDocument.createElement(HTML.TAG_DIV); - VpeCreationData creationData = new VpeCreationData(div); - NodeList children = sourceNode.getChildNodes(); - boolean jsfComponentFound = false; - /* - * 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 = 0; i < children.getLength(); i++) { - Node child = children.item(i); -// String sourcePrefix = child.getPrefix(); -// if (XmlUtil.hasTaglib(sourceNode, pageContext, sourcePrefix)) { -// String sourceNodeUri = XmlUtil.getTaglibUri(sourceNode, pageContext, sourcePrefix); - if( ((child.getNodeType()==Node.TEXT_NODE) && - (child.getNodeValue()!=null) - && (child.getNodeValue().trim().length()>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; + + 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(); + 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. + */ + 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 21098) +++ src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java (working copy) @@ -98,7 +98,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$ @@ -299,11 +304,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 21098) +++ 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 21098) +++ 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 21098) +++ 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 21098) +++ src/org/jboss/tools/vpe/editor/util/VisualDomUtil.java (working copy) @@ -11,11 +11,17 @@ 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.kb.IFaceletPageContext; +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 +48,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 +391,136 @@ } 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; + if (null != facetsParentNode) { + 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(0); + List oddTags = new ArrayList(0); + List htmlTags = new ArrayList(0); + 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, RF, FACELETS, A4J. + */ + 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. + */ + if (null != lastJSFComponent) { + 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 21098) +++ 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 21098) +++ 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/RichFacesTabPanelTemplate.java =================================================================== --- src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTabPanelTemplate.java (revision 21098) +++ src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTabPanelTemplate.java (working copy) @@ -77,7 +77,6 @@ private static Map toggleMap = new HashMap(); public VpeCreationData create(VpePageContext pageContext, Node sourceNode, nsIDOMDocument visualDocument) { - Element sourceElement = (Element)sourceNode; nsIDOMElement table = visualDocument.createElement(HTML.TAG_TABLE); @@ -184,7 +183,7 @@ if(child.getNodeName().endsWith(TAB)) { i++; if (active) { - RichFacesTabTemplate.encodeBody(creationData, + RichFacesTabTemplate.encodeBody(pageContext, creationData, (Element) child, visualDocument, inerTr, true, ComponentUtil.getAttribute(sourceElement, CONTENT_CLASS) Index: src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesDataGridTemplate.java =================================================================== --- src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesDataGridTemplate.java (revision 21098) +++ src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesDataGridTemplate.java (working copy) @@ -12,6 +12,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.StringTokenizer; import org.jboss.tools.jsf.vpe.richfaces.ComponentUtil; @@ -21,6 +22,7 @@ import org.jboss.tools.vpe.editor.template.VpeCreationData; import org.jboss.tools.vpe.editor.util.Constants; 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; @@ -55,35 +57,50 @@ String tableClass = sourceElement.getAttribute(RichFaces.ATTR_STYLE_CLASS); table.setAttribute(HTML.ATTR_CLASS, "dr-table rich-table " + (tableClass==null?Constants.EMPTY:tableClass)); //$NON-NLS-1$ - // Encode colgroup definition. + /* + * Encode colgroup definition. + */ int columnsLength = getColumnsCount(sourceElement); nsIDOMElement colgroup = visualDocument.createElement(HTML.TAG_COLGROUP); colgroup.setAttribute(HTML.ATTR_SPAN, String.valueOf(columnsLength)); table.appendChild(colgroup); + + /* + * Encode Caption + */ + Element caption = SourceDomUtil.getFacetByName(sourceElement, RichFaces.NAME_FACET_CAPTION); + Map> captionFacetChildren = VisualDomUtil.findFacetElements(caption, pageContext); + Node captionBody = ComponentUtil.getFacetBody(captionFacetChildren); + encodeCaption(pageContext, creationData, sourceElement, visualDocument, table, captionBody); - //Encode Caption - encodeCaption(creationData, sourceElement, visualDocument, table); - - // Encode Header - Element header = ComponentUtil.getFacet(sourceElement, RichFaces.NAME_FACET_HEADER); - if(header!=null) { + /* + * Encode Header + */ + Element header = SourceDomUtil.getFacetByName(sourceElement, RichFaces.NAME_FACET_HEADER); + Map> headerFacetChildren = VisualDomUtil.findFacetElements(header, pageContext); + Node headerBody = ComponentUtil.getFacetBody(headerFacetChildren); + if (headerBody != null) { nsIDOMElement thead = visualDocument.createElement(HTML.TAG_THEAD); table.appendChild(thead); String headerClass = (String) sourceElement.getAttribute(RichFaces.ATTR_HEADER_CLASS); - encodeTableHeaderOrFooterFacet(pageContext, creationData, thead, columnsLength, visualDocument, header, + encodeTableHeaderOrFooterFacet(pageContext, creationData, thead, columnsLength, visualDocument, headerBody, "dr-table-header rich-table-header", //$NON-NLS-1$ "dr-table-header-continue rich-table-header-continue", //$NON-NLS-1$ "dr-table-headercell rich-table-headercell", //$NON-NLS-1$ headerClass, HTML.TAG_TD); } - // Encode Footer - Element footer = ComponentUtil.getFacet(sourceElement, RichFaces.NAME_FACET_FOOTER); - if (footer != null) { + /* + * Encode Footer + */ + Element footer = SourceDomUtil.getFacetByName(sourceElement, RichFaces.NAME_FACET_FOOTER); + Map> footerFacetChildren = VisualDomUtil.findFacetElements(footer, pageContext); + Node footerBody = ComponentUtil.getFacetBody(footerFacetChildren); + if (footerBody != null) { nsIDOMElement tfoot = visualDocument.createElement(HTML.TAG_TFOOT); table.appendChild(tfoot); String footerClass = (String) sourceElement.getAttribute(RichFaces.ATTR_FOOTER_CLASS); - encodeTableHeaderOrFooterFacet(pageContext, creationData, tfoot, columnsLength, visualDocument, footer, + encodeTableHeaderOrFooterFacet(pageContext, creationData, tfoot, columnsLength, visualDocument, footerBody, "dr-table-footer rich-table-footer", //$NON-NLS-1$ "dr-table-footer-continue rich-table-footer-continue", //$NON-NLS-1$ "dr-table-footercell rich-table-footercell", //$NON-NLS-1$ @@ -95,9 +112,9 @@ /* * https://jira.jboss.org/jira/browse/JBIDE-3491 + * Encode body. * Add text nodes to children list too. */ - //Create mapping to Encode body List children = ComponentUtil.getChildren(sourceElement, true); sourceElement.getAttribute(RichFaces.ATTR_ELEMENTS); @@ -113,8 +130,33 @@ nsIDOMElement td = visualDocument.createElement(HTML.TAG_TD); tr.appendChild(td); td.setAttribute(HTML.ATTR_CLASS, "dr-table-cell rich-table-cell " + getColumnClass(columnIndex)); //$NON-NLS-1$ + /* + * Add HTML elements from caption, header and footer. + */ + VpeChildrenInfo childInfo = null; + if (captionFacetChildren.get(VisualDomUtil.FACET_HTML_TAGS).size() > 0) { + childInfo = new VpeChildrenInfo(td); + for (Node child : captionFacetChildren.get(VisualDomUtil.FACET_HTML_TAGS)) { + childInfo.addSourceChild(child); + } + creationData.addChildrenInfo(childInfo); + } + if (headerFacetChildren.get(VisualDomUtil.FACET_HTML_TAGS).size() > 0) { + childInfo = new VpeChildrenInfo(td); + for (Node child : headerFacetChildren.get(VisualDomUtil.FACET_HTML_TAGS)) { + childInfo.addSourceChild(child); + } + creationData.addChildrenInfo(childInfo); + } + if (footerFacetChildren.get(VisualDomUtil.FACET_HTML_TAGS).size() > 0) { + childInfo = new VpeChildrenInfo(td); + for (Node child : footerFacetChildren.get(VisualDomUtil.FACET_HTML_TAGS)) { + childInfo.addSourceChild(child); + } + creationData.addChildrenInfo(childInfo); + } if(!children.isEmpty()) { - VpeChildrenInfo childInfo = new VpeChildrenInfo(td); + childInfo = new VpeChildrenInfo(td); for (Node child : children) { childInfo.addSourceChild(child); } Index: src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTabTemplate.java =================================================================== --- src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTabTemplate.java (revision 21098) +++ src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTabTemplate.java (working copy) @@ -11,14 +11,20 @@ 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.HtmlComponentUtil; +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.ResourceUtil; +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.mozilla.interfaces.nsIDOMText; @@ -39,7 +45,6 @@ private final static String VPE_USER_TOGGLE_ID = "vpe-user-toggle-id"; //$NON-NLS-1$ private static final String DISABLED = "disabled"; //$NON-NLS-1$ - private static final String LABEL = "label"; //$NON-NLS-1$ private static final String LABEL_WIDTH = "labelWidth"; //$NON-NLS-1$ private static final String CSS_HEADER = "rich-tab-header"; //$NON-NLS-1$ @@ -76,16 +81,17 @@ * @param contentStyle * @return the tab body */ - public static VpeCreationData encodeBody(VpeCreationData creationData, + public static VpeCreationData encodeBody( + VpePageContext pageContext, + VpeCreationData creationData, Element sourceElement, nsIDOMDocument visualDocument, nsIDOMElement parentTr, boolean active, String contentClass, String contentStyle) { + nsIDOMElement td = visualDocument.createElement(HTML.TAG_TD); - nsIDOMElement td = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TD); - if(creationData==null) { creationData = new VpeCreationData(td); } else { @@ -94,61 +100,80 @@ if(!active) { return creationData; } -// td.setAttribute("style", "position: relative;"); - td.setAttribute(HtmlComponentUtil.HTML_HEIGHT_ATTR, HUNDRED_PERCENTS); + td.setAttribute(HTML.ATTR_HEIGHT, HUNDRED_PERCENTS); - nsIDOMElement table = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TABLE); + nsIDOMElement table = visualDocument.createElement(HTML.TAG_TABLE); td.appendChild(table); - table.setAttribute(HtmlComponentUtil.HTML_BORDER_ATTR, ZERO); - table.setAttribute(HtmlComponentUtil.HTML_CELLPADDING_ATTR, TEN); - table.setAttribute(HtmlComponentUtil.HTML_CELLSPACING_ATTR, ZERO); - table.setAttribute(HtmlComponentUtil.HTML_WIDTH_ATTR, HUNDRED_PERCENTS); - table.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,RichFacesTabPanelTemplate.CSS_CONTENT_POSITION); - table.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, BODY_TABLE_STYLE); + table.setAttribute(HTML.ATTR_BORDER, ZERO); + table.setAttribute(HTML.ATTR_CELLPADDING, TEN); + table.setAttribute(HTML.ATTR_CELLSPACING, ZERO); + table.setAttribute(HTML.ATTR_WIDTH, HUNDRED_PERCENTS); + table.setAttribute(HTML.ATTR_CLASS,RichFacesTabPanelTemplate.CSS_CONTENT_POSITION); + table.setAttribute(HTML.ATTR_STYLE, BODY_TABLE_STYLE); - nsIDOMElement tr = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TR); + nsIDOMElement tr = visualDocument.createElement(HTML.TAG_TR); table.appendChild(tr); - td = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TD); + td = visualDocument.createElement(HTML.TAG_TD); tr.appendChild(td); - td.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, - ComponentUtil.getAttribute(sourceElement, HtmlComponentUtil.HTML_STYLECLASS_ATTR) + td.setAttribute(HTML.ATTR_CLASS, + ComponentUtil.getAttribute(sourceElement, RichFaces.ATTR_STYLE_CLASS) + SPACE + contentClass); - td.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, - ComponentUtil.getAttribute(sourceElement, HtmlComponentUtil.HTML_STYLE_ATTR) + td.setAttribute(HTML.ATTR_STYLE, + ComponentUtil.getAttribute(sourceElement, HTML.ATTR_STYLE) + STYLE_SEMICOLUMN + contentStyle); + Map> labelFacetChildren = null; + Element labelFacet = SourceDomUtil.getFacetByName(sourceElement, RichFaces.NAME_FACET_LABEL); + if (null != labelFacet) { + labelFacetChildren = VisualDomUtil.findFacetElements(labelFacet, pageContext); + } + /* + * https://jira.jboss.org/jira/browse/JBIDE-3373 + * If there are some odd HTML elements from facet + * add them to the panel body first. + */ + boolean labelHtmlElementsPresents = ((labelFacetChildren != null) && (labelFacetChildren + .get(VisualDomUtil.FACET_HTML_TAGS).size() > 0)); + VpeChildrenInfo bodyInfo = new VpeChildrenInfo(td); + if (labelHtmlElementsPresents) { + for (Node node : labelFacetChildren.get(VisualDomUtil.FACET_HTML_TAGS)) { + bodyInfo.addSourceChild(node); + } + } + + /* + * Add the rest tab's content + */ List children = ComponentUtil.getChildren(sourceElement, true); - VpeChildrenInfo bodyInfo = new VpeChildrenInfo(td); for (Node child : children) { bodyInfo.addSourceChild(child); } creationData.addChildrenInfo(bodyInfo); - return creationData; } public VpeCreationData create(VpePageContext pageContext, Node sourceNode, nsIDOMDocument visualDocument) { - nsIDOMElement table = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_DIV); - //table.setAttribute("include-tab", ""); + nsIDOMElement table = visualDocument.createElement(HTML.TAG_DIV); VpeCreationData creationData = new VpeCreationData(table); - nsIDOMElement headerTable = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TABLE); - headerTable.setAttribute(HtmlComponentUtil.HTML_BORDER_ATTR, ZERO); - headerTable.setAttribute(HtmlComponentUtil.HTML_CELLPADDING_ATTR, ZERO); - headerTable.setAttribute(HtmlComponentUtil.HTML_CELLSPACING_ATTR, ZERO); + nsIDOMElement headerTable = visualDocument.createElement(HTML.TAG_TABLE); + headerTable.setAttribute(HTML.ATTR_BORDER, ZERO); + headerTable.setAttribute(HTML.ATTR_CELLPADDING, ZERO); + headerTable.setAttribute(HTML.ATTR_CELLSPACING, ZERO); headerTable.setAttribute(TAB_HEADER_ATTR, YES); - headerTable.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, - HtmlComponentUtil.CSS_DISPLAY + headerTable.setAttribute(HTML.ATTR_STYLE, + HTML.STYLE_PARAMETER_DISPLAY + ":" + DISABLED_ELEMENT_STYLE + STYLE_SEMICOLUMN); //$NON-NLS-1$ - headerTable.appendChild(encodeHeader(pageContext, creationData, (Element)sourceNode, visualDocument, table, false, EMPTY, EMPTY, EMPTY, EMPTY,EMPTY)); - nsIDOMElement bodyTable = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TABLE); - bodyTable.setAttribute(HtmlComponentUtil.HTML_BORDER_ATTR, ZERO); - bodyTable.setAttribute(HtmlComponentUtil.HTML_CELLPADDING_ATTR, ZERO); - bodyTable.setAttribute(HtmlComponentUtil.HTML_CELLSPACING_ATTR, ZERO); + headerTable.appendChild(encodeHeader(pageContext, creationData, + (Element) sourceNode, visualDocument, table, false, EMPTY, + EMPTY, EMPTY, EMPTY, EMPTY)); + nsIDOMElement bodyTable = visualDocument.createElement(HTML.TAG_TABLE); + bodyTable.setAttribute(HTML.ATTR_BORDER, ZERO); + bodyTable.setAttribute(HTML.ATTR_CELLPADDING, ZERO); + bodyTable.setAttribute(HTML.ATTR_CELLSPACING, ZERO); bodyTable.setAttribute(TAB_BODY_ATTR, YES); - //bodyTable.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, HtmlComponentUtil.CSS_DISPLAY+" : "+DISABLED_ELEMENT_STYLE+";"); //$NON-NLS-1$ //$NON-NLS-2$ table.appendChild(headerTable); table.appendChild(bodyTable); - encodeBody(creationData, (Element)sourceNode, visualDocument, bodyTable, true, EMPTY, EMPTY); + encodeBody(pageContext, creationData, (Element)sourceNode, visualDocument, bodyTable, true, EMPTY, EMPTY); return creationData; } @@ -175,10 +200,9 @@ String inactiveTabClass, String disabledTabClass, String toggleId) { - - nsIDOMElement headerTd = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TD); + nsIDOMElement headerTd = visualDocument.createElement(HTML.TAG_TD); parentTr.appendChild(headerTd); - headerTd.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, HEADER_TD_STYLE); + headerTd.setAttribute(HTML.ATTR_STYLE, HEADER_TD_STYLE); String styleClass = RichFacesTabPanelTemplate.CSS_CELL_DISABLED + SPACE + CSS_DISABLED; if(!TRUE.equalsIgnoreCase(sourceElement.getAttribute(DISABLED))) { @@ -188,26 +212,26 @@ styleClass = RichFacesTabPanelTemplate.CSS_CELL_INACTIVE; } } - headerTd.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, styleClass); + headerTd.setAttribute(HTML.ATTR_CLASS, styleClass); headerTd.setAttribute(VPE_USER_TOGGLE_ID, toggleId); - nsIDOMElement table = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TABLE); + nsIDOMElement table = visualDocument.createElement(HTML.TAG_TABLE); headerTd.appendChild(table); - table.setAttribute(HtmlComponentUtil.HTML_BORDER_ATTR, ZERO); - table.setAttribute(HtmlComponentUtil.HTML_CELLPADDING_ATTR, ZERO); - table.setAttribute(HtmlComponentUtil.HTML_CELLSPACING_ATTR, ZERO); - table.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, HEADER_TABLE_STYLE); + table.setAttribute(HTML.ATTR_BORDER, ZERO); + table.setAttribute(HTML.ATTR_CELLPADDING, ZERO); + table.setAttribute(HTML.ATTR_CELLSPACING, ZERO); + table.setAttribute(HTML.ATTR_STYLE, HEADER_TABLE_STYLE); table.setAttribute(VPE_USER_TOGGLE_ID, toggleId); - nsIDOMElement mainTr = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TR); + nsIDOMElement mainTr = visualDocument.createElement(HTML.TAG_TR); table.appendChild(mainTr); encodeSpacer(mainTr, visualDocument); - nsIDOMElement mainTd = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TD); + nsIDOMElement mainTd = visualDocument.createElement(HTML.TAG_TD); mainTr.appendChild(mainTd); mainTd.setAttribute(VPE_USER_TOGGLE_ID, toggleId); - table = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TABLE); + table = visualDocument.createElement(HTML.TAG_TABLE); mainTd.appendChild(table); String labelWidth = ComponentUtil.getAttribute(sourceElement, LABEL_WIDTH); @@ -228,15 +252,15 @@ labelWidth = HUNDRED_PERCENTS; } tableStyle += WIDTH_STYLE_NAME + labelWidth + STYLE_SEMICOLUMN; - table.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, tableStyle); - table.setAttribute(HtmlComponentUtil.HTML_BORDER_ATTR, ZERO); - table.setAttribute(HtmlComponentUtil.HTML_CELLPADDING_ATTR, ZERO); - table.setAttribute(HtmlComponentUtil.HTML_CELLSPACING_ATTR, ZERO); + table.setAttribute(HTML.ATTR_STYLE, tableStyle); + table.setAttribute(HTML.ATTR_BORDER, ZERO); + table.setAttribute(HTML.ATTR_CELLPADDING, ZERO); + table.setAttribute(HTML.ATTR_CELLSPACING, ZERO); table.setAttribute(VPE_USER_TOGGLE_ID, toggleId); - nsIDOMElement tr = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TR); + nsIDOMElement tr = visualDocument.createElement(HTML.TAG_TR); table.appendChild(tr); - mainTd = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TD); + mainTd = visualDocument.createElement(HTML.TAG_TD); tr.appendChild(mainTd); styleClass = CSS_HEADER @@ -257,18 +281,30 @@ + SPACE + inactiveTabClass; } } - String tabStyleClass = ComponentUtil.getAttribute(sourceElement, HtmlComponentUtil.HTML_STYLECLASS_ATTR); + String tabStyleClass = ComponentUtil.getAttribute(sourceElement, RichFaces.ATTR_STYLE_CLASS); styleClass += SPACE + headerClass + SPACE + tabStyleClass; - mainTd.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, styleClass); + mainTd.setAttribute(HTML.ATTR_CLASS, styleClass); mainTd.setAttribute(VPE_USER_TOGGLE_ID, toggleId); - Node labelFacet = ComponentUtil.getFacet(sourceElement, LABEL, true); + + /* + * https://jira.jboss.org/jira/browse/JBIDE-3373 + * Encode the Label Facet + * Find elements from the f:facet + */ + Element labelFacet = SourceDomUtil.getFacetByName(sourceElement, RichFaces.NAME_FACET_LABEL); if (null != labelFacet) { - VpeChildrenInfo child = new VpeChildrenInfo(mainTd); - child.addSourceChild(labelFacet); - creationData.addChildrenInfo(child); - } else if (sourceElement.hasAttribute(LABEL)) { - Attr labelAttr = sourceElement.getAttributeNode(LABEL); + /* + * By adding attribute VPE-FACET to this visual node + * we force JsfFacet to be rendered inside it + * without creating an additional and superfluous visual tag. + */ + mainTd.setAttribute(VpeVisualDomBuilder.VPE_FACET, RichFaces.NAME_FACET_LABEL); + VpeChildrenInfo labelInfo = new VpeChildrenInfo(mainTd); + labelInfo.addSourceChild(labelFacet); + creationData.addChildrenInfo(labelInfo); + } else if (sourceElement.hasAttribute(RichFaces.ATTR_LABEL)) { + Attr labelAttr = sourceElement.getAttributeNode(RichFaces.ATTR_LABEL); if (null != labelAttr) { String bundleValue = ResourceUtil.getBundleValue(pageContext, labelAttr.getValue()); mainTd.appendChild(visualDocument.createTextNode(bundleValue)); @@ -285,20 +321,20 @@ * Add */ private static void encodeSpacer(nsIDOMElement parentTr, nsIDOMDocument visualDocument) { - nsIDOMElement td = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TD); + nsIDOMElement td = visualDocument.createElement(HTML.TAG_TD); parentTr.appendChild(td); - td.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, + td.setAttribute(HTML.ATTR_CLASS, RichFacesTabPanelTemplate.CSS_SIDE_CELL + SPACE + RichFacesTabPanelTemplate.CSS_SIDE_BORDER); String style = ComponentUtil.getBackgoundImgStyle(BORDER_FILE_PATH); - td.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, style); - nsIDOMElement img = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_IMG); + td.setAttribute(HTML.ATTR_STYLE, style); + nsIDOMElement img = visualDocument.createElement(HTML.TAG_IMG); td.appendChild(img); ComponentUtil.setImg(img, SPACER_FILE_PATH); - img.setAttribute(HtmlComponentUtil.HTML_WIDTH_ATTR, ONE); - img.setAttribute(HtmlComponentUtil.HTML_HEIGHT_ATTR, ONE); - img.setAttribute(HtmlComponentUtil.HTML_BORDER_ATTR, ZERO); + img.setAttribute(HTML.ATTR_WIDTH, ONE); + img.setAttribute(HTML.ATTR_HEIGHT, ONE); + img.setAttribute(HTML.ATTR_BORDER, ZERO); } Index: src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTogglePanelTemplate.java =================================================================== --- src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTogglePanelTemplate.java (revision 21098) +++ src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTogglePanelTemplate.java (working copy) @@ -20,15 +20,18 @@ 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.mozilla.interfaces.nsIDOMDocument; import org.mozilla.interfaces.nsIDOMElement; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -// This template defines the toggling methods but doesn't implements VpeToggableTemplate -// because of external toggle control. - +/** + * This template defines the toggling methods + * but doesn't implements VpeToggableTemplate + * because of external toggle control. + */ public class RichFacesTogglePanelTemplate extends VpeAbstractTemplate { private static Map toggleMap = new HashMap(); @@ -39,7 +42,7 @@ Element sourceElement = (Element)sourceNode; - nsIDOMElement div = visualDocument.createElement("div"); //$NON-NLS-1$ + nsIDOMElement div = visualDocument.createElement(HTML.TAG_DIV); VpeCreationData creationData = new VpeCreationData(div); Index: src/org/jboss/tools/jsf/vpe/richfaces/ComponentUtil.java =================================================================== --- src/org/jboss/tools/jsf/vpe/richfaces/ComponentUtil.java (revision 21098) +++ src/org/jboss/tools/jsf/vpe/richfaces/ComponentUtil.java (working copy) @@ -18,6 +18,7 @@ import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; +import java.util.Map; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IPath; @@ -31,6 +32,8 @@ import org.jboss.tools.vpe.editor.util.ElService; import org.jboss.tools.vpe.editor.util.FileUtil; 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.nsIDOMElement; import org.mozilla.interfaces.nsIDOMNode; import org.mozilla.interfaces.nsIDOMNodeList; @@ -971,4 +974,47 @@ } return widthDouble; } -} \ No newline at end of file + + /** + * If there are several JSF tags inside RichFaces tag + * only the first one will be returned. + * + * @param pageContext the page context + * @param sourceElement the source element + * @param facetName the name of the facet + * @return the first JSF tag + */ + public static Node getFacetBody(VpePageContext pageContext, + Element sourceElement, String facetName) { + Element facet = SourceDomUtil.getFacetByName(sourceElement, facetName); + Map> facetChildren = VisualDomUtil + .findFacetElements(facet, pageContext); + return getFacetBody(facetChildren); + } + + /** + * Select the first JSF component among facet's children + * + * @param facetChildren the map returned from + * {@link VisualDomUtil#findFacetElements(Element, VpePageContext)} + * @return the first JSF tag + */ + public static Node getFacetBody(Map> facetChildren) { + Node facetBody = null; + /* + * Display the first JSF Tag + */ + if (facetChildren.get(VisualDomUtil.FACET_ODD_TAGS).size() > 0) { + List oddTags = new ArrayList(0); + oddTags.addAll(facetChildren.get(VisualDomUtil.FACET_ODD_TAGS)); + facetBody = oddTags.get(0); + } else if (facetChildren.get(VisualDomUtil.FACET_JSF_TAG).size() > 0) { + /* + * Display the last JSF Tag + */ + facetBody = facetChildren.get(VisualDomUtil.FACET_JSF_TAG).get(0); + } + return facetBody; + } + +} Index: src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesDataTableTemplate.java =================================================================== --- src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesDataTableTemplate.java (revision 21098) +++ src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesDataTableTemplate.java (working copy) @@ -11,7 +11,12 @@ package org.jboss.tools.jsf.vpe.richfaces.template; import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + import org.jboss.tools.jsf.vpe.richfaces.ComponentUtil; +import org.jboss.tools.jsf.vpe.richfaces.RichFacesTemplatesActivator; import org.jboss.tools.jsf.vpe.richfaces.template.util.RichFaces; import org.jboss.tools.vpe.editor.context.VpePageContext; import org.jboss.tools.vpe.editor.template.VpeAbstractTemplate; @@ -19,6 +24,7 @@ import org.jboss.tools.vpe.editor.template.VpeCreationData; import org.jboss.tools.vpe.editor.util.Constants; 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.jboss.tools.vpe.editor.util.VpeStyleUtil; import org.mozilla.interfaces.nsIDOMDocument; @@ -29,11 +35,10 @@ import org.w3c.dom.NodeList; public class RichFacesDataTableTemplate extends VpeAbstractTemplate { - + public VpeCreationData create(VpePageContext pageContext, Node sourceNode, nsIDOMDocument visualDocument) { Element sourceElement = (Element)sourceNode; - nsIDOMElement table = visualDocument.createElement(HTML.TAG_TABLE); VisualDomUtil.copyAttributes(sourceNode, table); @@ -59,19 +64,33 @@ colgroup.appendChild(col); } } + + /* + * Encode Caption + */ + Element caption = SourceDomUtil.getFacetByName(sourceElement, RichFaces.NAME_FACET_CAPTION); + Map> captionFacetChildren = VisualDomUtil.findFacetElements(caption, pageContext); + Node captionNode= null; + if (captionFacetChildren.get(VisualDomUtil.FACET_JSF_TAG).size() > 0) { + captionNode = captionFacetChildren.get(VisualDomUtil.FACET_JSF_TAG).get(0); + } + encodeCaption(pageContext, creationData, sourceElement, visualDocument,table,captionNode); - //Encode Caption - encodeCaption(creationData, sourceElement, visualDocument, table); - - // Encode Header - Node header = ComponentUtil.getFacet((Element)sourceElement, RichFaces.NAME_FACET_HEADER,true); - final boolean hasColumnWithHeader = hasColumnWithFacet(columns, RichFaces.NAME_FACET_HEADER); - if(header!=null || hasColumnWithHeader) { + /* + * Encode Header + */ + Element header = SourceDomUtil.getFacetByName(sourceElement, RichFaces.NAME_FACET_HEADER); + Map> headerFacetChildren = VisualDomUtil.findFacetElements(header, pageContext); + boolean headerJsfElementPresents = headerFacetChildren.get(VisualDomUtil.FACET_JSF_TAG).size() > 0; + boolean hasColumnWithHeader = hasColumnWithFacet(columns, RichFaces.NAME_FACET_HEADER); + if(headerJsfElementPresents || hasColumnWithHeader) { nsIDOMElement thead = visualDocument.createElement(HTML.TAG_THEAD); table.appendChild(thead); String headerClass = (String) sourceElement.getAttribute(RichFaces.ATTR_HEADER_CLASS); - if(header != null) { - encodeTableHeaderOrFooterFacet(pageContext, creationData, thead, columnsLength, visualDocument, header, + if(headerJsfElementPresents) { + Node node = headerFacetChildren.get(VisualDomUtil.FACET_JSF_TAG).get(0); + encodeTableHeaderOrFooterFacet(pageContext, creationData, + thead, columnsLength, visualDocument, node, "dr-table-header rich-table-header", //$NON-NLS-1$ "dr-table-header-continue rich-table-header-continue", //$NON-NLS-1$ "dr-table-headercell rich-table-headercell", //$NON-NLS-1$ @@ -84,16 +103,21 @@ if(styleClass!=null) { tr.setAttribute(HTML.ATTR_CLASS, styleClass); } - encodeHeaderOrFooterFacets(pageContext, creationData, tr, visualDocument, columns, + encodeHeaderOrFooterFacets(pageContext, creationData, tr, + visualDocument, columns, "dr-table-subheadercell rich-table-subheadercell", //$NON-NLS-1$ headerClass, RichFaces.NAME_FACET_HEADER, HTML.TAG_TD); } } - // Encode Footer - Node footer = ComponentUtil.getFacet((Element)sourceElement, RichFaces.NAME_FACET_FOOTER,true); - final boolean hasColumnWithFooter = hasColumnWithFacet(columns, RichFaces.NAME_FACET_FOOTER); - if (footer != null || hasColumnWithFooter) { + /* + * Encode Footer + */ + Element footer = SourceDomUtil.getFacetByName(sourceElement, RichFaces.NAME_FACET_FOOTER); + Map> footerFacetChildren = VisualDomUtil.findFacetElements(footer, pageContext); + boolean footerJsfElementPresents = footerFacetChildren.get(VisualDomUtil.FACET_JSF_TAG).size() > 0; + boolean hasColumnWithFooter = hasColumnWithFacet(columns, RichFaces.NAME_FACET_FOOTER); + if (footerJsfElementPresents || hasColumnWithFooter) { nsIDOMElement tfoot = visualDocument.createElement(HTML.TAG_TFOOT); table.appendChild(tfoot); String footerClass = (String) sourceElement.getAttribute(RichFaces.ATTR_FOOTER_CLASS); @@ -104,12 +128,15 @@ if(styleClass!=null) { tr.setAttribute(HTML.ATTR_CLASS, styleClass); } - encodeHeaderOrFooterFacets(pageContext, creationData, tr, visualDocument, columns, + encodeHeaderOrFooterFacets(pageContext, creationData, tr, + visualDocument, columns, "dr-table-subfootercell rich-table-subfootercell", //$NON-NLS-1$ footerClass, RichFaces.NAME_FACET_FOOTER, HTML.TAG_TD); } - if (footer != null) { - encodeTableHeaderOrFooterFacet(pageContext, creationData, tfoot, columnsLength, visualDocument, footer, + if (footerJsfElementPresents) { + Node node = footerFacetChildren.get(VisualDomUtil.FACET_JSF_TAG).get(0); + encodeTableHeaderOrFooterFacet(pageContext, creationData, + tfoot, columnsLength, visualDocument, node, "dr-table-footer rich-table-footer", //$NON-NLS-1$ "dr-table-footer-continue rich-table-footer-continue", //$NON-NLS-1$ "dr-table-footercell rich-table-footercell", //$NON-NLS-1$ @@ -123,10 +150,15 @@ return creationData; } - protected void encodeCaption(VpeCreationData creationData, Element sourceElement, nsIDOMDocument visualDocument, nsIDOMElement table) { - //Encode caption - Element captionFromFacet = ComponentUtil.getFacet(sourceElement, RichFaces.NAME_FACET_CAPTION); - if (captionFromFacet != null) { + protected void encodeCaption(VpePageContext pageContext, + VpeCreationData creationData, Element sourceElement, + nsIDOMDocument visualDocument, nsIDOMElement table, + Node captionBody) { + + /* + * Encode caption + */ + if (null != captionBody) { String captionClass = (String) table.getAttribute(RichFaces.ATTR_CAPTION_CLASS); String captionStyle = (String) table.getAttribute(RichFaces.ATTR_CAPTION_STYLE); @@ -143,53 +175,72 @@ } VpeChildrenInfo cap = new VpeChildrenInfo(caption); - cap.addSourceChild(captionFromFacet); + /* + * Display existed JSF component + */ + cap.addSourceChild(captionBody); creationData.addChildrenInfo(cap); } } - public static void encodeHeaderOrFooterFacets(VpePageContext pageContext, VpeCreationData creationData, - nsIDOMElement parentTr, nsIDOMDocument visualDocument, ArrayList headersOrFooters, - String skinCellClass, String headerClass, String facetName, String element) { + public static void encodeHeaderOrFooterFacets(VpePageContext pageContext, + VpeCreationData creationData, nsIDOMElement parentTr, + nsIDOMDocument visualDocument, ArrayList headersOrFooters, + String skinCellClass, String headerClass, String facetName, + String element) { + for (Element column : headersOrFooters) { - String classAttribute = facetName + "Class"; //$NON-NLS-1$ - - String columnHeaderClass = column.getAttribute(classAttribute); - nsIDOMElement td = visualDocument.createElement(element); - parentTr.appendChild(td); - String styleClass = ComponentUtil.encodeStyleClass(null, skinCellClass, headerClass, columnHeaderClass); - if (!RichFacesColumnTemplate.isVisible(column)) { - VisualDomUtil.setSubAttribute(td, HTML.ATTR_STYLE, - HTML.STYLE_PARAMETER_DISPLAY, HTML.STYLE_VALUE_NONE); + Element facet = SourceDomUtil.getFacetByName(column, facetName); + /* + * If facet is null unwanted cells might be added. + * Thus do not add TD for such facets. + */ + if (null != facet) { + String classAttribute = facetName + "Class"; //$NON-NLS-1$ + + String columnHeaderClass = column.getAttribute(classAttribute); + nsIDOMElement td = visualDocument.createElement(element); + parentTr.appendChild(td); + String styleClass = ComponentUtil.encodeStyleClass(null, skinCellClass, headerClass, columnHeaderClass); + if (!RichFacesColumnTemplate.isVisible(column)) { + VisualDomUtil.setSubAttribute(td, HTML.ATTR_STYLE, + HTML.STYLE_PARAMETER_DISPLAY, HTML.STYLE_VALUE_NONE); + } + td.setAttribute(HTML.ATTR_CLASS, styleClass); + td.setAttribute(HTML.ATTR_SCOPE, "col"); //$NON-NLS-1$ + String colspan = column.getAttribute("colspan"); //$NON-NLS-1$ + if(colspan!=null && colspan.length()>0) { + td.setAttribute(HTML.ATTR_COLSPAN, colspan); + } + + if (RichFaces.NAME_FACET_HEADER.equals(facetName)) { + nsIDOMElement icon = RichFacesColumnTemplate.getHeaderIcon(pageContext, column, visualDocument); + if (icon != null) { + td.appendChild(icon); + } + } + /* + * Add facet source here + */ + VpeChildrenInfo childrenInfo = new VpeChildrenInfo(td); + childrenInfo.addSourceChild(facet); + creationData.addChildrenInfo(childrenInfo); } - td.setAttribute(HTML.ATTR_CLASS, styleClass); - td.setAttribute(HTML.ATTR_SCOPE, "col"); //$NON-NLS-1$ - String colspan = column.getAttribute("colspan"); //$NON-NLS-1$ - if(colspan!=null && colspan.length()>0) { - td.setAttribute(HTML.ATTR_COLSPAN, colspan); - } - Node facetBody = ComponentUtil.getFacet(column, facetName,true); - - nsIDOMElement span = visualDocument.createElement(HTML.TAG_SPAN); - td.appendChild(span); - if (RichFaces.NAME_FACET_HEADER.equals(facetName)) { - nsIDOMElement icon = RichFacesColumnTemplate.getHeaderIcon(pageContext, column, visualDocument); - if (icon != null) { - td.appendChild(icon); - } - } - - VpeChildrenInfo childrenInfo = new VpeChildrenInfo(span); - childrenInfo.addSourceChild(facetBody); - creationData.addChildrenInfo(childrenInfo); - } } - protected void encodeTableHeaderOrFooterFacet(final VpePageContext pageContext, VpeCreationData creationData, - nsIDOMElement parentTheadOrTfood, int columns, nsIDOMDocument visualDocument, Node facetBody, - String skinFirstRowClass, String skinRowClass, String skinCellClass, String facetBodyClass, String element) { + protected void encodeTableHeaderOrFooterFacet( + final VpePageContext pageContext, VpeCreationData creationData, + nsIDOMElement parentTheadOrTfood, int columns, + nsIDOMDocument visualDocument, Node facetBody, + String skinFirstRowClass, String skinRowClass, + String skinCellClass, String facetBodyClass, String facetVisualNode) { + + if (null == facetBody) { + RichFacesTemplatesActivator.getDefault().logError("Facet Body is null !"); + } + boolean isColumnGroup = facetBody.getNodeName().endsWith(RichFaces.TAG_COLUMN_GROUP); boolean isSubTable = facetBody.getNodeName().endsWith(RichFaces.TAG_SUB_TABLE); if(isColumnGroup) { @@ -207,7 +258,7 @@ String style = ComponentUtil.getHeaderBackgoundImgStyle(); tr.setAttribute(HTML.ATTR_STYLE, style); - nsIDOMElement td = visualDocument.createElement(element); + nsIDOMElement td = visualDocument.createElement(facetVisualNode); tr.appendChild(td); styleClass = ComponentUtil.encodeStyleClass(null, skinCellClass, facetBodyClass, null); Index: src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesPanelTemplate.java =================================================================== --- src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesPanelTemplate.java (revision 21098) +++ 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,57 @@ 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 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/RichFacesColumnTemplate.java =================================================================== --- src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesColumnTemplate.java (revision 21098) +++ src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesColumnTemplate.java (working copy) @@ -12,6 +12,7 @@ import java.util.ArrayList; 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; @@ -51,8 +52,33 @@ td.setAttribute(HTML.ATTR_CLASS, columnClass); final VpeCreationData creationData = new VpeCreationData(td); - // Create mapping to Encode body + Element headerFacet = SourceDomUtil.getFacetByName(sourceElement, + RichFaces.NAME_FACET_HEADER); + Element footerFacet = SourceDomUtil.getFacetByName(sourceElement, + RichFaces.NAME_FACET_FOOTER); + Map> headerFacetChildren = VisualDomUtil + .findFacetElements(headerFacet, pageContext); + Map> footerFacetChildren = VisualDomUtil + .findFacetElements(footerFacet, pageContext); + boolean headerHtmlElementPresents = headerFacetChildren.get(VisualDomUtil.FACET_HTML_TAGS).size() > 0; + boolean footerHtmlElementPresents = footerFacetChildren.get(VisualDomUtil.FACET_HTML_TAGS).size() > 0; + /* + * Encode html elements from facets to the column body + */ VpeChildrenInfo tdInfo = new VpeChildrenInfo(td); + if (headerHtmlElementPresents) { + for (Node child : headerFacetChildren.get(VisualDomUtil.FACET_HTML_TAGS)) { + tdInfo.addSourceChild(child); + } + } + if (footerHtmlElementPresents) { + for (Node child : footerFacetChildren.get(VisualDomUtil.FACET_HTML_TAGS)) { + tdInfo.addSourceChild(child); + } + } + /* + * Encode body + */ List children = ComponentUtil.getChildren(sourceElement,true); for (Node child : children) { if (!isFacet(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 21098) +++ src/org/jboss/tools/jsf/vpe/richfaces/template/util/RichFaces.java (working copy) @@ -42,12 +42,14 @@ public static final String ATTR_LOCALE = "locale"; //$NON-NLS-1$ public static final String ATTR_CONTROLS_TYPE = "controlsType"; //$NON-NLS-1$ public static final String ATTR_DEFAULT_LABEL = "defaultLabel"; //$NON-NLS-1$ + public static final String ATTR_LABEL = "label"; //$NON-NLS-1$ public static final String ATTR_DIRECTION = "direction"; //$NON-NLS-1$ 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$ @@ -75,6 +77,7 @@ public static final String ATTR_POSITION = "position"; //$NON-NLS-1$ /** FACETS NAMES **/ + public static final String NAME_FACET_LABEL = "label"; //$NON-NLS-1$ public static final String NAME_FACET_CAPTION = "caption"; //$NON-NLS-1$ public static final String NAME_FACET_FOOTER = "footer"; //$NON-NLS-1$ public static final String NAME_FACET_HEADER = "header"; //$NON-NLS-1$ Index: src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesExtendedDataTableTemplate.java =================================================================== --- src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesExtendedDataTableTemplate.java (revision 21098) +++ src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesExtendedDataTableTemplate.java (working copy) @@ -10,8 +10,10 @@ ******************************************************************************/ package org.jboss.tools.jsf.vpe.richfaces.template; +import java.io.ObjectInputStream.GetField; import java.util.ArrayList; 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; @@ -20,6 +22,7 @@ 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; @@ -147,8 +150,8 @@ tr.setAttribute(HTML.ATTR_CLASS, styleClass); filterTR.setAttribute(HTML.ATTR_CLASS, styleClass); } - encodeHeaderFacets(vpeCreationData, tr, filterTR, visualDocument, - columns, + encodeHeaderFacets(pageContext, vpeCreationData, tr, filterTR, + visualDocument, columns, DR_TABLE_SUBHEADERCELL_RICH_TABLE_SUBHEADERCELL, headerClass); // Add footer @@ -163,8 +166,8 @@ if (styleFooterClass != null) { tfootTR.setAttribute(HTML.ATTR_CLASS, styleFooterClass); } - encodeFooterFacets(vpeCreationData, tfootTR, visualDocument, - columns, + encodeFooterFacets(pageContext, vpeCreationData, tfootTR, + visualDocument, columns, DR_TABLE_SUBFOOTERCELL_RICH_TABLE_SUBFOOTERCELL, styleFooterClass); @@ -284,9 +287,10 @@ * @param skinCellClass * @param footerClass */ - public static void encodeFooterFacets(VpeCreationData creationData, - nsIDOMElement parentTr, nsIDOMDocument visualDocument, - ArrayList footers, String skinCellClass, String footerClass) { + public void encodeFooterFacets(VpePageContext pageContext, + VpeCreationData creationData, nsIDOMElement parentTr, + nsIDOMDocument visualDocument, ArrayList footers, + String skinCellClass, String footerClass) { String classAttribute = "footerClass"; //$NON-NLS-1$ String styleClass = EMPTY; for (Element column : footers) { @@ -302,11 +306,19 @@ if (colspan != null && colspan.length() > 0) { td.setAttribute(HTML.ATTR_COLSPAN, colspan); } - Element facetBody = ComponentUtil.getFacet(column, FOOTER); - - VpeChildrenInfo child = new VpeChildrenInfo(td); - child.addSourceChild(facetBody); - creationData.addChildrenInfo(child); + /* + * Get all facet's children. And display only the first one JSF tag. + */ + Node facetBody = ComponentUtil.getFacetBody(pageContext, column, + RichFaces.NAME_FACET_FOOTER); + /* + * Add suitable facet child if there is any. + */ + if (null != facetBody) { + VpeChildrenInfo child = new VpeChildrenInfo(td); + child.addSourceChild(facetBody); + creationData.addChildrenInfo(child); + } } nsIDOMElement td = visualDocument.createElement(HTML.TAG_TD); @@ -325,10 +337,10 @@ * @param skinCellClass * @param headerClass */ - public static void encodeHeaderFacets(VpeCreationData creationData, - nsIDOMElement parentTr, nsIDOMElement filterTR, - nsIDOMDocument visualDocument, ArrayList headers, - String skinCellClass, String headerClass) { + public void encodeHeaderFacets(VpePageContext pageContext, + VpeCreationData creationData, nsIDOMElement parentTr, + nsIDOMElement filterTR, nsIDOMDocument visualDocument, + ArrayList headers, String skinCellClass, String headerClass) { String classAttribute = "headerClass"; //$NON-NLS-1$ String styleClass = EMPTY; // Check filter @@ -361,11 +373,19 @@ if (colspan != null && colspan.length() > 0) { td.setAttribute(HTML.ATTR_COLSPAN, colspan); } - Element facetBody = ComponentUtil.getFacet(column, HEADER); - - VpeChildrenInfo child = new VpeChildrenInfo(span); - child.addSourceChild(facetBody); - creationData.addChildrenInfo(child); + /* + * Get all facet's children. And display only the first one JSF tag. + */ + Node facetBody = ComponentUtil.getFacetBody(pageContext, column, + RichFaces.NAME_FACET_HEADER); + /* + * Add suitable facet child if there is any. + */ + if (null != facetBody) { + VpeChildrenInfo child = new VpeChildrenInfo(span); + child.addSourceChild(facetBody); + creationData.addChildrenInfo(child); + } // Add filter if (existFilters) { nsIDOMElement filterTD = visualDocument @@ -413,28 +433,7 @@ td.appendChild(visualDocument.createTextNode(SPACE)); filterTR.appendChild(td); } - - /** - * Checks, whether it is necessary to re-create an element at change of - * attribute - * - * @param pageContext - * Contains the information on edited page. - * @param sourceElement - * The current element of the source tree. - * @param visualDocument - * The document of the visual tree. - * @param visualNode - * The current node of the visual tree. - * @param data - * The arbitrary data, built by a method create - * @param name - * Attribute name - * @param value - * Attribute value - * @return true if it is required to re-create an element at a - * modification of attribute, false otherwise. - */ + @Override public boolean recreateAtAttrChange(VpePageContext pageContext, Element sourceElement, nsIDOMDocument visualDocument, Index: src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesMessageTemplate.java =================================================================== --- src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesMessageTemplate.java (revision 21098) +++ 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 21098) +++ 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); } Index: src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesSimpleTogglePanelTemplate.java =================================================================== --- src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesSimpleTogglePanelTemplate.java (revision 21098) +++ src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesSimpleTogglePanelTemplate.java (working copy) @@ -24,6 +24,8 @@ import org.jboss.tools.vpe.editor.template.VpeToggableTemplate; import org.jboss.tools.vpe.editor.util.Constants; 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; @@ -87,19 +89,36 @@ headerDiv.setAttribute(HTML.ATTR_STYLE, "position : relative; " //$NON-NLS-1$ + ComponentUtil.getHeaderBackgoundImgStyle()); - // http://jira.jboss.com/jira/browse/JBIDE-791 - Element firstElementOfHeaderFacet = ComponentUtil.getFacet( - sourceElement, RichFaces.NAME_FACET_HEADER); - if (firstElementOfHeaderFacet != null) { - VpeChildrenInfo headerInfo = new VpeChildrenInfo(headerDiv); - headerInfo.addSourceChild(firstElementOfHeaderFacet); + /* + * http://jira.jboss.com/jira/browse/JBIDE-791 + * https://jira.jboss.org/jira/browse/JBIDE-3373 + * + * 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); + /* + * By adding attribute VPE-FACET to this visual node + * we force JsfFacet to be rendered inside it + * without creating an additional and superfluous visual tag. + */ + headerDiv.setAttribute(VpeVisualDomBuilder.VPE_FACET, RichFaces.NAME_FACET_HEADER); + /* + * Add header facet to the ChildrenInfo + */ + VpeChildrenInfo headerInfo = new VpeChildrenInfo(headerDiv); + headerInfo.addSourceChild(headerFacet); creationData.addChildrenInfo(headerInfo); } else { - String label = ComponentUtil - .getAttribute(sourceElement, ATTR_LABEL); - headerDiv.appendChild(visualDocument.createTextNode(label)); + /* + * Otherwise show label attribute value as panel header + */ + headerDiv.appendChild(visualDocument.createTextNode(ComponentUtil + .getAttribute(sourceElement, ATTR_LABEL))); } - // /// nsIDOMElement switchDiv = visualDocument.createElement(HTML.TAG_DIV); headerDiv.appendChild(switchDiv); @@ -147,9 +166,24 @@ + Constants.WHITE_SPACE + CSS_RICH_STGLPANEL_BODY + Constants.WHITE_SPACE + ComponentUtil.getAttribute(sourceElement, ATTR_BODY_CLASS)); - + + /* + * 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(td); + 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(td); for (Node child : children) { bodyInfo.addSourceChild(child); } Index: src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesSubTableTemplate.java =================================================================== --- src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesSubTableTemplate.java (revision 21098) +++ src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesSubTableTemplate.java (working copy) @@ -47,9 +47,10 @@ public VpeCreationData encode(final VpePageContext pageContext, VpeCreationData creationData, final Element sourceElement, final nsIDOMDocument visualDocument, nsIDOMElement parentVisualNode) { - if(creationData!=null) { - // Encode header + /* + * Encode header + */ encodeHeader(pageContext, creationData, sourceElement, visualDocument, parentVisualNode); } @@ -132,7 +133,8 @@ if(parentVisualNode!=null) { // Encode footer - encodeFooter(pageContext, creationData, sourceElement, visualDocument, parentVisualNode); + encodeFooter(pageContext, creationData, sourceElement, + visualDocument, parentVisualNode); } return creationData; } @@ -190,36 +192,58 @@ final Element sourceElement = (Element)sourceNode; final nsIDOMElement tbody = visualDocument.createElement(HTML.TAG_TBODY); VpeCreationData creationData = new VpeCreationData(tbody); - creationData = encode(pageContext, creationData, sourceElement, visualDocument, tbody); + creationData = encode(pageContext, creationData, sourceElement, + visualDocument, tbody); return creationData; } protected void encodeHeader(final VpePageContext pageContext, final VpeCreationData creationData, final Element sourceElement, final nsIDOMDocument visualDocument, final nsIDOMElement parentVisualNode) { - encodeHeaderOrFooter(pageContext, creationData, sourceElement, visualDocument, parentVisualNode, RichFaces.NAME_FACET_HEADER, "dr-subtable-header rich-subtable-header", "dr-subtable-headercell rich-subtable-headercell"); //$NON-NLS-1$ //$NON-NLS-2$ + encodeHeaderOrFooter( + pageContext, + creationData, + sourceElement, + visualDocument, + parentVisualNode, + RichFaces.NAME_FACET_HEADER, + "dr-subtable-header rich-subtable-header", //$NON-NLS-1$ + "dr-subtable-headercell rich-subtable-headercell"); //$NON-NLS-1$ } protected void encodeFooter(final VpePageContext pageContext, final VpeCreationData creationData, final Element sourceElement, final nsIDOMDocument visualDocument, final nsIDOMElement parentVisualNode) { - encodeHeaderOrFooter(pageContext, creationData, sourceElement, visualDocument, parentVisualNode, RichFaces.NAME_FACET_FOOTER, "dr-subtable-footer rich-subtable-footer", "dr-subtable-footercell rich-subtable-footercell"); //$NON-NLS-1$ //$NON-NLS-2$ + encodeHeaderOrFooter( + pageContext, + creationData, + sourceElement, + visualDocument, + parentVisualNode, + RichFaces.NAME_FACET_FOOTER, + "dr-subtable-footer rich-subtable-footer", //$NON-NLS-1$ + "dr-subtable-footercell rich-subtable-footercell"); //$NON-NLS-1$ } - protected void encodeHeaderOrFooter(final VpePageContext pageContext, final VpeCreationData creationData, - final Element sourceElement, final nsIDOMDocument visualDocument, final nsIDOMElement parentVisualNode, - final String facetName, final String trClass, final String tdClass) { - final ArrayList columns = RichFacesDataTableTemplate.getColumns(sourceElement); - //final ArrayList columnsHeaders = ComponentUtil.getColumnsWithFacet(columns, facetName); - final boolean hasColumnWithFacet = RichFacesDataTableTemplate.hasColumnWithFacet(columns, facetName); - if(hasColumnWithFacet) { + protected void encodeHeaderOrFooter(final VpePageContext pageContext, + final VpeCreationData creationData, final Element sourceElement, + final nsIDOMDocument visualDocument, + final nsIDOMElement parentVisualNode, final String facetName, + final String trClass, final String tdClass) { + + final ArrayList columns = RichFacesDataTableTemplate + .getColumns(sourceElement); + // final ArrayList columnsHeaders = + // ComponentUtil.getColumnsWithFacet(columns, facetName); + final boolean hasColumnWithFacet = RichFacesDataTableTemplate + .hasColumnWithFacet(columns, facetName); + if (hasColumnWithFacet) { final nsIDOMElement tr = visualDocument.createElement(HTML.TAG_TR); parentVisualNode.appendChild(tr); final String styleClass = trClass; - if(styleClass!=null) { + if (styleClass != null) { tr.setAttribute(HTML.ATTR_CLASS, styleClass); } - RichFacesDataTableTemplate.encodeHeaderOrFooterFacets(pageContext, creationData, tr, visualDocument, columns, - tdClass, - null, facetName, HTML.TAG_TD); + RichFacesDataTableTemplate.encodeHeaderOrFooterFacets(pageContext, + creationData, tr, visualDocument, columns, tdClass, null, + facetName, HTML.TAG_TD); } - } private boolean isHeader(final Element sourceElement) {