Author: yradtsevich
Date: 2008-11-06 15:51:30 -0500 (Thu, 06 Nov 2008)
New Revision: 11597
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesDataTableChildrenEncoder.java
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesColumnGroupTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesColumnTemplate.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/RichFacesOrderingList.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesScrollableDataTableTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesSubTableTemplate.java
Log:
CODING IN PROGRESS - issue JBIDE-2984: Wrap <rich:*Table> in <tbody>
https://jira.jboss.org/jira/browse/JBIDE-2984
Templates have been fixed: <rich:columnGroup>, <rich:column>,
<rich:dataTable>, <rich:orderingList>, <rich:scrollableDataTable>,
<rich:subTable>.
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesColumnGroupTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesColumnGroupTemplate.java 2008-11-06
20:37:35 UTC (rev 11596)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesColumnGroupTemplate.java 2008-11-06
20:51:30 UTC (rev 11597)
@@ -21,7 +21,8 @@
public class RichFacesColumnGroupTemplate extends RichFacesSubTableTemplate {
- public static RichFacesColumnGroupTemplate DEFAULT_INSTANCE = new
RichFacesColumnGroupTemplate();
+ /** @deprecated no one another template should know about this template */
+ public static final RichFacesColumnGroupTemplate DEFAULT_INSTANCE = new
RichFacesColumnGroupTemplate();
private static String styleClass;
public RichFacesColumnGroupTemplate() {
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesColumnTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesColumnTemplate.java 2008-11-06
20:37:35 UTC (rev 11596)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesColumnTemplate.java 2008-11-06
20:51:30 UTC (rev 11597)
@@ -17,7 +17,6 @@
import org.jboss.tools.jsf.vpe.richfaces.template.util.RichFaces;
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.mapping.VpeDomMapping;
-import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
import org.jboss.tools.vpe.editor.template.VpeAbstractTemplate;
import org.jboss.tools.vpe.editor.template.VpeChildrenInfo;
import org.jboss.tools.vpe.editor.template.VpeCreationData;
@@ -31,7 +30,7 @@
import org.w3c.dom.Node;
public class RichFacesColumnTemplate extends VpeAbstractTemplate {
- private static final String HEADER_ICON_STYLE = "vertical-align:middle;";
+ private static final String HEADER_ICON_STYLE = "vertical-align:middle;";
//$NON-NLS-1$
private static final String SORTABLE_PATH = "column/sortable.gif";
//$NON-NLS-1$
public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
nsIDOMDocument visualDocument) {
@@ -50,7 +49,9 @@
VpeChildrenInfo tdInfo = new VpeChildrenInfo(td);
List<Node> children = ComponentUtil.getChildren(sourceElement,true);
for (Node child : children) {
- tdInfo.addSourceChild(child);
+ if (!isFacet(child)) {
+ tdInfo.addSourceChild(child);
+ }
}
creationData.addChildrenInfo(tdInfo);
@@ -62,6 +63,14 @@
return creationData;
}
+ /**@param child a node
+ * @return <code>true</code>, if the <code>node</code> is
<code>rich:facet</code> tag,
+ * <code>false</code> otherwise*/
+ private boolean isFacet(Node child) {
+ boolean ret = child.getNodeName().endsWith(RichFaces.TAG_FACET);
+ return ret;
+ }
+
private String getColumnClass(Element sourceElement) {
String columnClass;
if(isHeader(sourceElement)) {
@@ -152,4 +161,10 @@
return null;
}
}
+
+ public static boolean isBreakBefore(Node child) {
+ String breakBeforeVal = ((Element)child).getAttribute(RichFaces.ATTR_BREAK_BEFORE);
+ boolean breakBefore = breakBeforeVal != null &&
breakBeforeVal.equalsIgnoreCase(RichFaces.VAL_TRUE);
+ return breakBefore;
+ }
}
\ No newline at end of file
Added:
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
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesDataTableChildrenEncoder.java 2008-11-06
20:51:30 UTC (rev 11597)
@@ -0,0 +1,127 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jsf.vpe.richfaces.template;
+
+import java.util.List;
+
+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.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.mozilla.interfaces.nsIDOMNode;
+import org.mozilla.interfaces.nsIDOMNodeList;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**@author yradtsevich */
+class RichFacesDataTableChildrenEncoder {
+ private static final String TAG_SUB_TABLE_OR_COLUMN_GROUP_CONTAINER =
"subTableOrColumnGroup-container"; //$NON-NLS-1$
+ private VpeCreationData creationData;
+ private nsIDOMDocument visualDocument;
+ private Element sourceElement;
+ private nsIDOMElement table;
+
+ public RichFacesDataTableChildrenEncoder(VpeCreationData creationData,
+ nsIDOMDocument visualDocument, Element sourceElement,
+ nsIDOMElement table) {
+ this.creationData = creationData;
+ this.visualDocument = visualDocument;
+ this.sourceElement = sourceElement;
+ this.table = table;
+ }
+
+ public void encodeChildren() {
+ // Create mapping to Encode body
+ List<Node> children = ComponentUtil.getChildren(sourceElement);
+ boolean createNewRow = true;
+ for (Node child : children) {
+ String nodeName = child.getNodeName();
+ if (nodeName.endsWith(RichFaces.TAG_COLUMN) ||
+ nodeName.endsWith(RichFaces.TAG_COLUMNS)) {
+ createNewRow |= RichFacesColumnTemplate.isBreakBefore(child);
+ addColumnToRow(child, createNewRow);
+ createNewRow = false;
+ } else if(nodeName.endsWith(RichFaces.TAG_SUB_TABLE)
+ || nodeName.endsWith(RichFaces.TAG_COLUMN_GROUP)) {
+ addSubTableOrColumnGroupToTable(child);
+ createNewRow = true;
+ } else {
+ VpeChildrenInfo childInfo = new VpeChildrenInfo(table);
+ childInfo.addSourceChild(child);
+ creationData.addChildrenInfo(childInfo);
+ createNewRow = true;
+ }
+ }
+ }
+
+ private nsIDOMElement addSubTableOrColumnGroupToTable(Node subTableOrColumnGroupNode) {
+ nsIDOMElement subTableOrColumnGroupContainer =
visualDocument.createElement(TAG_SUB_TABLE_OR_COLUMN_GROUP_CONTAINER);
+ table.appendChild(subTableOrColumnGroupContainer);
+ VpeChildrenInfo childInfo = new VpeChildrenInfo(subTableOrColumnGroupContainer);
+ childInfo.addSourceChild(subTableOrColumnGroupNode);
+ creationData.addChildrenInfo(childInfo);
+
+ return subTableOrColumnGroupContainer;
+ }
+
+ private nsIDOMElement currentRow = null;
+ private VpeChildrenInfo currentRowChildrenInfo = null;
+ private int rowNumber = 0;
+ private nsIDOMElement addColumnToRow(Node columnNode, boolean createNewRow) {
+ if ( createNewRow || (currentRow == null) ) {
+ currentRow = visualDocument.createElement(HTML.TAG_TR);
+ table.appendChild(currentRow);
+ currentRowChildrenInfo = new VpeChildrenInfo(currentRow);
+ creationData.addChildrenInfo(currentRowChildrenInfo);
+ rowNumber++;
+ if (rowNumber == 1) {
+ currentRow.setAttribute(HTML.ATTR_CLASS, "dr-table-firstrow
rich-table-firstrow"); //$NON-NLS-1$
+ } else {
+ currentRow.setAttribute(HTML.ATTR_CLASS, "dr-table-row rich-table-row");
//$NON-NLS-1$
+ }
+ }
+
+ currentRowChildrenInfo.addSourceChild(columnNode);
+ return currentRow;
+ }
+
+ public static void validateChildren(VpePageContext pageContext, Node sourceNode,
+ nsIDOMDocument visualDocument, VpeCreationData creationData) {
+ nsIDOMNode visualNode = creationData.getNode();
+ fixSubTables(visualNode);
+ }
+
+ private static void fixSubTables(nsIDOMNode node) {
+ nsIDOMElement element = (nsIDOMElement) node;
+ nsIDOMNodeList subTableContainers =
element.getElementsByTagName(TAG_SUB_TABLE_OR_COLUMN_GROUP_CONTAINER);
+ long length = subTableContainers.getLength();
+ for (int i = 0; i < length; i++) {
+ nsIDOMNode subTableContainer = subTableContainers.item(0);
+ nsIDOMNodeList subTableContainerChildren = subTableContainer.getChildNodes();
+ nsIDOMNode containerParent = subTableContainer.getParentNode();
+ if (subTableContainerChildren != null
+ && subTableContainerChildren.getLength() == 1) {
+ nsIDOMNode subTableMainTag = subTableContainerChildren.item(0);
+ subTableContainer.removeChild(subTableMainTag);
+ containerParent.insertBefore(subTableMainTag, subTableContainer);
+ } else {
+ RuntimeException e = new RuntimeException("This is probably a bug.
subTable-container should have one inner tag.");//$NON-NLS-1$
+ RichFacesTemplatesActivator.getPluginLog().logError(e);
+ }
+ containerParent.removeChild(subTableContainer);
+ }
+ }
+}
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 2008-11-06
20:37:35 UTC (rev 11596)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesDataTableTemplate.java 2008-11-06
20:51:30 UTC (rev 11597)
@@ -7,12 +7,11 @@
*
* Contributors:
* Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ ******************************************************************************/
package org.jboss.tools.jsf.vpe.richfaces.template;
import java.util.ArrayList;
import java.util.List;
-
import org.jboss.tools.jsf.vpe.richfaces.ComponentUtil;
import org.jboss.tools.jsf.vpe.richfaces.template.util.RichFaces;
import org.jboss.tools.vpe.editor.context.VpePageContext;
@@ -30,8 +29,6 @@
public class RichFacesDataTableTemplate extends VpeAbstractTemplate {
- private static final String ATTR_BREAK_BEFORE = "breakBefore"; //$NON-NLS-1$
-
public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
nsIDOMDocument visualDocument) {
Element sourceElement = (Element)sourceNode;
@@ -119,50 +116,9 @@
}
}
- nsIDOMElement tbody = visualDocument.createElement(HTML.TAG_TBODY);
- table.appendChild(tbody);
+ new RichFacesDataTableChildrenEncoder(creationData, visualDocument,
+ sourceElement, table).encodeChildren();
- // Create mapping to Encode body
- List<Node> children = ComponentUtil.getChildren(sourceElement);
- boolean firstRow = true;
- nsIDOMElement tr = null;
- VpeChildrenInfo trInfo = null;
- for (Node child : children) {
- String nodeName = child.getNodeName();
- if(nodeName.endsWith(RichFaces.TAG_COLUMN) ||
- nodeName.endsWith(RichFaces.TAG_COLUMNS)) {
- String breakBefore = ((Element)child).getAttribute(ATTR_BREAK_BEFORE);
- if(breakBefore!=null && breakBefore.equalsIgnoreCase(Constants.TRUE)) {
- tr = null;
- }
- if(tr==null) {
- tr = visualDocument.createElement(HTML.TAG_TR);
- if(firstRow) {
- tr.setAttribute(HTML.ATTR_CLASS, "dr-table-firstrow
rich-table-firstrow"); //$NON-NLS-1$
- firstRow = false;
- } else {
- tr.setAttribute(HTML.ATTR_CLASS, "dr-table-row rich-table-row");
//$NON-NLS-1$
- }
- trInfo = new VpeChildrenInfo(tr);
- tbody.appendChild(tr);
- creationData.addChildrenInfo(trInfo);
- }
- trInfo.addSourceChild(child);
-
- } else if(nodeName.endsWith(RichFaces.TAG_COLUMN_GROUP)) {
- RichFacesColumnGroupTemplate.DEFAULT_INSTANCE.encode(pageContext, creationData,
(Element)child, visualDocument, tbody);
- tr = null;
- } else if(nodeName.endsWith(RichFaces.TAG_SUB_TABLE)) {
- RichFacesSubTableTemplate.DEFAULT_INSTANCE.encode(pageContext, creationData,
(Element)child, visualDocument, tbody);
- tr = null;
- } else {
- VpeChildrenInfo childInfo = new VpeChildrenInfo(tbody);
- childInfo.addSourceChild(child);
- creationData.addChildrenInfo(childInfo);
- tr = null;
- }
- }
-
return creationData;
}
@@ -225,7 +181,9 @@
}
}
- 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 element) {
boolean isColumnGroup = facetBody.getNodeName().endsWith(RichFaces.TAG_COLUMN_GROUP);
boolean isSubTable = facetBody.getNodeName().endsWith(RichFaces.TAG_SUB_TABLE);
if(isColumnGroup) {
@@ -342,7 +300,7 @@
} 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 (Boolean.getBoolean(column.getAttribute(ATTR_BREAK_BEFORE))) {
+ if (Boolean.getBoolean(column.getAttribute(RichFaces.ATTR_BREAK_BEFORE))) {
count = Math.max(currentLength,count);
currentLength = 0;
}
@@ -370,19 +328,7 @@
@Override
public void validate(VpePageContext pageContext, Node sourceNode,
nsIDOMDocument visualDocument, VpeCreationData data) {
- Element sourceElement = (Element) sourceNode;
- List<Node> children = ComponentUtil.getChildren(sourceElement);
- if (children != null) {
- for (Node child : children) {
- if (child.getNodeName().endsWith(RichFaces.TAG_COLUMN_GROUP)) {
- RichFacesColumnGroupTemplate.DEFAULT_INSTANCE.validate(pageContext, child,
visualDocument, data);
- } else if (child.getNodeName().endsWith(RichFaces.TAG_SUB_TABLE)) {
- RichFacesSubTableTemplate.DEFAULT_INSTANCE.validate(pageContext, child,
visualDocument, data);
- }
- }
- }
-
- super.validate(pageContext, sourceNode, visualDocument, data);
+ RichFacesDataTableChildrenEncoder.validateChildren(pageContext, sourceNode,
visualDocument, data);
}
@Override
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesOrderingList.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesOrderingList.java 2008-11-06
20:37:35 UTC (rev 11596)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesOrderingList.java 2008-11-06
20:51:30 UTC (rev 11597)
@@ -445,8 +445,6 @@
.createElement(HtmlComponentUtil.HTML_TAG_THEAD);
nsIDOMElement tfoot = visualDocument
.createElement(HtmlComponentUtil.HTML_TAG_TFOOT);
- nsIDOMElement tbody = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TBODY);
ArrayList<Element> columns = getColumns(sourceElement);
int columnsLength = getColumnsCount(sourceElement, columns);
@@ -524,8 +522,11 @@
String listWidth = sourceElement.getAttribute(LIST_WIDTH);
String listHeight = sourceElement.getAttribute(LIST_HEIGHT);
String listClass = sourceElement.getAttribute(LIST_CLASS);
- String rowClasses = sourceElement.getAttribute(ROW_CLASSES);
+ // TODO: implement support of rowClasses
+ // following line commented by yradtsevich because the variable rowClasses was not
used
+ //String rowClasses = sourceElement.getAttribute(ROW_CLASSES);
+
String divStyle = HtmlComponentUtil.HTML_WIDTH_ATTR + " : "
+ (listWidth == null ? DEFAULT_LIST_WIDTH : listWidth) + ";"
+ HtmlComponentUtil.HTML_HEIGHT_ATTR + " : "
@@ -544,44 +545,10 @@
contentTable.removeAttribute(HtmlComponentUtil.HTML_ATR_HEIGHT);
contentTable.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, "width:
100%;");
- // Create mapping to Encode body
- for (int i = 0; i < NUM_ROW; i++) {
- List<Node> children = ComponentUtil.getChildren(sourceElement);
- nsIDOMElement tr = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TR);
- tr.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, CSS_LIST_ROW_CLASS + " "
+ (null == rowClasses ? "" : rowClasses) );
- VpeChildrenInfo trInfo = new VpeChildrenInfo(tr);
- tbody.appendChild(tr);
- creationData.addChildrenInfo(trInfo);
-
- for (Node child : children) {
- String nodeName = child.getNodeName();
- if (nodeName.endsWith(COLUMN) || nodeName.endsWith(COLUMNS)) {
- trInfo.addSourceChild(child);
- } else if (nodeName.endsWith(":columnGroup")) {
- RichFacesColumnGroupTemplate.DEFAULT_INSTANCE.encode(pageContext,
- creationData, (Element) child, visualDocument,
- tbody);
- tr = null;
- trInfo = null;
- } else if (nodeName.endsWith(":subTable")) {
- RichFacesSubTableTemplate.DEFAULT_INSTANCE.encode(pageContext,
- creationData, (Element) child, visualDocument,
- tbody);
- tr = null;
- trInfo = null;
- } else {
- VpeChildrenInfo childInfo = new VpeChildrenInfo(tbody);
- childInfo.addSourceChild(child);
- creationData.addChildrenInfo(childInfo);
- tr = null;
- trInfo = null;
- }
- }
- }
-
- // ---------- FINILAZING -----------
+ // ---------- FINALIZING and children encoding -----------
contentTable.appendChild(thead);
- contentTable.appendChild(tbody);
+ new RichFacesDataTableChildrenEncoder(creationData, visualDocument,
+ sourceElement, contentTable).encodeChildren();
//contentTable.appendChild(tfoot);
contentDiv.appendChild(contentTable);
//outputDiv.appendChild(contentDiv);
@@ -937,4 +904,12 @@
nsIDOMElement visualNode, Object data, String name, String value) {
return true;
}
+
+ /* (non-Javadoc)
+ * @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
+ public void validate(VpePageContext pageContext, Node sourceNode,
+ nsIDOMDocument visualDocument, VpeCreationData data) {
+ RichFacesDataTableChildrenEncoder.validateChildren(pageContext, sourceNode,
visualDocument, data);
+ }
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesScrollableDataTableTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesScrollableDataTableTemplate.java 2008-11-06
20:37:35 UTC (rev 11596)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesScrollableDataTableTemplate.java 2008-11-06
20:51:30 UTC (rev 11597)
@@ -231,53 +231,9 @@
.createElement(HtmlComponentUtil.HTML_TAG_TBODY);
table.appendChild(tbody);
- // Create mapping to Encode body
for (int i = 0; i < NUM_ROW; i++) {
- List<Node> children = ComponentUtil.getChildren(sourceElement);
- boolean firstRow = true;
- nsIDOMElement tr = null;
- VpeChildrenInfo trInfo = null;
- for (Node child : children) {
- if (child.getNodeName().endsWith(COLUMN) || child.getNodeName().endsWith(COLUMNS)) {
- String breakBefore = ((Element) child)
- .getAttribute("breakBefore");
- if (breakBefore != null
- && breakBefore.equalsIgnoreCase("true")) {
- tr = null;
- }
- if (tr == null) {
- tr = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TR);
- if (firstRow) {
- tr.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
- "dr-table-firstrow rich-table-firstrow");
- firstRow = false;
- } else {
- tr.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
- "dr-table-row rich-table-row");
- }
- trInfo = new VpeChildrenInfo(tr);
- tbody.appendChild(tr);
- creationData.addChildrenInfo(trInfo);
- }
- trInfo.addSourceChild(child);
- } else if (child.getNodeName().endsWith(":columnGroup")) {
- RichFacesColumnGroupTemplate.DEFAULT_INSTANCE.encode(pageContext,
- creationData, (Element) child, visualDocument,
- tbody);
- tr = null;
- } else if (child.getNodeName().endsWith(":subTable")) {
- RichFacesSubTableTemplate.DEFAULT_INSTANCE.encode(pageContext,
- creationData, (Element) child, visualDocument,
- tbody);
- tr = null;
- } else {
- VpeChildrenInfo childInfo = new VpeChildrenInfo(tbody);
- childInfo.addSourceChild(child);
- creationData.addChildrenInfo(childInfo);
- tr = null;
- }
- }
+ new RichFacesDataTableChildrenEncoder(creationData, visualDocument,
+ sourceElement, table).encodeChildren();
}
return creationData;
@@ -503,7 +459,7 @@
int span = Integer.parseInt(sourceElement.getAttribute("columns"));
count = count > 0 ? span : calculateRowColumns(sourceElement, columns);
} catch (NumberFormatException e) {
- count = count = calculateRowColumns(sourceElement, columns);
+ count = calculateRowColumns(sourceElement, columns);
}
return count;
}
@@ -590,6 +546,14 @@
return true;
}
+ /* (non-Javadoc)
+ * @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
+ public void validate(VpePageContext pageContext, Node sourceNode,
+ nsIDOMDocument visualDocument, VpeCreationData data) {
+ RichFacesDataTableChildrenEncoder.validateChildren(pageContext, sourceNode,
visualDocument, data);
+ }
+
// @Override
// public void removeAttribute(VpePageContext pageContext,
// Element sourceElement, nsIDOMDocument visualDocument,
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 2008-11-06
20:37:35 UTC (rev 11596)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesSubTableTemplate.java 2008-11-06
20:51:30 UTC (rev 11597)
@@ -41,22 +41,14 @@
private static final String DEAFAULT_CELL_CLASS = "dr-subtable-cell
rich-subtable-cell"; //$NON-NLS-1$
private static List<String> rowClasses;
private static List<String> columnClasses;
- public static RichFacesSubTableTemplate DEFAULT_INSTANCE = new
RichFacesSubTableTemplate();
+
+ /** @deprecated no one another template should know about this template */
+ public static final RichFacesSubTableTemplate DEFAULT_INSTANCE = new
RichFacesSubTableTemplate();
-
public RichFacesSubTableTemplate() {
super();
}
-
- /**
- * Encode columnGroup
- * @param creationData
- * @param columnGroupSourceElement
- * @param visualDocument
- * @param parentVisualNode
- * @return
- */
public VpeCreationData encode(final VpePageContext pageContext, VpeCreationData
creationData, final Element sourceElement,
final nsIDOMDocument visualDocument, nsIDOMElement parentVisualNode) {
@@ -114,7 +106,7 @@
curTr = visualDocument.createElement(HTML.TAG_TR);
ComponentUtil.copyAttributes(sourceElement, curTr);
- if(header) {
+ if (header) {
curTr.setAttribute(HTML.ATTR_CLASS, getHeaderContinueClass());
} else if(footer) {
curTr.setAttribute(HTML.ATTR_CLASS, getFooterContinueClass());
@@ -150,17 +142,26 @@
public void validate(final VpePageContext pageContext, final Node sourceNode,
final nsIDOMDocument visualDocument, final VpeCreationData creationData) {
initClasses(sourceNode, pageContext);
- final List<VpeChildrenInfo> childrenInfoList =
creationData.getChildrenInfoList();
- if (childrenInfoList != null) {
- for (final VpeChildrenInfo childrenInfo : childrenInfoList) {
- final List<Node> sourceChildren = childrenInfo.getSourceChildren();
- if (sourceChildren != null
- && sourceChildren.size() > 0
- && sourceChildren.get(0).getParentNode() == sourceNode) {
- final nsIDOMNodeList visualChildren =
childrenInfo.getVisualParent().getChildNodes();
- addStylesToCells(visualDocument, visualChildren);
+
+ nsIDOMNode visualNode = creationData.getNode();
+ if (visualNode != null && visualNode.getNodeName().equals(HTML.TAG_TBODY)) {
+ // we are called by VpeVisualDomBuilder
+ addStylesToCells(visualDocument, visualNode.getChildNodes());
+ } else {
+ // we are called by a validator of another template
+ // TODO: this case should be removed when no one template will call the method
+ final List<VpeChildrenInfo> childrenInfoList =
creationData.getChildrenInfoList();
+ if (childrenInfoList != null) {
+ for (final VpeChildrenInfo childrenInfo : childrenInfoList) {
+ final List<Node> sourceChildren = childrenInfo.getSourceChildren();
+ if (sourceChildren != null
+ && sourceChildren.size() > 0
+ && sourceChildren.get(0).getParentNode() == sourceNode) {
+ final nsIDOMNodeList visualChildren =
childrenInfo.getVisualParent().getChildNodes();
+ addStylesToCells(visualDocument, visualChildren);
+ }
}
- }
+ }
}
}
@@ -184,7 +185,9 @@
public VpeCreationData create(final VpePageContext pageContext, final Node sourceNode,
final nsIDOMDocument visualDocument) {
final Element sourceElement = (Element)sourceNode;
- final VpeCreationData creationData = encode(pageContext, null, sourceElement,
visualDocument, null);
+ final nsIDOMElement tbody = visualDocument.createElement(HTML.TAG_TBODY);
+ VpeCreationData creationData = new VpeCreationData(tbody);
+ creationData = encode(pageContext, creationData, sourceElement, visualDocument,
tbody);
return creationData;
}
@@ -296,8 +299,7 @@
/* (non-Javadoc)
- * @see
org.jboss.tools.vpe.editor.template.VpeAbstractTemplate#isRecreateAtAttrChange(org.jboss.tools.vpe.editor.context.VpePageContext,
org.w3c.dom.Element, org.mozilla.interfaces.nsIDOMDocument,
org.mozilla.interfaces.nsIDOMElement, java.lang.Object, java.lang.String,
java.lang.String)
- */
+ * @see
org.jboss.tools.vpe.editor.template.VpeAbstractTemplate#isRecreateAtAttrChange(org.jboss.tools.vpe.editor.context.VpePageContext,
org.w3c.dom.Element, org.mozilla.interfaces.nsIDOMDocument,
org.mozilla.interfaces.nsIDOMElement, java.lang.Object, java.lang.String,
java.lang.String) */
@Override
public boolean isRecreateAtAttrChange(final VpePageContext pageContext,
final Element sourceElement, final nsIDOMDocument visualDocument,
@@ -307,8 +309,7 @@
/* (non-Javadoc)
- * @see
org.jboss.tools.vpe.editor.template.VpeAbstractTemplate#getNodeForUptate(org.jboss.tools.vpe.editor.context.VpePageContext,
org.w3c.dom.Node, org.mozilla.interfaces.nsIDOMNode, java.lang.Object)
- */
+ * @see
org.jboss.tools.vpe.editor.template.VpeAbstractTemplate#getNodeForUptate(org.jboss.tools.vpe.editor.context.VpePageContext,
org.w3c.dom.Node, org.mozilla.interfaces.nsIDOMNode, java.lang.Object) */
@Override
public Node getNodeForUptate(VpePageContext pageContext, Node sourceNode,
nsIDOMNode visualNode, Object data) {