Author: dmaliarevich
Date: 2011-08-25 09:18:41 -0400 (Thu, 25 Aug 2011)
New Revision: 34309
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesCollapsibleSubTableTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesDataTableChildrenEncoder.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesDataTableTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesSubTableTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/util/RichFaces.java
Log:
https://issues.jboss.org/browse/JBIDE-8950 , collapsibleSubTable template was recreated,
header and footer were added, helper classes were used.
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesCollapsibleSubTableTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesCollapsibleSubTableTemplate.java 2011-08-25
11:35:14 UTC (rev 34308)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesCollapsibleSubTableTemplate.java 2011-08-25
13:18:41 UTC (rev 34309)
@@ -12,30 +12,112 @@
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;
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.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
-public class RichFacesCollapsibleSubTableTemplate extends RichFacesSubTableTemplate {
+public class RichFacesCollapsibleSubTableTemplate extends VpeAbstractTemplate {
+ private static final String CST_TBODY_CLASS = "rf-cst"; //$NON-NLS-1$
+ private static final String CST_ROW_CLASS = "rf-cst-r"; //$NON-NLS-1$
+ private static final String CST_FIRST_RAW_CLASS = "rf-cst-fst-r";
//$NON-NLS-1$
+ private static final String CST_CELL_CLASS = "rf-cst-c"; //$NON-NLS-1$
+ private static final String CST_HEADER_CLASS = "rf-cst-hdr"; //$NON-NLS-1$
+ private static final String CST_FIRST_HEADER_CLASS = "rf-cst-hdr-fst";
//$NON-NLS-1$
+ private static final String CST_FIRST_HEADER_ROW_CLASS = "rf-cst-hdr-fst-r";
//$NON-NLS-1$
+ private static final String CST_HEADER_CELL_CLASS = "rf-cst-hdr-c";
//$NON-NLS-1$
+ private static final String CST_SUBHEADER_CLASS = "rf-cst-shdr";
//$NON-NLS-1$
+ private static final String CST_SUBHEADER_CELL_CLASS = "rf-cst-shdr-c";
//$NON-NLS-1$
+ private static final String CST_FOOTER_CLASS = "rf-cst-ftr"; //$NON-NLS-1$
+ private static final String CST_FIRST_FOOTER_CLASS = "rf-cst-ftr-fst";
//$NON-NLS-1$
+ private static final String CST_FOOTER_CELL_CLASS = "rf-cst-ftr-c";
//$NON-NLS-1$
+ private static final String CST_SUBFOOTER_CLASS = "rf-cst-sftr";
//$NON-NLS-1$
+ private static final String CST_FIRST_SUBFOOTER_CLASS = "rf-cst-sftr-fst";
//$NON-NLS-1$
+ private static final String CST_SUBFOOTER_CELL_CLASS = "rf-cst-sftr-c";
//$NON-NLS-1$
+
public VpeCreationData create(final VpePageContext pageContext,
final Node sourceNode, final nsIDOMDocument visualDocument) {
- final Element sourceElement = (Element)sourceNode;
+ final Element sourceElement = (Element) sourceNode;
final nsIDOMElement tbody = visualDocument.createElement(HTML.TAG_TBODY);
- String style = "display: table-row-group;"; //$NON-NLS-1$
+ /*
+ * Copy attributes from the source node to visual node.
+ */
+ VisualDomUtil.copyAttributes(sourceNode, tbody);
+ /*
+ * Add collapsible style property
+ */
+ String displayStyle = "display: table-row-group;"; //$NON-NLS-1$
if (RichFaces.readCollapsedStateFromSourceNode(sourceNode)) {
- style = "display: none;"; //$NON-NLS-1$
+ displayStyle = "display: none;"; //$NON-NLS-1$
}
+ /*
+ * Get previous style attribute value
+ */
+ String style = null;
+ if (sourceElement.hasAttribute(HTML.ATTR_STYLE)) {
+ style = sourceElement.getAttribute(HTML.ATTR_STYLE);
+ }
+ style += displayStyle;
+ /*
+ * Re-set style to the visual node
+ */
tbody.setAttribute(HTML.ATTR_STYLE, style);
+ tbody.setAttribute(HTML.ATTR_CLASS, CST_TBODY_CLASS);
+ /*
+ * Create VpeCreationData for this visual node.
+ * Initialize ChildrenEncoder.
+ */
VpeCreationData creationData = new VpeCreationData(tbody);
- creationData = encodeSubTable(pageContext, creationData, sourceElement,
- visualDocument, tbody);
+ RichFacesDataTableChildrenEncoder childrenEncoder = new
RichFacesDataTableChildrenEncoder(
+ creationData, visualDocument, sourceElement, tbody);
+ childrenEncoder.setRowClasses(CST_FIRST_RAW_CLASS, CST_ROW_CLASS);
+ /*
+ * Encode header
+ */
+ childrenEncoder.encodeTableHeader(
+ pageContext, tbody, null,
+ HTML.TAG_TD, RichFaces.NAME_FACET_HEADER, CST_HEADER_CLASS,
+ null, null, null, CST_HEADER_CELL_CLASS);
+ /*
+ * Encode children
+ */
+ childrenEncoder.encodeChildren();
+ /*
+ * Encode footer
+ */
+ childrenEncoder.encodeTableFooter(
+ pageContext, tbody, null,
+ HTML.TAG_TD, RichFaces.NAME_FACET_FOOTER, CST_FOOTER_CLASS,
+ null, null, null, CST_FOOTER_CELL_CLASS);
+
return creationData;
}
+
+ @Override
+ public void validate(VpePageContext pageContext, Node sourceNode,
+ nsIDOMDocument visualDocument, VpeCreationData creationData) {
+ RichFacesDataTableChildrenEncoder.validateChildren(
+ pageContext, sourceNode, visualDocument, creationData);
+ /*
+ * Apply css styles to the generated visual node.
+ */
+ final RichFacesDataTableStyleClassesApplier styleClassesApplier =
+ new RichFacesDataTableStyleClassesApplier(visualDocument, pageContext, sourceNode);
+ styleClassesApplier.applyClasses((nsIDOMElement) creationData.getNode());
+ }
+
+ /**
+ * Method that is responsible for collapsing/expanding subtable
+ *
+ * @param sourceNode source node for the subtable
+ * @param toggleId the id
+ */
public void toggle(Node sourceNode, String toggleId) {
/*
* Collapsed state will be changed.
@@ -47,4 +129,5 @@
sourceNode.setUserData(RichFaces.COLLAPSED_STATE, "true", null);
//$NON-NLS-1$
}
}
+
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesDataTableChildrenEncoder.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesDataTableChildrenEncoder.java 2011-08-25
11:35:14 UTC (rev 34308)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesDataTableChildrenEncoder.java 2011-08-25
13:18:41 UTC (rev 34309)
@@ -10,7 +10,9 @@
******************************************************************************/
package org.jboss.tools.jsf.vpe.richfaces.template;
+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.RichFacesTemplatesActivator;
@@ -21,6 +23,7 @@
import org.jboss.tools.vpe.editor.template.VpeCreatorUtil;
import org.jboss.tools.vpe.editor.template.VpeTemplate;
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;
@@ -67,16 +70,16 @@
private static final String TAG_SUB_TABLE_OR_COLUMN_GROUP_CONTAINER =
"subTableOrColumnGroup-container"; //$NON-NLS-1$
private final VpeCreationData creationData;
private final nsIDOMDocument visualDocument;
- private final Element sourceElement;
- private final nsIDOMElement table;
+ private final Element tableSourceElement;
+ private final nsIDOMElement tableVisualTag;
public RichFacesDataTableChildrenEncoder(final VpeCreationData creationData,
- final nsIDOMDocument visualDocument, final Element sourceElement,
- final nsIDOMElement table) {
+ final nsIDOMDocument visualDocument, final Element tableSourceElement,
+ final nsIDOMElement tableVisualTag) {
this.creationData = creationData;
this.visualDocument = visualDocument;
- this.sourceElement = sourceElement;
- this.table = table;
+ this.tableSourceElement = tableSourceElement;
+ this.tableVisualTag = tableVisualTag;
}
/**
@@ -93,8 +96,8 @@
// except ones specified in another vpeChildrenInfo's
final VpeChildrenInfo childInfo = new VpeChildrenInfo(null);
creationData.addChildrenInfo(childInfo);
-
- final List<Node> children = ComponentUtil.getChildren(sourceElement);
+
+ final List<Node> children = ComponentUtil.getChildren(tableSourceElement);
boolean createNewRow = true;
for (final Node child : children) {
final String nodeName = child.getNodeName();
@@ -122,15 +125,16 @@
final nsIDOMNode visualNode = creationData.getNode();
fixSubTables(visualNode);
}
-
+
/**
* Creates a container for {@code subTableOrColumnGroupNode} in {@code table}
* and adds an appropriate object of {@link VpeChildrenInfo} to {@code creationData}.
* <BR/>The container is the tag {@link
#TAG_SUB_TABLE_OR_COLUMN_GROUP_CONTAINER}.
*/
private nsIDOMElement addSubTableOrColumnGroupToTable(final Node
subTableOrColumnGroupNode) {
- final nsIDOMElement subTableOrColumnGroupContainer =
visualDocument.createElement(TAG_SUB_TABLE_OR_COLUMN_GROUP_CONTAINER);
- table.appendChild(subTableOrColumnGroupContainer);
+ final nsIDOMElement subTableOrColumnGroupContainer = visualDocument
+ .createElement(TAG_SUB_TABLE_OR_COLUMN_GROUP_CONTAINER);
+ tableVisualTag.appendChild(subTableOrColumnGroupContainer);
final VpeChildrenInfo childInfo = new VpeChildrenInfo(subTableOrColumnGroupContainer);
childInfo.addSourceChild(subTableOrColumnGroupNode);
creationData.addChildrenInfo(childInfo);
@@ -150,7 +154,7 @@
private nsIDOMElement addColumnToRow(final Node columnNode, final boolean createNewRow)
{
if ( createNewRow || (currentRow == null) ) {
currentRow = visualDocument.createElement(HTML.TAG_TR);
- table.appendChild(currentRow);
+ tableVisualTag.appendChild(currentRow);
currentRowChildrenInfo = new VpeChildrenInfo(currentRow);
creationData.addChildrenInfo(currentRowChildrenInfo);
rowNumber++;
@@ -172,7 +176,7 @@
* */
private void addElementToTable(final Node node) {
final nsIDOMElement tr = this.visualDocument.createElement(HTML.TAG_TR);
- table.appendChild(tr);
+ tableVisualTag.appendChild(tr);
final nsIDOMElement td = this.visualDocument.createElement(HTML.TAG_TD);
td.setAttribute(HTML.ATTR_COLSPAN, HTML.VALUE_COLSPAN_ALL);
@@ -200,8 +204,264 @@
final RuntimeException e = new RuntimeException("This is probably a bug.
subTable-container should have one inner tag.");//$NON-NLS-1$
RichFacesTemplatesActivator.getPluginLog().logError(e);
}
-
+
VisualDomUtil.replaceNodeByItsChildren(subTableContainer);
}
}
+
+ /**
+ * Encoded facets from columns to the table.
+ *
+ * @param pageContext VpePageContext
+ * @param columnsWithFacets list of the source elements for columns
+ * @param facetName {@code "header"} or {@code "footer"} or other
+ * @param visualParentTR visal element to put {@code "<tr>"} to
+ * @param visualElementForTD string name for facet cell (usually {@code <td>})
+ * @param cellClass css class for the facet's cell
+ * @param headerClass user defined css class for column's header
+ */
+ public void encodeColumnsFacets(VpePageContext pageContext,
+ ArrayList<Element> columnsWithFacets, String facetName,
+ nsIDOMElement visualParentTR, String visualElementForTD,
+ String cellClass, String headerClass) {
+
+ for (Element column : columnsWithFacets) {
+ Element facet = SourceDomUtil.getFacetByName(pageContext,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.hasAttribute(classAttribute) ?
column.getAttribute(classAttribute) : null;
+ nsIDOMElement td = visualDocument.createElement(visualElementForTD);
+ visualParentTR.appendChild(td);
+ String styleClass = ComponentUtil.encodeStyleClass(null, cellClass, 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, HTML.TAG_COL);
+ if(column.hasAttribute(HTML.ATTR_COLSPAN)) {
+ String colspan = column.getAttribute(HTML.ATTR_COLSPAN);
+ 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);
+ }
+ }
+ }
+
+ /**
+ * Adds the header or footer facets to the table
+ *
+ * @param pageContext VpePageContext
+ * @param visualTagForFacet {@code <thead>} or {@code <tfoot>} or any
similar
+ * @param innerFacetSourceNode single source elemen``t to be rendered inside facet
+ * @param visualElementForTD string name for facet cell (usually {@code <td>})
+ * @param facetTHeadClass css class for {@code <thead>} or {@code <tfoot>}
or any similar
+ * @param firstRowClass css class for the first facet row
+ * @param rowClass css class for the facet's row
+ * @param cellClass css class for the facet's cell
+ */
+ public void encodeTableFacets(VpePageContext pageContext,
+ nsIDOMElement visualTagForFacet, Element innerFacetSourceNode,
+ String visualElementForTD, String facetTHeadClass,
+ String firstRowClass, String rowClass, String cellClass) {
+
+ if (null == innerFacetSourceNode) {
+ RichFacesTemplatesActivator.getDefault().logError("Source element to be rendered
inside facet is 'null' !"); //$NON-NLS-1$
+ }
+
+ boolean isColumnGroup =
innerFacetSourceNode.getNodeName().endsWith(RichFaces.TAG_COLUMN_GROUP);
+ boolean isSubTable =
innerFacetSourceNode.getNodeName().endsWith(RichFaces.TAG_SUB_TABLE);
+ if(isColumnGroup) {
+ RichFacesColumnGroupTemplate.DEFAULT_INSTANCE.encodeSubTable(pageContext,
creationData, innerFacetSourceNode, visualDocument, visualTagForFacet);
+ } else if(isSubTable) {
+ RichFacesSubTableTemplate.DEFAULT_INSTANCE.encodeSubTable(pageContext, creationData,
innerFacetSourceNode, visualDocument, visualTagForFacet);
+ } else {
+ nsIDOMElement tr = visualDocument.createElement(HTML.TAG_TR);
+ visualTagForFacet.appendChild(tr);
+ // TODO facetTHeadClass should be applied only once
+ // TODO rowClass is never applied
+ String styleClass = ComponentUtil.encodeStyleClass(null, firstRowClass,
facetTHeadClass, null);
+ if(styleClass!=null) {
+ tr.setAttribute(HTML.ATTR_CLASS, styleClass);
+ }
+ String style = ComponentUtil.getHeaderBackgoundImgStyle();
+ tr.setAttribute(HTML.ATTR_STYLE, style);
+
+ nsIDOMElement td = visualDocument.createElement(visualElementForTD);
+ tr.appendChild(td);
+ // TODO facetTHeadClass should be applied only once
+ styleClass = ComponentUtil.encodeStyleClass(null, cellClass, facetTHeadClass, null);
+ if(styleClass!=null) {
+ td.setAttribute(HTML.ATTR_CLASS, styleClass);
+ }
+ // the cell spans the entire row
+ td.setAttribute(HTML.ATTR_COLSPAN, HTML.VALUE_COLSPAN_ALL);
+ td.setAttribute(HTML.ATTR_SCOPE, HTML.TAG_COLGROUP);
+ VpeChildrenInfo child = new VpeChildrenInfo(td);
+ child.addSourceChild(innerFacetSourceNode);
+ creationData.addChildrenInfo(child);
+ }
+ }
+
+ /**
+ * Encodes the whole table's header and columns' header
+ *
+ * @param pageContext VpePageContext
+ * @param visualParentForFacetTHead visual node to put facet's {@code <thead>}
or {@code <tfoot>} or similar
+ * @param visualTagForFacetTHead what tag will be rendered: {@code <thead>} or
{@code <tfoot>} or other
+ * @param visualElementForTD string name for facet cell (usually {@code <td>})
+ * @param facetName {@code "header"} or {@code "footer"} or other
+ * @param customFacetClass user's class for columns' headers/footer
+ * @param facetTHeadClass user's class for table's headers/footer
+ * @param firstRowClass css class for the first row in table's headers/footer
+ * @param rowClass css class for non-first row in table's headers/footer
+ * @param cellClass css class for the facet's cell
+ */
+ public void encodeTableHeader(VpePageContext pageContext,
+ nsIDOMElement visualParentForFacetTHead,
+ String visualTagForFacetTHead, String visualElementForTD,
+ String facetName, String customFacetClass, String facetTHeadClass,
+ String firstRowClass, String rowClass, String cellClass) {
+
+ Element facetSourceElement = SourceDomUtil.getFacetByName(pageContext,
+ tableSourceElement, facetName);
+
+ ArrayList<Element> columns = RichFaces.getColumns(tableSourceElement);
+ int columnsLength = RichFaces.getColumnsCount(tableSourceElement, columns);
+
+ Map<String, List<Node>> facetChildren =
VisualDomUtil.findFacetElements(facetSourceElement, pageContext);
+ boolean headerJsfElementPresents =
facetChildren.get(VisualDomUtil.FACET_JSF_TAG).size() > 0;
+ boolean hasColumnWithFacets = RichFaces.hasColumnWithFacet(columns, facetName);
+ if(headerJsfElementPresents || hasColumnWithFacets) {
+ nsIDOMElement createdVisualTagForFacetTHead = null;
+ if ((null == visualTagForFacetTHead) ||
"".equalsIgnoreCase(visualTagForFacetTHead)) { //$NON-NLS-1$
+ /*
+ * For subtables mostly:
+ * Header won't be placed into separate thead or tfoot tag.
+ * Then put it to the parent's visual node.
+ */
+ createdVisualTagForFacetTHead = visualParentForFacetTHead;
+ } else {
+ createdVisualTagForFacetTHead = visualDocument.createElement(
+ visualTagForFacetTHead); //thead or tfoot
+ visualParentForFacetTHead.appendChild(createdVisualTagForFacetTHead);
+ }
+ String facetClass = null;
+ if (tableSourceElement.hasAttribute(facetName + "Class")) { //$NON-NLS-1$
+ facetClass = tableSourceElement.getAttribute(facetName + "Class");
//$NON-NLS-1$
+ }
+ /*
+ * Encode facet for the whole table
+ */
+ if(headerJsfElementPresents) {
+ Element node = (Element) facetChildren.get(VisualDomUtil.FACET_JSF_TAG).get(0);
+ encodeTableFacets(pageContext,
+ createdVisualTagForFacetTHead, node, visualElementForTD,
+ facetTHeadClass, firstRowClass, rowClass, cellClass);
+ }
+ /*
+ * Encode facets for columns
+ */
+ if(hasColumnWithFacets) {
+ nsIDOMElement visualParentTR = visualDocument.createElement(HTML.TAG_TR);
+ createdVisualTagForFacetTHead.appendChild(visualParentTR);
+ String styleClass = ComponentUtil.encodeStyleClass(null, customFacetClass, null,
facetClass);
+ if(styleClass!=null) {
+ visualParentTR.setAttribute(HTML.ATTR_CLASS, styleClass);
+ }
+ encodeColumnsFacets(pageContext,
+ columns, facetName, visualParentTR, visualElementForTD,
+ cellClass, facetClass);
+ }
+ }
+ }
+
+ /**
+ * Encodes the whole table's footer and columns' footer
+ *
+ * @param pageContext VpePageContext
+ * @param visualParentForFacetTHead visual node to put facet's {@code <thead>}
or {@code <tfoot>} or similar
+ * @param visualTagForFacetTHead what tag will be rendered: {@code <thead>} or
{@code <tfoot>} or other
+ * @param visualElementForTD string name for facet cell (usually {@code <td>})
+ * @param facetName {@code "header"} or {@code "footer"} or other
+ * @param customFacetClass user's class for columns' headers/footer
+ * @param facetTHeadClass user's class for table's headers/footer
+ * @param firstRowClass css class for the first row in table's headers/footer
+ * @param rowClass css class for non-first row in table's headers/footer
+ * @param cellClass css class for the facet's cell
+ */
+ public void encodeTableFooter(VpePageContext pageContext,
+ nsIDOMElement visualParentForFacetTHead,
+ String visualTagForFacetTHead, String visualElementForTD,
+ String facetName, String customFacetClass, String facetTHeadClass,
+ String firstRowClass, String rowClass, String cellClass) {
+
+ Element facetSourceElement = SourceDomUtil.getFacetByName(pageContext,
+ tableSourceElement, facetName);
+
+ ArrayList<Element> columns = RichFaces.getColumns(tableSourceElement);
+ int columnsLength = RichFaces.getColumnsCount(tableSourceElement, columns);
+
+ Map<String, List<Node>> facetChildren =
VisualDomUtil.findFacetElements(facetSourceElement, pageContext);
+ boolean headerJsfElementPresents =
facetChildren.get(VisualDomUtil.FACET_JSF_TAG).size() > 0;
+ boolean hasColumnWithFacets = RichFaces.hasColumnWithFacet(columns, facetName);
+ if(headerJsfElementPresents || hasColumnWithFacets) {
+ nsIDOMElement createdVisualTagForFacetTHead = null;
+ if ((null == visualTagForFacetTHead) ||
"".equalsIgnoreCase(visualTagForFacetTHead)) { //$NON-NLS-1$
+ /*
+ * For subtables mostly:
+ * Header won't be placed into separate thead or tfoot tag.
+ * Then put it to the parent's visual node.
+ */
+ createdVisualTagForFacetTHead = visualParentForFacetTHead;
+ } else {
+ createdVisualTagForFacetTHead = visualDocument.createElement(
+ visualTagForFacetTHead); //thead or tfoot
+ visualParentForFacetTHead.appendChild(createdVisualTagForFacetTHead);
+ }
+ String facetClass = null;
+ if (tableSourceElement.hasAttribute(facetName + "Class")) { //$NON-NLS-1$
+ facetClass = tableSourceElement.getAttribute(facetName + "Class");
//$NON-NLS-1$
+ }
+ /*
+ * Encode facets for columns first
+ */
+ if(hasColumnWithFacets) {
+ nsIDOMElement visualParentTR = visualDocument.createElement(HTML.TAG_TR);
+ createdVisualTagForFacetTHead.appendChild(visualParentTR);
+ String styleClass = ComponentUtil.encodeStyleClass(null, customFacetClass, null,
facetClass);
+ if(styleClass!=null) {
+ visualParentTR.setAttribute(HTML.ATTR_CLASS, styleClass);
+ }
+ encodeColumnsFacets(pageContext,
+ columns, facetName, visualParentTR, visualElementForTD,
+ cellClass, facetClass);
+ }
+ /*
+ * Encode facet for the whole table
+ */
+ if(headerJsfElementPresents) {
+ Element node = (Element) facetChildren.get(VisualDomUtil.FACET_JSF_TAG).get(0);
+ encodeTableFacets(pageContext,
+ createdVisualTagForFacetTHead, node, visualElementForTD,
+ facetTHeadClass, firstRowClass, rowClass, cellClass);
+ }
+ }
+ }
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesDataTableTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesDataTableTemplate.java 2011-08-25
11:35:14 UTC (rev 34308)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesDataTableTemplate.java 2011-08-25
13:18:41 UTC (rev 34309)
@@ -52,8 +52,8 @@
table.setAttribute(HTML.ATTR_CLASS, tableClass);
// Encode colgroup definition.
- ArrayList<Element> columns = getColumns(sourceElement);
- int columnsLength = getColumnsCount(sourceElement, columns);
+ ArrayList<Element> columns = RichFaces.getColumns(sourceElement);
+ int columnsLength = RichFaces.getColumnsCount(sourceElement, columns);
nsIDOMElement colgroup = visualDocument.createElement(HTML.TAG_COLGROUP);
colgroup.setAttribute(HTML.ATTR_SPAN, String.valueOf(columnsLength));
table.appendChild(colgroup);
@@ -87,13 +87,17 @@
sourceElement, RichFaces.NAME_FACET_HEADER);
Map<String, List<Node>> headerFacetChildren =
VisualDomUtil.findFacetElements(header, pageContext);
boolean headerJsfElementPresents =
headerFacetChildren.get(VisualDomUtil.FACET_JSF_TAG).size() > 0;
- boolean hasColumnWithHeader = hasColumnWithFacet(columns,
RichFaces.NAME_FACET_HEADER);
+ boolean hasColumnWithHeader = RichFaces.hasColumnWithFacet(columns,
RichFaces.NAME_FACET_HEADER);
if(headerJsfElementPresents || hasColumnWithHeader) {
nsIDOMElement thead = visualDocument.createElement(HTML.TAG_THEAD);
table.appendChild(thead);
- String headerClass = sourceElement.hasAttribute(RichFaces.ATTR_HEADER_CLASS) ?
sourceElement.getAttribute(RichFaces.ATTR_HEADER_CLASS) : null;
+ String headerClass = sourceElement.hasAttribute(RichFaces.ATTR_HEADER_CLASS)
+ ? sourceElement.getAttribute(RichFaces.ATTR_HEADER_CLASS) : null;
if(headerJsfElementPresents) {
Node node = headerFacetChildren.get(VisualDomUtil.FACET_JSF_TAG).get(0);
+ /*
+ * Encode Header for the whole table first
+ */
encodeTableHeaderOrFooterFacet(pageContext, creationData,
thead, columnsLength, visualDocument, node,
"dr-table-header rich-table-header", //$NON-NLS-1$
@@ -108,6 +112,9 @@
if(styleClass!=null) {
tr.setAttribute(HTML.ATTR_CLASS, styleClass);
}
+ /*
+ * Encode Header for columns
+ */
encodeHeaderOrFooterFacets(pageContext, creationData, tr,
visualDocument, columns,
"dr-table-subheadercell rich-table-subheadercell", //$NON-NLS-1$
@@ -122,11 +129,12 @@
sourceElement, RichFaces.NAME_FACET_FOOTER);
Map<String, List<Node>> footerFacetChildren =
VisualDomUtil.findFacetElements(footer, pageContext);
boolean footerJsfElementPresents =
footerFacetChildren.get(VisualDomUtil.FACET_JSF_TAG).size() > 0;
- boolean hasColumnWithFooter = hasColumnWithFacet(columns,
RichFaces.NAME_FACET_FOOTER);
+ boolean hasColumnWithFooter = RichFaces.hasColumnWithFacet(columns,
RichFaces.NAME_FACET_FOOTER);
if (footerJsfElementPresents || hasColumnWithFooter) {
nsIDOMElement tfoot = visualDocument.createElement(HTML.TAG_TFOOT);
table.appendChild(tfoot);
- String footerClass = sourceElement.hasAttribute(RichFaces.ATTR_FOOTER_CLASS) ?
sourceElement.getAttribute(RichFaces.ATTR_FOOTER_CLASS) : null;
+ String footerClass = sourceElement.hasAttribute(RichFaces.ATTR_FOOTER_CLASS)
+ ? sourceElement.getAttribute(RichFaces.ATTR_FOOTER_CLASS) : null;
if(hasColumnWithFooter) {
nsIDOMElement tr = visualDocument.createElement(HTML.TAG_TR);
tfoot.appendChild(tr);
@@ -134,6 +142,9 @@
if(styleClass!=null) {
tr.setAttribute(HTML.ATTR_CLASS, styleClass);
}
+ /*
+ * Encode Footer for columns first
+ */
encodeHeaderOrFooterFacets(pageContext, creationData, tr,
visualDocument, columns,
"dr-table-subfootercell rich-table-subfootercell", //$NON-NLS-1$
@@ -141,6 +152,9 @@
}
if (footerJsfElementPresents) {
Node node = footerFacetChildren.get(VisualDomUtil.FACET_JSF_TAG).get(0);
+ /*
+ * Encode Footer for the whole table
+ */
encodeTableHeaderOrFooterFacet(pageContext, creationData,
tfoot, columnsLength, visualDocument, node,
"dr-table-footer rich-table-footer", //$NON-NLS-1$
@@ -283,91 +297,7 @@
}
}
- public static ArrayList<Element> getColumns(Node parentSourceElement) {
- ArrayList<Element> columns = new ArrayList<Element>();
- NodeList children = parentSourceElement.getChildNodes();
- for(int i=0; i<children.getLength(); i++) {
- Node child = children.item(i);
- String nodeName = child.getNodeName();
- if((child instanceof Element) && (
- nodeName.endsWith(RichFaces.TAG_COLUMN) ||
- nodeName.endsWith(RichFaces.TAG_COLUMNS)
- )) {
- columns.add((Element)child);
- }
- }
- return columns;
- }
-
/**
- * Returns true if and only if {@code columns} contains at least one column that have
facet
- * with given {@code facetName}.
- */
- public static boolean hasColumnWithFacet(ArrayList<Element> columns, String
facetName) {
- for (Element column : columns) {
- Node body = ComponentUtil.getFacet(column, facetName, true);
- if(body!=null) {
- return true;
- }
- }
-
- return false;
- }
-
- protected int getColumnsCount(Element sourceElement, ArrayList<Element> columns)
{
- int count = 0;
- // check for exact value in component
- try {
- count = Integer.parseInt(sourceElement.getAttribute(RichFaces.ATTR_COLUMNS));
- } catch (NumberFormatException e) {
- count = calculateRowColumns(sourceElement, columns);
- }
- return count;
- }
-
- /*
- * Calculate max number of columns per row. For rows, recursive calculate
- * max length.
- */
- private int calculateRowColumns(Element sourceElement, ArrayList<Element> columns)
{
- int count = 0;
- int currentLength = 0;
- for (Element column : columns) {
- if (ComponentUtil.isRendered(column)) {
- String nodeName = column.getNodeName();
- if (nodeName.endsWith(RichFaces.TAG_COLUMN_GROUP)) {
- // Store max calculated value of previous rows.
- count = Math.max(currentLength,count);
- // Calculate number of columns in row.
- currentLength = calculateRowColumns(sourceElement, getColumns(column));
- // Store max calculated value
- count = Math.max(currentLength,count);
- currentLength = 0;
- } else if (nodeName.equals(sourceElement.getPrefix() + Constants.COLON +
RichFaces.TAG_COLUMN) ||
- nodeName.equals(sourceElement.getPrefix() + Constants.COLON +
RichFaces.TAG_COLUMNS)) {
- // For new row, save length of previous.
- if (RichFacesColumnTemplate.isBreakBefore(column)) {
- count = Math.max(currentLength,count);
- currentLength = 0;
- }
- String colspanStr = column.getAttribute("colspan"); //$NON-NLS-1$
- try {
- currentLength += Integer.parseInt(colspanStr);
- } catch (NumberFormatException e) {
- currentLength++;
- }
- } else if (nodeName.endsWith(RichFaces.TAG_COLUMN)) {
- // UIColumn always have colspan == 1.
- currentLength++;
- }
- }
- }
- return Math.max(currentLength,count);
- }
-
-
-
- /**
* @see
org.jboss.tools.vpe.editor.template.VpeAbstractTemplate#validate(org.jboss.tools.vpe.editor.context.VpePageContext,
org.w3c.dom.Node, org.mozilla.interfaces.nsIDOMDocument,
org.jboss.tools.vpe.editor.template.VpeCreationData)
*/
@Override
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesSubTableTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesSubTableTemplate.java 2011-08-25
11:35:14 UTC (rev 34308)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesSubTableTemplate.java 2011-08-25
13:18:41 UTC (rev 34309)
@@ -38,6 +38,11 @@
private static List<String> rowClasses;
private static List<String> columnClasses;
+ private static final String ST_HEADER_CLASS = "dr-subtable-header
rich-subtable-header";
+ private static final String ST_HEADER_CONTINUE_CLASS = "dr-subtable-header-continue
rich-subtable-header-continue";
+ private static final String ST_FOOTER_CLASS = "dr-subtable-footer
rich-subtable-footer";
+ private static final String ST_FOOTER_CONTINUE_CLASS = "dr-subtable-footer-continue
rich-subtable-footer-continue";
+
/** @deprecated no one another template should know about this template */
public static final RichFacesSubTableTemplate DEFAULT_INSTANCE = new
RichFacesSubTableTemplate();
@@ -227,12 +232,10 @@
final nsIDOMElement parentVisualNode, final String facetName,
final String trClass, final String tdClass) {
- final ArrayList<Element> columns = RichFacesDataTableTemplate
- .getColumns(sourceElement);
+ final ArrayList<Element> columns = RichFaces.getColumns(sourceElement);
// final ArrayList<Element> columnsHeaders =
// ComponentUtil.getColumnsWithFacet(columns, facetName);
- final boolean hasColumnWithFacet = RichFacesDataTableTemplate
- .hasColumnWithFacet(columns, facetName);
+ final boolean hasColumnWithFacet = RichFaces.hasColumnWithFacet(columns, facetName);
if (hasColumnWithFacet) {
final nsIDOMElement tr = visualDocument.createElement(HTML.TAG_TR);
parentVisualNode.appendChild(tr);
@@ -260,21 +263,21 @@
}
protected String getHeaderClass() {
- return "dr-subtable-header rich-subtable-header"; //$NON-NLS-1$
+ return ST_HEADER_CLASS;
}
protected String getHeaderContinueClass() {
- return "dr-subtable-header-continue rich-subtable-header-continue";
//$NON-NLS-1$
+ return ST_HEADER_CONTINUE_CLASS;
}
protected String getFooterClass() {
- return "dr-subtable-footer rich-subtable-footer"; //$NON-NLS-1$
+ return ST_FOOTER_CLASS;
}
protected String getFooterContinueClass() {
- return "dr-subtable-footer-continue rich-subtable-footer-continue";
//$NON-NLS-1$
+ return ST_FOOTER_CONTINUE_CLASS;
}
-
+
protected String getRowClass(final int row) {
String rowClass = DEAFAULT_CELL_CLASS;
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/util/RichFaces.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/util/RichFaces.java 2011-08-25
11:35:14 UTC (rev 34308)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/util/RichFaces.java 2011-08-25
13:18:41 UTC (rev 34309)
@@ -14,9 +14,12 @@
import java.util.ArrayList;
import java.util.List;
+import org.jboss.tools.jsf.vpe.richfaces.ComponentUtil;
+import org.jboss.tools.jsf.vpe.richfaces.template.RichFacesColumnTemplate;
import org.jboss.tools.vpe.editor.template.expression.VpeExpression;
import org.jboss.tools.vpe.editor.template.expression.VpeExpressionBuilder;
import org.jboss.tools.vpe.editor.template.expression.VpeExpressionBuilderException;
+import org.jboss.tools.vpe.editor.util.Constants;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -166,12 +169,98 @@
return list;
}
+ /**
+ * Reads COLLAPSED_STATE attribute's value from the source node
+ *
+ * @param sourceNode the verifiable source node
+ * @return true, if node is collapsed
+ */
public static boolean readCollapsedStateFromSourceNode(Node sourceNode) {
- boolean colapsed = false;
+ boolean isCollapsed = false;
String collapsedState = (String) sourceNode.getUserData(COLLAPSED_STATE);
if ((collapsedState != null) &&
("true".equalsIgnoreCase(collapsedState))){ //$NON-NLS-1$
- colapsed = true;
+ isCollapsed = true;
}
- return colapsed;
+ return isCollapsed;
}
+
+ public static ArrayList<Element> getColumns(Node parentSourceElement) {
+ ArrayList<Element> columns = new ArrayList<Element>();
+ NodeList children = parentSourceElement.getChildNodes();
+ for(int i=0; i<children.getLength(); i++) {
+ Node child = children.item(i);
+ String nodeName = child.getNodeName();
+ if((child instanceof Element) && (nodeName.endsWith(TAG_COLUMN)
+ || nodeName.endsWith(TAG_COLUMNS))) {
+ columns.add((Element)child);
+ }
+ }
+ return columns;
+ }
+
+ /**
+ * Returns true if and only if {@code columns} contains at least one column that have
facet
+ * with given {@code facetName}.
+ */
+ public static boolean hasColumnWithFacet(ArrayList<Element> columns, String
facetName) {
+ for (Element column : columns) {
+ Node body = ComponentUtil.getFacet(column, facetName, true);
+ if(body!=null) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static int getColumnsCount(Element sourceElement, ArrayList<Element>
columns) {
+ int count = 0;
+ // check for exact value in component
+ try {
+ count = Integer.parseInt(sourceElement.getAttribute(ATTR_COLUMNS));
+ } catch (NumberFormatException e) {
+ count = calculateRowColumns(sourceElement, columns);
+ }
+ return count;
+ }
+
+ /*
+ * Calculate max number of columns per row.
+ * For rows, recursive calculate max length.
+ */
+ public static int calculateRowColumns(Element sourceElement, ArrayList<Element>
columns) {
+ int count = 0;
+ int currentLength = 0;
+ for (Element column : columns) {
+ if (ComponentUtil.isRendered(column)) {
+ String nodeName = column.getNodeName();
+ if (nodeName.endsWith(TAG_COLUMN_GROUP)) {
+ // Store max calculated value of previous rows.
+ count = Math.max(currentLength,count);
+ // Calculate number of columns in row.
+ currentLength = calculateRowColumns(sourceElement, getColumns(column));
+ // Store max calculated value
+ count = Math.max(currentLength,count);
+ currentLength = 0;
+ } else if (nodeName.equals(sourceElement.getPrefix() + Constants.COLON + TAG_COLUMN)
||
+ nodeName.equals(sourceElement.getPrefix() + Constants.COLON + TAG_COLUMNS)) {
+ // For new row, save length of previous.
+ if (RichFacesColumnTemplate.isBreakBefore(column)) {
+ count = Math.max(currentLength,count);
+ currentLength = 0;
+ }
+ String colspanStr = column.getAttribute("colspan"); //$NON-NLS-1$
+ try {
+ currentLength += Integer.parseInt(colspanStr);
+ } catch (NumberFormatException e) {
+ currentLength++;
+ }
+ } else if (nodeName.endsWith(TAG_COLUMN)) {
+ // UIColumn always have colspan == 1.
+ currentLength++;
+ }
+ }
+ }
+ return Math.max(currentLength, count);
+ }
+
}