List of usage examples for javax.swing.tree TreePath TreePath
public TreePath(Object lastPathComponent)
From source file:ru.apertum.qsystem.client.forms.FAdmin.java
private void textFieldSearchServiceKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textFieldSearchServiceKeyReleased TreeNode node = null;/*from ww w . ja v a 2 s. c om*/ boolean flag = evt.getKeyCode() != 114; final QService ser = (QService) treeServices.getLastSelectedPathComponent(); for (Object object : ((ATreeModel) treeServices.getModel()).getNodes()) { final QService service = (QService) object; if (flag) { if (service.toString().toLowerCase() .contains(textFieldSearchService.getText().trim().toLowerCase())) { node = (TreeNode) object; break; } } else { if (!flag && (ser == null || service.getId().equals(ser.getId()))) { flag = true; } } } if (node != null) { TreeNode[] nodes = ((DefaultTreeModel) treeServices.getModel()).getPathToRoot(node); TreePath path = new TreePath(nodes); treeServices.setSelectionPath(path); treeServices.setExpandsSelectedPaths(true); treeServices.scrollPathToVisible(path); } else { Toolkit.getDefaultToolkit().beep(); } }
From source file:com.android.tools.idea.uibuilder.structure.NlComponentTreeTest.java
public void testSelectionInTreeIsPropagatedToModel() { assertNull(myTree.getSelectionPaths()); assertFalse(myModel.getSelectionModel().getSelection().iterator().hasNext()); NlComponent root = (NlComponent) myTree.getModel().getRoot(); NlComponent node1 = root.getChild(1); NlComponent node2 = root.getChild(2); myTree.addSelectionPath(new TreePath(new Object[] { root, node1 })); myTree.addSelectionPath(new TreePath(new Object[] { root, node2 })); Iterator<NlComponent> selected = myModel.getSelectionModel().getSelection().iterator(); assertEquals(node1, selected.next()); assertEquals(node2, selected.next()); assertFalse(selected.hasNext());/*from www .j a v a2 s. co m*/ }
From source file:com.android.tools.idea.uibuilder.structure.NlComponentTreeTest.java
private String toTree() { StringBuilder sb = new StringBuilder(); describe(sb, new TreePath(myTree.getModel().getRoot()), 0); return sb.toString(); }
From source file:net.sourceforge.squirrel_sql.client.gui.HelpViewerWindow.java
private void selectTreeNodeForURL(URL url) { // Strip local part of URL. String key = url.toString();/*ww w . j ava 2 s.co m*/ final int idx = key.lastIndexOf('#'); if (idx > -1) { key = key.substring(0, idx); } DefaultMutableTreeNode node = _nodes.get(key); if (node != null) // && node != _tree.getLastSelectedPathComponent()) { DefaultTreeModel model = (DefaultTreeModel) _tree.getModel(); TreePath path = new TreePath(model.getPathToRoot(node)); if (path != null) { _tree.expandPath(path); _tree.scrollPathToVisible(path); _tree.setSelectionPath(path); } } }
From source file:nl.salp.warcraft4j.dev.ui.CascFileTreeModel.java
public void update(CascService cascService) { this.root = new CascFileTreeNode("/"); cascService.getAllCascFiles().forEach(this::add); modelListeners.forEach(l -> l.treeStructureChanged(new TreeModelEvent(this, new TreePath(root)))); }
From source file:nl.tudelft.goal.SimpleIDE.FilePanel.java
/** * Appends a node to the children of another node. Shorthand for two calls * to {@link #treeModel}.<br>/*from ww w . jav a 2 s . c o m*/ * If parent is null, the child is removed from its parent (if it has one). * If the node was not a child of the {@link #nullNode}, it will be moved * there. Otherwise, this call would be the same as {@link #removeFileNode}. * * @param parent * The desired parent of the given child. * @param child * The node that is to be appended to the list of children of the * given parent. */ private void appendNode(FileNode parent, FileNode child) { boolean oldParentWasNullNode = child.getParent() == this.nullNode; if (child.getParent() != null) { this.treeModel.removeNodeFromParent(child); } if (parent != null) { this.treeModel.insertNodeInto(child, parent, parent.getChildCount()); this.fileTree.expandPath(new TreePath(child.getPath())); } else if (!oldParentWasNullNode && child.getType() != NodeType.MASFILE) { // automatically move the old node to the null-node when it // has been removed, unless it is a MAS-file this.treeModel.insertNodeInto(child, this.nullNode, this.nullNode.getChildCount()); this.fileTree.expandPath(new TreePath(child.getPath())); refreshSpuriousList(); } }
From source file:nl.tudelft.goal.SimpleIDE.FilePanel.java
/** * Selects a single node in the tree, and expands the tree so that the given * node is visible. Assumes the given node is inside the tree. * * @param node// www . j av a 2 s. c o m * The node to be selected. Can be <code>null</code>, in which * case the result will be that nothing is selected. */ private void selectNode(FileNode node) { if (node == null) { this.fileTree.setSelectionPath(null); } else { TreePath selectedPath = new TreePath(node.getPath()); this.fileTree.setSelectionPath(selectedPath); this.fileTree.expandPath(selectedPath); } }
From source file:nl.tudelft.goal.SimpleIDE.FilePanel.java
/** * Updates the tree model so that the children of the given mas node * correspond to the agent files described in the mas file. Any goal files * that are children of the given mas node but are not referenced to in the * mas file will be moved to the null file node. * * @param masNode//from www.j a v a2 s .co m * The mas node of which the children should be refreshed. * @param showLoadError * If this is <code>false</code>, any GOALException thrown when * getting the agent file names will be ignored. If * <code>true</code>, the user will be notified of them.<br> * Use <code>false</code> when this is called after saving, as * the message should have already been displayed. */ private void refreshMASNode(MASNode masNode) { // Do nothing if the given node is not part of the tree (or null) if (!this.rootNode.isNodeDescendant(masNode)) { return; } // Do nothing if the file is not validated. MASProgram mas = this.platform.getMASProgram(masNode.getBaseFile()); if (mas == null) { return; } // Compare current nodes with current agent files associated with MAS // file. // Get current node children. List<FileNode> currentChildren = getChildrenOf(masNode); // Get the associated files. List<File> currentFiles = new ArrayList<File>(); for (FileNode node : currentChildren) { currentFiles.add(node.getBaseFile()); } // Get new agent files. List<File> newFiles = this.platform.getMASProgram(masNode.getBaseFile()).getAgentFiles(); // Get new emotion file. String emoString = this.platform.getMASProgram(masNode.getBaseFile()).getEmotionFile(); if (emoString != null) { if (new File(emoString).isAbsolute()) { newFiles.add(new File(emoString)); } else { String emoPath = masNode.getBaseFile().getParentFile().getAbsolutePath(); newFiles.add(new File(emoPath, emoString)); } } // Check whether nodes need to be removed, i.e., whether they do not // correspond with any files associated with the MAS file. for (FileNode node : currentChildren) { if (!newFiles.contains(node.getBaseFile())) { // Move node to the spurious file node. appendNode(null, node); } } // CHECK is this always absolute path? String masdir = masNode.getBaseFile().getParent(); // Check whether agent files need to be inserted. for (File agentFile : newFiles) { if (!agentFile.exists()) { // doesn't exist. Suggest to create String path = agentFile.getPath(); File newFile = new File(path); if (!newFile.isAbsolute()) { // If relative, prepend MAS dir. #2926 newFile = new File(FilenameUtils.concat(masdir, agentFile.getPath())); } try { proposeToCreate(this, newFile, Extension.GOAL); this.platform.parseGOALFile(newFile, mas.getKRInterface(newFile)); } catch (GOALUserError ignore) { // this file does not really exist. #2692 // We want to continue here to handle all other GOAL files, // even if user cancelled creation of one of these or IO // error happened. } catch (ParserException e) { // Even in case of serious parse errors we simply skip // the current agent file and continue with the next. // We want to process as many agent files as we can. continue; } } if (!currentFiles.contains(agentFile)) { FileNode newNode; if (Extension.getFileExtension(agentFile) == Extension.EMOTION) { newNode = new EmotionNode(agentFile); } else { newNode = new GOALNode(agentFile); } this.allFiles.add(newNode); // GOALNode newNode = insertGOALfile(agentFile.getAgentFile()); appendNode(masNode, newNode); // also let the tree scroll to the newly added node this.fileTree.scrollPathToVisible(new TreePath(masNode.getPath())); } } refreshSpuriousList(); }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java
public void selectNode(Object nodeObject, ETreeType treeType) { JTree tree = getTree(treeType); DepositTreeModel model = (DepositTreeModel) tree.getModel(); DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) model.getRoot(); DefaultMutableTreeNode node = findNode(rootNode, nodeObject); if (node != null) { LOG.debug("selectNode Node object found"); TreePath path = new TreePath(node.getPath()); tree.scrollPathToVisible(path);/*from ww w . ja va 2 s. c o m*/ tree.setSelectionPath(path); } else { LOG.debug("selectNode Node object not found"); } }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java
public void expandNode(JTree whichTree, DefaultMutableTreeNode node, boolean recurse) { whichTree.expandPath(new TreePath(node.getPath())); if (recurse && node.getChildCount() > 0) { for (int i = 0; i < node.getChildCount(); i++) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(i); expandNode(whichTree, child, recurse); }// ww w .j ava 2 s. c om } }