private void editSelected() { CheckedTreeNode node = getSelectedToolNode(); if (node != null && node.getUserObject() instanceof Tool) { Tool selected = (Tool) node.getUserObject(); if (selected != null) { String oldGroupName = selected.getGroup(); ToolEditorDialog dlg = new ToolEditorDialog(this); dlg.setData(selected, getGroups()); dlg.show(); if (dlg.isOK()) { selected.copyFrom(dlg.getData()); String newGroupName = selected.getGroup(); if (!Comparing.equal(oldGroupName, newGroupName)) { CheckedTreeNode oldGroupNode = (CheckedTreeNode) node.getParent(); removeNodeFromParent(node); ((ToolsGroup) oldGroupNode.getUserObject()).removeElement(selected); if (oldGroupNode.getChildCount() == 0) { removeNodeFromParent(oldGroupNode); } insertNewTool(selected, true); } else { (getModel()).nodeChanged(node); } myIsModified = true; update(); } } } }
private void insertNewTool(final Tool newTool, boolean setSelection) { CheckedTreeNode groupNode = findGroupNode(newTool.getGroup()); if (groupNode == null) { groupNode = insertNewGroup(new ToolsGroup(newTool.getGroup())); nodeWasInserted(groupNode); } CheckedTreeNode tool = insertNewTool(groupNode, newTool); if (setSelection) { TreePath treePath = new TreePath(tool.getPath()); myTree.expandPath(treePath); myTree.getSelectionModel().setSelectionPath(treePath); } myIsModified = true; }
public void selectTool(final String actionId) { Object root = myTree.getModel().getRoot(); if (root == null || !(root instanceof CheckedTreeNode)) { return; } final List<CheckedTreeNode> nodes = new ArrayList<CheckedTreeNode>(); new Object() { @SuppressWarnings("unchecked") public void collect(CheckedTreeNode node) { if (node.isLeaf()) { Object userObject = node.getUserObject(); if (userObject instanceof Tool && actionId.equals(((Tool) userObject).getActionId())) { nodes.add(node); } } else { for (int i = 0; i < node.getChildCount(); i++) { final TreeNode child = node.getChildAt(i); if (child instanceof CheckedTreeNode) { collect((CheckedTreeNode) child); } } } } }.collect((CheckedTreeNode) root); if (nodes.isEmpty()) { return; } myTree.getSelectionModel().setSelectionPath(new TreePath(nodes.get(0).getPath())); }
private CheckedTreeNode insertNewTool(final CheckedTreeNode groupNode, final Tool toolCopy) { CheckedTreeNode toolNode = new CheckedTreeNode(toolCopy); toolNode.setChecked(toolCopy.isEnabled()); ((ToolsGroup) groupNode.getUserObject()).addElement(toolCopy); groupNode.add(toolNode); nodeWasInserted(toolNode); return toolNode; }