Author: dmaliarevich
Date: 2008-12-17 12:56:32 -0500 (Wed, 17 Dec 2008)
New Revision: 12645
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesAbstractTreeTemplate.java
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesRecursiveTreeNodesAdaptorTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTreeNodeTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTreeNodesAdaptorTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTreeTemplate.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-883, code adjustment.
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesAbstractTreeTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesAbstractTreeTemplate.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesAbstractTreeTemplate.java 2008-12-17
17:56:32 UTC (rev 12645)
@@ -0,0 +1,689 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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:
+ * 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.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.template.VpeAbstractTemplate;
+import org.jboss.tools.vpe.editor.template.VpeChildrenInfo;
+import org.jboss.tools.vpe.editor.template.VpeCreationData;
+import org.jboss.tools.vpe.editor.util.Constants;
+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.mozilla.interfaces.nsIDOMText;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public abstract class RichFacesAbstractTreeTemplate extends VpeAbstractTemplate {
+
+ public static final String TREE = "tree"; //$NON-NLS-1$
+ public static final String TREE_NODE = "treeNode"; //$NON-NLS-1$
+ public static final String TREE_NODES_ADAPTOR = "treeNodesAdaptor";
//$NON-NLS-1$
+ public static final String RECURSIVE_TREE_NODES_ADAPTOR =
"recursiveTreeNodesAdaptor"; //$NON-NLS-1$
+ public static final String SHOW_LINES_ATTR_NAME = "showConnectingLines";
//$NON-NLS-1$
+
+ public static final String DEFAULT_ICON_PARAM_VALUE = "DEFAULT_ICON_PARAM";
//$NON-NLS-1$
+ public static final String ICON_PARAM_NAME = "richFacesTreeNodeParam";
//$NON-NLS-1$
+ public static final String DEFAULT_ICON_EXPANDED_PARAM_VALUE =
"DEFAULT_ICON_EXPANDED_PARAM"; //$NON-NLS-1$
+ public static final String UNDEFINED_ICON = "/tree/unresolved.gif";
//$NON-NLS-1$
+ public static final String NODE_ICON_LEAF_ATTR_NAME = "iconLeaf";
//$NON-NLS-1$
+ public static final String ICON_NODE_WITH_LINES =
"/tree/iconNodeWithLines.gif"; //$NON-NLS-1$
+ public static final String ICON_NODE_WITH_LINE =
"/tree/iconNodeWithLine.gif"; //$NON-NLS-1$
+ public static final String ICON_EXPANDED_WITH_LINES =
"/tree/iconCollapsedWithLines.gif"; //$NON-NLS-1$
+ public static final String ICON_NODE_WITHOUT_LINES = "/tree/iconNode.gif";
//$NON-NLS-1$
+ public static final String ICON_EXPANDED_WITHOUT_LINES =
"/tree/iconCollapsed.gif"; //$NON-NLS-1$
+ public static final String ICON_NOT_EXPANDED_WITH_LINES =
"/tree/iconNotCollapsedWithLines.gif"; //$NON-NLS-1$
+ public static final String ICON_NOT_EXPANDED_WITH_ALL_LINES =
"/tree/iconNotCollapsedWithAllLines.gif"; //$NON-NLS-1$
+ public static final String ICON_NOT_EXPANDED_WITHOUT_LINES =
"/tree/iconNotCollapsed.gif"; //$NON-NLS-1$
+ public static final String ICON_EXPANDED_ADAPTER_WITH_LINES =
"/tree/iconClosedNodeWithLines.gif"; //$NON-NLS-1$
+ public static final String ICON_EXPANDED_ADAPTER_WITHOUT_LINES =
"/tree/iconClosedNode.gif"; //$NON-NLS-1$
+ public static final String ICON_LEAF_WITH_LINES =
"/tree/iconLeafWithLines.gif"; //$NON-NLS-1$
+ public static final String ICON_RIGHT_LINE = "/tree/rightLine.gif";
//$NON-NLS-1$
+ public static final String ICON_LEFT_LINE = "/tree/leftLine.gif";
//$NON-NLS-1$
+ public static final String ICON_LINE = "/tree/line.gif"; //$NON-NLS-1$
+ public static final String ICON_LEAF_WITHOUT_LINES = "/tree/iconLeaf.gif";
//$NON-NLS-1$
+ protected static final String TREE_TABLE_PICTURE_STYLE_CLASS_NAME =
"treePictureStyle"; //$NON-NLS-1$
+ protected static final String STYLE_CLASS_FOR_NODE_TITLE =
"treeNodeNameStyle"; //$NON-NLS-1$
+ protected static final String NODE_TITLE_STYLE_CLASS_ATTR_NAME =
"nodeClass"; //$NON-NLS-1$
+ protected static final String NODE_ICON_EXPANDED_ATTR_NAME =
"iconExpanded"; //$NON-NLS-1$
+ protected static final String NODE_ICON_ATTR_NAME = "icon"; //$NON-NLS-1$
+ protected static final String TREE_TABLE_ATR_CELLSPACING_VALUE = "0px";
//$NON-NLS-1$
+ protected static final String TREE_TABLE_ATR_CELLPADDING_VALUE = "0px";
//$NON-NLS-1$
+ protected static final String TREE_TABLE_ATR_BORDER_VALUE = "0px";
//$NON-NLS-1$
+ protected static final String NODE_LINES_STYLE = "background-position: center;
background-repeat: repeat-y;"; //$NON-NLS-1$
+
+ /**
+ * Get showConnectingLines attribute
+ *
+ * @param sourceNode
+ * @return
+ */
+ protected boolean getShowLinesAttr(Node sourceNode) {
+ String treeName = sourceNode.getPrefix() + Constants.COLON + TREE;
+ do {
+ sourceNode = sourceNode.getParentNode();
+ if (!(sourceNode instanceof Element)) {
+ return true;
+ }
+ } while (!sourceNode.getNodeName().equals(treeName));
+
+ String showLinesParam = ((Element) sourceNode)
+ .getAttribute(SHOW_LINES_ATTR_NAME);
+
+ boolean showLinesValue = true;
+ if (showLinesParam != null
+ && Constants.FALSE.equalsIgnoreCase(showLinesParam)) {
+ showLinesValue = false;
+ }
+ return showLinesValue;
+ }
+
+ /**
+ * Is adapter between treeNodes
+ *
+ * @param sourceNode
+ * @return
+ */
+ protected boolean isAdapterBetweenNodes(Node sourceNode) {
+ Node parentNode = sourceNode.getParentNode();
+ NodeList childs = parentNode.getChildNodes();
+ Node beforeAdapterNode = null;
+ Node afterAdapterNode = null;
+ Node adapterNode = null;
+ String treeNodeName = sourceNode.getPrefix() + Constants.COLON
+ + TREE_NODE;
+ for (int i = 0; i < childs.getLength(); i++) {
+ Node el = childs.item(i);
+ if (!(el instanceof Element)) {
+ continue;
+ }
+ if (el.equals(sourceNode)) {
+ adapterNode = el;
+ } else {
+ if (el.getNodeName().equals(treeNodeName)) {
+ if (adapterNode == null) {
+ beforeAdapterNode = el;
+ } else {
+ afterAdapterNode = el;
+ }
+ }
+
+ }
+
+ }
+
+ if (beforeAdapterNode != null && afterAdapterNode != null) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Next element is Adaptor
+ *
+ * @param sourceNode
+ * @return
+ */
+ protected boolean isHasNextAdaptorElement(Node sourceNode) {
+ Node parentTree = sourceNode.getParentNode();
+ if (!(parentTree instanceof Element)) {
+ return true;
+ }
+ NodeList childs = parentTree.getChildNodes();
+ String treeNodesAdaptorName = parentTree.getPrefix() + Constants.COLON
+ + TREE_NODES_ADAPTOR;
+ String treeRecursiveNodesAdaptorName = parentTree.getPrefix()
+ + Constants.COLON + RECURSIVE_TREE_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 (sourceNode.equals(el)) {
+ lastElement = el;
+ }
+ }
+ if (el.getNodeName().equals(treeNodesAdaptorName)
+ || el.getNodeName().equals(treeRecursiveNodesAdaptorName)) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Has Next element
+ *
+ * @param sourceNode
+ * @return
+ */
+ protected boolean isHasNextParentAdaptorElement(Node sourceNode) {
+ Node tree = sourceNode.getParentNode();
+ if (!(tree instanceof Element)) {
+ return true;
+ }
+ Node parentTree = tree.getParentNode();
+ if (!(parentTree instanceof Element)) {
+ return true;
+ }
+ NodeList childs = parentTree.getChildNodes();
+ String treeNodeName = parentTree.getPrefix() + Constants.COLON
+ + TREE_NODE;
+ String treeNodesAdaptorName = parentTree.getPrefix() + Constants.COLON
+ + TREE_NODES_ADAPTOR;
+ String treeRecursiveNodesAdaptorName = parentTree.getPrefix()
+ + Constants.COLON + RECURSIVE_TREE_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(tree)) {
+ lastElement = el;
+ }
+ }
+
+ if (el.getNodeName().equals(treeNodeName)
+ || el.getNodeName().equals(treeNodesAdaptorName)
+ || el.getNodeName().equals(treeRecursiveNodesAdaptorName)) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ *
+ * @param sourceNode
+ * @return
+ */
+ protected boolean isHasParentAdapter(Node sourceNode) {
+ String treeNodesAdaptorName = sourceNode.getPrefix() + Constants.COLON
+ + TREE_NODES_ADAPTOR;
+ String recursiveTreeNodesAdaptorName = sourceNode.getPrefix()
+ + Constants.COLON + RECURSIVE_TREE_NODES_ADAPTOR;
+ Node node = sourceNode.getParentNode();
+ if (node.getNodeName().equals(treeNodesAdaptorName)
+ || node.getNodeName().equals(recursiveTreeNodesAdaptorName)) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ *
+ * Function for parsing tree by tree nodes;
+ *
+ * @param pageContext
+ * @param sourceNode
+ * @param visualDocument
+ * @return
+ */
+ protected 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() + Constants.COLON
+ + TREE_NODE;
+ String treeNodesAdaptorName = sourceNode.getPrefix() + Constants.COLON
+ + TREE_NODES_ADAPTOR;
+ String recursiveTreeNodesAdaptorName = sourceNode.getPrefix()
+ + Constants.COLON + RECURSIVE_TREE_NODES_ADAPTOR;
+ 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);
+ }
+ }
+ }
+
+ /**
+ * Create simple tree node attribute.Used for creating more complex trees.
+ *
+ * @param treeNodeTitle
+ * @param visualDocument
+ * @return tree
+ */
+ protected void createBasicTree(VpePageContext pageContext,
+ nsIDOMDocument visualDocument, nsIDOMElement treeRow,
+ Node sourceNode, VpeCreationData vpeCreationData) {
+ // creates icon node
+ String backgroundLinePath = null;
+
+ boolean showLinesValue = getShowLinesAttr((Element) sourceNode);
+ nsIDOMElement iconNode = visualDocument.createElement(HTML.TAG_TD);
+ // creates icon with status of node(collapsed or not) node
+ nsIDOMElement td1 = visualDocument.createElement(HTML.TAG_TD);
+ // sets icon node
+ 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_LINE
+ : ICON_NODE_WITHOUT_LINES);
+ } 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(HTML.ATTR_STYLE,
+ "background-image: url(file://" + path + "); " //$NON-NLS-1$
//$NON-NLS-2$
+ + NODE_LINES_STYLE);
+ }
+ } else if ((isAdaptorChild(sourceNode) && isLastElement(sourceNode) &&
(isLastElementAfterAdaptor(sourceNode) == isAdaptorInTree(sourceNode)))
+ || (!isAdaptorChild(sourceNode) && isLastElement(sourceNode))
+ || (isAdaptorChild(sourceNode) && isOnlyOneNodeInAdaptor(sourceNode))) {
+
+ if (isAdaptorChild(sourceNode)
+ && isOnlyOneNodeInAdaptor(sourceNode)
+ && !isLastElementAfterAdaptor(sourceNode)
+ && isHasNextParentAdaptorElement(sourceNode)) {
+ backgroundLinePath = RichFacesTemplatesActivator
+ .getPluginResourcePath()
+ + ICON_LINE;
+ setAttributeForPictureNode(
+ pageContext,
+ visualDocument,
+ (Element) sourceNode,
+ td1,
+ NODE_ICON_EXPANDED_ATTR_NAME,
+ showLinesValue == true ? ICON_NOT_EXPANDED_WITH_ALL_LINES
+ : ICON_NOT_EXPANDED_WITHOUT_LINES);
+ } else {
+ backgroundLinePath = RichFacesTemplatesActivator
+ .getPluginResourcePath()
+ + ICON_RIGHT_LINE;
+ setAttributeForPictureNode(pageContext, visualDocument,
+ (Element) sourceNode, td1,
+ NODE_ICON_EXPANDED_ATTR_NAME,
+ showLinesValue == true ? ICON_NOT_EXPANDED_WITH_LINES
+ : ICON_NOT_EXPANDED_WITHOUT_LINES);
+ }
+
+ setAttributeForPictureNode(pageContext, visualDocument,
+ (Element) sourceNode, iconNode, NODE_ICON_LEAF_ATTR_NAME,
+ showLinesValue == true ? ICON_LEAF_WITH_LINES
+ : ICON_LEAF_WITHOUT_LINES);
+ } else {
+ backgroundLinePath = RichFacesTemplatesActivator
+ .getPluginResourcePath()
+ + ICON_RIGHT_LINE;
+ setAttributeForPictureNode(pageContext, visualDocument,
+ (Element) sourceNode, td1, NODE_ICON_EXPANDED_ATTR_NAME,
+ showLinesValue == true ? ICON_EXPANDED_WITH_LINES
+ : ICON_EXPANDED_WITHOUT_LINES);
+
+ if (showLinesValue) {
+ String path = RichFacesTemplatesActivator
+ .getPluginResourcePath()
+ + ICON_LEFT_LINE;
+ iconNode.setAttribute(HTML.ATTR_STYLE,
+ "background-image: url(file://" + path + "); " //$NON-NLS-1$
//$NON-NLS-2$
+ + NODE_LINES_STYLE);
+ }
+
+ setAttributeForPictureNode(pageContext, visualDocument,
+ (Element) sourceNode, iconNode, NODE_ICON_ATTR_NAME,
+ showLinesValue == true ? ICON_NODE_WITH_LINES
+ : ICON_NODE_WITHOUT_LINES);
+ }
+
+ if (showLinesValue) {
+ td1.setAttribute(HTML.ATTR_STYLE,
+ "background-image: url(file://" + backgroundLinePath //$NON-NLS-1$
+ + "); " + NODE_LINES_STYLE); //$NON-NLS-1$
+ }
+ treeRow.appendChild(td1);
+ treeRow.appendChild(iconNode);
+ // creates Tree Node Name Message
+ nsIDOMElement nodeTitle = visualDocument.createElement(HTML.TAG_TD);
+ addBasicNodeTitleAttributes(nodeTitle);
+ // Create mapping to Encode body
+ String treeRecursiveNodesAdaptorName = sourceNode.getPrefix()
+ + Constants.COLON + RECURSIVE_TREE_NODES_ADAPTOR;
+ if (sourceNode.getNodeName().equals(treeRecursiveNodesAdaptorName)) {
+ Element sourceElement = (Element) sourceNode;
+ String nodes = sourceElement
+ .getAttribute(RichFacesRecursiveTreeNodesAdaptorTemplate.NODES_NAME);
+ nsIDOMElement span = visualDocument.createElement(HTML.TAG_SPAN);
+ nsIDOMText text = visualDocument
+ .createTextNode((nodes == null) ? Constants.EMPTY : nodes);
+ span.appendChild(text);
+ nodeTitle.appendChild(span);
+ } else {
+ VpeChildrenInfo tdInfo = new VpeChildrenInfo(nodeTitle);
+
+ // Create mapping to Encode body
+ List<Node> children = ComponentUtil.getChildren(
+ (Element) sourceNode, false);
+ for (Node child : children) {
+ tdInfo.addSourceChild(child);
+ }
+ vpeCreationData.addChildrenInfo(tdInfo);
+ }
+ treeRow.appendChild(nodeTitle);
+
+ }
+
+ /**
+ *
+ * @param parentTree
+ * @param sourceNode
+ * @return
+ */
+ protected boolean isLastElement(nsIDOMNode sourceNode) {
+ nsIDOMNode parentTree = sourceNode.getParentNode();
+ if (!(parentTree instanceof Element)) {
+ return true;
+ }
+ nsIDOMNodeList childs = parentTree.getChildNodes();
+ String treeNodeName = parentTree.getPrefix() + Constants.COLON
+ + TREE_NODE;
+ String treeNodesAdaptorName = parentTree.getPrefix() + Constants.COLON
+ + TREE_NODES_ADAPTOR;
+ String treeRecursiveNodesAdaptorName = parentTree.getPrefix()
+ + Constants.COLON + RECURSIVE_TREE_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)) {
+ return true;
+ }
+
+ String treeNodesAdaptorName = sourceNode.getPrefix() + Constants.COLON
+ + TREE_NODES_ADAPTOR;
+ String treeRecursiveNodesAdaptorName = sourceNode.getPrefix()
+ + Constants.COLON + RECURSIVE_TREE_NODES_ADAPTOR;
+ if (parentNode.getNodeName().equals(treeNodesAdaptorName)
+ || parentNode.getNodeName().equals(
+ treeRecursiveNodesAdaptorName)) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Node is last element
+ *
+ * @param parentTree
+ * @param sourceNode
+ * @return
+ */
+ protected boolean isLastElement(Node sourceNode) {
+ Node parentTree = sourceNode.getParentNode();
+ if (!(parentTree instanceof Element)) {
+ return true;
+ }
+ NodeList childs = parentTree.getChildNodes();
+ String treeNodeName = parentTree.getPrefix() + Constants.COLON
+ + TREE_NODE;
+ String treeNodesAdaptorName = parentTree.getPrefix() + Constants.COLON
+ + TREE_NODES_ADAPTOR;
+ String treeRecursiveNodesAdaptorName = parentTree.getPrefix()
+ + Constants.COLON + RECURSIVE_TREE_NODES_ADAPTOR;
+ 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)) {
+ lastElement = el;
+ }
+ }
+ return sourceNode.equals(lastElement);
+ }
+
+ /**
+ * Adds basic attributes to tree
+ *
+ * @param img
+ */
+
+ private void addBasicAttributesToPicture(nsIDOMElement img) {
+ img.setAttribute(HTML.ATTR_CLASS, TREE_TABLE_PICTURE_STYLE_CLASS_NAME);
+ }
+
+ /**
+ * Sets attributes for no node title name
+ *
+ * @param nodeTitle
+ */
+ private void addBasicNodeTitleAttributes(nsIDOMElement nodeTitle) {
+ nodeTitle.setAttribute(HTML.ATTR_CLASS, STYLE_CLASS_FOR_NODE_TITLE);
+ }
+
+ /**
+ * Used for setting images into tree nodes
+ *
+ * @param pageContext
+ * page context
+ * @param visualDocument
+ * visual document
+ * @param sourceNode
+ * treeNode element
+ * @param iconCell
+ * cell were image should be setted
+ * @param nodeAttrName
+ * image attr name( icon, iconExpanded, ...)
+ * @param defaultImage
+ * (image by default)
+ */
+ private void setAttributeForPictureNode(VpePageContext pageContext,
+ nsIDOMDocument visualDocument, Element sourceNode,
+ nsIDOMElement iconCell, String nodeAttrName, String defaultImage) {
+ if (RichFacesTemplatesActivator.getDefault().isDebugging()) {
+ System.out.println("call setAttributeForPictureNode"); //$NON-NLS-1$
+ }
+ nsIDOMElement img = visualDocument.createElement(HTML.TAG_IMG);
+ addBasicAttributesToPicture(img);
+ iconCell.appendChild(img);
+ // get image from treeNode
+ String imgName = sourceNode.getAttribute(nodeAttrName);
+ // if in tree node image doesn't exist we get image attr from tree
+ if (imgName == null || imgName.length() == 0) {
+ Node parentElement = sourceNode.getParentNode();
+ if (parentElement instanceof Element) {
+ imgName = ((Element) parentElement).getAttribute(nodeAttrName);
+ }
+ } else {
+ img.setAttribute(ICON_PARAM_NAME, Constants.EMPTY);
+ }
+ // if we can't get attribute from parent we use default attribute
+ addBasicAttributesToPicture(img);
+ iconCell.appendChild(img);
+ if (imgName == null || imgName.length() == 0) {
+ ComponentUtil.setImg(img, defaultImage);
+ } else {
+ ComponentUtil.setImgFromResources(pageContext, img, imgName,
+ UNDEFINED_ICON);
+ }
+ if (nodeAttrName.equals(NODE_ICON_EXPANDED_ATTR_NAME)) {
+ img
+ .setAttribute(ICON_PARAM_NAME,
+ DEFAULT_ICON_EXPANDED_PARAM_VALUE);
+ } else if (nodeAttrName.equals(NODE_ICON_ATTR_NAME)) {
+ img.setAttribute(ICON_PARAM_NAME, DEFAULT_ICON_PARAM_VALUE);
+ } else if (nodeAttrName.equals(NODE_ICON_LEAF_ATTR_NAME)) {
+ img.setAttribute(ICON_PARAM_NAME, NODE_ICON_LEAF_ATTR_NAME);
+ }
+ }
+
+ private boolean isOnlyOneNodeInAdaptor(Node sourceNode) {
+ Node parent = sourceNode.getParentNode();
+ NodeList list = parent.getChildNodes();
+ Node currentNode = null;
+ String treeNodeName = sourceNode.getPrefix() + Constants.COLON
+ + RichFacesTreeTemplate.TREE_NODE_NAME;
+ for (int i = 0; i < list.getLength(); i++) {
+ Node el = list.item(i);
+ if (!(el instanceof Element)) {
+ continue;
+ }
+ if (el.getNodeName().equals(treeNodeName)) {
+ if (currentNode == null) {
+ currentNode = el;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Node has element after adaptor
+ *
+ * @param sourceNode
+ * @return
+ */
+ private boolean isLastElementAfterAdaptor(Node sourceNode) {
+ Node nodeAdaptor = sourceNode.getParentNode();
+ if (!(nodeAdaptor instanceof Element)) {
+ return true;
+ }
+ 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() + Constants.COLON
+ + TREE_NODES_ADAPTOR;
+ String treeRecursiveNodesAdaptorName = adaptorNode.getPrefix()
+ + Constants.COLON + RECURSIVE_TREE_NODES_ADAPTOR;
+ if (adaptorNode.getNodeName().equals(treeNodesAdaptorName)
+ || adaptorNode.getNodeName().equals(
+ treeRecursiveNodesAdaptorName)) {
+ Node treeNode = adaptorNode.getParentNode();
+ String treeName = treeNode.getPrefix() + Constants.COLON + TREE;
+ if (treeNode.getNodeName().equals(treeName)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Set attributes for treeNode
+ *
+ * @param table
+ */
+ protected void addBasicTreeNodeAttributes(nsIDOMElement table) {
+ if (table == null) {
+ return;
+ }
+ table.setAttribute(HTML.ATTR_CELLPADDING,
+ TREE_TABLE_ATR_CELLPADDING_VALUE);
+ table.setAttribute(HTML.ATTR_CELLSPACING,
+ TREE_TABLE_ATR_CELLSPACING_VALUE);
+ table.setAttribute(HTML.ATTR_BORDER, TREE_TABLE_ATR_BORDER_VALUE);
+ table.setAttribute(HTML.ATTR_CLASS, "dr-tree-full-width"); //$NON-NLS-1$
+ }
+
+ /**
+ * Checks for attributes for node and if such exist convert it's to html
+ * atributes.
+ *
+ * @param sourceNode
+ * @param tableRow
+ */
+ protected void addAttributeToTableNode(Element sourceNode,
+ nsIDOMElement tableRow) {
+
+ String attrValue = sourceNode
+ .getAttribute(NODE_TITLE_STYLE_CLASS_ATTR_NAME);
+ if ((attrValue != null) && (attrValue.length() > 0)) {
+ tableRow.setAttribute(HTML.ATTR_CLASS, attrValue);
+ }
+ }
+
+}
Property changes on:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesAbstractTreeTemplate.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesRecursiveTreeNodesAdaptorTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesRecursiveTreeNodesAdaptorTemplate.java 2008-12-17
16:30:18 UTC (rev 12644)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesRecursiveTreeNodesAdaptorTemplate.java 2008-12-17
17:56:32 UTC (rev 12645)
@@ -13,7 +13,6 @@
import org.jboss.tools.jsf.vpe.richfaces.ComponentUtil;
import org.jboss.tools.jsf.vpe.richfaces.RichFacesTemplatesActivator;
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;
@@ -30,36 +29,39 @@
*
*/
public class RichFacesRecursiveTreeNodesAdaptorTemplate extends
- RichFacesTreeNodeTemplate {
+ RichFacesAbstractTreeTemplate {
- private static final String TREE_NAME = "tree"; //$NON-NLS-1$
-
- private final static String TREE_NODE_NAME = "treeNode"; //$NON-NLS-1$
-
- public final static String TREE_NODES_ADAPTOR_NAME = "treeNodesAdaptor";
//$NON-NLS-1$
-
- public final static String RECURSIVE_TREE_NODES_ADAPTOR_NAME =
"recursiveTreeNodesAdaptor"; //$NON-NLS-1$
-
private static final String STYLE_PATH = "/tree/tree.css"; //$NON-NLS-1$
-
public static final String ICON_DIV_LINE = "/tree/divLine.gif";
//$NON-NLS-1$
-
private static final String ADAPTER_LINES_STYLE = "background-position: left
center; background-repeat: repeat-y;"; //$NON-NLS-1$
-
public static final String ID_ATTR_NAME = "ID"; //$NON-NLS-1$
-
public static final String NODES_NAME = "nodes"; //$NON-NLS-1$
public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
nsIDOMDocument visualDocument) {
if (isEmptyNode(sourceNode)) {
- return super.create(pageContext, sourceNode, visualDocument);
+ nsIDOMElement div = visualDocument.createElement(HTML.TAG_DIV);
+ nsIDOMElement visualElement = visualDocument
+ .createElement(HTML.TAG_TABLE);
+ addBasicTreeNodeAttributes(visualElement);
+ div.appendChild(visualElement);
+ nsIDOMElement tbody = visualDocument.createElement(HTML.TAG_TBODY);
+
+ nsIDOMElement tableRow = visualDocument.createElement(HTML.TAG_TR);
+ addAttributeToTableNode((Element) sourceNode, tableRow);
+ visualElement.appendChild(tbody);
+ tbody.appendChild(tableRow);
+
+ VpeCreationData vpeCreationData = new VpeCreationData(div);
+ createBasicTree(pageContext, visualDocument, tableRow, sourceNode,
+ vpeCreationData);
+ return vpeCreationData;
} else {
ComponentUtil.setCSSLink(pageContext, STYLE_PATH,
- "treeNodesAdaptor"); //$NON-NLS-1$
+ TREE_NODES_ADAPTOR);
nsIDOMElement visualElement = visualDocument
.createElement(HTML.TAG_DIV);
- visualElement.setAttribute(ID_ATTR_NAME, TREE_NODES_ADAPTOR_NAME);
+ visualElement.setAttribute(ID_ATTR_NAME, TREE_NODES_ADAPTOR);
if (isHasParentAdapter(sourceNode)) {
visualElement.setAttribute(HTML.ATTR_CLASS,
"dr-tree-h-ic-div"); //$NON-NLS-1$
@@ -83,176 +85,6 @@
/**
*
- * 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;
//$NON-NLS-1$
- String treeNodesAdaptorName = sourceNode.getPrefix() + ":" //$NON-NLS-1$
- + TREE_NODES_ADAPTOR_NAME;
- String recursiveTreeNodesAdaptorName = sourceNode.getPrefix() + ":"
//$NON-NLS-1$
- + 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() + ":" //$NON-NLS-1$
- + TREE_NODES_ADAPTOR_NAME;
- String recursiveTreeNodesAdaptorName = sourceNode.getPrefix() + ":"
//$NON-NLS-1$
- + 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; //$NON-NLS-1$
- 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")) { //$NON-NLS-1$
- showLinesValue = false;
- }
- return showLinesValue;
- }
-
- /**
- * Has Next element
- *
- * @param sourceNode
- * @return
- */
- private boolean isHasNextParentAdaptorElement(Node sourceNode) {
- Node tree = sourceNode.getParentNode();
- if (!(tree instanceof Element)) {
- return true;
- }
- Node parentTree = tree.getParentNode();
- if (!(parentTree instanceof Element)) {
- return true;
- }
- NodeList childs = parentTree.getChildNodes();
- String treeNodeName = parentTree.getPrefix() + ":" //$NON-NLS-1$
- + RichFacesTreeTemplate.TREE_NODE_NAME;
- String treeNodesAdaptorName = parentTree.getPrefix() + ":" //$NON-NLS-1$
- + RichFacesTreeTemplate.TREE_NODES_ADAPTOR;
- String treeRecursiveNodesAdaptorName = parentTree.getPrefix() + ":"
//$NON-NLS-1$
- + 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(tree)) {
- lastElement = el;
- }
- }
-
- if (el.getNodeName().equals(treeNodeName)
- || el.getNodeName().equals(treeNodesAdaptorName)
- || el.getNodeName().equals(treeRecursiveNodesAdaptorName)) {
- return true;
- }
- return false;
- }
-
- /**
- * Is adapter between treeNodes
- *
- * @param sourceNode
- * @return
- */
- private boolean isAdapterBetweenNodes(Node sourceNode) {
- Node parentNode = sourceNode.getParentNode();
- NodeList childs = parentNode.getChildNodes();
- Node beforeAdapterNode = null;
- Node afterAdapterNode = null;
- Node adapterNode = null;
- String treeNodeName = sourceNode.getPrefix() + ":" //$NON-NLS-1$
- + RichFacesTreeTemplate.TREE_NODE_NAME;
- for (int i = 0; i < childs.getLength(); i++) {
- Node el = childs.item(i);
- if (!(el instanceof Element)) {
- continue;
- }
- if (el.equals(sourceNode)) {
- adapterNode = el;
- } else {
- if (el.getNodeName().equals(treeNodeName)) {
- if (adapterNode == null) {
- beforeAdapterNode = el;
- } else {
- afterAdapterNode = el;
- }
- }
-
- }
-
- }
-
- if (beforeAdapterNode != null && afterAdapterNode != null) {
- return true;
- }
- return false;
- }
-
- /**
- *
* @param sourceElement
* @return
*/
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTreeNodeTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTreeNodeTemplate.java 2008-12-17
16:30:18 UTC (rev 12644)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTreeNodeTemplate.java 2008-12-17
17:56:32 UTC (rev 12645)
@@ -10,23 +10,16 @@
******************************************************************************/
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.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.jboss.tools.vpe.editor.util.Constants;
+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.mozilla.interfaces.nsIDOMText;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
/**
* Create template for rich:treeNodes element
@@ -34,68 +27,8 @@
* @author dsakovich(a)exadel.com
*
*/
-public class RichFacesTreeNodeTemplate extends VpeAbstractTemplate {
+public class RichFacesTreeNodeTemplate extends RichFacesAbstractTreeTemplate {
- public static final String DEFAULT_ICON_PARAM_VALUE =
"DEFAULT_ICON_PARAM";
-
- public static final String ICON_PARAM_NAME = "richFacesTreeNodeParam";
-
- public static final String DEFAULT_ICON_EXPANDED_PARAM_VALUE =
"DEFAULT_ICON_EXPANDED_PARAM";
-
- public static final String UNDEFINED_ICON = "/tree/unresolved.gif";
-
- public static final String NODE_ICON_LEAF_ATTR_NAME = "iconLeaf";
-
- public static final String ICON_NODE_WITH_LINES =
"/tree/iconNodeWithLines.gif";
-
- public static final String ICON_NODE_WITH_LINE =
"/tree/iconNodeWithLine.gif";
-
- public static final String ICON_EXPANDED_WITH_LINES =
"/tree/iconCollapsedWithLines.gif";
-
- public static final String ICON_NODE_WITHOUT_LINES = "/tree/iconNode.gif";
-
- public static final String ICON_EXPANDED_WITHOUT_LINES =
"/tree/iconCollapsed.gif";
-
- public static final String ICON_NOT_EXPANDED_WITH_LINES =
"/tree/iconNotCollapsedWithLines.gif";
-
- public static final String ICON_NOT_EXPANDED_WITH_ALL_LINES =
"/tree/iconNotCollapsedWithAllLines.gif";
-
- public static final String ICON_NOT_EXPANDED_WITHOUT_LINES =
"/tree/iconNotCollapsed.gif";
-
- public static final String ICON_EXPANDED_ADAPTER_WITH_LINES =
"/tree/iconClosedNodeWithLines.gif";
-
- public static final String ICON_EXPANDED_ADAPTER_WITHOUT_LINES =
"/tree/iconClosedNode.gif";
-
- public static final String ICON_LEAF_WITH_LINES =
"/tree/iconLeafWithLines.gif";
-
- public static final String ICON_RIGHT_LINE = "/tree/rightLine.gif";
-
- public static final String ICON_LEFT_LINE = "/tree/leftLine.gif";
-
- public static final String ICON_LINE = "/tree/line.gif";
-
- public static final String ICON_LEAF_WITHOUT_LINES = "/tree/iconLeaf.gif";
-
- private static final String TREE_TABLE_PICTURE_STYLE_CLASS_NAME =
"treePictureStyle";
-
- private static final String STYLE_CLASS_FOR_NODE_TITLE =
"treeNodeNameStyle";
-
- private static final String NODE_TITLE_STYLE_CLASS_ATTR_NAME =
"nodeClass";
-
- private static final String NODE_ICON_EXPANDED_ATTR_NAME = "iconExpanded";
-
- private static final String NODE_ICON_ATTR_NAME = "icon";
-
- 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";
-
- private static final String TREE_NAME = "tree";
-
- private static final String NODE_LINES_STYLE = "background-position: center;
background-repeat: repeat-y;";
-
/**
* Creates a node of the visual tree on the node of the source tree. This
* visual node should not have the parent node This visual node can have
@@ -112,17 +45,14 @@
public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
nsIDOMDocument visualDocument) {
- nsIDOMElement div = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_DIV);
+ nsIDOMElement div = visualDocument.createElement(HTML.TAG_DIV);
nsIDOMElement visualElement = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TABLE);
+ .createElement(HTML.TAG_TABLE);
addBasicTreeNodeAttributes(visualElement);
div.appendChild(visualElement);
- nsIDOMElement tbody = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TBODY);
+ nsIDOMElement tbody = visualDocument.createElement(HTML.TAG_TBODY);
- nsIDOMElement tableRow = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TR);
+ nsIDOMElement tableRow = visualDocument.createElement(HTML.TAG_TR);
addAttributeToTableNode((Element) sourceNode, tableRow);
visualElement.appendChild(tbody);
tbody.appendChild(tableRow);
@@ -133,241 +63,6 @@
return vpeCreationData;
}
- /**
- * Checks for attributes for node and if such exist convert it's to html
- * atributes.
- *
- * @param sourceNode
- * @param tableRow
- */
- private void addAttributeToTableNode(Element sourceNode,
- nsIDOMElement tableRow) {
-
- String attrValue = sourceNode
- .getAttribute(NODE_TITLE_STYLE_CLASS_ATTR_NAME);
- if ((attrValue != null) && (attrValue.length() > 0)) {
- tableRow.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, attrValue);
- }
- }
-
- /**
- * Used for setting images into tree nodes
- *
- * @param pageContext
- * page context
- * @param visualDocument
- * visual document
- * @param sourceNode
- * treeNode element
- * @param iconCell
- * cell were image should be setted
- * @param nodeAttrName
- * image attr name( icon, iconExpanded, ...)
- * @param defaultImage
- * (image by default)
- */
- private void setAttributeForPictureNode(VpePageContext pageContext,
- nsIDOMDocument visualDocument, Element sourceNode,
- nsIDOMElement iconCell, String nodeAttrName, String defaultImage) {
- if (RichFacesTemplatesActivator.getDefault().isDebugging()) {
- System.out.println("call setAttributeForPictureNode");
- }
- nsIDOMElement img = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_IMG);
- addBasicAttributesToPicture(img);
- iconCell.appendChild(img);
- // get image from treeNode
- String imgName = sourceNode.getAttribute(nodeAttrName);
- // if in tree node image doesn't exist we get image attr from tree
- if (imgName == null || imgName.length() == 0) {
- Node parentElement = sourceNode.getParentNode();
- if (parentElement instanceof Element) {
- imgName = ((Element) parentElement).getAttribute(nodeAttrName);
- }
- } else {
- img.setAttribute(ICON_PARAM_NAME, "");
- }
- // if we can't get attribute from parent we use default attribute
- addBasicAttributesToPicture(img);
- iconCell.appendChild(img);
- if (imgName == null || imgName.length() == 0) {
- ComponentUtil.setImg(img, defaultImage);
- } else {
- ComponentUtil.setImgFromResources(pageContext, img, imgName,
- UNDEFINED_ICON);
- }
- if (nodeAttrName.equals(NODE_ICON_EXPANDED_ATTR_NAME)) {
- img
- .setAttribute(ICON_PARAM_NAME,
- DEFAULT_ICON_EXPANDED_PARAM_VALUE);
- } else if (nodeAttrName.equals(NODE_ICON_ATTR_NAME)) {
- img.setAttribute(ICON_PARAM_NAME, DEFAULT_ICON_PARAM_VALUE);
- } else if (nodeAttrName.equals(NODE_ICON_LEAF_ATTR_NAME)) {
- img.setAttribute(ICON_PARAM_NAME, NODE_ICON_LEAF_ATTR_NAME);
- }
- }
-
- /**
- * Create simple tree node attribute.Used for creating more complex trees.
- *
- * @param treeNodeTitle
- * @param visualDocument
- * @return tree
- */
- private void createBasicTree(VpePageContext pageContext,
- nsIDOMDocument visualDocument, nsIDOMElement treeRow,
- Node sourceNode, VpeCreationData vpeCreationData) {
- // creates icon node
- String backgroundLinePath = null;
-
- boolean showLinesValue = getShowLinesAttr((Element) sourceNode);
- nsIDOMElement iconNode = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TD);
- // 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)
- && !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_LINE
- : ICON_NODE_WITHOUT_LINES);
- } 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)))
- || (!isAdaptorChild(sourceNode) && isLastElement(sourceNode))
- || (isAdaptorChild(sourceNode) && isOnlyOneNodeInAdaptor(sourceNode))) {
-
- if (isAdaptorChild(sourceNode)
- && isOnlyOneNodeInAdaptor(sourceNode)
- && !isLastElementAfterAdaptor(sourceNode)
- && isHasNextParentAdaptorElement(sourceNode)) {
- backgroundLinePath = RichFacesTemplatesActivator
- .getPluginResourcePath()
- + ICON_LINE;
- setAttributeForPictureNode(
- pageContext,
- visualDocument,
- (Element) sourceNode,
- td1,
- NODE_ICON_EXPANDED_ATTR_NAME,
- showLinesValue == true ? ICON_NOT_EXPANDED_WITH_ALL_LINES
- : ICON_NOT_EXPANDED_WITHOUT_LINES);
- } else {
- backgroundLinePath = RichFacesTemplatesActivator
- .getPluginResourcePath()
- + ICON_RIGHT_LINE;
- setAttributeForPictureNode(pageContext, visualDocument,
- (Element) sourceNode, td1,
- NODE_ICON_EXPANDED_ATTR_NAME,
- showLinesValue == true ? ICON_NOT_EXPANDED_WITH_LINES
- : ICON_NOT_EXPANDED_WITHOUT_LINES);
- }
-
- setAttributeForPictureNode(pageContext, visualDocument,
- (Element) sourceNode, iconNode, NODE_ICON_LEAF_ATTR_NAME,
- showLinesValue == true ? ICON_LEAF_WITH_LINES
- : ICON_LEAF_WITHOUT_LINES);
- } else {
- backgroundLinePath = RichFacesTemplatesActivator
- .getPluginResourcePath()
- + ICON_RIGHT_LINE;
- setAttributeForPictureNode(pageContext, visualDocument,
- (Element) sourceNode, td1, NODE_ICON_EXPANDED_ATTR_NAME,
- showLinesValue == true ? ICON_EXPANDED_WITH_LINES
- : ICON_EXPANDED_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);
- }
-
- setAttributeForPictureNode(pageContext, visualDocument,
- (Element) sourceNode, iconNode, NODE_ICON_ATTR_NAME,
- showLinesValue == true ? ICON_NODE_WITH_LINES
- : ICON_NODE_WITHOUT_LINES);
- }
-
- if (showLinesValue) {
- td1.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR,
- "background-image: url(file://" + backgroundLinePath
- + "); " + NODE_LINES_STYLE);
- }
- treeRow.appendChild(td1);
- treeRow.appendChild(iconNode);
- // creates Tree Node Name Message
- nsIDOMElement nodeTitle = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TD);
- addBasicNodeTitleAttributes(nodeTitle);
- // Create mapping to Encode body
- String treeRecursiveNodesAdaptorName = sourceNode.getPrefix() + ":"
- + RichFacesTreeTemplate.TREE_RECURSIVE_NODES_ADAPTOR;
- if (sourceNode.getNodeName().equals(treeRecursiveNodesAdaptorName)) {
- Element sourceElement = (Element) sourceNode;
- String nodes = sourceElement
- .getAttribute(RichFacesRecursiveTreeNodesAdaptorTemplate.NODES_NAME);
- nsIDOMElement span = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_SPAN);
- nsIDOMText text = visualDocument
- .createTextNode((nodes == null) ? "" : nodes);
- span.appendChild(text);
- nodeTitle.appendChild(span);
- } else {
- VpeChildrenInfo tdInfo = new VpeChildrenInfo(nodeTitle);
-
- // Create mapping to Encode body
- List<Node> children = ComponentUtil.getChildren(
- (Element) sourceNode, false);
- for (Node child : children) {
- tdInfo.addSourceChild(child);
- }
- vpeCreationData.addChildrenInfo(tdInfo);
- }
- treeRow.appendChild(nodeTitle);
-
- }
-
- /**
- * Sets attributes for no node title name
- *
- * @param nodeTitle
- */
- private void addBasicNodeTitleAttributes(nsIDOMElement nodeTitle) {
- nodeTitle.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
- STYLE_CLASS_FOR_NODE_TITLE);
- }
-
@Override
public void setAttribute(VpePageContext pageContext, Element sourceElement,
nsIDOMDocument visualDocument, nsIDOMNode visualNode, Object data,
@@ -386,7 +81,7 @@
nsIDOMElement.NS_IDOMELEMENT_IID);
ComponentUtil.setImgFromResources(pageContext, img, value,
UNDEFINED_ICON);
- img.setAttribute(ICON_PARAM_NAME, "");
+ img.setAttribute(ICON_PARAM_NAME, Constants.EMPTY);
} else if (NODE_ICON_ATTR_NAME.equals(name)
&& !isLastElement(visualNode)) {
nsIDOMElement iconCell = (nsIDOMElement) visualNode.getChildNodes()
@@ -395,7 +90,7 @@
.item(0).queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
ComponentUtil.setImgFromResources(pageContext, img, value,
UNDEFINED_ICON);
- img.setAttribute(ICON_PARAM_NAME, "");
+ img.setAttribute(ICON_PARAM_NAME, Constants.EMPTY);
} else if (NODE_ICON_LEAF_ATTR_NAME.equals(name)
&& isLastElement(sourceElement)) {
nsIDOMElement iconCell = (nsIDOMElement) visualNode.getChildNodes()
@@ -404,7 +99,7 @@
.item(0).queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
ComponentUtil.setImgFromResources(pageContext, img, value,
UNDEFINED_ICON);
- img.setAttribute(ICON_PARAM_NAME, "");
+ img.setAttribute(ICON_PARAM_NAME, Constants.EMPTY);
}
}
@@ -478,294 +173,4 @@
}
}
- /**
- *
- * @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)) {
- return true;
- }
-
- String treeNodesAdaptorName = sourceNode.getPrefix() + ":"
- + RichFacesTreeTemplate.TREE_NODES_ADAPTOR;
- String treeRecursiveNodesAdaptorName = sourceNode.getPrefix() + ":"
- + RichFacesTreeTemplate.TREE_RECURSIVE_NODES_ADAPTOR;
- if (parentNode.getNodeName().equals(treeNodesAdaptorName)
- || parentNode.getNodeName().equals(
- treeRecursiveNodesAdaptorName)) {
- return true;
- }
- return false;
- }
-
- /**
- * Node is last element
- *
- * @param parentTree
- * @param sourceNode
- * @return
- */
- private boolean isLastElement(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.getNodeName().equals(treeNodeName)
- || el.getNodeName().equals(treeNodesAdaptorName)
- || el.getNodeName().equals(treeRecursiveNodesAdaptorName)) {
- lastElement = el;
- }
- }
- return sourceNode.equals(lastElement);
- }
-
- /**
- * Next element is Adaptor
- *
- * @param sourceNode
- * @return
- */
- private boolean isHasNextAdaptorElement(Node sourceNode) {
- Node parentTree = sourceNode.getParentNode();
- if (!(parentTree instanceof Element)) {
- return true;
- }
- NodeList childs = parentTree.getChildNodes();
- 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 (sourceNode.equals(el)) {
- lastElement = el;
- }
- }
- if (el.getNodeName().equals(treeNodesAdaptorName)
- || el.getNodeName().equals(treeRecursiveNodesAdaptorName)) {
- return true;
- }
- return false;
- }
-
- /**
- * Adds basic attributes to tree
- *
- * @param img
- */
-
- private void addBasicAttributesToPicture(nsIDOMElement img) {
- img.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
- TREE_TABLE_PICTURE_STYLE_CLASS_NAME);
- }
-
- /**
- * 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");
- }
-
- /**
- * 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;
- }
-
- /**
- * Node has element after adaptor
- *
- * @param sourceNode
- * @return
- */
- private boolean isLastElementAfterAdaptor(Node sourceNode) {
- Node nodeAdaptor = sourceNode.getParentNode();
- if (!(nodeAdaptor instanceof Element)) {
- return true;
- }
- 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;
- }
-
- private boolean isOnlyOneNodeInAdaptor(Node sourceNode) {
- Node parent = sourceNode.getParentNode();
- NodeList list = parent.getChildNodes();
- Node currentNode = null;
- String treeNodeName = sourceNode.getPrefix() + ":"
- + RichFacesTreeTemplate.TREE_NODE_NAME;
- for (int i = 0; i < list.getLength(); i++) {
- Node el = list.item(i);
- if (!(el instanceof Element)) {
- continue;
- }
- if (el.getNodeName().equals(treeNodeName)) {
- if (currentNode == null) {
- currentNode = el;
- } else {
- return false;
- }
- } else {
- return false;
- }
- }
- return true;
- }
-
- /**
- * Has Next element
- *
- * @param sourceNode
- * @return
- */
- private boolean isHasNextParentAdaptorElement(Node sourceNode) {
- Node tree = sourceNode.getParentNode();
- if (!(tree instanceof Element)) {
- return true;
- }
- Node parentTree = tree.getParentNode();
- if (!(parentTree instanceof Element)) {
- return true;
- }
- NodeList childs = parentTree.getChildNodes();
- 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(tree)) {
- lastElement = el;
- }
- }
-
- if (el.getNodeName().equals(treeNodesAdaptorName)
- || el.getNodeName().equals(treeRecursiveNodesAdaptorName)) {
- return true;
- }
- return false;
- }
-
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTreeNodesAdaptorTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTreeNodesAdaptorTemplate.java 2008-12-17
16:30:18 UTC (rev 12644)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTreeNodesAdaptorTemplate.java 2008-12-17
17:56:32 UTC (rev 12645)
@@ -11,17 +11,13 @@
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.jboss.tools.vpe.editor.util.HTML;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
-import org.w3c.dom.Element;
import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
/**
* Create template for rich:treeNodesAdaptor element
@@ -29,40 +25,29 @@
* @author dsakovich(a)exadel.com
*
*/
-public class RichFacesTreeNodesAdaptorTemplate extends VpeAbstractTemplate {
+public class RichFacesTreeNodesAdaptorTemplate extends RichFacesAbstractTreeTemplate {
- private static final String TREE_NAME = "tree";
+ private static final String STYLE_PATH = "/tree/tree.css"; //$NON-NLS-1$
+ public static final String ICON_DIV_LINE = "/tree/divLine.gif";
//$NON-NLS-1$
+ private static final String ADAPTER_LINES_STYLE = "background-position: left
center; background-repeat: repeat-y;"; //$NON-NLS-1$
+ public static final String ID_ATTR_NAME = "ID"; //$NON-NLS-1$
- 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, "treeNodesAdaptor");
+ ComponentUtil.setCSSLink(pageContext, STYLE_PATH, TREE_NODES_ADAPTOR);
nsIDOMElement visualElement = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_DIV);
- visualElement.setAttribute(ID_ATTR_NAME, TREE_NODES_ADAPTOR_NAME);
+ .createElement(HTML .TAG_DIV);
+ visualElement.setAttribute(ID_ATTR_NAME, TREE_NODES_ADAPTOR);
if (isHasParentAdapter(sourceNode)) {
- visualElement.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
- "dr-tree-h-ic-div");
+ visualElement.setAttribute(HTML.ATTR_CLASS,
+ "dr-tree-h-ic-div"); //$NON-NLS-1$
if (getShowLinesAttr(sourceNode)
&& (isAdapterBetweenNodes(sourceNode) ||
isHasNextParentAdaptorElement(sourceNode))) {
String path = RichFacesTemplatesActivator
.getPluginResourcePath()
+ ICON_DIV_LINE;
- visualElement.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR,
- "background-image: url(file://" + path + "); "
+ visualElement.setAttribute(HTML.ATTR_STYLE,
+ "background-image: url(file://" + path + "); " //$NON-NLS-1$
//$NON-NLS-2$
+ ADAPTER_LINES_STYLE);
}
}
@@ -71,175 +56,4 @@
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 tree = sourceNode.getParentNode();
- if (!(tree instanceof Element)) {
- return true;
- }
- Node parentTree = tree.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(tree)) {
- lastElement = el;
- }
- }
-
- if (el.getNodeName().equals(treeNodeName)
- || el.getNodeName().equals(treeNodesAdaptorName)
- || el.getNodeName().equals(treeRecursiveNodesAdaptorName)) {
- return true;
- }
- return false;
- }
-
- /**
- * Is adapter between treeNodes
- *
- * @param sourceNode
- * @return
- */
- private boolean isAdapterBetweenNodes(Node sourceNode) {
- Node parentNode = sourceNode.getParentNode();
- NodeList childs = parentNode.getChildNodes();
- Node beforeAdapterNode = null;
- Node afterAdapterNode = null;
- Node adapterNode = null;
- String treeNodeName = sourceNode.getPrefix() + ":"
- + RichFacesTreeTemplate.TREE_NODE_NAME;
- for (int i = 0; i < childs.getLength(); i++) {
- Node el = childs.item(i);
- if (!(el instanceof Element)) {
- continue;
- }
- if (el.equals(sourceNode)) {
- adapterNode = el;
- } else {
- if (el.getNodeName().equals(treeNodeName)) {
- if (adapterNode == null) {
- beforeAdapterNode = el;
- } else {
- afterAdapterNode = el;
- }
- }
-
- }
-
- }
-
- if (beforeAdapterNode != null && afterAdapterNode != null) {
- return true;
- }
- return false;
- }
-
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTreeTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTreeTemplate.java 2008-12-17
16:30:18 UTC (rev 12644)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTreeTemplate.java 2008-12-17
17:56:32 UTC (rev 12645)
@@ -11,11 +11,12 @@
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.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.template.VpeAbstractTemplate;
import org.jboss.tools.vpe.editor.template.VpeChildrenInfo;
import org.jboss.tools.vpe.editor.template.VpeCreationData;
+import org.jboss.tools.vpe.editor.util.Constants;
+import org.jboss.tools.vpe.editor.util.HTML;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMNode;
@@ -35,22 +36,16 @@
/** Resurces */
- public static final String TREE_NODE_NAME = "treeNode";
+ public static final String TREE= "tree"; //$NON-NLS-1$
+ public static final String TREE_NODE_NAME = "treeNode"; //$NON-NLS-1$
+ public static final String TREE_NODES_ADAPTOR = "treeNodesAdaptor";
//$NON-NLS-1$
+ public static final String RECURSIVE_TREE_NODES_ADAPTOR =
"recursiveTreeNodesAdaptor"; //$NON-NLS-1$
+ public static final String SHOW_LINES_ATTR_NAME = "showConnectingLines";
//$NON-NLS-1$
+ private static final String STYLE_PATH = "/tree/tree.css"; //$NON-NLS-1$
+ private static final String ICON_ATTR = "icon"; //$NON-NLS-1$
+ private static final String TREE_STYLE_CLASS_ATR_NAME = "styleClass";
//$NON-NLS-1$
+ private static final String ICON_COLLAPSED_ATTR_NAME = "iconExpanded";
//$NON-NLS-1$
- public static final String TREE_NODES_ADAPTOR = "treeNodesAdaptor";
-
- public static final String TREE_RECURSIVE_NODES_ADAPTOR =
"recursiveTreeNodesAdaptor";
-
- public static final String SHOW_LINES_ATTR_NAME = "showConnectingLines";
-
- private static final String STYLE_PATH = "/tree/tree.css";
-
- private static final String ICON_ATTR = "icon";
-
- private static final String TREE_STYLE_CLASS_ATR_NAME = "styleClass";
-
- private static final String ICON_COLLAPSED_ATTR_NAME = "iconExpanded";
-
/**
* Creates a node of the visual tree on the node of the source tree. This
* visual node should not have the parent node This visual node can have
@@ -67,20 +62,20 @@
public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
nsIDOMDocument visualDocument) {
// sets css for tree on page
- ComponentUtil.setCSSLink(pageContext, STYLE_PATH, "tree");
+ ComponentUtil.setCSSLink(pageContext, STYLE_PATH, TREE);
nsIDOMElement visualElement = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_DIV);
+ .createElement(HTML.TAG_DIV);
Element sourceElement = (Element) sourceNode;
String style = sourceElement
- .getAttribute(HtmlComponentUtil.HTML_STYLE_ATTR);
+ .getAttribute(HTML.ATTR_STYLE);
if (style != null) {
visualElement
- .setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, style);
+ .setAttribute(HTML.ATTR_STYLE, style);
}
String styleClass = sourceElement
- .getAttribute(HtmlComponentUtil.HTML_CLASS_ATTR);
+ .getAttribute(HTML.ATTR_CLASS);
if (styleClass != null) {
- visualElement.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
+ visualElement.setAttribute(HTML.ATTR_CLASS,
styleClass);
}
VpeCreationData vpeCreationData = new VpeCreationData(visualElement);
@@ -101,17 +96,17 @@
private void setStylesAttributesToTree(nsIDOMElement treeTable,
Element sourceNode) {
String styleAttr = sourceNode
- .getAttribute(HtmlComponentUtil.HTML_STYLE_ATTR);
+ .getAttribute(HTML.ATTR_STYLE);
if (styleAttr != null && styleAttr.length() != 0) {
- setAttributeToTree(treeTable, HtmlComponentUtil.HTML_STYLE_ATTR,
+ setAttributeToTree(treeTable, HTML.ATTR_STYLE,
removeFromStyleWithAndHeight(styleAttr));
treeTable
- .setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, styleAttr);
+ .setAttribute(HTML.ATTR_STYLE, styleAttr);
}
String styleClassAttr = sourceNode
.getAttribute(TREE_STYLE_CLASS_ATR_NAME);
if ((styleClassAttr != null) && (styleClassAttr.length() != 0)) {
- setAttributeToTree(treeTable, HtmlComponentUtil.HTML_CLASS_ATTR,
+ setAttributeToTree(treeTable, HTML.ATTR_CLASS,
styleClassAttr);
}
}
@@ -123,13 +118,13 @@
*/
private String removeFromStyleWithAndHeight(String styleArgs) {
StringBuffer result = new StringBuffer();
- String[] mas = styleArgs.split(";");
+ String[] mas = styleArgs.split(Constants.SEMICOLON);
for (String styleAttr : mas) {
- if ((styleAttr.indexOf(HtmlComponentUtil.HTML_ATR_WIDTH) != -1)
- || (styleAttr.indexOf(HtmlComponentUtil.HTML_ATR_HEIGHT) != -1)) {
+ if ((styleAttr.indexOf(HTML.ATTR_WIDTH) != -1)
+ || (styleAttr.indexOf(HTML.ATTR_HEIGHT) != -1)) {
continue;
}
- result.append(styleAttr + ";");
+ result.append(styleAttr + Constants.SEMICOLON);
}
return result.toString();
}
@@ -147,7 +142,7 @@
nsIDOMElement element = (nsIDOMElement) node
.queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
if (node.getNodeName().equalsIgnoreCase(
- HtmlComponentUtil.HTML_TAG_TABLE)) {
+ HTML.TAG_TABLE)) {
element.setAttribute(attrName, attrValue);
}
nsIDOMNodeList list2 = node.getChildNodes();
@@ -196,13 +191,13 @@
String id = element
.getAttribute(RichFacesTreeNodesAdaptorTemplate.ID_ATTR_NAME);
if (id == null)
- id = "";
+ id = Constants.EMPTY;
if (node.getNodeName().equalsIgnoreCase(
- HtmlComponentUtil.HTML_TAG_DIV)
+ HTML.TAG_DIV)
&& list.getLength() == 2
&& !(id
- .equalsIgnoreCase(RichFacesTreeNodesAdaptorTemplate.TREE_NODES_ADAPTOR_NAME) ||
id
-
.equalsIgnoreCase(RichFacesTreeNodesAdaptorTemplate.RECURSIVE_TREE_NODES_ADAPTOR_NAME)))
{
+ .equalsIgnoreCase(TREE_NODES_ADAPTOR) || id
+ .equalsIgnoreCase(RECURSIVE_TREE_NODES_ADAPTOR))) {
nsIDOMNode table1 = list.item(0);
nsIDOMNode table2 = list.item(1);
node.removeChild(table1);
@@ -238,11 +233,11 @@
nsIDOMElement childTree = null;
nsIDOMElement childLast = null;
int lenght = nodeList.getLength();
- String treeNodeName = sourceNode.getPrefix() + ":" + TREE_NODE_NAME;
- String treeNodesAdaptorName = sourceNode.getPrefix() + ":"
+ String treeNodeName = sourceNode.getPrefix() + Constants.COLON + TREE_NODE_NAME;
+ String treeNodesAdaptorName = sourceNode.getPrefix() + Constants.COLON
+ TREE_NODES_ADAPTOR;
- String recursiveTreeNodesAdaptorName = sourceNode.getPrefix() + ":"
- + TREE_RECURSIVE_NODES_ADAPTOR;
+ String recursiveTreeNodesAdaptorName = sourceNode.getPrefix() + Constants.COLON
+ + RECURSIVE_TREE_NODES_ADAPTOR;
VpeChildrenInfo vpeChildrenInfo = null;
for (int i = 0; i < lenght; i++) {
if (!(nodeList.item(i) instanceof Element)) {
@@ -295,14 +290,14 @@
nsIDOMDocument visualDocument, nsIDOMNode visualNode, Object data,
String name, String value) {
if (TREE_STYLE_CLASS_ATR_NAME.equalsIgnoreCase(name)) {
- setAttributeToTree(visualNode, HtmlComponentUtil.HTML_CLASS_ATTR,
+ setAttributeToTree(visualNode, HTML.ATTR_CLASS,
value);
- } else if (HtmlComponentUtil.HTML_STYLE_ATTR.equalsIgnoreCase(name)) {
- setAttributeToTree(visualNode, HtmlComponentUtil.HTML_STYLE_ATTR,
+ } else if (HTML.ATTR_STYLE.equalsIgnoreCase(name)) {
+ setAttributeToTree(visualNode, HTML.ATTR_STYLE,
removeFromStyleWithAndHeight(value));
nsIDOMElement visualElement = (nsIDOMElement)
visualNode.queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
visualElement.setAttribute(
- HtmlComponentUtil.HTML_STYLE_ATTR, value);
+ HTML.ATTR_STYLE, value);
}
}
@@ -311,11 +306,11 @@
Element sourceElement, nsIDOMDocument visualDocument,
nsIDOMNode visualNode, Object data, String name) {
if (TREE_STYLE_CLASS_ATR_NAME.equalsIgnoreCase(name)) {
- setAttributeToTree(visualNode, HtmlComponentUtil.HTML_CLASS_ATTR,
- "");
- } else if (HtmlComponentUtil.HTML_STYLE_ATTR.equalsIgnoreCase(name)) {
- setAttributeToTree(visualNode, HtmlComponentUtil.HTML_STYLE_ATTR,
- "");
+ setAttributeToTree(visualNode, HTML.ATTR_CLASS,
+ Constants.EMPTY);
+ } else if (HTML.ATTR_STYLE.equalsIgnoreCase(name)) {
+ setAttributeToTree(visualNode, HTML.ATTR_STYLE,
+ Constants.EMPTY);
}
}
@@ -329,8 +324,8 @@
private nsIDOMElement createBasicTree(nsIDOMDocument visualDocument) {
nsIDOMElement div = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_DIV);
- div.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, "dr-tree-h-ic-div");
+ .createElement(HTML.TAG_DIV);
+ div.setAttribute(HTML.ATTR_CLASS, "dr-tree-h-ic-div"); //$NON-NLS-1$
return div;
}