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 void rebuildTree() { final TreeStateSnapshot treeStateSnapshot = new TreeStateSnapshot(this); myRootNode.removeAllChildren(); myDescriptorToNodeMap.clear(); myDescriptorToNodeMap.put((TreeDescriptor) myRootNode.getUserObject(), myRootNode); // build tree for (final Breakpoint breakpoint : myBreakpoints) { CheckedTreeNode node = createNode(new BreakpointDescriptor(breakpoint)); node.setChecked(breakpoint.ENABLED); addNode(node); } // remove all package nodes with one child final int count = myRootNode.getChildCount(); final List<CheckedTreeNode> children = new ArrayList<CheckedTreeNode>(); for (int idx = 0; idx < count; idx++) { CheckedTreeNode child = (CheckedTreeNode) myRootNode.getChildAt(idx); if (!(child.getUserObject() instanceof PackageDescriptor)) { children.add(child); continue; } while (child.getUserObject() instanceof PackageDescriptor && child.getChildCount() <= 1) { child = (CheckedTreeNode) child.getChildAt(0); } if (!(child.getUserObject() instanceof PackageDescriptor)) { child = (CheckedTreeNode) child.getParent(); } for (CheckedTreeNode childToRemove = (CheckedTreeNode) child.getParent(); !childToRemove.equals(myRootNode); childToRemove = (CheckedTreeNode) childToRemove.getParent()) { myDescriptorToNodeMap.remove(childToRemove.getUserObject()); } children.add(child); } for (final CheckedTreeNode aChildren : children) { aChildren.removeFromParent(); } myRootNode.removeAllChildren(); for (final CheckedTreeNode child : children) { myRootNode.add(child); } sortChildren(myRootNode); ((DefaultTreeModel) getModel()).nodeStructureChanged(myRootNode); treeStateSnapshot.restore(this); expandPath(new TreePath(myRootNode)); }