@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; }
/** * Updates the tree node according to the favorite status. * * @param node Tree node to update. * @param isFavorite If true, the node is a favorite. */ private void setFavoriteStatus(Treenode node, boolean isFavorite) { String img = IconUtil.getIconPath(isFavorite ? "starOn.png" : "starOff.png", "16x16", null); node.setImage(img); node.setAttribute("favorite", isFavorite); tnFavorites.setVisible(isFavorite || tnFavorites.getFirstChild() != null); }
node.setAttribute("other", other); node.setAttribute("path", path); setFavoriteStatus(node, isFavorite);
/** * Place the specified tree node in edit mode. In this mode, the node's label is replaced with a * text box containing the label's value. * * @param node Target tree node. */ private void editNodeStart(Treenode node) { txtLabel.setAttribute(ITEM_ATTR, node); if (node == null) { popLabel.close(); } else { String label = node.getLabel(); node.setAttribute(LABEL_ATTR, label); txtLabel.setValue(label); node.setLabel(null); popLabel.open(node, "left top", "left top"); txtLabel.setFocus(true); } }