List of usage examples for javax.swing.tree TreePath getLastPathComponent
public Object getLastPathComponent()
From source file:com.nbt.NBTTreeTableModel.java
protected void fireTreeNodesInserted(Object source, TreePath path) { Object parent = path.getLastPathComponent(); int count = getChildCount(parent); int[] childIndices = new int[count]; Object[] children = new Object[count]; for (int i = 0; i < count; i++) { childIndices[i] = i;/*from w ww .j a va2s .c om*/ children[i] = getChild(parent, i); } fireTreeNodesInserted(source, path, childIndices, children); }
From source file:Main.java
public void getPaths(JTree tree, TreePath parent, boolean expanded, List<TreePath> list) { if (expanded && !tree.isVisible(parent)) { return;// w ww.ja va 2s . c o m } list.add(parent); TreeNode node = (TreeNode) parent.getLastPathComponent(); if (node.getChildCount() >= 0) { for (Enumeration e = node.children(); e.hasMoreElements();) { TreeNode n = (TreeNode) e.nextElement(); TreePath path = parent.pathByAddingChild(n); getPaths(tree, path, expanded, list); } } }
From source file:com.nbt.NBTTreeTableModel.java
protected void fireTreeNodesInserted(Object source, TreePath path, Object... children) { Object parent = path.getLastPathComponent(); int length = children.length; int[] childIndices = new int[length]; for (int i = 0; i < length; i++) { Object child = children[i]; childIndices[i] = getIndexOfChild(parent, child); if (childIndices[i] == -1) throw new IllegalArgumentException("child index is -1"); }/*from ww w. ja v a2 s .c o m*/ fireTreeNodesInserted(source, path, childIndices, children); }
From source file:com.microsoft.alm.plugin.idea.git.ui.pullrequest.PullRequestsTreeModel.java
public GitPullRequest getSelectedPullRequest() { final TreePath treeModel = selectionModel.getLeadSelectionPath(); return treeModel == null ? null : ((PRTreeNode) treeModel.getLastPathComponent()).getGitPullRequest(); }
From source file:hu.bme.mit.sette.snippetbrowser.SnippetBrowser.java
private void initialized() { DefaultTreeModel model = new DefaultTreeModel(new SnippetProjectTreeNode(snippetProject)); treeSnippets.setModel(model);//from ww w.ja v a2 s . c om treeSnippets.addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { if (treeSnippets.getSelectionCount() == 1) { TreeNodeBase<?, ?> treeNode = (TreeNodeBase<?, ?>) treeSnippets.getSelectionPath() .getLastPathComponent(); txtrInfo.setText(treeNode.getDescription()); } else if (treeSnippets.getSelectionCount() > 1) { int projectContainerCnt = 0; int projectSnippetCnt = 0; projectContainerCnt = snippetProject.getModel().getContainers().size(); for (SnippetContainer container : snippetProject.getModel().getContainers()) { projectSnippetCnt += container.getSnippets().size(); } int containerCnt = 0; int containerSnippetCnt = 0; int snippetCnt = 0; for (TreePath path : treeSnippets.getSelectionPaths()) { Object node = path.getLastPathComponent(); if (node instanceof SnippetContainerTreeNode) { containerCnt++; SnippetContainerTreeNode obj = (SnippetContainerTreeNode) node; containerSnippetCnt += obj.getContainer().getSnippets().size(); } else if (node instanceof SnippetTreeNode) { snippetCnt++; } } String[] lines = new String[3]; lines[0] = String.format("Project contains %d container(s) with %d snippet(s)", projectContainerCnt, projectSnippetCnt); lines[1] = String.format("Selected %d container(s) (%d snippet(s))", containerCnt, containerSnippetCnt); lines[2] = String.format("Selected %d snippet(s)", snippetCnt); txtrInfo.setText(StringUtils.join(lines, '\n')); } else { txtrInfo.setText("[No selection]"); } } }); }
From source file:net.sourceforge.atunes.kernel.actions.RemoveFromDiskAction.java
private void fromRepositoryOrDeviceView() { TreePath[] paths = NavigationHandler.getInstance().getCurrentView().getTree().getSelectionPaths(); final List<Folder> foldersToRemove = new ArrayList<Folder>(); if (paths != null) { for (TreePath path : paths) { Object treeNode = ((DefaultMutableTreeNode) path.getLastPathComponent()).getUserObject(); if (treeNode instanceof Folder) { foldersToRemove.add((Folder) treeNode); }//from ww w . ja v a 2s .c om } } RepositoryHandler.getInstance().removeFolders(foldersToRemove); VisualHandler.getInstance().showIndeterminateProgressDialog(LanguageTool.getString("PLEASE_WAIT")); new SwingWorker<Void, Void>() { @Override protected Void doInBackground() { for (Folder folder : foldersToRemove) { try { FileUtils.deleteDirectory(folder.getFolderPath()); logger.info(LogCategories.REPOSITORY, StringUtils.getString("Removed folder ", folder)); } catch (IOException e) { logger.info(LogCategories.REPOSITORY, StringUtils.getString("Could not remove folder ", folder, e.getMessage())); } } return null; } @Override protected void done() { VisualHandler.getInstance().hideIndeterminateProgressDialog(); } }.execute(); }
From source file:it.unibas.spicygui.controllo.tree.ActionSelectionCondition.java
private INode getNodeSelected() { TreePath treePath = jTree.getSelectionPath(); DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) treePath.getLastPathComponent(); TreeNodeAdapter adapter = (TreeNodeAdapter) treeNode.getUserObject(); return adapter.getINode(); }
From source file:Main.java
public void removeCurrentNode() { TreePath currentSelection = tree.getSelectionPath(); if (currentSelection != null) { DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode) (currentSelection.getLastPathComponent()); MutableTreeNode parent = (MutableTreeNode) (currentNode.getParent()); if (parent != null) { treeModel.removeNodeFromParent(currentNode); return; }// w ww . j av a 2 s .c o m } }
From source file:Main.java
public DefaultMutableTreeNode addObject(Object child) { DefaultMutableTreeNode parentNode = null; TreePath parentPath = tree.getSelectionPath(); if (parentPath == null) { parentNode = rootNode;// w w w.j a v a 2 s. c o m } else { parentNode = (DefaultMutableTreeNode) (parentPath.getLastPathComponent()); } return addObject(parentNode, child, true); }
From source file:it.unibas.spicygui.controllo.tree.ActionSelectionCondition.java
private void deleteSelectionCondition(boolean oldButtonState, String oldSelectionCondition, SelectionConditionInfo selectionConditionInfo) { try {// ww w .j a va 2 s . c o m INode iNode = getNodeSelected(); TreePath treePath = jTree.getSelectionPath(); DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) treePath.getLastPathComponent(); review.removeSelectionCondition(selectionConditionInfo.getSelectionCondition(), dataSource); selectionConditionInfo.setSelectionCondition(null); selectionConditionInfo.setExpressionString(""); analisiSelection.creaWidgetEsisteSelectionCondition(treeNode, selectionConditionInfo.getExpressionString(), selectionConditionInfo.getSelectionCondition()); VMDPinWidget vMDPinWidget = (VMDPinWidget) iNode.getAnnotation(Costanti.PIN_WIDGET_TREE); vMDPinWidget.setToolTipText(null); aggiorna(); } catch (ExpressionSyntaxException e) { creator.undo(selectionConditionInfo.getSelectionCondition(), dataSource); DialogDisplayer.getDefault() .notify(new NotifyDescriptor.Message( NbBundle.getMessage(Costanti.class, Costanti.SYNTAX_WARNING) + " : " + e.getMessage(), DialogDescriptor.WARNING_MESSAGE)); StatusDisplayer.getDefault() .setStatusText(NbBundle.getMessage(Costanti.class, Costanti.SYNTAX_WARNING)); ripristina(oldButtonState, oldSelectionCondition, selectionConditionInfo); } }