/** * Ensures that this node is visible (i.e., all of its parent tree nodes are expanded. */ public void makeVisible() { BaseComponent node = getParent(); while (node instanceof Treenode) { ((Treenode) node).setCollapsed(false); node = node.getParent(); } scrollIntoView(); }
Treenode item = null; for (BaseComponent comp : parent.getChildren()) { if (comp instanceof Treenode) { item = (Treenode) comp; if (caseSensitive ? item.getLabel().equals(label) : item.getLabel().equalsIgnoreCase(label)) { return item; try { item = clazz.newInstance(); item.setLabel(label); item.setHint(label); parent.addChild(item); return item; } catch (Exception e) {
/** * 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); }
/** * 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; }
/** * 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; }
boolean disabled = def.isDisabled() || def.isForbidden(); Treenode node = TreeUtil.findNode(tree, path, true); node.setData(def); node.setHint(StringUtils.defaultString(def.getDescription(), noDescriptionHint)); node.addEventListener(ClickEvent.TYPE, (event) -> { if (event.getTargetId().endsWith("-img")) { EventUtil.send(ON_FAVORITE, event.getTarget(), null); node.setDisabled(true); } else { node.addEventForward(DblclickEvent.TYPE, btnOK, ClickEvent.TYPE); node.addEventListener(ON_FAVORITE, other == null ? favoriteListener1 : favoriteListener2); node.setAttribute("other", other); node.setAttribute("path", path); setFavoriteStatus(node, isFavorite);
/** * 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; }
/** * Returns the path of the specified tree node. This consists of the indexes or labels of this * and all parent nodes separated by a "\" character. * * @param item The node (tree item) whose path is to be returned. If this value is null, a zero * length string is returned. * @param useLabels If true, use the labels as identifiers; otherwise, use indexes. * @return The path of the node as described. */ public static String getPath(Treenode item, boolean useLabels) { StringBuilder sb = new StringBuilder(); boolean needsDelim = false; while (item != null) { if (needsDelim) { sb.insert(0, '\\'); } else { needsDelim = true; } sb.insert(0, useLabels ? item.getLabel() : item.getIndex()); item = (Treenode) item.getParent(); } return sb.toString(); }
/** * Update control states for current selection. */ private void updateControls() { Treenode selectedNode = tree.getSelectedNode(); ElementUI selectedElement = getElement(selectedNode); contextMenu.updateStates(selectedElement, btnAdd, btnDelete, btnCopy, btnCut, btnPaste, btnProperties, btnAbout); BaseComponent parent = selectedNode == null ? null : selectedNode.getParent(); //parent = parent == null ? null : parent.getParent(); Treenode target = parent instanceof Treenode ? (Treenode) parent : null; btnLeft.setDisabled(movementType(selectedNode, target, false) == MovementType.INVALID); target = selectedNode == null ? null : (Treenode) selectedNode.getPreviousSibling(); btnRight.setDisabled(movementType(selectedNode, target, false) == MovementType.INVALID); btnUp.setDisabled(movementType(selectedNode, target, true) == MovementType.INVALID); target = selectedNode == null ? null : (Treenode) selectedNode.getNextSibling(); btnDown.setDisabled(movementType(selectedNode, target, true) == MovementType.INVALID); btnToFront.addStyle("opacity", bringToFront ? null : "0.5"); if (selectedElement != null) { window.setContext(contextMenu.getMenupopup()); contextMenu.setOwner(selectedElement); } if (selectedNode != null) { selectedNode.setSelected(false); selectedNode.setSelected(true); } }
next = (Treenode) current.getFirstChild(); next = (Treenode) current.getNextSibling(); BaseComponent parent = next.getParent();
@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; }
/** * 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); } }
/** * Promote the selected tree node. */ @EventHandler(value = "click", target = "@btnLeft") private void onClick$btnLeft() { Treenode node = tree.getSelectedNode(); Treenode parent = (Treenode) node.getParent(); parent.getParent().addChild(node, parent.getNextSibling()); doChanged(true); }
private void doDrop(Treenode dragged, Treenode target, boolean allowExchange) { ElementBase eleTarget = getElement(target); ElementBase eleDragged = getElement(dragged); switch (movementType(dragged, target, allowExchange)) { case INVALID: return; case EXCHANGE: eleDragged.setIndex(eleTarget.getIndex()); target.getParent().addChild(dragged, target); break; case FIRST: eleDragged.setIndex(0); target.addChild(dragged, 0); break; case RELOCATE: eleDragged.setParent(eleTarget); getTreenode(target).addChild(dragged); break; } updateDroppable(); updateControls(); }
private Treenode findSelected(Treenode node, Treenode selnode) { if (node.isSelected()) { if (selnode != null) { selnode._setSelected(false, true, false); } selnode = node; } for (BaseComponent child : node.getChildren()) { selnode = findSelected((Treenode) child, selnode); } return selnode; }
/** * Called after a node's label has been edited. Updates the node's label with the edited value * and takes the node out of edit mode. */ private void editNodeStop() { Treenode currentEdit = (Treenode) txtLabel.getAttribute(ITEM_ATTR); txtLabel.removeAttribute(ITEM_ATTR); popLabel.close(); if (currentEdit != null) { String oldLabel = (String) currentEdit.getAttribute(LABEL_ATTR); String newLabel = txtLabel.getValue(); newLabel = newLabel != null && !newLabel.trim().isEmpty() ? newLabel : oldLabel; currentEdit.setLabel(newLabel); if (!newLabel.equals(oldLabel)) { updateLabel(currentEdit, newLabel); } } }
/** * Override to enable promotion of items * * @param node The node to test. * @return True if the node can be demoted. */ protected boolean canDemote(Treenode node) { return hierarchical && node.getParent() != tree; }
private void expandOrCollapse(BaseComponent parent, boolean collapse) { for (BaseComponent child : parent.getChildren()) { ((Treenode) child).setCollapsed(collapse); expandOrCollapse(child, collapse); } }