@Override public Treenode render(Node node) { Treenode tnode = new Treenode(); if (node.getNodeType() == Node.TEXT_NODE) { setLabel(tnode, node.getNodeValue(), XMLConstants.STYLE_CONTENT); } else if (node.getNodeType() == Node.COMMENT_NODE) { setLabel(tnode, "<!--" + node.getNodeValue() + "-->", XMLConstants.STYLE_COMMENT); } else if (node.getParentNode() == null) { // Closing tag tnode.setAttribute("closing", true); setLabel(tnode, XMLUtil.formatNodeName(node, TagFormat.CLOSING), XMLConstants.STYLE_TAG); } else { boolean leaf = !node.hasChildNodes(); String label = "<" + node.getNodeName(); NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { for (int i = 0; i < attrs.getLength(); i++) { Node attr = attrs.item(i); label += " " + attr.getNodeName() + "='" + attr.getNodeValue() + "'"; } } setLabel(tnode, label + (leaf ? " />" : ">"), XMLConstants.STYLE_TAG); tnode.addEventListener("toggle", nodeListener); } return tnode; }
/** * Recursively create tree items that correspond to the topic tree from the help view. * * @param tc The root node to receive newly created tree nodes. * @param node A topic tree node. * @return Newly created tree node. */ private Treenode addNode(BaseComponent tc, HelpTopicNode node) { HelpTopic topic = node.getTopic(); Treenode parent = new Treenode(); parent.setLabel(topic.getLabel()); parent.setData(topic); topics.put(topic, parent); tc.addChild(parent); for (HelpTopicNode child : node.getChildren()) { addNode(parent, child); } parent.setCollapsed(false); return parent; }
/** * Creates a tree node associated with the specified UI element. * * @param ele UI element * @return Newly created tree node. */ private Treenode createNode(ElementBase ele) { String label = ele.getDisplayName(); String instanceName = ele.getInstanceName(); PluginDefinition def = ele.getDefinition(); if (!label.equalsIgnoreCase(instanceName)) { label += " - " + instanceName; } Treenode node = new Treenode(); node.setLabel(label); node.setData(ele); node.setHint(StringUtils.defaultString(def.getDescription(), noDescriptionHint)); node.addEventForward(DropEvent.class, window, null); node.addEventForward(DblclickEvent.class, btnProperties, ClickEvent.TYPE); if (!ele.isLocked() && !def.isInternal()) { node.setDragid("d" + dragId++); } return node; }
/** * Adds a tree node under the specified parent. * * @param proxy The proxy associated with the tree node. * @param parent The tree parent to receive the new tree node. * @param insertAfter Tree node after which new node will be added (may be null). * @return The newly created tree node. */ protected Treenode addTreenode(Proxy proxy, BaseComponent parent, Treenode insertAfter) { Treenode node = null; if (proxy != null) { node = new Treenode(); parent = parent == null ? (insertAfter == null ? tree : insertAfter.getParent()) : parent; BaseComponent refChild = insertAfter == null ? null : insertAfter.getNextSibling(); parent.addChild(node, refChild); proxy.setItem(node); initProxy(proxy); if (hasLabelProperty(proxy.getDefinition().getClazz())) { node.addEventForward(DblclickEvent.TYPE, tree, null); } } return node; }