/** * A group of tool groups have been added. * * @param name The catalog name * @param groups The list of tool groups added */ public void toolGroupsAdded(String name, List<ToolGroup> groups) { if (!name.equals(catalog.getName())) return; TreePath path = new TreePath(catalogRoot); Object[] children = new Object[groups.size()]; int[] indicies = new int[groups.size()]; for (int i = 0; i < groups.size(); i++) { ToolGroup group = groups.get(i); ToolGroupTreeNode child = new ToolGroupTreeNode(group, catalogRoot); catalogRoot.insert(child, catalogRoot.getChildCount()); int index = catalogRoot.getIndex(child); indicies[i] = index; children[i] = child; // System.out.println("Catalog bulk root adding group " + group.getName()); } TreeModelEvent treeEvent = new TreeModelEvent(this, path, indicies, children); fireTreeNodesInserted(treeEvent); // Add listeners later to make sure we don't end up with any weird // side effects of a fast building tree. for (int i = 0; i < groups.size(); i++) { ToolGroup group = groups.get(i); group.addToolGroupListener(this); } }
/** * A tool has been removed. Batched removes will come through the toolsRemoved method. * * @param name The catalog name * @param group The toolGroup removed from */ public void toolGroupRemoved(String name, ToolGroup group) { if (!name.equals(catalog.getName())) return; group.removeToolGroupListener(this); TreePath path = new TreePath(catalogRoot); Object[] children = new Object[1]; int[] indicies = new int[1]; ToolGroupTreeNode child = catalogRoot.getTreeNodeChild(group); int index = catalogRoot.getIndex(child); indicies[0] = index; children[0] = child; catalogRoot.remove(child); TreeModelEvent treeEvent = new TreeModelEvent(this, path, indicies, children); fireTreeNodesRemoved(treeEvent); }
/** * A tool group has been added. Batched adds will come through the toolsAdded method. * * @param name The catalog name * @param group The toolGroup added to */ public void toolGroupAdded(String name, ToolGroup group) { if (!name.equals(catalog.getName())) return; TreePath path = new TreePath(catalogRoot); Object[] children = new Object[1]; int[] indicies = new int[1]; ToolGroupTreeNode child = new ToolGroupTreeNode(group, catalogRoot); catalogRoot.insert(child, catalogRoot.getChildCount()); int index = catalogRoot.getIndex(child); indicies[0] = index; children[0] = child; // System.out.println("Catalog root adding group " + group.getName()); TreeModelEvent treeEvent = new TreeModelEvent(this, path, indicies, children); fireTreeNodesInserted(treeEvent); group.addToolGroupListener(this); }
/** * A group of tool groups have been removed. * * @param name The catalog name * @param groups The list of tool groups that have been removed */ public void toolGroupsRemoved(String name, List<ToolGroup> groups) { if (!name.equals(catalog.getName())) return; TreePath path = new TreePath(catalogRoot); Object[] children = new Object[groups.size()]; int[] indicies = new int[groups.size()]; for (int i = 0; i < groups.size(); i++) { ToolGroup group = groups.get(i); group.removeToolGroupListener(this); ToolGroupTreeNode child = catalogRoot.getTreeNodeChild(group); int index = catalogRoot.getIndex(child); indicies[i] = index; children[i] = child; catalogRoot.remove(child); } TreeModelEvent treeEvent = new TreeModelEvent(this, path, indicies, children); fireTreeNodesRemoved(treeEvent); }
/** * Get the index of the given child in the parent node. * * @param parent The parent node to check for * @param child The child to find the index of * @return The position of the child in the parent */ public int getIndexOfChild(Object parent, Object child) { ToolGroupTreeNode treeNode = (ToolGroupTreeNode) parent; return treeNode.getIndex((TreeNode) child); }