List of usage examples for javax.swing.tree DefaultMutableTreeNode getPath
public TreeNode[] getPath()
From source file:org.apache.oodt.cas.workflow.gui.perspective.view.impl.DefaultTreeView.java
private TreePath getTreePath(TreePath currentPath, ViewState state) { String lookingForPath = state.getCurrentMetGroup(); Stack<DefaultMutableTreeNode> stack = new Stack<DefaultMutableTreeNode>(); DefaultMutableTreeNode baseNode = (DefaultMutableTreeNode) currentPath.getLastPathComponent(); for (int i = 0; i < baseNode.getChildCount(); i++) { stack.push((DefaultMutableTreeNode) baseNode.getChildAt(i)); }/*ww w. j a va 2 s . com*/ while (!stack.empty()) { DefaultMutableTreeNode node = stack.pop(); if (node.getUserObject().equals("static-metadata")) { for (int i = 0; i < node.getChildCount(); i++) { stack.push((DefaultMutableTreeNode) node.getChildAt(i)); } } else if (node.getUserObject() instanceof ConcurrentHashMap) { String key = (String) ((ConcurrentHashMap<String, String>) node.getUserObject()).keySet().iterator() .next(); if (lookingForPath.equals(key)) { return new TreePath(node.getPath()); } else if (lookingForPath.startsWith(key + "/")) { lookingForPath = lookingForPath.substring(lookingForPath.indexOf("/") + 1); stack.clear(); for (int i = 0; i < node.getChildCount(); i++) { stack.add((DefaultMutableTreeNode) node.getChildAt(i)); } } } } return currentPath; }
From source file:org.kuali.test.ui.components.repositorytree.RepositoryTree.java
/** * * @param platformName/* www . java2 s .co m*/ * @return */ public Platform selectPlatformByName(String platformName) { Platform retval = null; Enumeration<DefaultMutableTreeNode> e = getRootNode().children(); while (e.hasMoreElements()) { DefaultMutableTreeNode node = e.nextElement(); Platform p = (Platform) node.getUserObject(); if (p.getName().equals(platformName)) { getSelectionModel().setSelectionPath(new TreePath(node.getPath())); retval = p; break; } } return retval; }
From source file:org.mbari.aved.ui.classifier.knowledgebase.ConceptTree.java
/** * Makes the children nodes under the specified node invisible. * * @param node The node on which to act. *//*from www . j a v a 2 s .com*/ private void makeChildrenInvisible(DefaultMutableTreeNode node) { Enumeration children = node.children(); while (children.hasMoreElements()) { DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) children.nextElement(); if (!childNode.isLeaf()) { makeChildrenInvisible(childNode); TreeNode[] nodesFromRoot = childNode.getPath(); TreePath pathFromRoot = new TreePath(nodesFromRoot); collapsePath(pathFromRoot); } } }
From source file:org.mbari.aved.ui.classifier.knowledgebase.ConceptTree.java
/** * Makes the children nodes under the specified node visible. * * @param node The node on which to act. *//*from w w w . j a v a 2s. c om*/ private void makeChildrenVisible(DefaultMutableTreeNode node) { // RxTBD wcpr The Java API interaction of using TreeNodes and TreePaths // doesn't seem to make sense. There should be a cleaner way to implement // this method. if (node.isLeaf()) { return; } // Expand the node TreeConcept treeConcept = (TreeConcept) node.getUserObject(); treeConcept.lazyExpand(node); boolean allChildrenAreLeaves = true; Enumeration children = node.children(); while (children.hasMoreElements()) { DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) children.nextElement(); if (!childNode.isLeaf()) { makeChildrenVisible(childNode); allChildrenAreLeaves = false; } } if (allChildrenAreLeaves) { DefaultMutableTreeNode lastNode = (DefaultMutableTreeNode) node.getLastChild(); TreeNode[] nodesFromRoot = node.getPath(); TreePath pathFromRoot = new TreePath(nodesFromRoot).pathByAddingChild(lastNode); makeVisible(pathFromRoot); } }
From source file:org.mbari.aved.ui.classifier.knowledgebase.ConceptTree.java
/** * Sets the selected tree node to the node representing the specified * <code>Concept</code> name. * * @param name The new selectedConcept value *///from w w w . j av a 2 s . c o m public void setSelectedConcept(String name) { if (name == null) { return; } // RxNOTE Strategy: The tree node for the Concept being selected may not // yet be expanded, so expand down to the desired node. DefaultMutableTreeNode treeNode = expandDownToNode(name); // Now select the node and scroll to it. TreePath path = new TreePath(treeNode.getPath()); setSelectionPath(path); scrollPathToVisible(path); }
From source file:org.mbari.aved.ui.classifier.knowledgebase.ConceptTree.java
/** * Sets the parent node of the currently selected node to be the node * representing the <code>Concept</code> of the specified name. * * @param newParentName The name of the <code>Concept</code> for which the currently selected * node is to become a child.// www . j a va 2 s. c om */ public void updateTreeNodeParent(String newParentName) { // Get the node being moved DefaultMutableTreeNode conceptNode = (DefaultMutableTreeNode) getSelectionPath().getLastPathComponent(); String conceptNodeName = ((TreeConcept) conceptNode.getUserObject()).getName(); DefaultTreeModel treeModel = (DefaultTreeModel) getModel(); // Remove node from current parent node and update structure DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) conceptNode.getParent(); parentNode.remove(conceptNode); treeModel.nodeStructureChanged(parentNode); // Get the new parent node DefaultMutableTreeNode newParentNode = expandDownToNode(newParentName); TreeConcept treeConcept = (TreeConcept) newParentNode.getUserObject(); boolean parentNeededExpanding = treeConcept.lazyExpand(newParentNode); // Branch on whether parent needed expanding: // - The parent node needed to be expanded. The call to lazyExpand() // updates the parent node's children so we don't need to explicitly add // the new child node. Find and select the new child node. // - The parent node is already expanded, so insert the new child node in // the appropriate slot and select the new child node. if (parentNeededExpanding) { Enumeration children = newParentNode.children(); while (children.hasMoreElements()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) children.nextElement(); String nodeName = ((TreeConcept) node.getUserObject()).getName(); if (nodeName.equals(conceptNodeName)) { setSelectionPath(new TreePath(node.getPath())); break; } } } else { // Insert the node at the appropriate point in the new parent node. int insertPosition = 0; Enumeration children = newParentNode.children(); while (children.hasMoreElements()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) children.nextElement(); String nodeName = ((TreeConcept) node.getUserObject()).getName(); if (0 < nodeName.compareTo(conceptNodeName)) { break; } else { insertPosition++; } } treeModel.insertNodeInto(conceptNode, newParentNode, insertPosition); setSelectionPath(new TreePath(conceptNode.getPath())); } }
From source file:org.mbari.aved.ui.classifier.knowledgebase.SearchableConceptTreePanel.java
/** * Loads the branch of a particular concept. This method does the following * <ol>//from w w w . jav a 2s. c o m * <li>Walks from the concept up the tree to the root concept, storing * the concepts in a list. (This is very fast)</li> * <li>Starts walking from the root down (using lazyExpand), searching each * childnode for a matching primary name (which was stored in the first * step</li> * <li>If a matching primary name is found this stops otherwise * it opens the next level and searches for the next mathc in the list.</li> * <li></li> * </ol> * @param concept */ private void openNode(final Concept concept) { if (log.isDebugEnabled()) { log.debug("Opening node containing " + concept); } if (concept == null) { return; } // Get the list of concepts up to root final LinkedList conceptList = new LinkedList(); Concept c = concept; while (c != null) { conceptList.add(c); c = (Concept) c.getParentConcept(); } // Walk the tree from root on down opening nodes as we go final ListIterator i = conceptList.listIterator(conceptList.size()); // Skip the root i.previous(); final JTree tree = getJTree(); final DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel(); final DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) treeModel.getRoot(); TreePath path = new TreePath(rootNode.getPath()); tree.setSelectionPath(path); DefaultMutableTreeNode parentNode = rootNode; while (i.hasPrevious()) { c = (Concept) i.previous(); final TreeConcept parentTreeConcept = (TreeConcept) parentNode.getUserObject(); parentTreeConcept.lazyExpand(parentNode); // treeModel.reload(parentNode); final Enumeration enm = parentNode.children(); while (enm.hasMoreElements()) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode) enm.nextElement(); final TreeConcept tc = (TreeConcept) node.getUserObject(); if (tc.getName().equals(c.getPrimaryConceptNameAsString())) { parentNode = node; break; } } } final TreeNode _parentNode = parentNode; SwingUtilities.invokeLater(new Runnable() { public void run() { treeModel.reload(_parentNode); tree.scrollPathToVisible(new TreePath(_parentNode)); } }); }
From source file:org.objectstyle.cayenne.modeler.ProjectTreeView.java
private void initFromModel(Project project) { // build model ProjectTreeModel model = new ProjectTreeModel(project); setRootVisible(false);//from ww w .jav a2 s . c om setModel(model); // expand top level getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); Enumeration level = model.getRootNode().children(); while (level.hasMoreElements()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) level.nextElement(); TreePath path = new TreePath(node.getPath()); expandPath(path); } }
From source file:org.objectstyle.cayenne.modeler.ProjectTreeView.java
/** Makes node current, visible and selected. */ protected void showNode(DefaultMutableTreeNode node) { TreePath path = new TreePath(node.getPath()); scrollPathToVisible(path);/* w w w .j ava 2s .c o m*/ setSelectionPath(path); }
From source file:org.openconcerto.erp.model.RubriquePayeTree.java
public RubriquePayeTree() { super();//from w ww . j a v a 2s.c o m this.setModel(model); DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer(); renderer.setOpenIcon(null); renderer.setClosedIcon(null); renderer.setLeafIcon(null); this.setCellRenderer(renderer); DefaultMutableTreeNode currentNode = ((DefaultMutableTreeNode) this.getModel().getRoot()).getNextNode(); do { if (currentNode.getLevel() == 1) this.expandPath(new TreePath(currentNode.getPath())); currentNode = currentNode.getNextNode(); } while (currentNode != null); }