/** Removes the current selected group. */ final void removeSelectedGroup() { TreePath[] selectionPaths = this.tree.getSelectionPaths(); if (selectionPaths == null) { return; } DefaultTreeModel model = (DefaultTreeModel) this.tree.getModel(); ElementTreeNode rootNode = (ElementTreeNode) model.getRoot(); for (TreePath selectionPath : selectionPaths) { ElementTreeNode treeNode = (ElementTreeNode) selectionPath.getLastPathComponent(); if (treeNode.getUserObject() instanceof ElementGroup) { ElementGroup elementGroup = (ElementGroup) treeNode.getUserObject(); this.model.removeGroup(elementGroup); model.nodesWereRemoved( rootNode, new int[] {rootNode.getIndex(treeNode)}, new Object[] {treeNode}); } } }
/** Adds a new group to our tree and element model. */ final void addNewGroup() { DefaultTreeModel model = (DefaultTreeModel) this.tree.getModel(); boolean groupSummaryVisibleByDefault = UIManager.getBoolean(GROUP_SUMMARY_VISIBLE_DEFAULT); boolean scopeVisibleByDefault = UIManager.getBoolean(ANALOG_SCOPE_VISIBLE_DEFAULT); int groupCount = this.model.getGroups().size(); String name = String.format("Group %d", Integer.valueOf(groupCount + 1)); // Create model structure... ElementGroup newGroup = this.model.addGroup(name); newGroup.setVisible(true); SignalElement groupSummaryElement = SignalElement.createGroupSummaryElement(newGroup); groupSummaryElement.setEnabled(groupSummaryVisibleByDefault); newGroup.addElement(groupSummaryElement); SignalElement analogScopeElement = SignalElement.createAnalogScopeElement(newGroup); analogScopeElement.setEnabled(scopeVisibleByDefault); newGroup.addElement(analogScopeElement); // Create tree structure... ElementTreeNode rootNode = (ElementTreeNode) model.getRoot(); ElementTreeNode groupNode = new ElementTreeNode(newGroup); rootNode.add(groupNode); groupNode.add(new ElementTreeNode(groupSummaryElement)); groupNode.add(new ElementTreeNode(analogScopeElement)); int index = rootNode.getIndex(groupNode); model.nodesWereInserted(rootNode, new int[] {index}); model.nodeStructureChanged(groupNode); this.tree.expandRow(index); }