List of usage examples for javax.swing.tree TreePath TreePath
public TreePath(Object lastPathComponent)
From source file:org.nuclos.client.explorer.ExplorerNode.java
/** * expand all children of this node/*w w w. j ava 2s.co m*/ * @param tree */ public void expandAllChildren(final JTree tree) { for (int i = getChildCount() - 1; i >= 0; i--) { final TreePath treePath = new TreePath( (((DefaultMutableTreeNode) ExplorerNode.this.getChildAt(i))).getPath()); if (!tree.isExpanded(treePath)) { tree.expandPath(treePath); } } }
From source file:org.nuclos.client.explorer.ExplorerNode.java
/** * collapse all children of this node/*from www. j a v a2 s.co m*/ * @param tree */ public void collapseAllChildren(JTree tree) { for (int i = getChildCount() - 1; i >= 0; i--) { tree.collapsePath(new TreePath(((DefaultMutableTreeNode) this.getChildAt(i)).getPath())); } }
From source file:org.nuclos.client.explorer.ExplorerNode.java
public static TreePath findDescendant(DefaultTreeModel model, String idPath) { String[] idComponent = idPath.split("/"); ExplorerNode<?> root = (ExplorerNode<?>) model.getRoot(); if (idComponent.length == 0 || !idComponent[0].equals(root.getTreeNode().getIdentifier())) return null; ExplorerNode<?>[] path = new ExplorerNode<?>[idComponent.length]; path[0] = root;/* w w w . j a v a 2 s . co m*/ for (int i = 1; i < path.length; i++) { ExplorerNode<?> child = path[i - 1].findChildNodeWithIdentifier(idComponent[i]); if (child == null) return null; path[i] = child; } return new TreePath(path); }
From source file:org.objectstyle.cayenne.modeler.ProjectTreeView.java
private void initFromModel(Project project) { // build model ProjectTreeModel model = new ProjectTreeModel(project); setRootVisible(false);/*from w w w . j av a2 s . c o m*/ 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);//from w ww.j a va 2s. c om setSelectionPath(path); }
From source file:org.openconcerto.erp.model.RubriquePayeTree.java
public RubriquePayeTree() { super();// www . j a va 2 s .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); }
From source file:org.openconcerto.erp.panel.ITreeSelection.java
public void setValue(Integer val) { if (val == null) val = EMPTY_ID; // TODO Auto-generated method stub ITreeSelectionNode v = this.mapNode.get(val); if (v.getId() == val) { this.setExpandsSelectedPaths(true); this.setSelectionPath(new TreePath(v.getPath())); }// w ww .jav a 2s . co m // System.err.println("Set value Tree " + val); // if (this.rootNode != null) { // for (int i = 0; i < this.rootNode.getChildCount(); i++) { // Object o = this.rootNode.getChildAt(i); // if (o instanceof FamilleTreeNode) { // FamilleTreeNode v = (FamilleTreeNode) o; // if (v.getId() == val) { // System.err.println("Select TreeNode row Id " + val); // this.setExpandsSelectedPaths(true); // this.setSelectionPath(new TreePath(v.getPath())); // } // } // } // } }
From source file:org.openehealth.coms.cc.consent_applet.applet.ConsentApplet.java
/** * Listener which handles the expansion of TreeNodes * //from ww w. j av a 2s.c o m * @return */ private TreeExpansionListener getMyTreeExpansionListener() { return new TreeExpansionListener() { public void treeCollapsed(TreeExpansionEvent arg0) { } public void treeExpanded(TreeExpansionEvent arg0) { //Normal Tree, load child Nodes from the server if (arg0.getPath().getLastPathComponent() instanceof LazyOIDTreeNode) { LazyOIDTreeNode node = (LazyOIDTreeNode) arg0.getPath().getLastPathComponent(); if (!node.isLeaf() && !node.hasBeenExpanded()) { node.setHasBeenExpanded(true); requestTreeNode(node); } } //Search Tree, expand as usual else if (arg0.getPath().getLastPathComponent() instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) arg0.getPath().getLastPathComponent(); JTree tree = (JTree) arg0.getSource(); tree.expandPath(new TreePath(node.getPath())); } }; }; }
From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserComponent.java
/** * Implemented as specified by the {@link Browser} interface. * @see Browser#setFoundInBrowser(Set)// w ww.ja va2s . c o m */ public void setFoundInBrowser(Set nodes) { if (nodes == null || nodes.size() == 0) { model.setFoundNodes(null); // reset default value. model.setFoundNodeIndex(-1); // reset default value. view.getTreeDisplay().repaint(); return; } List<Object> list = new ArrayList<Object>(nodes.size()); Iterator i = nodes.iterator(); final JTree tree = view.getTreeDisplay(); while (i.hasNext()) list.add(i.next()); Comparator c = new Comparator() { public int compare(Object o1, Object o2) { TreeImageDisplay node1 = (TreeImageDisplay) o1; TreeImageDisplay node2 = (TreeImageDisplay) o2; int i1 = tree.getRowForPath(new TreePath(node1.getPath())); int i2 = tree.getRowForPath(new TreePath(node2.getPath())); return (i1 - i2); } }; Collections.sort(list, c); model.setFoundNodes(list); model.setFoundNodeIndex(0); handleNodeDisplay((TreeImageDisplay) list.get(0)); tree.repaint(); }
From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java
/** * Reacts to node expansion event./* w w w. j a v a 2s . c o m*/ * * @param node The node to handle. * @param expanded Pass <code>true</code> is the node is expanded, * <code>false</code> otherwise. */ private void onNodeNavigation(TreeImageDisplay node, boolean expanded) { node.setExpanded(expanded); controller.onNodeNavigation(node, expanded); treeDisplay.clearSelection(); try { treeDisplay.setSelectionPath(new TreePath(node.getPath())); } catch (Exception e) { } treeDisplay.repaint(); }