Java Code Examples for com.intellij.util.ui.tree.TreeUtil#selectPath()

The following examples show how to use com.intellij.util.ui.tree.TreeUtil#selectPath() . 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: AsyncProjectViewSupport.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static boolean selectPaths(@Nonnull JTree tree, @Nonnull List<TreePath> paths, @Nonnull TreeVisitor visitor) {
  if (paths.isEmpty()) return false;
  if (paths.size() > 1) {
    if (visitor instanceof ProjectViewNodeVisitor) {
      ProjectViewNodeVisitor nodeVisitor = (ProjectViewNodeVisitor)visitor;
      return selectPaths(tree, new SelectionDescriptor(nodeVisitor.getElement(), nodeVisitor.getFile(), paths));
    }
    if (visitor instanceof ProjectViewFileVisitor) {
      ProjectViewFileVisitor fileVisitor = (ProjectViewFileVisitor)visitor;
      return selectPaths(tree, new SelectionDescriptor(null, fileVisitor.getElement(), paths));
    }
  }
  TreePath path = paths.get(0);
  tree.expandPath(path); // request to expand found path
  TreeUtil.selectPath(tree, path); // select and scroll to center
  return true;
}
 
Example 2
Source File: AbstractProjectViewPane.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void expand(@Nullable final Object[] path, final boolean requestFocus) {
  if (getTreeBuilder() == null || path == null) return;
  AbstractTreeUi ui = getTreeBuilder().getUi();
  if (ui != null) ui.buildNodeForPath(path);

  DefaultMutableTreeNode node = ui == null ? null : ui.getNodeForPath(path);
  if (node == null) {
    return;
  }
  TreePath treePath = new TreePath(node.getPath());
  myTree.expandPath(treePath);
  if (requestFocus) {
    IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> IdeFocusManager.getGlobalInstance().requestFocus(myTree, true));
  }
  TreeUtil.selectPath(myTree, treePath);
}
 
Example 3
Source File: UsageViewImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
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 4
Source File: OccurenceNavigatorSupport.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public OccurenceInfo goNextOccurence() {
  DefaultMutableTreeNode node = findNode(myTree, true);
  if (node == null) return null;
  TreePath treePath = new TreePath(node.getPath());
  TreeUtil.selectPath(myTree, treePath);
  Navigatable editSourceDescriptor = createDescriptorForNode(node);
  if (editSourceDescriptor == null) return null;
  Counters counters = calculatePosition(node);
  return new OccurenceInfo(editSourceDescriptor, counters.myFoundOccurenceNumber, counters.myOccurencesCount);
}
 
Example 5
Source File: OccurenceNavigatorSupport.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public OccurenceInfo goPreviousOccurence() {
  DefaultMutableTreeNode node = findNode(myTree, false);
  if (node == null) return null;
  TreePath treePath = new TreePath(node.getPath());
  TreeUtil.selectPath(myTree, treePath);
  Navigatable editSourceDescriptor = createDescriptorForNode(node);
  if (editSourceDescriptor == null) return null;
  Counters counters = calculatePosition(node);
  return new OccurenceInfo(editSourceDescriptor, counters.myFoundOccurenceNumber, counters.myOccurencesCount);
}
 
Example 6
Source File: BreakpointItemsTreeController.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void selectBreakpointItem(@Nullable final BreakpointItem breakpoint, TreePath path) {
  BreakpointItemNode node = myNodes.get(breakpoint);
  if (node != null) {
    TreeUtil.selectNode(myTreeView, node);
  }
  else {
    TreeUtil.selectPath(myTreeView, path);
  }
}
 
Example 7
Source File: ChangesViewManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void selectChange(@Nonnull Change change) {
  DefaultMutableTreeNode root = (DefaultMutableTreeNode)myView.getModel().getRoot();
  DefaultMutableTreeNode node = TreeUtil.findNodeWithObject(root, change);
  if (node != null) {
    TreePath path = TreeUtil.getPathFromRoot(node);
    TreeUtil.selectPath(myView, path, false);
  }
}
 
Example 8
Source File: VisibleTreeState.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void restoreVisibleState(Tree tree) {
  ArrayList<TreePath> pathsToExpand = new ArrayList<TreePath>();
  ArrayList<TreePath> toSelect = new ArrayList<TreePath>();
  traverseNodes((DefaultMutableTreeNode)tree.getModel().getRoot(), pathsToExpand, toSelect);
  TreeUtil.restoreExpandedPaths(tree, pathsToExpand);
  if (toSelect.isEmpty()) {
    TreeUtil.selectFirstNode(tree);
  }
  else {
    for (final TreePath aToSelect : toSelect) {
      TreeUtil.selectPath(tree, aToSelect);
    }
  }
}
 
