List of usage examples for javax.swing.tree TreePath TreePath
public TreePath(Object lastPathComponent)
From source file:com.sec.ose.osi.ui.frm.main.identification.JTreeAllFiles.java
private TreePath getTreePathByFilePathString(DefaultMutableTreeNode rootNode, String selectedFilePath) { TreePath tp = null;// w w w . ja v a 2 s . co m if (selectedFilePath != null) { DefaultMutableTreeNode node = null; Enumeration<?> enumer = rootNode.breadthFirstEnumeration(); String sFilePath = ""; DefaultTreeModel m_model = new DefaultTreeModel(rootNode); TreeNode[] nodes = null; while (enumer.hasMoreElements()) { node = (DefaultMutableTreeNode) enumer.nextElement(); if (node.getUserObject().equals("/")) continue; sFilePath = ((FileNodeInfo) node.getUserObject()).getFilePath(); if (sFilePath.equals(selectedFilePath)) { nodes = m_model.getPathToRoot(node); tp = new TreePath(nodes); break; } } } return tp; }
From source file:ClassTree.java
/** * Adds a new class and any parent classes that aren't yet part of the tree * @param c the class to add//from w ww.jav a2 s . co m * @return the newly added node. */ public DefaultMutableTreeNode addClass(Class<?> c) { // add a new class to the tree // skip non-class types if (c.isInterface() || c.isPrimitive()) return null; // if the class is already in the tree, return its node DefaultMutableTreeNode node = findUserObject(c); if (node != null) return node; // class isn't present--first add class parent recursively Class<?> s = c.getSuperclass(); DefaultMutableTreeNode parent; if (s == null) parent = root; else parent = addClass(s); // add the class as a child to the parent DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(c); model.insertNodeInto(newNode, parent, parent.getChildCount()); // make node visible TreePath path = new TreePath(model.getPathToRoot(newNode)); tree.makeVisible(path); return newNode; }
From source file:jshm.gui.GuiUtil.java
public static List<TreePath> getExpandedPaths(final JXTreeTable tree) { final TreeTableModel model = tree.getTreeTableModel(); final List<TreePath> paths = new ArrayList<TreePath>(); getExpandedPaths(tree, model, new TreePath(model.getRoot()), paths); for (TreePath p : paths) System.out.println(p);// ww w .j a v a2s .c o m return paths; }
From source file:edu.harvard.i2b2.previousquery.QueryPreviousRunsPanel.java
public DefaultMutableTreeNode addNode(QueryConceptTreeNodeData node, DefaultMutableTreeNode parent) { DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(node); QueryConceptTreeNodeData tmpData = new QueryConceptTreeNodeData(); tmpData.name("working ......"); tmpData.tooltip("A tmp node"); tmpData.visualAttribute("LAO"); DefaultMutableTreeNode tmpNode = new DefaultMutableTreeNode(tmpData); treeModel.insertNodeInto(childNode, parent, parent.getChildCount()); if (!(node.visualAttribute().startsWith("L") || node.visualAttribute().equalsIgnoreCase("MA"))) { treeModel.insertNodeInto(tmpNode, childNode, childNode.getChildCount()); }//from ww w.ja va 2s . co m //Make sure the user can see the lovely new node. jTree1.scrollPathToVisible(new TreePath(childNode.getPath())); return childNode; }
From source file:net.sf.jhylafax.addressbook.AddressBook.java
public AddressBook() { ContactModelFactory cmf = Pim.getContactModelFactory(); JHylaFAX.initializeToolkit();//from w ww . j a v a2 s .co m initialize(); ContactDatabase contactDatabase = Pim.getContactDBFactory().createContactDatabase(); // initialize tree content DefaultMutableTreeNode localAddressBookTreeNode = new DefaultMutableTreeNode(); localAddressBook = new ContactCollection(contactDatabase, i18n.tr("Local Address Book")); localAddressBookTreeNode.setUserObject(localAddressBook); rootNode.add(localAddressBookTreeNode); addressBookTree.expandPath(new TreePath(rootNode)); addressBookTree.setSelectionRow(0); updateActions(); }
From source file:com.hp.alm.ali.idea.ui.chooser.FilterableTree.java
public void run() { final HierarchicalEntityModel model = (HierarchicalEntityModel) getModel(); synchronized (model) { String filter;/*from w ww . j a v a 2s . c o m*/ synchronized (queue) { filter = queue.removeFirst(); } final Set<EntityNode> expanded = new HashSet<EntityNode>(); for (EntityNode node : model.getNodes()) { if (isExpanded(new TreePath(node.getPath().toArray()))) { expanded.add(node); } } model.setFilter(filter); model.clearChildFilteredFlag(); if (!filter.isEmpty()) { model.getStatus().loading(); try { String entityType = model.getEntityType(); Set<String> processed = new HashSet<String>(); LinkedList<String> ordered = new LinkedList<String>(); while (entityType != null && processed.add(entityType)) { ordered.addFirst(entityType); // parent first (may spare us from some missing-parent requests) entityType = Metadata.getParentEntity(entityType); } for (String entity : ordered) { handle(model, entity, filter); } model.getStatus().clear(); } catch (Exception e) { model.getStatus().info("Failed to load data", e, null, null); } } UIUtil.invokeAndWaitIfNeeded(new Runnable() { public void run() { List<EntityNode> toLoad = new LinkedList<EntityNode>(); for (EntityNode node : model.getNodes()) { node.filterVisible(); TreePath path = new TreePath(node.getPath().toArray()); if (node.isChildMatching()) { collapsePath(path); // workaround for expand not working sometimes (?!) expandPath(path); } else if (expanded.contains(node)) { expandPath(path); } if (node.isIncomplete() && node.matchesFilter()) { toLoad.add(node); } } if (!toLoad.isEmpty()) { model.lazyLoadChildren(toLoad, false); } } }); } }
From source file:com.haulmont.cuba.desktop.gui.data.TreeModelAdapter.java
public TreePath getTreePath(Object object) { List<Object> list = new ArrayList<>(); if (object instanceof Entity) { Node node = createNode((Entity) object); list.add(node);//from ww w.ja v a 2 s . c om if (datasource.getHierarchyPropertyName() != null) { Entity entity = (Entity) object; while (entity.getValue(datasource.getHierarchyPropertyName()) != null) { entity = entity.getValue(datasource.getHierarchyPropertyName()); // noinspection ConstantConditions if (!datasource.containsItem(entity.getId())) { break; // Child entities with removed parent are happen to be thrown to tree root. } Node parentNode = createNode(entity); list.add(0, parentNode); node.setParent(parentNode); node = parentNode; } } else { List<Object> treePath = getTreePath(getRoot(), (Entity) object); if (treePath != null) { treePath.add(0, rootNode); return new TreePath(treePath.toArray()); } } list.add(0, rootNode); node.setParent(rootNode); } else if (object instanceof Node) { list.add(object); Node n = (Node) object; while (n.getParent() != null) { Object parent = n.getParent(); list.add(0, parent); if (!(parent instanceof Node)) break; else n = (Node) parent; } } else { list.add(object); } return new TreePath(list.toArray(new Object[list.size()])); }
From source file:TreeUtil.java
public static TreePath makeTreePath(String path, DefaultMutableTreeNode parentNode) { DefaultMutableTreeNode tempNode = parentNode; TreePath res = new TreePath(parentNode); StringTokenizer tok = new StringTokenizer(path, "."); String currentPath = null;//from ww w . ja va 2s .c o m while (tok.hasMoreTokens()) { String myTok = tok.nextToken(); currentPath = (currentPath == null) ? myTok : currentPath + "." + myTok; for (int j = 0; j < tempNode.getChildCount(); j++) { DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) tempNode.getChildAt(j); if (childNode.toString().equals(myTok)) { tempNode = childNode; res = res.pathByAddingChild(tempNode); break; } } } return res; }
From source file:de.tbuchloh.kiskis.gui.treeview.TreeView.java
/** * @param node/* w w w .j a va 2 s . c o m*/ * to make visible */ public void display(final MyTreeNode node) { LOG.debug("displaying node=" + node); final TreeNode[] path = _treeModel.getPathToRoot(node); _treeModel.reload(node); if (path != null) { final TreePath treePath = new TreePath(path); this.makeVisible(treePath); this.setSelectionPath(treePath); } }
From source file:com.wwidesigner.gui.StudyView.java
protected void updateView() { // Reset the Constraints category as needed. study.updateConstraints();/*from w w w. jav a2 s .c om*/ // Build the selection tree. DefaultMutableTreeNode root = new DefaultMutableTreeNode(); List<TreePath> selectionPaths = new ArrayList<TreePath>(); // Add all static categories and selection options to the tree. for (String category : study.getCategoryNames()) { DefaultMutableTreeNode node = new DefaultMutableTreeNode(category); if (node != null) { node.setAllowsChildren(true); root.add(node); } String selectedSub = study.getSelectedSub(category); Map<String, String> toolTips = study.getCategory(category).getToolTips(); for (String name : study.getSubcategories(category)) { TreeNodeWithToolTips childNode = new TreeNodeWithToolTips(name); if (childNode != null) { node.add(childNode); if (name.equals(selectedSub)) { selectionPaths.add(new TreePath(childNode.getPath())); } String tip = toolTips.get(name); if (tip != null) { childNode.setToolTip(tip); } } } } TreeModel model = new DefaultTreeModel(root); tree.setModel(model); TreeUtils.expandAll(tree); tree.setSelectionPaths(selectionPaths.toArray(new TreePath[0])); setStudyViewName(); // Update on the appropriate thread SwingUtilities.invokeLater(new Runnable() { public void run() { updateActions(); } }); }