com.intellij.util.ui.tree.TreeUtil Java Examples
The following examples show how to use
com.intellij.util.ui.tree.TreeUtil.
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: RunConfigurable.java From consulo with Apache License 2.0 | 6 votes |
private void applyConfiguration(DefaultMutableTreeNode typeNode, SingleConfigurationConfigurable<?> configurable) throws ConfigurationException { try { if (configurable != null) { configurable.apply(); RunManagerImpl.getInstanceImpl(myProject).fireRunConfigurationChanged(configurable.getSettings()); } } catch (ConfigurationException e) { for (int i = 0; i < typeNode.getChildCount(); i++) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode)typeNode.getChildAt(i); if (Comparing.equal(configurable, node.getUserObject())) { TreeUtil.selectNode(myTree, node); break; } } throw e; } }
Example #2
Source File: PushLog.java From consulo with Apache License 2.0 | 6 votes |
@Override protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) { if (e.getKeyCode() == KeyEvent.VK_ENTER && e.getModifiers() == 0 && pressed) { if (myTree.isEditing()) { myTree.stopEditing(); } else { DefaultMutableTreeNode node = (DefaultMutableTreeNode)myTree.getLastSelectedPathComponent(); if (node != null) { myTree.startEditingAtPath(TreeUtil.getPathFromRoot(node)); } } return true; } if (myAllowSyncStrategy && e.getKeyCode() == KeyEvent.VK_F2 && e.getModifiers() == InputEvent.ALT_MASK && pressed) { startSyncEditing(); return true; } return super.processKeyBinding(ks, e, condition, pressed); }
Example #3
Source File: RunConfigurable.java From consulo with Apache License 2.0 | 6 votes |
@RequiredUIAccess @Override public void update(AnActionEvent e) { boolean isEnabled = TreeUtil.findNodeWithObject(DEFAULTS, myTree.getModel(), myRoot) != null; TreePath path = myTree.getSelectionPath(); if (path != null) { Object o = path.getLastPathComponent(); if (o instanceof DefaultMutableTreeNode && ((DefaultMutableTreeNode)o).getUserObject().equals(DEFAULTS)) { isEnabled = false; } o = path.getParentPath().getLastPathComponent(); if (o instanceof DefaultMutableTreeNode && ((DefaultMutableTreeNode)o).getUserObject().equals(DEFAULTS)) { isEnabled = false; } } e.getPresentation().setEnabled(isEnabled); }
Example #4
Source File: BreakpointItemsTreeController.java From consulo with Apache License 2.0 | 6 votes |
public void buildTree(@Nonnull Collection<? extends BreakpointItem> breakpoints) { final TreeState state = TreeState.createOn(myTreeView, myRoot); myRoot.removeAllChildren(); myNodes.clear(); for (BreakpointItem breakpoint : breakpoints) { BreakpointItemNode node = new BreakpointItemNode(breakpoint); CheckedTreeNode parent = getParentNode(breakpoint); parent.add(node); myNodes.put(breakpoint, node); } TreeUtil.sortRecursively(myRoot, COMPARATOR); myInBuild = true; ((DefaultTreeModel)(myTreeView.getModel())).nodeStructureChanged(myRoot); state.applyTo(myTreeView, myRoot); myInBuild = false; }
Example #5
Source File: MasterDetailsComponent.java From consulo with Apache License 2.0 | 6 votes |
protected void clearChildren() { TreeUtil.traverseDepth(myRoot, new TreeUtil.Traverse() { @Override public boolean accept(Object node) { if (node instanceof MyNode) { final MyNode treeNode = ((MyNode)node); treeNode.getConfigurable().disposeUIResources(); if (!(treeNode instanceof MyRootNode)) { treeNode.setUserObject(null); } } return true; } }); myRoot.removeAllChildren(); }
Example #6
Source File: ScopeChooserConfigurable.java From consulo with Apache License 2.0 | 6 votes |
private void reloadTree() { myRoot.removeAllChildren(); loadScopes(mySharedScopesManager); loadScopes(myLocalScopesManager); if (isModified()) { loadStateOrder(); } final List<String> order = getScopesState().myOrder; TreeUtil.sort(myRoot, new Comparator<DefaultMutableTreeNode>() { @Override public int compare(final DefaultMutableTreeNode o1, final DefaultMutableTreeNode o2) { final int idx1 = order.indexOf(((MyNode)o1).getDisplayName()); final int idx2 = order.indexOf(((MyNode)o2).getDisplayName()); return idx1 - idx2; } }); }
Example #7
Source File: BaseToolsPanel.java From consulo with Apache License 2.0 | 6 votes |
public void reset() { List<ToolsGroup<T>> groups = getToolsGroups(); for (ToolsGroup group : groups) { insertNewGroup((ToolsGroup)group.copy()); } if ((getTreeRoot()).getChildCount() > 0) { myTree.setSelectionInterval(0, 0); } else { myTree.getSelectionModel().clearSelection(); } (getModel()).nodeStructureChanged(null); TreeUtil.expand(myTree, 5); myIsModified = false; update(); }
Example #8
Source File: RunConfigurable.java From consulo with Apache License 2.0 | 6 votes |
@RequiredUIAccess @Override public void actionPerformed(final AnActionEvent e) { TreeNode defaults = TreeUtil.findNodeWithObject(DEFAULTS, myTree.getModel(), myRoot); if (defaults != null) { final ConfigurationType configurationType = getSelectedConfigurationType(); if (configurationType != null) { defaults = TreeUtil.findNodeWithObject(configurationType, myTree.getModel(), defaults); } final DefaultMutableTreeNode defaultsNode = (DefaultMutableTreeNode)defaults; if (defaultsNode == null) { return; } final TreePath path = TreeUtil.getPath(myRoot, defaultsNode); myTree.expandPath(path); TreeUtil.selectInTree(defaultsNode, true, myTree); myTree.scrollPathToVisible(path); } }
Example #9
Source File: ChangesTreeList.java From consulo with Apache License 2.0 | 6 votes |
private int findRowContainingFile(@Nonnull TreeNode root, @Nonnull final VirtualFile toSelect) { final Ref<Integer> row = Ref.create(-1); TreeUtil.traverse(root, node -> { if (node instanceof DefaultMutableTreeNode) { Object userObject = ((DefaultMutableTreeNode)node).getUserObject(); if (userObject instanceof Change) { if (matches((Change)userObject, toSelect)) { TreeNode[] path = ((DefaultMutableTreeNode)node).getPath(); row.set(getRowForPath(new TreePath(path))); } } } return row.get() == -1; }); return row.get(); }
Example #10
Source File: MongoEditionPanel.java From nosql4idea with Apache License 2.0 | 6 votes |
public void addKey(String key, Object value) { List<TreeNode> node = new LinkedList<TreeNode>(); NoSqlTreeNode treeNode = new NoSqlTreeNode(MongoKeyValueDescriptor.createDescriptor(key, value)); if (value instanceof DBObject) { JsonTreeModel.processDbObject(treeNode, (DBObject) value); } node.add(treeNode); DefaultTreeModel treeModel = (DefaultTreeModel) editTableView.getTree().getModel(); NoSqlTreeNode parentNode = getParentNode(); if (parentNode == null) { parentNode = (NoSqlTreeNode) treeModel.getRoot(); } TreeUtil.addChildrenTo(parentNode, node); treeModel.reload(parentNode); }
Example #11
Source File: WatchesRootNode.java From consulo with Apache License 2.0 | 6 votes |
public void addWatchExpression(@Nullable XStackFrame stackFrame, @Nonnull XExpression expression, int index, boolean navigateToWatchNode) { WatchNodeImpl message = new WatchNodeImpl(myTree, this, expression, stackFrame); if (index == -1) { myChildren.add(message); index = myChildren.size() - 1; } else { myChildren.add(index, message); } fireNodeInserted(index); TreeUtil.selectNode(myTree, message); if (navigateToWatchNode) { myTree.scrollPathToVisible(message.getPath()); } }
Example #12
Source File: AbstractTreeUi.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull private Runnable wrapScrollTo(Runnable onDone, @Nonnull Object element, @Nonnull DefaultMutableTreeNode node, boolean addToSelection, boolean canBeCentered, boolean scroll) { return new TreeRunnable("AbstractTreeUi.wrapScrollTo") { @Override public void perform() { int row = getRowIfUnderSelection(element); if (row == -1) row = myTree.getRowForPath(new TreePath(node.getPath())); int top = row - 2; int bottom = row + 2; if (canBeCentered && Registry.is("ide.tree.autoscrollToVCenter")) { int count = TreeUtil.getVisibleRowCount(myTree) - 1; top = count > 0 ? row - count / 2 : row; bottom = count > 0 ? top + count : row; } TreeUtil.showAndSelect(myTree, top, bottom, row, -1, addToSelection, scroll).doWhenDone(wrapDone(onDone, "AbstractTreeUi.wrapScrollTo.onDone")); } }; }
Example #13
Source File: JsonTreeTableView.java From nosql4idea with Apache License 2.0 | 6 votes |
public JsonTreeTableView(TreeNode rootNode, ColumnInfo[] columnInfos) { super(new ListTreeTableModelOnColumns(rootNode, columnInfos)); this.columns = columnInfos; final TreeTableTree tree = getTree(); tree.setShowsRootHandles(true); tree.setRootVisible(false); UIUtil.setLineStyleAngled(tree); setTreeCellRenderer(new KeyCellRenderer()); TreeUtil.expand(tree, 2); new TreeTableSpeedSearch(this, new Convertor<TreePath, String>() { @Override public String convert(final TreePath path) { final NoSqlTreeNode node = (NoSqlTreeNode) path.getLastPathComponent(); NodeDescriptor descriptor = node.getDescriptor(); return descriptor.getFormattedKey(); } }); }
Example #14
Source File: FileStructurePopup.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull private Promise<TreePath> rebuildAndSelect(boolean refilterOnly, Object selection) { AsyncPromise<TreePath> result = new AsyncPromise<>(); myStructureTreeModel.getInvoker().runOrInvokeLater(() -> { if (refilterOnly) { myFilteringStructure.refilter(); myStructureTreeModel.invalidate().onSuccess( res -> (selection == null ? myAsyncTreeModel.accept(o -> TreeVisitor.Action.CONTINUE) : select(selection)).onError(ignore2 -> result.setError("rejected")).onSuccess(p -> UIUtil.invokeLaterIfNeeded(() -> { TreeUtil.expand(getTree(), myTreeModel instanceof StructureViewCompositeModel ? 3 : 2); TreeUtil.ensureSelection(myTree); mySpeedSearch.refreshSelection(); result.setResult(p); }))); } else { myTreeStructure.rebuildTree(); myStructureTreeModel.invalidate().onSuccess(res -> rebuildAndSelect(true, selection).processed(result)); } }); return result; }
Example #15
Source File: ModulesDependenciesPanel.java From consulo with Apache License 2.0 | 6 votes |
private static void sortSubTree(final DefaultMutableTreeNode root) { TreeUtil.sort(root, new Comparator() { @Override public int compare(final Object o1, final Object o2) { DefaultMutableTreeNode node1 = (DefaultMutableTreeNode)o1; DefaultMutableTreeNode node2 = (DefaultMutableTreeNode)o2; if (!(node1.getUserObject() instanceof MyUserObject)){ return 1; } else if (!(node2.getUserObject() instanceof MyUserObject)){ return -1; } return (node1.getUserObject().toString().compareToIgnoreCase(node2.getUserObject().toString())); } }); }
Example #16
Source File: StructureViewComponent.java From consulo with Apache License 2.0 | 6 votes |
@Override public void treeNodesInserted(TreeModelEvent e) { TreePath parentPath = e.getTreePath(); if (Boolean.TRUE.equals(UIUtil.getClientProperty(tree, STRUCTURE_VIEW_STATE_RESTORED_KEY))) return; if (parentPath == null || parentPath.getPathCount() > autoExpandDepth.asInteger() - 1) return; Object[] children = e.getChildren(); if (smartExpand && children.length == 1) { expandLater(parentPath, children[0]); } else { for (Object o : children) { NodeDescriptor descriptor = TreeUtil.getUserObject(NodeDescriptor.class, o); if (descriptor != null && isAutoExpandNode(descriptor)) { expandLater(parentPath, o); } } } }
Example #17
Source File: CustomizableActionsPanel.java From consulo with Apache License 2.0 | 5 votes |
public void apply() throws ConfigurationException { final List<TreePath> treePaths = TreeUtil.collectExpandedPaths(myActionsTree); if (mySelectedSchema != null) { CustomizationUtil.optimizeSchema(myActionsTree, mySelectedSchema); } restorePathsAfterTreeOptimization(treePaths); CustomActionsSchema.getInstance().copyFrom(mySelectedSchema); setCustomizationSchemaForCurrentProjects(); }
Example #18
Source File: FileSystemTreeImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public void select(VirtualFile[] file, @Nullable final Runnable onDone) { if (myAsyncTreeModel != null) { switch (file.length) { case 0: myTree.clearSelection(); if (onDone != null) onDone.run(); break; case 1: myTree.clearSelection(); TreeUtil.promiseSelect(myTree, new FileNodeVisitor(file[0])).onProcessed(path -> { if (onDone != null) onDone.run(); }); break; default: myTree.clearSelection(); TreeUtil.promiseSelect(myTree, Stream.of(file).map(FileNodeVisitor::new)).onProcessed(paths -> { if (onDone != null) onDone.run(); }); break; } } else { Object[] elements = new Object[file.length]; for (int i = 0; i < file.length; i++) { VirtualFile eachFile = file[i]; elements[i] = getFileElementFor(eachFile); } myTreeBuilder.select(elements, onDone); } }
Example #19
Source File: TestTreeView.java From consulo with Apache License 2.0 | 5 votes |
@Override public void paint(Graphics g) { super.paint(g); final TestFrameworkRunningModel model = myModel; if (model == null) return; final TestConsoleProperties properties = model.getProperties(); if (TestConsoleProperties.SHOW_INLINE_STATISTICS.value(properties)) { Rectangle visibleRect = getVisibleRect(); Rectangle clip = g.getClipBounds(); final int visibleRowCount = TreeUtil.getVisibleRowCountForFixedRowHeight(this); final int firstRow = getClosestRowForLocation(0, visibleRect.y); for (int row = firstRow; row < Math.min(firstRow + visibleRowCount + 1, getRowCount()); row++) { if (isExpandableHandlerVisibleForCurrentRow(row)) { continue; } Object node = getPathForRow(row).getLastPathComponent(); if (node instanceof DefaultMutableTreeNode) { Object data = ((DefaultMutableTreeNode)node).getUserObject(); if (data instanceof BaseTestProxyNodeDescriptor) { final AbstractTestProxy testProxy = ((BaseTestProxyNodeDescriptor)data).getElement(); final String durationString = testProxy.getDurationString(properties); if (durationString != null) { Rectangle rowBounds = getRowBounds(row); rowBounds.x = 0; rowBounds.width = Integer.MAX_VALUE; if (rowBounds.intersects(clip)) { final Rectangle fullRowRect = new Rectangle(visibleRect.x, rowBounds.y, visibleRect.width, rowBounds.height); final boolean rowSelected = isRowSelected(row); final boolean hasTreeFocus = hasFocus(); paintRowData(this, durationString, fullRowRect, (Graphics2D)g, rowSelected, hasTreeFocus); } } } } } } }
Example #20
Source File: UsageViewImpl.java From consulo with Apache License 2.0 | 5 votes |
private void showNode(@Nonnull final UsageNode node) { ApplicationManager.getApplication().assertIsDispatchThread(); if (!isDisposed() && !myPresentation.isDetachedMode()) { fireEvents(); TreePath usagePath = new TreePath(node.getPath()); myTree.expandPath(usagePath.getParentPath()); TreeUtil.selectPath(myTree, usagePath); } }
Example #21
Source File: SingleInspectionProfilePanel.java From consulo with Apache License 2.0 | 5 votes |
@Override protected void onlineFilter() { if (mySelectedProfile == null) return; final String filter = getFilter(); getExpandedNodes(mySelectedProfile).saveVisibleState(myTreeTable.getTree()); fillTreeData(filter, true); reloadModel(); if (filter == null || filter.isEmpty()) { restoreTreeState(); } else { TreeUtil.expandAll(myTreeTable.getTree()); } }
Example #22
Source File: CertificateTreeBuilder.java From consulo with Apache License 2.0 | 5 votes |
public void selectFirstCertificate() { if (!isEmpty()) { Tree tree = (Tree)getTree(); TreePath path = TreeUtil.getFirstLeafNodePath(tree); tree.addSelectionPath(path); } }
Example #23
Source File: Tree.java From consulo with Apache License 2.0 | 5 votes |
/** * Hack to prevent loosing multiple selection on Mac when clicking Ctrl+Left Mouse Button. * See faulty code at BasicTreeUI.selectPathForEvent():2245 * * Another hack to match selection UI (wide) and selection behavior (narrow) in Nimbus/GTK+. */ @Override protected void processMouseEvent(final MouseEvent e) { MouseEvent e2 = e; if (SystemInfo.isMac) { if (SwingUtilities.isLeftMouseButton(e) && e.isControlDown() && e.getID() == MouseEvent.MOUSE_PRESSED) { int modifiers = e.getModifiers() & ~(InputEvent.CTRL_MASK | InputEvent.BUTTON1_MASK) | InputEvent.BUTTON3_MASK; e2 = new MouseEvent(e.getComponent(), e.getID(), e.getWhen(), modifiers, e.getX(), e.getY(), e.getClickCount(), true, MouseEvent.BUTTON3); } } else if (UIUtil.isUnderNimbusLookAndFeel() || UIUtil.isUnderGTKLookAndFeel()) { if (SwingUtilities.isLeftMouseButton(e) && (e.getID() == MouseEvent.MOUSE_PRESSED || e.getID() == MouseEvent.MOUSE_CLICKED)) { final TreePath path = getClosestPathForLocation(e.getX(), e.getY()); if (path != null) { final Rectangle bounds = getPathBounds(path); if (bounds != null && e.getY() > bounds.y && e.getY() < bounds.y + bounds.height && (e.getX() >= bounds.x + bounds.width || e.getX() < bounds.x && !TreeUtil.isLocationInExpandControl(this, path, e.getX(), e.getY()))) { int newX = bounds.x + bounds.width - 2; e2 = MouseEventAdapter.convert(e, e.getComponent(), newX, e.getY()); } } } } super.processMouseEvent(e2); }
Example #24
Source File: StructureViewComponent.java From consulo with Apache License 2.0 | 5 votes |
@TestOnly public AsyncPromise<Void> rebuildAndUpdate() { AsyncPromise<Void> result = new AsyncPromise<>(); rebuild(); TreeVisitor visitor = path -> { AbstractTreeNode node = TreeUtil.getLastUserObject(AbstractTreeNode.class, path); if (node != null) node.update(); return TreeVisitor.Action.CONTINUE; }; myAsyncTreeModel.accept(visitor).onProcessed(ignore -> result.setResult(null)); return result; }
Example #25
Source File: SimpleTree.java From consulo with Apache License 2.0 | 5 votes |
@Nullable public TreePath getPathFor(SimpleNode node) { final TreeNode nodeWithObject = TreeUtil.findNodeWithObject((DefaultMutableTreeNode)getModel().getRoot(), node); if (nodeWithObject != null) { return TreeUtil.getPathFromRoot(nodeWithObject); } return null; }
Example #26
Source File: CheckboxTreeNoPolicy.java From consulo with Apache License 2.0 | 5 votes |
public CheckboxTreeNoPolicy(CheckboxTreeCellRendererBase cellRenderer, @Nullable CheckedTreeNode root) { setRootVisible(false); setShowsRootHandles(true); setLineStyleAngled(); TreeUtil.installActions(this); installRenderer(cellRenderer); addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (isToggleEvent(e)) { TreePath treePath = getLeadSelectionPath(); if (treePath == null) return; final Object o = treePath.getLastPathComponent(); if (!(o instanceof CheckedTreeNode)) return; CheckedTreeNode firstNode = (CheckedTreeNode)o; boolean checked = toggleNode(firstNode); TreePath[] selectionPaths = getSelectionPaths(); for (int i = 0; selectionPaths != null && i < selectionPaths.length; i++) { final TreePath selectionPath = selectionPaths[i]; final Object o1 = selectionPath.getLastPathComponent(); if (!(o1 instanceof CheckedTreeNode)) continue; CheckedTreeNode node = (CheckedTreeNode)o1; checkNode(node, checked); ((DefaultTreeModel)getModel()).nodeChanged(node); } e.consume(); } } }); setSelectionRow(0); if (root != null) { setModel(new DefaultTreeModel(root)); } }
Example #27
Source File: AbstractProjectViewPane.java From consulo with Apache License 2.0 | 5 votes |
public final void restoreExpandedPaths() { if (myTree == null || myTreeStateRestored.getAndSet(true)) return; TreeState treeState = myReadTreeState.get(getSubId()); if (treeState != null && !treeState.isEmpty()) { treeState.applyTo(myTree); } else if (myTree.isSelectionEmpty()) { TreeUtil.promiseSelectFirst(myTree); } }
Example #28
Source File: ProjectViewImpl.java From consulo with Apache License 2.0 | 5 votes |
public void apply(final AbstractProjectViewPane viewPane) { if (viewPane == null) { return; } AbstractTreeBuilder treeBuilder = viewPane.getTreeBuilder(); JTree tree = viewPane.myTree; if (treeBuilder != null) { DefaultTreeModel treeModel = (DefaultTreeModel)tree.getModel(); List<TreePath> paths = new ArrayList<>(myElements.length); for (final Object element : myElements) { DefaultMutableTreeNode node = treeBuilder.getNodeForElement(element); if (node == null) { treeBuilder.buildNodeForElement(element); node = treeBuilder.getNodeForElement(element); } if (node != null) { paths.add(new TreePath(treeModel.getPathToRoot(node))); } } if (!paths.isEmpty()) { tree.setSelectionPaths(paths.toArray(new TreePath[0])); } } else { List<TreeVisitor> visitors = AbstractProjectViewPane.createVisitors(myElements); if (1 == visitors.size()) { TreeUtil.promiseSelect(tree, visitors.get(0)); } else if (!visitors.isEmpty()) { TreeUtil.promiseSelect(tree, visitors.stream()); } } }
Example #29
Source File: WatchInplaceEditor.java From consulo with Apache License 2.0 | 5 votes |
@Override public void doOKAction() { XExpression expression = getExpression(); super.doOKAction(); int index = myRootNode.removeChildNode(myNode); if (!XDebuggerUtilImpl.isEmptyExpression(expression) && index != -1) { myWatchesView.addWatchExpression(expression, index, false); } TreeUtil.selectNode(myTree, myNode); }
Example #30
Source File: PsiViewerDialog.java From consulo with Apache License 2.0 | 5 votes |
private static void initTree(JTree tree) { UIUtil.setLineStyleAngled(tree); tree.setRootVisible(false); tree.setShowsRootHandles(true); tree.updateUI(); ToolTipManager.sharedInstance().registerComponent(tree); TreeUtil.installActions(tree); new TreeSpeedSearch(tree); }