void onEdit() { DefaultTreeModel model = (DefaultTreeModel) m_tree.getModel(); TreePath path = m_tree.getSelectionPath(); DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); Organization org = (Organization) node.getUserObject(); OrganizationEditorDlg dlg = null; if (parent == model.getRoot()) dlg = new OrganizationEditorDlg( pohaci.gumunda.cgui.GumundaMainFrame.getMainFrame(), m_conn, m_sessionid, null, org); else dlg = new OrganizationEditorDlg( pohaci.gumunda.cgui.GumundaMainFrame.getMainFrame(), m_conn, m_sessionid, (DefaultMutableTreeNode) node.getParent(), org); dlg.setVisible(true); if (dlg.getResponse() == JOptionPane.OK_OPTION) { node.setUserObject(dlg.getOrganization()); model.nodeChanged(node); } }
/** 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}); } } }
public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { DefaultTreeModel model = (DefaultTreeModel) m_tree.getModel(); TreePath path = m_tree.getSelectionPath(); if (path != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); if (node == model.getRoot()) { mi_add.setEnabled(true); mi_edit.setEnabled(false); mi_delete.setEnabled(false); } else { mi_add.setEnabled(true); mi_edit.setEnabled(true); mi_delete.setEnabled(true); } Rectangle rectangle = m_tree.getPathBounds(path); if (rectangle.contains(e.getPoint())) m_popupMenu.show(m_tree, e.getX(), e.getY()); } } }
void onAdd() { DefaultTreeModel model = (DefaultTreeModel) m_tree.getModel(); TreePath path = m_tree.getSelectionPath(); DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); OrganizationEditorDlg dlg = null; if (node == model.getRoot()) dlg = new OrganizationEditorDlg( pohaci.gumunda.cgui.GumundaMainFrame.getMainFrame(), m_conn, m_sessionid, null); else dlg = new OrganizationEditorDlg( pohaci.gumunda.cgui.GumundaMainFrame.getMainFrame(), m_conn, m_sessionid, node); dlg.setVisible(true); if (dlg.getResponse() == JOptionPane.OK_OPTION) { Organization org = new Organization(dlg.getOrganization(), dlg.getOrganization().getCode()); DefaultMutableTreeNode child = new DefaultMutableTreeNode(org); model.insertNodeInto(child, node, node.getChildCount()); m_tree.scrollPathToVisible(new TreePath(model.getPathToRoot(child))); } }
/** 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); }
protected DefaultMutableTreeNode getRootNode() { return (DefaultMutableTreeNode) myTreeModel.getRoot(); }