List of usage examples for javax.swing JTree getModel
public TreeModel getModel()
TreeModel
that is providing the data. From source file:org.eclipse.jubula.rc.swing.tester.util.TreeOperationContext.java
/** * Creates a new instance. The JTree must have a tree model. * //from ww w .j a va2s .c o m * @param queuer The queuer * @param robot The Robot * @param tree The tree */ public TreeOperationContext(IEventThreadQueuer queuer, IRobot robot, JTree tree) { super(queuer, robot, tree); Validate.notNull(tree.getModel()); m_model = tree.getModel(); }
From source file:org.eclipse.jubula.rc.swing.tester.util.TreeOperationContext.java
/** * {@inheritDoc}//w ww . j av a 2 s .c om */ public Object[] getRootNodes() { JTree tree = (JTree) getTree(); // If the root is visible, just return that. if (tree.isRootVisible()) { return new Object[] { tree.getModel().getRoot() }; } // If the root is not visible, return all direct children of the // non-visible root. return getChildren(tree.getModel().getRoot()); }
From source file:org.eclipse.wb.tests.designer.swing.model.component.JTreeTest.java
public void test_JTree_parsing() throws Exception { ContainerInfo panel = parseContainer("import javax.swing.tree.*;", "public class Test extends JPanel {", " public Test() {", " JTree tree = new JTree();", " add(tree);", " tree.setModel(new DefaultTreeModel(", " new DefaultMutableTreeNode('(root)') {", " {", " DefaultMutableTreeNode node1 = new DefaultMutableTreeNode('1');", " DefaultMutableTreeNode node2 = new DefaultMutableTreeNode('11');", " node1.add(node2);", " add(node1);", " node1 = new DefaultMutableTreeNode('2');", " node1.add(new DefaultMutableTreeNode('21'));", " add(node1);", " }", " }", " ));", " }", "}"); panel.refresh();//from w w w .j av a 2 s. c om // ComponentInfo treeInfo = panel.getChildrenComponents().get(0); JTree treeObject = (JTree) treeInfo.getObject(); // validate model { TreeModel model = treeObject.getModel(); assertNotNull(model); DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) model.getRoot(); { assertEquals("(root)", rootNode.getUserObject()); assertEquals(2, rootNode.getChildCount()); } { DefaultMutableTreeNode node_1 = (DefaultMutableTreeNode) rootNode.getChildAt(0); assertEquals("1", node_1.getUserObject()); assertEquals(1, node_1.getChildCount()); { DefaultMutableTreeNode node_2 = (DefaultMutableTreeNode) node_1.getChildAt(0); assertEquals("11", node_2.getUserObject()); assertEquals(0, node_2.getChildCount()); } } { DefaultMutableTreeNode node_1 = (DefaultMutableTreeNode) rootNode.getChildAt(1); assertEquals("2", node_1.getUserObject()); assertEquals(1, node_1.getChildCount()); { DefaultMutableTreeNode node_2 = (DefaultMutableTreeNode) node_1.getChildAt(0); assertEquals("21", node_2.getUserObject()); assertEquals(0, node_2.getChildCount()); } } } // check "model" property { Property modelProperty = treeInfo.getPropertyByTitle("model"); PropertyEditor modelEditor = modelProperty.getEditor(); // text { String text = (String) ReflectionUtils.invokeMethod2(modelEditor, "getText", Property.class, modelProperty); assertEquals("(root), +1, ++11, +2, ++21", text); } // tooltip { String tooltip = getPropertyTooltipText(modelEditor, modelProperty); assertEquals(StringUtils.join( new String[] { "(root)", " 1", " 11", " 2", " 21" }, "\n"), tooltip); // position PropertyTooltipProvider provider = modelEditor.getAdapter(PropertyTooltipProvider.class); assertSame(PropertyTooltipProvider.BELOW, provider.getTooltipPosition()); } } }
From source file:org.geopublishing.atlasViewer.GpCoreUtil.java
/** * If expand is true, expands all nodes in the tree. Otherwise, collapses * all nodes in the tree.//from w w w . j a v a 2 s. c o m */ public final static void expandAll(final JTree tree, final boolean expand) { final TreeNode root = (TreeNode) tree.getModel().getRoot(); // Traverse tree from root expandAll(tree, new TreePath(root), expand); }
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 ww .j a va 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.nuclos.client.explorer.ExplorerNode.java
/** * refreshes the current node (and its children) and notifies the given treemodel * @param dtm the DefaultTreeModel to notify. Must contain this node. * @throws CommonFinderException if the object presented by this node no longer exists. *//*from w ww . j a v a 2 s . c o m*/ public void refresh(final JTree tree, boolean fullRefreshCurrent) throws CommonFinderException { List<String> lstExpandedPathsResult = new ArrayList<String>(); ExplorerNode.createExpandendPathsForTree(new TreePath(tree.getModel().getRoot()), tree, lstExpandedPathsResult); final TreePath selected = tree.getSelectionPath(); DefaultTreeModel dtm = (DefaultTreeModel) tree.getModel(); unloadChildren(); final TN treenode = getTreeNode(); if (treenode.implementsNewRefreshMethod()) { TN refreshed = null; if (fullRefreshCurrent && !this.isRoot()) { TreeNode parentTreeNode = ((ExplorerNode<TN>) this.getParent()).getTreeNode(); parentTreeNode.removeSubNodes(); List<? extends TreeNode> parentSubNodes = parentTreeNode.getSubNodes(); for (TreeNode parentSubNode : parentSubNodes) { if (ObjectUtils.equals(parentSubNode.getId(), treenode.getId())) refreshed = (TN) parentSubNode; } if (refreshed == null) { this.removeFromParent(); dtm.nodeStructureChanged(this); return; } } else { refreshed = (TN) treenode.refreshed(); } setTreeNode(refreshed); } else { treenode.refresh(); } treenode.removeSubNodes(); loadChildren(true); assert getChildrenHaveBeenLoaded(); dtm.nodeStructureChanged(this); ExplorerNode.expandTreeAsync(lstExpandedPathsResult, tree); if (selected != null) { List<Object> pathEssence = CollectionUtils.asList(selected.getPath()); Collections.reverse(pathEssence); if (pathEssence.size() > 1) { pathEssence = pathEssence.subList(0, pathEssence.size() - 1); new Thread(new TreeExpander(tree, pathEssence)).start(); } } }
From source file:org.nuclos.client.explorer.ExplorerNode.java
static void expandTreeAsync(List<String> lstExpandedPaths, final JTree tree) { for (final String idPath : lstExpandedPaths) { SwingUtilities.invokeLater(new Runnable() { @Override/*from w w w. j ava2s .c om*/ public void run() { DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); TreePath path = ExplorerNode.findDescendant(model, idPath); if (path != null) tree.expandPath(path); } }); } }
From source file:org.nuclos.client.ui.collect.searcheditor.SearchConditionTreeNode.java
protected void refresh(JTree tree) { this.refresh((DefaultTreeModel) tree.getModel()); }
From source file:org.olivier.ihm.FramePUMLCleanerControler.java
/** * Filtre le fichier PUML stock dans le textArea partir du filtre contenu * dans le JTree/*from www . j ava 2 s . com*/ * * @param jTextAreaFichier * @param jTreeFiltre */ private void filtrerFichier(JTextArea jTextAreaFichier, JTree jTreeFiltre) { jTextAreaFichier.setText(""); // Liste des noeuds supprimer final DefaultMutableTreeNode nodeToDelete = getNodeToDelete( (DefaultMutableTreeNode) jTreeFiltre.getModel().getRoot(), checkTreeManager.getSelectionModel().getSelectionPaths()); // traitement des lignes for (String line : lines) { if (isLinePrintable(line, nodeToDelete)) { jTextAreaFichier.append(line + "\n"); } } jTextAreaFichier.requestFocus(); }
From source file:org.openmicroscopy.shoola.agents.util.SelectionWizardUI.java
/** * Updates the specified tree./* ww w.j av a 2 s. c o m*/ * * @param tree The tree to update. * @param nodes The collection of nodes to handle. */ private void populateTreeItems(JTree tree, List<TreeImageDisplay> nodes) { DefaultTreeModel dtm = (DefaultTreeModel) tree.getModel(); TreeImageDisplay parent = (TreeImageDisplay) dtm.getRoot(); parent.removeAllChildrenDisplay(); parent.removeAllChildren(); Iterator<TreeImageDisplay> i = nodes.iterator(); TreeImageDisplay node, child; Iterator<TreeImageDisplay> j; Set<TreeImageDisplay> toExpand = new HashSet<TreeImageDisplay>(); while (i.hasNext()) { node = i.next(); node.setDisplayItems(false); Object ho = node.getUserObject(); if (ho instanceof TagAnnotationData) { TagAnnotationData tag = (TagAnnotationData) ho; if (!TagAnnotationData.INSIGHT_TAGSET_NS.equals(tag.getNameSpace()) || node.hasChildrenDisplay()) { dtm.insertNodeInto(node, parent, parent.getChildCount()); } } else { dtm.insertNodeInto(node, parent, parent.getChildCount()); } if (node.hasChildrenDisplay()) { node.removeAllChildren(); tree.expandPath(new TreePath(node.getPath())); Collection<TreeImageDisplay> l = node.getChildrenDisplay(); l = sorter.sort(l); j = l.iterator(); while (j.hasNext()) { child = j.next(); child.setDisplayItems(false); if (!isSelected(child) && !isFiltered(child)) { dtm.insertNodeInto(child, node, node.getChildCount()); toExpand.add(node); tree.expandPath(new TreePath(node.getPath())); } } } } dtm.reload(); i = toExpand.iterator(); while (i.hasNext()) { tree.expandPath(new TreePath(i.next().getPath())); } }