Author: dsakovich
Date: 2007-10-15 13:29:09 -0400 (Mon, 15 Oct 2007)
New Revision: 4207
Added:
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/tree/divLine.gif
Modified:
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/tree/tree.css
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesRecursiveTreeNodesAdaptorTemplate.java
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTreeNodeTemplate.java
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTreeNodesAdaptorTemplate.java
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTreeTemplate.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-847 add RichFaces
treeNodesAdaptor,recursiveTreeNodesAdaptor
Added:
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/tree/divLine.gif
===================================================================
(Binary files differ)
Property changes on:
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/tree/divLine.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified:
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/tree/tree.css
===================================================================
---
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/tree/tree.css 2007-10-15
17:25:04 UTC (rev 4206)
+++
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/tree/tree.css 2007-10-15
17:29:09 UTC (rev 4207)
@@ -10,8 +10,8 @@
}
.dr-tree-h-ic-div {
- margin-left: 8px;
- padding-left: 14px;
+ margin-left: 10px;
+ padding-left: 12px;
}
.dr-tree-full-width {
Modified:
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesRecursiveTreeNodesAdaptorTemplate.java
===================================================================
---
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesRecursiveTreeNodesAdaptorTemplate.java 2007-10-15
17:25:04 UTC (rev 4206)
+++
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesRecursiveTreeNodesAdaptorTemplate.java 2007-10-15
17:29:09 UTC (rev 4207)
@@ -1,106 +1,202 @@
-/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and 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
- *
- * Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.jsf.vpe.richfaces.template;
-
-import org.jboss.tools.jsf.vpe.richfaces.HtmlComponentUtil;
-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.mozilla.interfaces.nsIDOMDocument;
-import org.mozilla.interfaces.nsIDOMElement;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-/**
- * Create template for rich:recursiveTreeNodesAdaptor element
- *
- * @author dsakovich(a)exadel.com
- *
- */
-public class RichFacesRecursiveTreeNodesAdaptorTemplate extends
- VpeAbstractTemplate {
- private final static String TREE_NODE_NAME = "treeNode";
-
- private static final String TREE_TABLE_ATR_CELLSPACING_VALUE = "0px";
-
- private static final String TREE_TABLE_ATR_CELLPADDING_VALUE = "0px";
-
- private static final String TREE_TABLE_ATR_BORDER_VALUE = "0px";
-
- public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
- nsIDOMDocument visualDocument) {
- nsIDOMElement visualElement = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TABLE);
- addBasicTreeNodeAttributes(visualElement);
- VpeCreationData vpeCreationData = new VpeCreationData(visualElement);
- parseTree(pageContext, sourceNode, visualDocument, vpeCreationData,
- visualElement);
- return vpeCreationData;
- }
-
- /**
- *
- * Function for parsing tree by tree nodes;
- *
- * @param pageContext
- * @param sourceNode
- * @param visualDocument
- * @return
- */
- public void parseTree(VpePageContext pageContext, Node sourceNode,
- nsIDOMDocument visualDocument, VpeCreationData vpeCreationData,
- nsIDOMElement parentElement) {
- NodeList nodeList = sourceNode.getChildNodes();
- Element element = null;
- int lenght = nodeList.getLength();
- String treeNodeName = sourceNode.getPrefix() + ":" + TREE_NODE_NAME;
- VpeChildrenInfo vpeChildrenInfo = null;
- for (int i = 0; i < lenght; i++) {
- if (!(nodeList.item(i) instanceof Element)) {
- continue;
- }
- element = (Element) nodeList.item(i);
- if (element.getNodeName().equals(treeNodeName)) {
- nsIDOMElement tr = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TR);
- nsIDOMElement td = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TD);
- tr.appendChild(td);
- vpeChildrenInfo = new VpeChildrenInfo(td);
- vpeCreationData.addChildrenInfo(vpeChildrenInfo);
- vpeChildrenInfo.addSourceChild(element);
- parentElement.appendChild(tr);
- }
- }
- }
-
- /**
- * Set attributes for treeNode
- *
- * @param table
- */
- private void addBasicTreeNodeAttributes(nsIDOMElement table) {
- if (table == null) {
- return;
- }
- table.setAttribute(HtmlComponentUtil.HTML_CELLPADDING_ATTR,
- TREE_TABLE_ATR_CELLPADDING_VALUE);
- table.setAttribute(HtmlComponentUtil.HTML_CELLSPACING_ATTR,
- TREE_TABLE_ATR_CELLSPACING_VALUE);
- table.setAttribute(HtmlComponentUtil.HTML_BORDER_ATTR,
- TREE_TABLE_ATR_BORDER_VALUE);
- table.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
- "dr-tree-full-width");
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and 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
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jsf.vpe.richfaces.template;
+
+import org.jboss.tools.jsf.vpe.richfaces.ComponentUtil;
+import org.jboss.tools.jsf.vpe.richfaces.HtmlComponentUtil;
+import org.jboss.tools.jsf.vpe.richfaces.RichFacesTemplatesActivator;
+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.mozilla.interfaces.nsIDOMDocument;
+import org.mozilla.interfaces.nsIDOMElement;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Create template for rich:recursiveTreeNodesAdaptor element
+ *
+ * @author dsakovich(a)exadel.com
+ *
+ */
+public class RichFacesRecursiveTreeNodesAdaptorTemplate extends
+ VpeAbstractTemplate {
+
+ private static final String TREE_NAME = "tree";
+
+ private final static String TREE_NODE_NAME = "treeNode";
+
+ public final static String TREE_NODES_ADAPTOR_NAME = "treeNodesAdaptor";
+
+ public final static String RECURSIVE_TREE_NODES_ADAPTOR_NAME =
"recursiveTreeNodesAdaptor";
+
+ private static final String STYLE_PATH = "/tree/tree.css";
+
+ public static final String ICON_DIV_LINE = "/tree/divLine.gif";
+
+ private static final String ADAPTER_LINES_STYLE = "background-position: left
center; background-repeat: repeat-y;";
+
+ public static final String ID_ATTR_NAME = "ID";
+
+ public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
+ nsIDOMDocument visualDocument) {
+ ComponentUtil.setCSSLink(pageContext, STYLE_PATH,
+ "recursiveTreeNodesAdaptor");
+ nsIDOMElement visualElement = visualDocument
+ .createElement(HtmlComponentUtil.HTML_TAG_DIV);
+ visualElement.setAttribute(ID_ATTR_NAME,
+ RECURSIVE_TREE_NODES_ADAPTOR_NAME);
+ if (isHasParentAdapter(sourceNode)) {
+ visualElement.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
+ "dr-tree-h-ic-div");
+ if (getShowLinesAttr(sourceNode)
+ && isHasNextParentAdaptorElement(sourceNode)) {
+ String path = RichFacesTemplatesActivator
+ .getPluginResourcePath()
+ + ICON_DIV_LINE;
+ visualElement.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR,
+ "background-image: url(file://" + path + "); "
+ + ADAPTER_LINES_STYLE);
+ }
+ }
+ VpeCreationData vpeCreationData = new VpeCreationData(visualElement);
+ parseTree(pageContext, sourceNode, visualDocument, vpeCreationData,
+ visualElement);
+ return vpeCreationData;
+ }
+
+ /**
+ *
+ * Function for parsing tree by tree nodes;
+ *
+ * @param pageContext
+ * @param sourceNode
+ * @param visualDocument
+ * @return
+ */
+ public void parseTree(VpePageContext pageContext, Node sourceNode,
+ nsIDOMDocument visualDocument, VpeCreationData vpeCreationData,
+ nsIDOMElement parentElement) {
+ NodeList nodeList = sourceNode.getChildNodes();
+ Element element = null;
+ int lenght = nodeList.getLength();
+ String treeNodeName = sourceNode.getPrefix() + ":" + TREE_NODE_NAME;
+ String treeNodesAdaptorName = sourceNode.getPrefix() + ":"
+ + TREE_NODES_ADAPTOR_NAME;
+ String recursiveTreeNodesAdaptorName = sourceNode.getPrefix() + ":"
+ + RECURSIVE_TREE_NODES_ADAPTOR_NAME;
+ VpeChildrenInfo vpeChildrenInfo = null;
+ for (int i = 0; i < lenght; i++) {
+ if (!(nodeList.item(i) instanceof Element)) {
+ continue;
+ }
+ element = (Element) nodeList.item(i);
+ if (element.getNodeName().equals(treeNodeName)
+ || element.getNodeName().equals(
+ recursiveTreeNodesAdaptorName)) {
+ vpeChildrenInfo = new VpeChildrenInfo(parentElement);
+ vpeCreationData.addChildrenInfo(vpeChildrenInfo);
+ vpeChildrenInfo.addSourceChild(element);
+ } else if (element.getNodeName().equals(treeNodesAdaptorName)) {
+ vpeChildrenInfo = new VpeChildrenInfo(parentElement);
+ vpeCreationData.addChildrenInfo(vpeChildrenInfo);
+ vpeChildrenInfo.addSourceChild(element);
+ }
+ }
+ }
+
+ /**
+ *
+ * @param sourceNode
+ * @return
+ */
+ public boolean isHasParentAdapter(Node sourceNode) {
+ String treeNodesAdaptorName = sourceNode.getPrefix() + ":"
+ + TREE_NODES_ADAPTOR_NAME;
+ String recursiveTreeNodesAdaptorName = sourceNode.getPrefix() + ":"
+ + RECURSIVE_TREE_NODES_ADAPTOR_NAME;
+ Node node = sourceNode.getParentNode();
+ if (node.getNodeName().equals(treeNodesAdaptorName)
+ || node.getNodeName().equals(recursiveTreeNodesAdaptorName)) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Get showConnectingLines attribute
+ *
+ * @param sourceNode
+ * @return
+ */
+ private boolean getShowLinesAttr(Node sourceNode) {
+ String treeName = sourceNode.getPrefix() + ":" + TREE_NAME;
+ do {
+ sourceNode = sourceNode.getParentNode();
+ if (!(sourceNode instanceof Element)) {
+ return true;
+ }
+ } while (!sourceNode.getNodeName().equals(treeName));
+
+ String showLinesParam = ((Element) sourceNode)
+ .getAttribute(RichFacesTreeTemplate.SHOW_LINES_ATTR_NAME);
+
+ boolean showLinesValue = true;
+ if (showLinesParam != null &&
showLinesParam.equalsIgnoreCase("false")) {
+ showLinesValue = false;
+ }
+ return showLinesValue;
+ }
+
+ /**
+ * Has Next element
+ *
+ * @param sourceNode
+ * @return
+ */
+ private boolean isHasNextParentAdaptorElement(Node sourceNode) {
+ Node parentTree = sourceNode.getParentNode();
+ if (!(parentTree instanceof Element)) {
+ return true;
+ }
+ NodeList childs = parentTree.getChildNodes();
+ String treeNodeName = parentTree.getPrefix() + ":"
+ + RichFacesTreeTemplate.TREE_NODE_NAME;
+ String treeNodesAdaptorName = parentTree.getPrefix() + ":"
+ + RichFacesTreeTemplate.TREE_NODES_ADAPTOR;
+ String treeRecursiveNodesAdaptorName = parentTree.getPrefix() + ":"
+ + RichFacesTreeTemplate.TREE_RECURSIVE_NODES_ADAPTOR;
+ Node lastElement = null;
+ Node el = null;
+
+ for (int i = 0; i < childs.getLength(); i++) {
+ el = childs.item(i);
+ if (!(el instanceof Element)) {
+ continue;
+ }
+
+ if (lastElement != null) {
+ break;
+ }
+ if (el.equals(sourceNode)) {
+ lastElement = el;
+ }
+ }
+ if (el.getNodeName().equals(treeNodeName)
+ || el.getNodeName().equals(treeNodesAdaptorName)
+ || el.getNodeName().equals(treeRecursiveNodesAdaptorName)) {
+ return true;
+ }
+ return false;
+ }
+}
Modified:
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTreeNodeTemplate.java
===================================================================
---
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTreeNodeTemplate.java 2007-10-15
17:25:04 UTC (rev 4206)
+++
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTreeNodeTemplate.java 2007-10-15
17:29:09 UTC (rev 4207)
@@ -224,9 +224,9 @@
// creates icon with status of node(collapsed or not) node
nsIDOMElement td1 = visualDocument
.createElement(HtmlComponentUtil.HTML_TAG_TD);
-
// sets icon node
- if (!isLastElement(sourceNode) && isAdaptorChild(sourceNode)) {
+ if (!isLastElement(sourceNode) && isAdaptorChild(sourceNode)
+ && !isHasNextAdaptorElement(sourceNode)) {
backgroundLinePath = RichFacesTemplatesActivator
.getPluginResourcePath()
+ ICON_LINE;
@@ -238,7 +238,32 @@
(Element) sourceNode, iconNode, NODE_ICON_ATTR_NAME,
showLinesValue == true ? ICON_NODE_WITH_LINE
: ICON_NODE_WITHOUT_LINES);
- } else if ((isAdaptorChild(sourceNode) && isLastElement(sourceNode) &&
isLastElementAfterAdaptor(sourceNode))
+ } else if (!isLastElement(sourceNode) && isAdaptorChild(sourceNode)
+ && isHasNextAdaptorElement(sourceNode)) {
+ backgroundLinePath = RichFacesTemplatesActivator
+ .getPluginResourcePath()
+ + ICON_LINE;
+ setAttributeForPictureNode(pageContext, visualDocument,
+ (Element) sourceNode, td1, NODE_ICON_EXPANDED_ATTR_NAME,
+ showLinesValue == true ? ICON_EXPANDED_ADAPTER_WITH_LINES
+ : ICON_EXPANDED_ADAPTER_WITHOUT_LINES);
+ setAttributeForPictureNode(pageContext, visualDocument,
+ (Element) sourceNode, iconNode, NODE_ICON_ATTR_NAME,
+ showLinesValue == true ? ICON_NODE_WITH_LINES
+ : ICON_NODE_WITHOUT_LINES);
+ if (showLinesValue) {
+ String path = RichFacesTemplatesActivator
+ .getPluginResourcePath()
+ + ICON_LEFT_LINE;
+ iconNode.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR,
+ "background-image: url(file://" + path + "); "
+ + NODE_LINES_STYLE);
+ }
+ } else if ((isAdaptorChild(sourceNode) && isLastElement(sourceNode) &&
(isLastElementAfterAdaptor(sourceNode) == isAdaptorInTree(sourceNode)) /*
+ * &&
+ * (isAdaptorInTree(sourceNode) ==
+ * isLastElementAfterAdaptor(sourceNode))
+ */)
|| (!isAdaptorChild(sourceNode) && isLastElement(sourceNode))) {
backgroundLinePath = RichFacesTemplatesActivator
.getPluginResourcePath()
@@ -315,8 +340,8 @@
nsIDOMDocument visualDocument, nsIDOMNode visualNode, Object data,
String name, String value) {
/*
- * processed only next attributes iconExpanded and icon, becouse tree
- * allways shows as expanded and information is it leaf or not contains
+ * processed only next attributes iconExpanded and icon, because tree
+ * always shows as expanded and information is it leaf or not contains
* in model
*/
if (NODE_ICON_EXPANDED_ATTR_NAME.equalsIgnoreCase(name)) {
@@ -326,7 +351,6 @@
nsIDOMElement img = (nsIDOMElement) expandedIconCell
.getChildNodes().item(0).queryInterface(
nsIDOMElement.NS_IDOMELEMENT_IID);
-
ComponentUtil.setImgFromResources(pageContext, img, value,
UNDEFINED_ICON);
img.setAttribute(ICON_PARAM_NAME, "");
@@ -336,7 +360,6 @@
.item(1).queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
nsIDOMElement img = (nsIDOMElement) iconCell.getChildNodes()
.item(0).queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
-
ComponentUtil.setImgFromResources(pageContext, img, value,
UNDEFINED_ICON);
img.setAttribute(ICON_PARAM_NAME, "");
@@ -346,7 +369,6 @@
.item(1).queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
nsIDOMElement img = (nsIDOMElement) iconCell.getChildNodes()
.item(0).queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
-
ComponentUtil.setImgFromResources(pageContext, img, value,
UNDEFINED_ICON);
img.setAttribute(ICON_PARAM_NAME, "");
@@ -358,8 +380,8 @@
Element sourceElement, nsIDOMDocument visualDocument,
nsIDOMNode visualNode, Object data, String name) {
/*
- * processed only next attributes iconExpanded and icon, becouse tree
- * allways shows as expanded and information is it leaf or not contains
+ * processed only next attributes iconExpanded and icon, because tree
+ * always shows as expanded and information is it leaf or not contains
* in model
*/
@@ -371,7 +393,6 @@
nsIDOMElement img = (nsIDOMElement) expandedIconCell
.getChildNodes().item(0).queryInterface(
nsIDOMElement.NS_IDOMELEMENT_IID);
-
String parentAttrName = ((Element) sourceElement.getParentNode())
.getAttribute(NODE_ICON_EXPANDED_ATTR_NAME);
if (parentAttrName == null || parentAttrName.length() == 0) {
@@ -392,7 +413,6 @@
nsIDOMElement img = (nsIDOMElement) iconCell.getChildNodes()
.item(0).queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
-
String parentAttrName = ((Element) sourceElement.getParentNode())
.getAttribute(NODE_ICON_ATTR_NAME);
if (parentAttrName == null || parentAttrName.length() == 0) {
@@ -411,7 +431,6 @@
.item(1).queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
nsIDOMElement img = (nsIDOMElement) iconCell.getChildNodes()
.item(0).queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
-
String parentAttrName = ((Element) sourceElement.getParentNode())
.getAttribute(NODE_ICON_LEAF_ATTR_NAME);
if (parentAttrName == null || parentAttrName.length() == 0) {
@@ -428,9 +447,41 @@
/**
*
+ * @param parentTree
* @param sourceNode
* @return
*/
+ private boolean isLastElement(nsIDOMNode sourceNode) {
+ nsIDOMNode parentTree = sourceNode.getParentNode();
+ if (!(parentTree instanceof Element)) {
+ return true;
+ }
+ nsIDOMNodeList childs = parentTree.getChildNodes();
+ String treeNodeName = parentTree.getPrefix() + ":"
+ + RichFacesTreeTemplate.TREE_NODE_NAME;
+ String treeNodesAdaptorName = parentTree.getPrefix() + ":"
+ + RichFacesTreeTemplate.TREE_NODES_ADAPTOR;
+ String treeRecursiveNodesAdaptorName = parentTree.getPrefix() + ":"
+ + RichFacesTreeTemplate.TREE_RECURSIVE_NODES_ADAPTOR;
+ nsIDOMNode lastElement = null;
+ nsIDOMNode el = null;
+ for (int i = 0; i < childs.getLength(); i++) {
+ el = childs.item(i);
+ if (el.getNodeName().equals(treeNodeName)
+ || el.getNodeName().equals(treeNodesAdaptorName)
+ || el.getNodeName().equals(treeRecursiveNodesAdaptorName)) {
+ lastElement = el;
+ }
+ }
+ return sourceNode.equals(lastElement);
+ }
+
+ /**
+ * Node is Adaptor child
+ *
+ * @param sourceNode
+ * @return
+ */
private boolean isAdaptorChild(Node sourceNode) {
Node parentNode = sourceNode.getParentNode();
if (!(parentNode instanceof Element)) {
@@ -450,6 +501,7 @@
}
/**
+ * Node is last element
*
* @param parentTree
* @param sourceNode
@@ -481,34 +533,42 @@
}
/**
+ * Next element is Adaptor
*
- * @param parentTree
* @param sourceNode
* @return
*/
- private boolean isLastElement(nsIDOMNode sourceNode) {
- nsIDOMNode parentTree = sourceNode.getParentNode();
+ private boolean isHasNextAdaptorElement(Node sourceNode) {
+ Node parentTree = sourceNode.getParentNode();
if (!(parentTree instanceof Element)) {
return true;
}
- nsIDOMNodeList childs = parentTree.getChildNodes();
- String treeNodeName = parentTree.getPrefix() + ":"
- + RichFacesTreeTemplate.TREE_NODE_NAME;
+ NodeList childs = parentTree.getChildNodes();
String treeNodesAdaptorName = parentTree.getPrefix() + ":"
+ RichFacesTreeTemplate.TREE_NODES_ADAPTOR;
String treeRecursiveNodesAdaptorName = parentTree.getPrefix() + ":"
+ RichFacesTreeTemplate.TREE_RECURSIVE_NODES_ADAPTOR;
- nsIDOMNode lastElement = null;
- nsIDOMNode el = null;
+ Node lastElement = null;
+ Node el = null;
+
for (int i = 0; i < childs.getLength(); i++) {
el = childs.item(i);
- if (el.getNodeName().equals(treeNodeName)
- || el.getNodeName().equals(treeNodesAdaptorName)
- || el.getNodeName().equals(treeRecursiveNodesAdaptorName)) {
+ if (!(el instanceof Element)) {
+ continue;
+ }
+
+ if (lastElement != null) {
+ break;
+ }
+ if (el.equals(sourceNode)) {
lastElement = el;
}
}
- return sourceNode.equals(lastElement);
+ if (el.getNodeName().equals(treeNodesAdaptorName)
+ || el.getNodeName().equals(treeRecursiveNodesAdaptorName)) {
+ return true;
+ }
+ return false;
}
/**
@@ -567,6 +627,7 @@
}
/**
+ * Node has element after adaptor
*
* @param sourceNode
* @return
@@ -578,4 +639,30 @@
}
return isLastElement(nodeAdaptor);
}
+
+ /**
+ *
+ * @param sourceNode
+ * @return
+ */
+ private boolean isAdaptorInTree(Node sourceNode) {
+ Node adaptorNode = sourceNode.getParentNode();
+ if (!(adaptorNode instanceof Element)) {
+ return true;
+ }
+ String treeNodesAdaptorName = adaptorNode.getPrefix() + ":"
+ + RichFacesTreeTemplate.TREE_NODES_ADAPTOR;
+ String treeRecursiveNodesAdaptorName = adaptorNode.getPrefix() + ":"
+ + RichFacesTreeTemplate.TREE_RECURSIVE_NODES_ADAPTOR;
+ if (adaptorNode.getNodeName().equals(treeNodesAdaptorName)
+ || adaptorNode.getNodeName().equals(
+ treeRecursiveNodesAdaptorName)) {
+ Node treeNode = adaptorNode.getParentNode();
+ String treeName = treeNode.getPrefix() + ":" + TREE_NAME;
+ if (treeNode.getNodeName().equals(treeName)) {
+ return true;
+ }
+ }
+ return false;
+ }
}
Modified:
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTreeNodesAdaptorTemplate.java
===================================================================
---
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTreeNodesAdaptorTemplate.java 2007-10-15
17:25:04 UTC (rev 4206)
+++
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTreeNodesAdaptorTemplate.java 2007-10-15
17:29:09 UTC (rev 4207)
@@ -10,7 +10,9 @@
******************************************************************************/
package org.jboss.tools.jsf.vpe.richfaces.template;
+import org.jboss.tools.jsf.vpe.richfaces.ComponentUtil;
import org.jboss.tools.jsf.vpe.richfaces.HtmlComponentUtil;
+import org.jboss.tools.jsf.vpe.richfaces.RichFacesTemplatesActivator;
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.template.VpeAbstractTemplate;
import org.jboss.tools.vpe.editor.template.VpeChildrenInfo;
@@ -29,19 +31,41 @@
*/
public class RichFacesTreeNodesAdaptorTemplate extends VpeAbstractTemplate {
+ private static final String TREE_NAME = "tree";
+
private final static String TREE_NODE_NAME = "treeNode";
- private static final String TREE_TABLE_ATR_CELLSPACING_VALUE = "0px";
+ public final static String TREE_NODES_ADAPTOR_NAME = "treeNodesAdaptor";
- private static final String TREE_TABLE_ATR_CELLPADDING_VALUE = "0px";
+ public final static String RECURSIVE_TREE_NODES_ADAPTOR_NAME =
"recursiveTreeNodesAdaptor";
- private static final String TREE_TABLE_ATR_BORDER_VALUE = "0px";
+ private static final String STYLE_PATH = "/tree/tree.css";
+ public static final String ICON_DIV_LINE = "/tree/divLine.gif";
+
+ private static final String ADAPTER_LINES_STYLE = "background-position: left
center; background-repeat: repeat-y;";
+
+ public static final String ID_ATTR_NAME = "ID";
+
public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
nsIDOMDocument visualDocument) {
+ ComponentUtil.setCSSLink(pageContext, STYLE_PATH, "treeNodesAdaptor");
nsIDOMElement visualElement = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TABLE);
- addBasicTreeNodeAttributes(visualElement);
+ .createElement(HtmlComponentUtil.HTML_TAG_DIV);
+ visualElement.setAttribute(ID_ATTR_NAME, TREE_NODES_ADAPTOR_NAME);
+ if (isHasParentAdapter(sourceNode)) {
+ visualElement.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
+ "dr-tree-h-ic-div");
+ if (getShowLinesAttr(sourceNode)
+ && isHasNextParentAdaptorElement(sourceNode)) {
+ String path = RichFacesTemplatesActivator
+ .getPluginResourcePath()
+ + ICON_DIV_LINE;
+ visualElement.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR,
+ "background-image: url(file://" + path + "); "
+ + ADAPTER_LINES_STYLE);
+ }
+ }
VpeCreationData vpeCreationData = new VpeCreationData(visualElement);
parseTree(pageContext, sourceNode, visualDocument, vpeCreationData,
visualElement);
@@ -64,42 +88,112 @@
Element element = null;
int lenght = nodeList.getLength();
String treeNodeName = sourceNode.getPrefix() + ":" + TREE_NODE_NAME;
+ String treeNodesAdaptorName = sourceNode.getPrefix() + ":"
+ + TREE_NODES_ADAPTOR_NAME;
+ String recursiveTreeNodesAdaptorName = sourceNode.getPrefix() + ":"
+ + RECURSIVE_TREE_NODES_ADAPTOR_NAME;
VpeChildrenInfo vpeChildrenInfo = null;
for (int i = 0; i < lenght; i++) {
if (!(nodeList.item(i) instanceof Element)) {
continue;
}
element = (Element) nodeList.item(i);
- if (element.getNodeName().equals(treeNodeName)) {
- nsIDOMElement tr = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TR);
- nsIDOMElement td = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TD);
- tr.appendChild(td);
- vpeChildrenInfo = new VpeChildrenInfo(td);
+ if (element.getNodeName().equals(treeNodeName)
+ || element.getNodeName().equals(
+ recursiveTreeNodesAdaptorName)) {
+ vpeChildrenInfo = new VpeChildrenInfo(parentElement);
vpeCreationData.addChildrenInfo(vpeChildrenInfo);
vpeChildrenInfo.addSourceChild(element);
- parentElement.appendChild(tr);
+ } else if (element.getNodeName().equals(treeNodesAdaptorName)) {
+ vpeChildrenInfo = new VpeChildrenInfo(parentElement);
+ vpeCreationData.addChildrenInfo(vpeChildrenInfo);
+ vpeChildrenInfo.addSourceChild(element);
}
}
}
/**
- * Set attributes for treeNode
*
- * @param table
+ * @param sourceNode
+ * @return
*/
- private void addBasicTreeNodeAttributes(nsIDOMElement table) {
- if (table == null) {
- return;
+ public boolean isHasParentAdapter(Node sourceNode) {
+ String treeNodesAdaptorName = sourceNode.getPrefix() + ":"
+ + TREE_NODES_ADAPTOR_NAME;
+ String recursiveTreeNodesAdaptorName = sourceNode.getPrefix() + ":"
+ + RECURSIVE_TREE_NODES_ADAPTOR_NAME;
+ Node node = sourceNode.getParentNode();
+ if (node.getNodeName().equals(treeNodesAdaptorName)
+ || node.getNodeName().equals(recursiveTreeNodesAdaptorName)) {
+ return true;
}
- table.setAttribute(HtmlComponentUtil.HTML_CELLPADDING_ATTR,
- TREE_TABLE_ATR_CELLPADDING_VALUE);
- table.setAttribute(HtmlComponentUtil.HTML_CELLSPACING_ATTR,
- TREE_TABLE_ATR_CELLSPACING_VALUE);
- table.setAttribute(HtmlComponentUtil.HTML_BORDER_ATTR,
- TREE_TABLE_ATR_BORDER_VALUE);
- table.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
- "dr-tree-full-width");
+ return false;
}
+
+ /**
+ * Get showConnectingLines attribute
+ *
+ * @param sourceNode
+ * @return
+ */
+ private boolean getShowLinesAttr(Node sourceNode) {
+ String treeName = sourceNode.getPrefix() + ":" + TREE_NAME;
+ do {
+ sourceNode = sourceNode.getParentNode();
+ if (!(sourceNode instanceof Element)) {
+ return true;
+ }
+ } while (!sourceNode.getNodeName().equals(treeName));
+
+ String showLinesParam = ((Element) sourceNode)
+ .getAttribute(RichFacesTreeTemplate.SHOW_LINES_ATTR_NAME);
+
+ boolean showLinesValue = true;
+ if (showLinesParam != null &&
showLinesParam.equalsIgnoreCase("false")) {
+ showLinesValue = false;
+ }
+ return showLinesValue;
+ }
+
+ /**
+ * Has Next element
+ *
+ * @param sourceNode
+ * @return
+ */
+ private boolean isHasNextParentAdaptorElement(Node sourceNode) {
+ Node parentTree = sourceNode.getParentNode();
+ if (!(parentTree instanceof Element)) {
+ return true;
+ }
+ NodeList childs = parentTree.getChildNodes();
+ String treeNodeName = parentTree.getPrefix() + ":"
+ + RichFacesTreeTemplate.TREE_NODE_NAME;
+ String treeNodesAdaptorName = parentTree.getPrefix() + ":"
+ + RichFacesTreeTemplate.TREE_NODES_ADAPTOR;
+ String treeRecursiveNodesAdaptorName = parentTree.getPrefix() + ":"
+ + RichFacesTreeTemplate.TREE_RECURSIVE_NODES_ADAPTOR;
+ Node lastElement = null;
+ Node el = null;
+
+ for (int i = 0; i < childs.getLength(); i++) {
+ el = childs.item(i);
+ if (!(el instanceof Element)) {
+ continue;
+ }
+
+ if (lastElement != null) {
+ break;
+ }
+ if (el.equals(sourceNode)) {
+ lastElement = el;
+ }
+ }
+ if (el.getNodeName().equals(treeNodeName)
+ || el.getNodeName().equals(treeNodesAdaptorName)
+ || el.getNodeName().equals(treeRecursiveNodesAdaptorName)) {
+ return true;
+ }
+ return false;
+ }
}
Modified:
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTreeTemplate.java
===================================================================
---
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTreeTemplate.java 2007-10-15
17:25:04 UTC (rev 4206)
+++
branches/jbosstools_xulrunner/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTreeTemplate.java 2007-10-15
17:29:09 UTC (rev 4207)
@@ -10,8 +10,10 @@
******************************************************************************/
package org.jboss.tools.jsf.vpe.richfaces.template;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
import org.jboss.tools.jsf.vpe.richfaces.ComponentUtil;
import org.jboss.tools.jsf.vpe.richfaces.HtmlComponentUtil;
+import org.jboss.tools.jsf.vpe.richfaces.RichFacesTemplatesActivator;
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.template.VpeAbstractTemplate;
import org.jboss.tools.vpe.editor.template.VpeChildrenInfo;
@@ -20,6 +22,7 @@
import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMNode;
import org.mozilla.interfaces.nsIDOMNodeList;
+import org.mozilla.xpcom.XPCOMException;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -140,7 +143,7 @@
*/
private void setAttributeToTree(nsIDOMNode node, String attrName,
String attrValue) {
- if (!(node instanceof nsIDOMElement)) {
+ if (!(node instanceof Element)) {
return;
}
if (node.getNodeName().equalsIgnoreCase(
@@ -169,6 +172,8 @@
* Object <code>VpeCreationData</code>, built by a method
* <code>create</code>
*/
+
+ @Override
public void validate(VpePageContext pageContext, Node sourceNode,
nsIDOMDocument visualDocument, VpeCreationData data) {
super.validate(pageContext, sourceNode, visualDocument, data);
@@ -180,22 +185,41 @@
*
* @param node
*/
+ /**
+ * Revert tree elements in right order.
+ *
+ * @param node
+ */
private void revertTableRows(nsIDOMNode node) {
- nsIDOMNodeList list = node.getChildNodes();
- if (node.getNodeName().equalsIgnoreCase(HtmlComponentUtil.HTML_TAG_DIV)
- && list.getLength() == 2) {
- nsIDOMNode table1 = list.item(0);
- nsIDOMNode table2 = list.item(1);
- node.removeChild(table1);
- node.removeChild(table2);
- node.appendChild(table2);
- node.appendChild(table1);
+ try {
+ nsIDOMNodeList list = node.getChildNodes();
+ nsIDOMElement element = (nsIDOMElement) node
+ .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
+ String id = element
+ .getAttribute(RichFacesTreeNodesAdaptorTemplate.ID_ATTR_NAME);
+ if (id == null)
+ id = "";
+ if (node.getNodeName().equalsIgnoreCase(
+ HtmlComponentUtil.HTML_TAG_DIV)
+ && list.getLength() == 2
+ && !(id
+ .equalsIgnoreCase(RichFacesTreeNodesAdaptorTemplate.TREE_NODES_ADAPTOR_NAME) ||
id
+
.equalsIgnoreCase(RichFacesTreeNodesAdaptorTemplate.RECURSIVE_TREE_NODES_ADAPTOR_NAME)))
{
+ nsIDOMNode table1 = list.item(0);
+ nsIDOMNode table2 = list.item(1);
+ node.removeChild(table1);
+ node.removeChild(table2);
+ node.appendChild(table2);
+ node.appendChild(table1);
+ }
+ nsIDOMNodeList list2 = node.getChildNodes();
+ for (int i = 0; i < list2.getLength(); i++) {
+ revertTableRows(list2.item(i));
+ }
+ } catch (XPCOMException e) {
+ return;
}
- nsIDOMNodeList list2 = node.getChildNodes();
- for (int i = 0; i < list2.getLength(); i++) {
- revertTableRows(list2.item(i));
- }
}
/**