private void setLabel(Treenode node, String text, String sclass) { node.setLabel(text); node.addClass(sclass); }
/** * 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); } } }
try { item = clazz.newInstance(); item.setLabel(label); item.setHint(label); parent.addChild(item);
/** * Updates the label for this node. * * @param node A tree node. * @param label Updated label. */ private void updateLabel(Treenode node, String label) { Proxy proxy = getProxy(node); if (proxy != null) { proxy.setLabel(label); } else { node.setLabel(label); } if (node == tree.getSelectedNode() && labelEditor != null) { labelEditor.revert(); } doChanged(false); }
/** * 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; }
/** * 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); } }
/** * Call this to update the grid to reflect a newly selected target. */ private void selectionChanged() { selectionChanging = true; editNodeStop(); if (currentItem != null) { propertyGrid.commitChanges(true); Proxy proxy = getProxy(currentItem); if (proxy != null) { currentItem.setLabel(proxy.getLabel()); } } currentItem = tree.getSelectedNode(); propertyGrid.setTarget(getProxy(currentItem)); labelEditor = propertyGrid.findEditor(labelProperty, false); if (labelEditor != null) { labelEditor.getEditor().addEventForward(ChangeEvent.TYPE, tree, "onLabelChange"); } updateControls(); selectionChanging = false; }