Example 9
Source File: IntentionSettingsTree.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void selectIntention(String familyName) {
  final CheckedTreeNode child = findChildRecursively(getRoot(), familyName);
  if (child != null) {
    final TreePath path = new TreePath(child.getPath());
    TreeUtil.selectPath(myTree, path);
  }
}
 
Example 10
Source File: DependenciesPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void setSelected(AnActionEvent event, boolean flag) {
  DependencyUISettings.getInstance().UI_SHOW_FILES = flag;
  mySettings.UI_SHOW_FILES = flag;
  if (!flag && myLeftTree.getSelectionPath() != null && myLeftTree.getSelectionPath().getLastPathComponent() instanceof FileNode){
    TreeUtil.selectPath(myLeftTree, myLeftTree.getSelectionPath().getParentPath());
  }
  rebuild();
}
 
Example 11
Source File: ScopeTreeViewPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void reload(@Nullable final DefaultMutableTreeNode rootToReload) {
  final DefaultTreeModel treeModel = (DefaultTreeModel)myTree.getModel();
  if (rootToReload != null && rootToReload != treeModel.getRoot()) {
    final List<TreePath> treePaths = TreeUtil.collectExpandedPaths(myTree, new TreePath(rootToReload.getPath()));
    final List<TreePath> selectionPaths = TreeUtil.collectSelectedPaths(myTree, new TreePath(rootToReload.getPath()));
    final TreePath path = new TreePath(rootToReload.getPath());
    final boolean wasCollapsed = myTree.isCollapsed(path);
    final Runnable runnable = new Runnable() {
      @Override
      public void run() {
        if (!isTreeShowing() || rootToReload.getParent() == null) return;
        TreeUtil.sort(rootToReload, getNodeComparator());
        treeModel.reload(rootToReload);
        if (!wasCollapsed) {
          myTree.collapsePath(path);
          for (TreePath treePath : treePaths) {
            myTree.expandPath(treePath);
          }
          for (TreePath selectionPath : selectionPaths) {
            TreeUtil.selectPath(myTree, selectionPath);
          }
        }
      }
    };
    if (ApplicationManager.getApplication().isUnitTestMode()) {
      runnable.run();
    }
    else {
      SwingUtilities.invokeLater(runnable);
    }
  }
  else {
    TreeUtil.sort(treeModel, getNodeComparator());
    treeModel.reload();
  }
}
 
Example 12
Source File: TreeToolbarDecorator.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void createDefaultTreeActions() {
  final EditableTreeModel model = (EditableTreeModel)myTree.getModel();
  myAddAction = new AnActionButtonRunnable() {
    @Override
    public void run(AnActionButton button) {
      final TreePath path = myTree.getSelectionPath();
      final DefaultMutableTreeNode selected =
        path == null ? (DefaultMutableTreeNode)myTree.getModel().getRoot() : (DefaultMutableTreeNode)path.getLastPathComponent();
      final Object selectedNode = selected.getUserObject();

      myTree.stopEditing();
      Object element;
      if (model instanceof DefaultTreeModel && myProducer != null) {
         element = myProducer.createElement();
        if (element == null) return;
      } else {
        element = null;
      }
      DefaultMutableTreeNode parent = selected;
      if ((selectedNode instanceof SimpleNode && ((SimpleNode)selectedNode).isAlwaysLeaf()) || !selected.getAllowsChildren()) {
        parent = (DefaultMutableTreeNode)selected.getParent();
      }
      if (parent != null) {
       parent.insert(new DefaultMutableTreeNode(element), parent.getChildCount());
      }
      final TreePath createdPath = model.addNode(new TreePath(parent.getPath()));
      if (path != null) {
        TreeUtil.selectPath(myTree, createdPath);
        IdeFocusManager.getGlobalInstance().doForceFocusWhenFocusSettlesDown(myTree);
      }
    }
  };

  myRemoveAction = new AnActionButtonRunnable() {
    @Override
    public void run(AnActionButton button) {
      myTree.stopEditing();
      final TreePath path = myTree.getSelectionPath();
      model.removeNode(path);
    }
  };
}
 
Example 13
Source File: TreeSpeedSearch.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected void selectElement(Object element, String selectedText) {
  TreeUtil.selectPath(myComponent, (TreePath)element);
}
 
Example 14
Source File: BreakpointItemsTreeController.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void selectFirstBreakpointItem() {
  TreeUtil.selectPath(myTreeView, TreeUtil.getFirstLeafNodePath(myTreeView));
}
 
Example 15
Source File: InspectionTree.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void restore() {
  getSelectionModel().removeSelectionPaths(getSelectionModel().getSelectionPaths());
  TreeUtil.selectPath(InspectionTree.this, restorePath());
}