List of usage examples for javax.swing.tree TreePath getPath
public Object[] getPath()
From source file:org.hippoecm.frontend.plugins.console.browser.BrowserPlugin.java
@Override public void onModelChanged() { super.onModelChanged(); JcrNodeModel model = (JcrNodeModel) getDefaultModel(); TreePath treePath = treeModel.lookup(model); if (treePath != null) { ITreeState treeState = tree.getTreeState(); if (!navigating) { for (Object node : treePath.getPath()) { TreeNode treeNode = (TreeNode) node; if (!treeState.isNodeExpanded(treeNode)) { treeState.expandNode(treeNode); }/*from ww w . j a v a2s . c o m*/ } } treeState.selectNode(treePath.getLastPathComponent(), true); } }
From source file:org.kepler.objectmanager.repository.EcogridRepositoryLibrarySearcher.java
/** * search for value in the library/* w w w.ja v a2 s.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.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. */// w w w . j ava 2 s . com 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.olivier.ihm.FramePUMLCleanerControler.java
/** * Indique si un noeud est slectionn ou pas * * @param noeudATester Le noeud tester/*w w w . java2s . co m*/ * @param selectedPath La liste des noeuds slectionns * @return True si le noeud est slectionn, false sinon */ private boolean isNoeudSelected(final DefaultMutableTreeNode noeudATester, final TreePath[] selectedPath) { boolean isSelected = false; // parcours des categories for (TreePath path : selectedPath) { try { // Cette ligne plante quand on slectionne une catgorie complte d'ou le try-catch ! final DefaultMutableTreeNode unNoeudSelectionner = (DefaultMutableTreeNode) path.getPath()[2]; isSelected = noeudATester.toString().equals(unNoeudSelectionner.toString()); } catch (ArrayIndexOutOfBoundsException ex) { // Quand on choisit une catgorie complte, il faut parcourir les noeuds de cette manire : // recup de la categorie final DefaultMutableTreeNode categ = (DefaultMutableTreeNode) path.getLastPathComponent(); // parcours des noeuds dans la catgorie for (int j = 0; j < categ.getChildCount(); j++) { final TreeNode unNoeudSelectionner = categ.getChildAt(j); isSelected = noeudATester.toString().equals(unNoeudSelectionner.toString()); if (isSelected) { break; } } } // on sort de la boucle ds qu'on a la rponse if (isSelected) { break; } } return isSelected; }
From source file:org.orbisgis.sif.components.fstree.FileTree.java
private boolean contains(TreePath[] selectionPaths, TreePath path) { for (TreePath treePath : selectionPaths) { Object[] objectPath = treePath.getPath(); Object[] testPath = path.getPath(); if (objectPath.length != testPath.length) { return false; } else {/*from ww w .java 2s. c o m*/ for (int i = 0; i < testPath.length; i++) { if (testPath[i] != objectPath[i]) { return false; } } } return true; } return false; }
From source file:org.owasp.jbrofuzz.headers.HeaderLoader.java
protected Header getHeader(final TreePath treePath) { if (!((HeaderTreeNode) treePath.getLastPathComponent()).isLeaf()) { return Header.ZERO; }//from ww w . j av a 2 s.c o m for (final String headerName : headersMap.keySet()) { final Prototype proto = headersMap.get(headerName); final int catLength = proto.getNoOfCategories(); final String[] categories = new String[catLength]; proto.getCategories().toArray(categories); final Object[] path = treePath.getPath(); int success = path.length - 1; for (int i = 0; i < path.length; i++) { try { if (path[i + 1].toString().equalsIgnoreCase(categories[i])) { success--; } else { i = 32; } } catch (final ArrayIndexOutOfBoundsException exp) { i = 32; } } // We have found the header we were looking for if (success == 0) { final int noOfFields = proto.size(); final String[] output = new String[noOfFields]; proto.getPayloads().toArray(output); final StringBuffer myBuffer = new StringBuffer(); for (final String payload : output) { myBuffer.append(payload); myBuffer.append('\n'); } myBuffer.append('\n'); final String commentL = proto.getComment(); return new Header(noOfFields, myBuffer.toString(), commentL); } } return Header.ZERO; }
From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.model.RepositoryTreeModelTest.java
@Test public void testGetTreePathForSelection() { RepositoryTreeModel treeModel = new RepositoryTreeModel(); assertNotNull(treeModel);/*www. jav a 2 s .c om*/ treeModel.setFileSystemRoot(repositoryRoot); FileObject[] childFiles = new FileObject[] { childFile1, childFile2, childFile3 }; try { doReturn(childFiles).when(repositoryRoot).getChildren(); doReturn(childFileName1).when(childFile1).getName(); doReturn(childFileName2).when(childFile2).getName(); doReturn(childFileName3).when(childFile3).getName(); doReturn(repositoryRoot).when(childFile1).getParent(); doReturn(repositoryRoot).when(childFile2).getParent(); doReturn(repositoryRoot).when(childFile3).getParent(); TreePath path = treeModel.getTreePathForSelection(childFile2, null); assertEquals(2, path.getPath().length); assertEquals(childFile2, path.getLastPathComponent()); } catch (FileSystemException e) { e.printStackTrace(); } }
From source file:view.MainWindow.java
private ArrayList<File> getMultipleSelectedFiles(JTree jtree) { ArrayList<File> aLSelectedFiles = new ArrayList<>(); if (jtree == null) { return aLSelectedFiles; }//from w w w . j a va2 s . com if (jtree.getSelectionPath() == null) { return aLSelectedFiles; } for (TreePath tp : jtree.getSelectionPaths()) { String strSelectedFile = ""; Object[] paths = tp.getPath(); for (int i = 0; i < paths.length; i++) { strSelectedFile += paths[i]; if (i + 1 < paths.length) { strSelectedFile += File.separator; } } aLSelectedFiles.add(new File(strSelectedFile)); } return aLSelectedFiles; }