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); } }
void deleteNode(DefaultMutableTreeNode node) throws Exception { DefaultTreeModel model = (DefaultTreeModel) m_tree.getModel(); HRMBusinessLogic logic = new HRMBusinessLogic(m_conn); logic.orgLogic.deleteOrganization( logic, m_sessionid, IDBConstants.MODUL_MASTER_DATA, ((Organization) node.getUserObject())); model.removeNodeFromParent(node); }
/** * Update the layouts tree. * * @param current The name of the current layout or <CODE>null</CODE> if none. */ public void updateLayouts(Path current) throws PipelineException { DefaultMutableTreeNode root = null; { root = new DefaultMutableTreeNode(new TreeData(), true); { Path path = new Path(PackageInfo.getSettingsPath(), "layouts"); rebuildTreeModel(path, new Path("/"), root); } DefaultTreeModel model = (DefaultTreeModel) pTree.getModel(); model.setRoot(root); { Enumeration e = root.depthFirstEnumeration(); if (e != null) { while (e.hasMoreElements()) { DefaultMutableTreeNode tnode = (DefaultMutableTreeNode) e.nextElement(); pTree.expandPath(new TreePath(tnode.getPath())); } } } } pTree.clearSelection(); if (current != null) { TreePath tpath = null; DefaultMutableTreeNode tnode = root; for (String comp : current.getComponents()) { DefaultMutableTreeNode next = null; Enumeration e = tnode.children(); if (e != null) { while (e.hasMoreElements()) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) e.nextElement(); TreeData data = (TreeData) child.getUserObject(); if (data.toString().equals(comp)) { tpath = new TreePath(child.getPath()); next = child; break; } } } if (next == null) break; tnode = next; } if (tpath != null) { pTree.setSelectionPath(tpath); pTree.makeVisible(tpath); } } }
// {{{ removeSelectedNode() method private void removeSelectedNode() { TreePath path = resultTree.getSelectionPath(); if (path == null) return; MutableTreeNode value = (MutableTreeNode) path.getLastPathComponent(); if (path.getPathCount() > 1) { // Adjust selection so that repeating some removals // behave naturally. TreePath parentPath = path.getParentPath(); MutableTreeNode parent = (MutableTreeNode) parentPath.getLastPathComponent(); int removingIndex = parent.getIndex(value); int nextIndex = removingIndex + 1; if (nextIndex < parent.getChildCount()) { TreeNode next = parent.getChildAt(nextIndex); resultTree.setSelectionPath(parentPath.pathByAddingChild(next)); } else { resultTree.setSelectionPath(parentPath); } resultTreeModel.removeNodeFromParent(value); } HyperSearchOperationNode.removeNodeFromCache(value); if (resultTreeRoot.getChildCount() == 0) { hideDockable(); } } // }}}
public void nodeAdded(String fqn) { MyNode n, p; n = root.add(fqn); if (n != null) { p = (MyNode) n.getParent(); tree_model.reload(p); jtree.scrollPathToVisible(new TreePath(n.getPath())); } }
/* Simple tree node factory method - set's parent and user object. */ private DefaultMutableTreeNode makeNode(Object userObject, MutableTreeNode parent) { DefaultMutableTreeNode node = new DefaultMutableTreeNode(userObject); if (parent != null) { treeModel.insertNodeInto(node, parent, parent.getChildCount()); } return node; }
protected void doSort() { Pair<ElementNode, List<ElementNode>> pair = storeSelection(); Enumeration<ParentNode> children = getRootNodeChildren(); while (children.hasMoreElements()) { ParentNode classNode = children.nextElement(); sortNode(classNode, myComparator); myTreeModel.nodeStructureChanged(classNode); } restoreSelection(pair); }
public void nodeRemoved(String fqn) { MyNode n; TreeNode par; n = root.findNode(fqn); if (n != null) { n.removeAllChildren(); par = n.getParent(); n.removeFromParent(); tree_model.reload(par); } }
/** 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()); } } }
protected void restoreTree() { Pair<ElementNode, List<ElementNode>> selection = storeSelection(); DefaultMutableTreeNode root = getRootNode(); if (!myShowClasses || myContainerNodes.isEmpty()) { List<ParentNode> otherObjects = new ArrayList<ParentNode>(); Enumeration<ParentNode> children = getRootNodeChildren(); ParentNode newRoot = new ParentNode( null, new MemberChooserObjectBase(getAllContainersNodeName()), new Ref<Integer>(0)); while (children.hasMoreElements()) { final ParentNode nextElement = children.nextElement(); if (nextElement instanceof ContainerNode) { final ContainerNode containerNode = (ContainerNode) nextElement; Enumeration<MemberNode> memberNodes = containerNode.children(); List<MemberNode> memberNodesList = new ArrayList<MemberNode>(); while (memberNodes.hasMoreElements()) { memberNodesList.add(memberNodes.nextElement()); } for (MemberNode memberNode : memberNodesList) { newRoot.add(memberNode); } } else { otherObjects.add(nextElement); } } replaceChildren(root, otherObjects); sortNode(newRoot, myComparator); if (newRoot.children().hasMoreElements()) root.add(newRoot); } else { Enumeration<ParentNode> children = getRootNodeChildren(); while (children.hasMoreElements()) { ParentNode allClassesNode = children.nextElement(); Enumeration<MemberNode> memberNodes = allClassesNode.children(); ArrayList<MemberNode> arrayList = new ArrayList<MemberNode>(); while (memberNodes.hasMoreElements()) { arrayList.add(memberNodes.nextElement()); } Collections.sort(arrayList, myComparator); for (MemberNode memberNode : arrayList) { myNodeToParentMap.get(memberNode).add(memberNode); } } replaceChildren(root, myContainerNodes); } myTreeModel.nodeStructureChanged(root); defaultExpandTree(); restoreSelection(selection); }
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(); }
// {{{ removeAllNodes() method private void removeAllNodes() { resultTreeRoot.removeAllChildren(); resultTreeModel.reload(resultTreeRoot); setSearchStatus(null); hideDockable(); } // }}}
/* Clear all existing nodes from the tree model and rebuild from scratch. */ protected void refreshTree() { DefaultMutableTreeNode propertiesNode; DefaultMutableTreeNode leaf; // First clear the existing tree by simply enumerating // over the root node's children and removing them one by one. while (treeModel.getChildCount(rootNode) > 0) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) treeModel.getChild(rootNode, 0); treeModel.removeNodeFromParent(child); child.removeAllChildren(); child.removeFromParent(); } treeModel.nodeStructureChanged(rootNode); treeModel.reload(); tScrollPane.repaint(); // Now rebuild the tree below its root try { // Start by naming the root node from its URL: rootNode.setUserObject(dMeta.getURL()); // get metadata about user tables by building a vector of table names String usertables[] = {"TABLE", "GLOBAL TEMPORARY", "VIEW"}; ResultSet result = dMeta.getTables(null, null, null, usertables); Vector tables = new Vector(); // sqlbob@users Added remarks. Vector remarks = new Vector(); while (result.next()) { tables.addElement(result.getString(3)); remarks.addElement(result.getString(5)); } result.close(); // For each table, build a tree node with interesting info for (int i = 0; i < tables.size(); i++) { String name = (String) tables.elementAt(i); DefaultMutableTreeNode tableNode = makeNode(name, rootNode); ResultSet col = dMeta.getColumns(null, null, name, null); // sqlbob@users Added remarks. String remark = (String) remarks.elementAt(i); if ((remark != null) && !remark.trim().equals("")) { makeNode(remark, tableNode); } // With a child for each column containing pertinent attributes while (col.next()) { String c = col.getString(4); DefaultMutableTreeNode columnNode = makeNode(c, tableNode); String type = col.getString(6); makeNode("Type: " + type, columnNode); boolean nullable = col.getInt(11) != DatabaseMetaData.columnNoNulls; makeNode("Nullable: " + nullable, columnNode); } col.close(); DefaultMutableTreeNode indexesNode = makeNode("Indices", tableNode); ResultSet ind = dMeta.getIndexInfo(null, null, name, false, false); String oldiname = null; // A child node to contain each index - and its attributes while (ind.next()) { DefaultMutableTreeNode indexNode = null; boolean nonunique = ind.getBoolean(4); String iname = ind.getString(6); if ((oldiname == null || !oldiname.equals(iname))) { indexNode = makeNode(iname, indexesNode); makeNode("Unique: " + !nonunique, indexNode); oldiname = iname; } // And the ordered column list for index components makeNode(ind.getString(9), indexNode); } ind.close(); } // Finally - a little additional metadata on this connection propertiesNode = makeNode("Properties", rootNode); makeNode("User: "******"ReadOnly: " + cConn.isReadOnly(), propertiesNode); makeNode("AutoCommit: " + cConn.getAutoCommit(), propertiesNode); makeNode("Driver: " + dMeta.getDriverName(), propertiesNode); makeNode("Product: " + dMeta.getDatabaseProductName(), propertiesNode); makeNode("Version: " + dMeta.getDatabaseProductVersion(), propertiesNode); } catch (SQLException se) { propertiesNode = makeNode("Error getting metadata:", rootNode); makeNode(se.getMessage(), propertiesNode); makeNode(se.getSQLState(), propertiesNode); } treeModel.nodeStructureChanged(rootNode); treeModel.reload(); tScrollPane.repaint(); }