javax.swing.tree.TreePath Java Examples
The following examples show how to use
javax.swing.tree.TreePath.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RepositoryLocationChooser.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
/** * Creates a repository location out of the user choice. Either uses the selected entry, or creates a location * relative to the selected plus the location field text, or if nothing is selected creates an absolute path based * on the location field text. * * @return the location, never {@code null} * @throws MalformedRepositoryLocationException if the entered location does not represent a proper repository * location * @since 9.7 */ public RepositoryLocation getAsRepositoryLocation() throws MalformedRepositoryLocationException { final TreePath path = tree.getSelectionPath(); if (path == null || !(path.getLastPathComponent() instanceof Entry)) { // nothing selected in tree, only some value entered in name field. Take it, but who knows what it is return new RepositoryLocationBuilder().withLocationType(RepositoryLocationType.UNKNOWN).buildFromAbsoluteLocation(getLocationNameFieldText()); } Entry selectedEntry = (Entry) path.getLastPathComponent(); RepositoryLocation selectedLocation = selectedEntry.getLocation(); if (selectedEntry instanceof Folder) { // folder selected, but the name field may contain more if (getLocationNameFieldText().isEmpty()) { // no custom name entered, it's a folder selectedLocation = new RepositoryLocationBuilder().withLocationType(RepositoryLocationType.FOLDER).buildFromAbsoluteLocation(selectedLocation.getAbsoluteLocation()); } else { // custom name entered, who knows what it is, may have more than a single hit there selectedLocation = new RepositoryLocationBuilder().withLocationType(RepositoryLocationType.UNKNOWN). buildFromParentLocation(selectedLocation, getLocationNameFieldText()); } } else { // data entry selected, take it selectedLocation = new RepositoryLocationBuilder().withExpectedDataEntryType(((DataEntry) selectedEntry).getClass()).buildFromAbsoluteLocation(selectedLocation.getAbsoluteLocation()); } return selectedLocation; }
Example #2
Source File: InstancesListController.java From netbeans with Apache License 2.0 | 6 votes |
public TreePath getInstancePath(Instance instance) { TreePath instancePath = null; if (currentlyHasChildren()) { HeapWalkerNode[] children = getChildren(); for (int i = 0; i < children.length; i++) { if (children[i] instanceof InstancesListNode) { instancePath = ((InstancesListNode) children[i]).getInstancePath(instance); if (instancePath != null) { break; } } } } return instancePath; }
Example #3
Source File: DarculaTreeUI.java From Darcula with Apache License 2.0 | 6 votes |
@Override protected void paintExpandControl(Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds, TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf) { boolean isPathSelected = tree.getSelectionModel().isPathSelected(path); if (!isLeaf(row)) { setExpandedIcon(DarculaUIUtil.getTreeNodeIcon(true, isPathSelected, tree.hasFocus())); setCollapsedIcon(DarculaUIUtil.getTreeNodeIcon(false, isPathSelected, tree.hasFocus())); } super.paintExpandControl(g, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf); }
Example #4
Source File: JTreeOperator.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Waits path to be collapsed. * * @param path a path to wait collapsed. */ public void waitCollapsed(final TreePath path) { if (path != null) { getOutput().printLine("Wait \"" + path.toString() + "\" path to be collapsed in component \n : " + toStringSource()); getOutput().printGolden("Wait \"" + path.toString() + "\" path to be collapsed"); waitState(new ComponentChooser() { @Override public boolean checkComponent(Component comp) { return isCollapsed(path); } @Override public String getDescription() { return "Has \"" + path.toString() + "\" path collapsed"; } @Override public String toString() { return "JTreeOperator.waitCollapsed.ComponentChooser{description = " + getDescription() + '}'; } }); } else { throw (new NoSuchPathException()); } }
Example #5
Source File: AbstractTableView.java From ramus with GNU General Public License v3.0 | 6 votes |
@Override public void actionPerformed(ActionEvent e) { TreePath[] paths = table.getTreeSelectionModel() .getSelectionPaths(); List<Row> list = SelectableTableView .showRowSelectDialog(component, framework, engine, accessRules, qualifier, SelectType.RADIO); if ((list != null) && (list.size() == 1)) { Element element = list.get(0).getElement(); ArrayList<Element> elements = new ArrayList<Element>( paths.length); for (TreePath path : paths) { Row row = ((TreeTableNode) path.getLastPathComponent()) .getRow(); if (row != null) if (!element.equals(row.getElement())) { elements.add(row.getElement()); } } component.getRowSet().startUserTransaction(); engine.replaceElements( elements.toArray(new Element[elements.size()]), element); component.getRowSet().commitUserTransaction(); } }
Example #6
Source File: TreeUtils.java From weblaf with GNU General Public License v3.0 | 6 votes |
/** * Expands all {@link TreeNode}s loaded within {@link JTree} in a single call. * * @param tree {@link JTree} to expand {@link TreeNode}s for * @param node {@link TreeNode} under which all other {@link TreeNode}s should be expanded */ public static void expandLoaded ( @NotNull final JTree tree, @NotNull final TreeNode node ) { // Only expand parent for non-root nodes if ( node.getParent () != null ) { // Make sure this node's parent is expanded // We do not need to expand the node itself, we only need to make sure it is visible in the tree final TreePath path = getTreePath ( node.getParent () ); if ( !tree.isExpanded ( path ) ) { tree.expandPath ( path ); } } // Expanding all child nodes // We are asking node instead of tree model to avoid any additional data loading to occur for ( int index = 0; index < node.getChildCount (); index++ ) { expandLoaded ( tree, node.getChildAt ( index ) ); } }
Example #7
Source File: CreateExternalLocationAction.java From ghidra with Apache License 2.0 | 6 votes |
@Override public void actionPerformed(SymbolTreeActionContext context) { TreePath[] selectionPaths = context.getSelectedSymbolTreePaths(); if (selectionPaths.length != 1) { return; } Object object = selectionPaths[0].getLastPathComponent(); if (!(object instanceof LibrarySymbolNode) && !(object instanceof ImportsCategoryNode)) { return; } String externalName = null; if (object instanceof LibrarySymbolNode) { LibrarySymbolNode libraryNode = (LibrarySymbolNode) object; externalName = libraryNode.getName(); } final EditExternalLocationDialog dialog = new EditExternalLocationDialog(context.getProgram(), externalName); dialog.setHelpLocation(new HelpLocation("SymbolTreePlugin", "CreateExternalLocation")); plugin.getTool().showDialog(dialog); }
Example #8
Source File: TreePanel.java From nmonvisualizer with Apache License 2.0 | 6 votes |
@Override public final void dataRemoved(DataSet data) { DefaultMutableTreeNode root = (DefaultMutableTreeNode) ((DefaultTreeModel) tree.getModel()).getRoot(); for (int i = 0; i < root.getChildCount(); i++) { DataSet toSearch = (DataSet) ((DefaultMutableTreeNode) root.getChildAt(i)).getUserObject(); if (toSearch.equals(data)) { Object removed = root.getChildAt(i); root.remove(i); ((javax.swing.tree.DefaultTreeModel) tree.getModel()).nodesWereRemoved(root, new int[] { i }, new Object[] { removed }); // to remove a node requires it to be selected, so move the selection to the root tree.setSelectionPath(new TreePath(root)); break; } } }
Example #9
Source File: DualView.java From consulo with Apache License 2.0 | 6 votes |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component result = myRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); Object treeNode = null; final int modelRow = table.convertRowIndexToModel(row); if (myCurrentView == myTreeView) { TreePath path = myTreeView.getTree().getPathForRow(modelRow); if (path != null) { treeNode = path.getLastPathComponent(); } } else if (myCurrentView == myFlatView) { treeNode = myFlatView.getItems().get(modelRow); } myCellWrapper.wrap(result, table, value, isSelected, hasFocus, row, column, treeNode); return result; }
Example #10
Source File: SlingServerTreeManager.java From aem-ide-tooling-4-intellij with Apache License 2.0 | 6 votes |
private void popupInvoked(final Component comp, final int x, final int y) { Object userObject = null; final TreePath path = tree.getSelectionPath(); if(path != null) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); if(node != null) { userObject = node.getUserObject(); } } ActionManager actionManager = ActionManager.getInstance(); DefaultActionGroup group = new DefaultActionGroup(); if( userObject instanceof SlingServerNodeDescriptor || userObject instanceof SlingServerModuleNodeDescriptor ) { group.add(actionManager.getAction("AEM.Connection.Popup")); } else { group.add(actionManager.getAction("AEM.Root.Popup")); } final ActionPopupMenu popupMenu = ActionManager.getInstance().createActionPopupMenu(ActionPlaces.ANT_EXPLORER_POPUP, group); popupMenu.getComponent().show(comp, x, y); }
Example #11
Source File: CallTreeProvider.java From ghidra with Apache License 2.0 | 6 votes |
private void makeSelectionFromPaths(TreePath[] paths, boolean selectSource) { AddressSet set = new AddressSet(); for (TreePath path : paths) { CallNode callNode = (CallNode) path.getLastPathComponent(); Address address = null; if (selectSource) { address = callNode.getSourceAddress(); } else { address = callNode.getLocation().getAddress(); } set.addRange(address, address); } ProgramSelection selection = new ProgramSelection(set); tool.firePluginEvent( new ProgramSelectionPluginEvent(plugin.getName(), selection, currentProgram)); }
Example #12
Source File: CustomizationUtil.java From consulo with Apache License 2.0 | 6 votes |
public static ActionUrl getActionUrl(final TreePath treePath, int actionType) { ActionUrl url = new ActionUrl(); for (int i = 0; i < treePath.getPath().length - 1; i++) { Object o = ((DefaultMutableTreeNode)treePath.getPath()[i]).getUserObject(); if (o instanceof Group) { url.getGroupPath().add(((Group)o).getName()); } } final DefaultMutableTreeNode component = ((DefaultMutableTreeNode)treePath.getLastPathComponent()); url.setComponent(component.getUserObject()); DefaultMutableTreeNode node = component; final TreeNode parent = node.getParent(); url.setAbsolutePosition(parent != null ? parent.getIndex(node) : 0); url.setActionType(actionType); return url; }
Example #13
Source File: JSONTree.java From rest-client with Apache License 2.0 | 6 votes |
/** * * @Title : removeCurrentNode * @Description: Remove the currently selected node. * @Param : * @Return : void * @Throws : */ public void removeCurrentNode() { TreePath currentSelection = tree.getSelectionPath(); if (null == currentSelection) { return; } CheckBoxTreeNode currentNode = (CheckBoxTreeNode) (currentSelection.getLastPathComponent()); MutableTreeNode parent = (MutableTreeNode) (currentNode.getParent()); if (null != parent) { treeModel.removeNodeFromParent(currentNode); return; } // Either there was no selection, or the root was selected. toolkit.beep(); }
Example #14
Source File: ProgramListener.java From ghidra with Apache License 2.0 | 6 votes |
private TreePath findDescendant(TreePath path, String name) { ProgramNode node = (ProgramNode) path.getLastPathComponent(); if (node.getName().equals(name)) { return node.getTreePath(); } if (node.getAllowsChildren() && !node.wasVisited()) { tree.visitNode(node); } for (int i = 0; i < node.getChildCount(); i++) { ProgramNode child = (ProgramNode) node.getChildAt(i); TreePath p = findDescendant(child.getTreePath(), name); if (p != null) { return p; } } return null; }
Example #15
Source File: DnDAwareTree.java From consulo with Apache License 2.0 | 6 votes |
@Override protected Transferable createTransferable(JComponent component) { if (component instanceof JTree) { JTree tree = (JTree)component; TreePath[] selection = tree.getSelectionPaths(); if (selection != null && selection.length > 1) { return new TransferableList<TreePath>(selection) { @Override protected String toString(TreePath path) { return String.valueOf(path.getLastPathComponent()); } }; } } return null; }
Example #16
Source File: MainPanel.java From java-swing-tips with MIT License | 5 votes |
@Override public void treeWillExpand(TreeExpansionEvent e) throws ExpandVetoException { TreePath path = e.getPath(); Object o = path.getLastPathComponent(); if (o instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) o; File file = (File) node.getUserObject(); String name = file.getName(); // System.out.println(name); if (!name.isEmpty() && name.codePointAt(0) == '.') { throw new ExpandVetoException(e, "Tree expansion cancelled"); } } }
Example #17
Source File: ExtractMethodPanel.java From IntelliJDeodorant with MIT License | 5 votes |
/** * Opens the definition of appropriate method for the selected suggestion by double-clicking or Enter key pressing. */ private void openMethodDefinition(InputEvent e) { TreeTableTree treeTableTree = treeTable.getTree(); TreePath selectedPath = treeTableTree.getSelectionModel().getSelectionPath(); if (selectedPath != null) { Object o = selectedPath.getLastPathComponent(); if (o instanceof ASTSlice) { openDefinition(((ASTSlice) o).getSourceMethodDeclaration(), scope, (ASTSlice) o); } else if (o instanceof ExtractMethodCandidateGroup) { expandOrCollapsePath(e, treeTableTree, selectedPath); } } }
Example #18
Source File: MainPanel.java From java-swing-tips with MIT License | 5 votes |
@Override public boolean isCellEditable(EventObject e) { if (e instanceof MouseEvent && e.getSource() instanceof JTree) { MouseEvent me = (MouseEvent) e; JTree tree = (JTree) me.getComponent(); TreePath path = tree.getPathForLocation(me.getX(), me.getY()); if (path != null && path.getLastPathComponent() instanceof TreeNode) { return ((TreeNode) path.getLastPathComponent()).isLeaf(); } } return false; }
Example #19
Source File: TreeView.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException { // prepare wait cursor and optionally show it TreePath path = event.getPath(); prepareWaitCursor(DragDropUtilities.secureFindNode(path.getLastPathComponent())); }
Example #20
Source File: GUIBrowser.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private TreePath getSelectionPath() { JTree tree = getSelectedTree(); if (tree != null) { return tree.getSelectionPath(); } else { return null; } }
Example #21
Source File: TreeTableModelAdapter.java From visualvm with GNU General Public License v2.0 | 5 votes |
private TreePath getCurrentPath(TreePath oldPath) { if (oldPath == null || oldPath.getPathCount() < 1) return null; if (!treeTableModel.getRoot().equals(oldPath.getPathComponent(0))) return null; TreePath p = getRootPath(); Object[] op = oldPath.getPath(); CCTNode n = (CCTNode)treeTableModel.getRoot(); for (int i = 1; i < op.length; i++) { // #241115 CCTNode[] children = n.getChildren(); if (children == null) return null; CCTNode nn = null; for (CCTNode c : children) if (c.equals(op[i])) { nn = c; break; } if (nn == null) return null; n = nn; p = p.pathByAddingChild(n); } return p; }
Example #22
Source File: MultiTreeUI.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * Invokes the <code>getEditingPath</code> method on each UI handled by this object. * * @return the value obtained from the first UI, which is * the UI obtained from the default <code>LookAndFeel</code> */ public TreePath getEditingPath(JTree a) { TreePath returnValue = ((TreeUI) (uis.elementAt(0))).getEditingPath(a); for (int i = 1; i < uis.size(); i++) { ((TreeUI) (uis.elementAt(i))).getEditingPath(a); } return returnValue; }
Example #23
Source File: PToDoTree.java From PolyGlot with MIT License | 5 votes |
private void addSubtreeToCheckingStateTracking(DefaultMutableTreeNode node) { if (node instanceof ToDoTreeNode) { TreeNode[] path = node.getPath(); TreePath tp = new TreePath(path); ToDoNode cn = ((ToDoTreeNode)node).getNode(); nodesCheckingState.put(tp, cn); for (int i = 0 ; i < node.getChildCount() ; i++) { addSubtreeToCheckingStateTracking( (DefaultMutableTreeNode) tp.pathByAddingChild(node.getChildAt(i)).getLastPathComponent()); } } }
Example #24
Source File: MultiTreeUI.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
/** * Invokes the <code>getRowForPath</code> method on each UI handled by this object. * * @return the value obtained from the first UI, which is * the UI obtained from the default <code>LookAndFeel</code> */ public int getRowForPath(JTree a, TreePath b) { int returnValue = ((TreeUI) (uis.elementAt(0))).getRowForPath(a,b); for (int i = 1; i < uis.size(); i++) { ((TreeUI) (uis.elementAt(i))).getRowForPath(a,b); } return returnValue; }
Example #25
Source File: StoredObjectsTreeModel.java From swift-explorer with Apache License 2.0 | 5 votes |
public static List<TreePath> getTreeExpansionState (JTree tree) { if (tree == null) return null ; List<TreePath> ret = new ArrayList<TreePath> () ; for (int i = 0 ; i < tree.getRowCount() ; i++) { TreePath path = tree.getPathForRow(i) ; if (tree.isExpanded(path)) ret.add (path) ; } return ret ; }
Example #26
Source File: GTreeSelectNodeByNameTask.java From ghidra with Apache License 2.0 | 5 votes |
private void selectPath(final TreePath treePath, final TaskMonitor monitor) { runOnSwingThread(() -> { if (monitor.isCancelled()) { return; // we can be cancelled while waiting for Swing to run us } GTreeSelectionModel selectionModel = tree.getGTSelectionModel(); selectionModel.setSelectionPaths(new TreePath[] { treePath }, origin); jTree.scrollPathToVisible(treePath); }); }
Example #27
Source File: ProjectTree.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 5 votes |
private List<Scenario> getSelectedScenarios() { List<Scenario> scenarios = new ArrayList<>(); TreePath[] paths = tree.getSelectionPaths(); if (paths != null && paths.length > 0) { for (TreePath path : paths) { if (path.getLastPathComponent() instanceof ScenarioNode) { scenarios.add(((ScenarioNode) path.getLastPathComponent()).getScenario()); } } } return scenarios; }
Example #28
Source File: TypeEditorPanel.java From binnavi with Apache License 2.0 | 5 votes |
@Override public ImmutableList<TypeMember> getSelectedMembers() { final Builder<TypeMember> builder = ImmutableList.<TypeMember>builder(); final TreePath[] paths = typesTree.getSelectionPaths(); if (paths != null) { for (final TreePath path : typesTree.getSelectionPaths()) { final Object node = path.getLastPathComponent(); if (node instanceof TypeMemberTreeNode) { builder.add(((TypeMemberTreeNode) node).getTypeMember()); } } } return builder.build(); }
Example #29
Source File: ExtendedCheckTreeSelectionModel.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
public boolean isPartiallySelected(TreePath path) { if (isPathSelected(path, true)) { return false; } TreePath[] selectionPaths = getSelectionPaths(); if (selectionPaths == null) { return false; } for (int j = 0; j < selectionPaths.length; j++) { if (isDescendant(selectionPaths[j], path)) { return true; } } return false; }
Example #30
Source File: SynthTreeUI.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ @Override protected void paintVerticalPartOfLeg(Graphics g, Rectangle clipBounds, Insets insets, TreePath path) { if (drawVerticalLines) { super.paintVerticalPartOfLeg(g, clipBounds, insets, path); } }