List of usage examples for javax.swing.tree TreePath TreePath
public TreePath(Object lastPathComponent)
From source file:org.kepler.gui.SimpleLibrarySearcher.java
/** * return the path as a TreePath/*w w w .j a va2 s .co m*/ * *@return Description of the Return Value */ private TreePath createPathFromStack() { return new TreePath(_pathStack.toArray()); }
From source file:org.kepler.objectmanager.repository.EcogridRepositoryLibrarySearcher.java
/** * search for value in the library//from w ww . ja v a 2s . c o m * *@param value * the value to search for *@return Description of the Return Value * @throws RepositoryException * @throws AuthenticationException */ @Override public LibrarySearchResults search(String value, boolean authenticate) throws IllegalActionException, RepositoryException, AuthenticationException { try { _results = new LibrarySearchResults(); TreePath path = _library.getPathForRow(0); // get the container Object[] pathComps = path.getPath(); EntityLibrary topLevel = (EntityLibrary) pathComps[0]; EntityLibrary remoteLevel = null; try { remoteLevel = new EntityLibrary(topLevel, "Remote Components"); } catch (NameDuplicationException nde) { Iterator itt = topLevel.entityList().iterator(); while (itt.hasNext()) { CompositeEntity entity = (CompositeEntity) itt.next(); if (entity.getName().equals("Remote Components")) { remoteLevel = (EntityLibrary) entity; remoteLevel.setContainer(null); remoteLevel = new EntityLibrary(topLevel, "Remote Components"); } } } // setup the remote components part of the tree Object[] o = new Object[2]; o[0] = topLevel; o[1] = remoteLevel; _results.add(new TreePath(o)); // get the results from the repository OntologyCatalog ontCatalog = OntologyCatalog.instance(); // search the repository //System.out.println("EcogridRepositoryLibrarySearcher search('" + value + "')"); Iterator repoResults = repository.search(value, authenticate); Iterator<EcogridRepositoryResults> castRepoResultsIterator = (Iterator<EcogridRepositoryResults>) repoResults; List<EcogridRepositoryResults> repoResultsList = iteratorToList(castRepoResultsIterator); //System.out.println("EcogridRepositoryLibrarySearcher found " + repoResultsList.size() + " results"); List<List<EcogridRepositoryResults>> groupedResults = groupResultsByIndex(repoResultsList); //System.out.println("having " + groupedResults.size() + " groups"); // System.out.println("Matched KARs:"); // for (List<EcogridRepositoryResults> resultGroup : groupedResults) { // System.out.println("* " + resultGroup.get(0).getKarEntry().getParent().getId()); // } if (repoResults != null) { EntityLibrary karLevel = null; EntityLibrary repositoryLevel = null; for (List<EcogridRepositoryResults> repoResultsGroup : groupedResults) { //System.out.println("A group has "+repoResultsGroup.size()+" EcogridResult"); boolean isDone = false; for (EcogridRepositoryResults repoResult : repoResultsGroup) { if (!isDone) { karLevel = createKarLevel(remoteLevel, repoResult); // Get the remote repository level repositoryLevel = getRepositoryLevel(remoteLevel, repoResult.getKarEntry().getParent()); isDone = true; } // get each result from the repository CacheObject co = repoResult.getCacheObject(); ActorCacheObject aco = (ActorCacheObject) co; KarXml.KarEntry karEntry = repoResult.getKarEntry(); Object leafObject; if (co == null) { // Not an actor String name = repoResult.getName(); if (name == null) { name = "unnamed"; } NondraggableTreeItem nti = new NondraggableTreeItem(name); if (karEntry.isWorkflow()) { nti.setWorkflowLSID(karEntry.getLsid()); nti.setWorkflowName(karEntry.getWorkflowName()); } StringAttribute alternateGetPopupActionAttribute = new StringAttribute(nti, "_alternateGetPopupAction"); alternateGetPopupActionAttribute.setExpression(RepositoryPopup.class.getName()); StringAttribute notDraggableAttribute = new StringAttribute(nti, "_notDraggable"); notDraggableAttribute.setExpression("true"); // Not strictly needed, but makes reading the MOML a little nicer. //FIXME hardcode to add-on module if ("org.kepler.reporting.roml.ReportLayout" .equals(repoResult.getKarEntry().getType())) { ConfigurableAttribute thumbnailAttribute = new ConfigurableAttribute(nti, "_thumbnailRasterIcon"); thumbnailAttribute.setExpression("/actorthumbs/basic-report-sm.gif"); } leafObject = nti; } else { // An actor CacheNamedObj cno = new CacheNamedObj(new CompositeEntity(new Workspace()), co); if (karEntry.isWorkflow()) { cno.setWorkflowLSID(karEntry.getLsid()); cno.setWorkflowName(karEntry.getWorkflowName()); } StringAttribute entityIdAttribute = new StringAttribute(cno, "entityId"); entityIdAttribute.setExpression(aco.getLSID().toString()); StringAttribute alternateGetMomlActionAttribute = new StringAttribute(cno, "_alternateGetMomlAction"); alternateGetMomlActionAttribute.setExpression(AlternateGetMoml.class.getName()); StringAttribute alternateGetPopupActionAttribute = new StringAttribute(cno, "_alternateGetPopupAction"); alternateGetPopupActionAttribute.setExpression(RepositoryPopup.class.getName()); ConfigurableAttribute thumbnailAttribute = new ConfigurableAttribute(cno, "_thumbnailRasterIcon"); thumbnailAttribute.setExpression("/actorthumbs/basic-actor-sm.gif"); leafObject = cno; } // find the semantic types and loop through them to place // the results if (!skipOntology) { Vector<String> semTypes = repoResult.getSemanticTypes(); for (int k = 0; k < semTypes.size(); k++) { String semType = (String) semTypes.elementAt(k); // find the class, search only the library ontologies NamedOntClass ontClass = ontCatalog.getNamedOntClass(semType, true); if (ontClass == null) { // skip this component if it // doesn't have a known class continue; } // get the tree path that goes with this semantic type Object[] treePathArray = getTreePathObjectArray(ontClass, new Vector()); // add the tree path to the topLevel and remoteLevel // objects to make the fullTreePath Object[] fullTreePath = new Object[treePathArray.length + 3]; fullTreePath[0] = topLevel; fullTreePath[1] = remoteLevel; for (int i = 2; i < fullTreePath.length - 1; i++) { // put the treepath together to be added to the // results vector this just adds EntityLibraries try { // adding a space to the treePathArray content // is a hack to keep // the tree from stealing results from the // remote part and putting // them back into the local part. I'm not sure // why it does this // but keeping the names unique seems to be the // only way to // prevent results seepage. treePathArray[i - 2] = (String) treePathArray[i - 2] + " "; fullTreePath[i] = new EntityLibrary((CompositeEntity) fullTreePath[i - 1], (String) treePathArray[i - 2]); } catch (NameDuplicationException nde) { // if we get a NDE, we need to search the // existing tree for the // correct parent fullTreePath[i] = findEntity((String) treePathArray[i - 2], (CompositeEntity) fullTreePath[i - 1]); if (fullTreePath[i] == null) { System.out.println("ERROR: no path found for fullTreePath[" + i + "]"); } } } fullTreePath[fullTreePath.length - 1] = leafObject; _results.add(new TreePath(fullTreePath)); } } Object[] containmentRepresentation = getContainmentRepresentation(topLevel, remoteLevel, repositoryLevel, karLevel, leafObject); if (containmentRepresentation == null) { log.warn("Could not generate containment representation: " + repoResult.getName()); } else { _results.add(new TreePath(containmentRepresentation)); } } } } if (_results.size() == 1) {// no results were added, so remove the // Remote Components result tree _results = new LibrarySearchResults(); } return _results; } catch (NameDuplicationException nde) { nde.printStackTrace(); throw new IllegalActionException( "Error building remote repository " + "search results: " + nde.getMessage()); } }
From source file:org.kuali.test.ui.components.repositorytree.RepositoryTree.java
/** * * @param platformName//from w w w.j a v a 2 s . c o 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.languagetool.gui.ConfigurationDialog.java
@NotNull private JPanel getTreeButtonPanel(int num) { GridBagConstraints cons;/*from w w w . ja va 2 s . com*/ JPanel treeButtonPanel = new JPanel(); cons = new GridBagConstraints(); cons.gridx = 0; cons.gridy = 0; JButton expandAllButton = new JButton(messages.getString("guiExpandAll")); treeButtonPanel.add(expandAllButton, cons); expandAllButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { TreeNode root = (TreeNode) configTree[num].getModel().getRoot(); TreePath parent = new TreePath(root); for (Enumeration cat = root.children(); cat.hasMoreElements();) { TreeNode n = (TreeNode) cat.nextElement(); TreePath child = parent.pathByAddingChild(n); configTree[num].expandPath(child); } } }); cons.gridx = 1; cons.gridy = 0; JButton collapseAllButton = new JButton(messages.getString("guiCollapseAll")); treeButtonPanel.add(collapseAllButton, cons); collapseAllButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { TreeNode root = (TreeNode) configTree[num].getModel().getRoot(); TreePath parent = new TreePath(root); for (Enumeration categ = root.children(); categ.hasMoreElements();) { TreeNode n = (TreeNode) categ.nextElement(); TreePath child = parent.pathByAddingChild(n); configTree[num].collapsePath(child); } } }); return treeButtonPanel; }
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 w w w. ja v a 2 s . co m 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 av a 2 s . co m*/ 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 */// w w w. j ava2 s. co 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.//from w w w .j a v a 2 s. c o m */ 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 .ja v a2 s. co 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 w w. ja 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(); } } }