private void moveNode(final CheckedTreeNode toolNode, Direction dir) { CheckedTreeNode parentNode = (CheckedTreeNode) toolNode.getParent(); int index = parentNode.getIndex(toolNode); removeNodeFromParent(toolNode); int newIndex = dir.newIndex(index); parentNode.insert(toolNode, newIndex); getModel().nodesWereInserted(parentNode, new int[] {newIndex}); }
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; }
private CheckedTreeNode findGroupNode(final String group) { for (int i = 0; i < getTreeRoot().getChildCount(); i++) { CheckedTreeNode node = (CheckedTreeNode) getTreeRoot().getChildAt(i); ToolsGroup g = (ToolsGroup) node.getUserObject(); if (Comparing.equal(group, g.getName())) return node; } return null; }
private CheckedTreeNode insertNewGroup(final ToolsGroup groupCopy) { CheckedTreeNode root = getTreeRoot(); CheckedTreeNode groupNode = new CheckedTreeNode(groupCopy); root.add(groupNode); for (Tool tool : groupCopy.getElements()) { insertNewTool(groupNode, tool); } return groupNode; }
private void removeSelected() { CheckedTreeNode node = getSelectedToolNode(); if (node != null) { int result = Messages.showYesNoDialog( this, ToolsBundle.message("tools.delete.confirmation"), CommonBundle.getWarningTitle(), Messages.getWarningIcon()); if (result != 0) { return; } myIsModified = true; if (node.getUserObject() instanceof Tool) { Tool tool = (Tool) node.getUserObject(); CheckedTreeNode parentNode = (CheckedTreeNode) node.getParent(); ((ToolsGroup) parentNode.getUserObject()).removeElement(tool); removeNodeFromParent(node); if (parentNode.getChildCount() == 0) { removeNodeFromParent(parentNode); } } else if (node.getUserObject() instanceof ToolsGroup) { removeNodeFromParent(node); } update(); myTree.requestFocus(); } }
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; }
private void moveNode(final Direction direction) { CheckedTreeNode node = getSelectedNode(); if (node != null) { if (isMovingAvailable(node, direction)) { moveNode(node, direction); if (node.getUserObject() instanceof Tool) { ToolsGroup group = (ToolsGroup) (((CheckedTreeNode) node.getParent()).getUserObject()); Tool tool = (Tool) node.getUserObject(); moveElementInsideGroup(tool, group, direction); } TreePath path = new TreePath(node.getPath()); myTree.getSelectionModel().setSelectionPath(path); myTree.expandPath(path); myTree.requestFocus(); } } }
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 ToolsGroup[] getGroupList() { ArrayList<ToolsGroup> result = new ArrayList<ToolsGroup>(); MutableTreeNode root = (MutableTreeNode) myTree.getModel().getRoot(); for (int i = 0; i < root.getChildCount(); i++) { final CheckedTreeNode node = (CheckedTreeNode) root.getChildAt(i); for (int j = 0; j < node.getChildCount(); j++) { final CheckedTreeNode toolNode = (CheckedTreeNode) node.getChildAt(j); ((Tool) toolNode.getUserObject()).setEnabled(toolNode.isChecked()); } result.add((ToolsGroup) node.getUserObject()); } return result.toArray(new ToolsGroup[result.size()]); }
@Nullable private ToolsGroup getSelectedToolGroup() { CheckedTreeNode node = getSelectedToolNode(); if (node == null) return null; return node.getUserObject() instanceof ToolsGroup ? (ToolsGroup) node.getUserObject() : null; }
private void nodeWasInserted(final CheckedTreeNode groupNode) { (getModel()) .nodesWereInserted( groupNode.getParent(), new int[] {groupNode.getParent().getChildCount() - 1}); }
private boolean isMovingAvailable(final CheckedTreeNode toolNode, Direction dir) { TreeNode parent = toolNode.getParent(); int index = parent.getIndex(toolNode); return dir.isAvailable(index, parent.getChildCount()); }