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

The following examples show how to use com.intellij.util.ui.tree.TreeUtil#getLastUserObject() . 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: StructureViewComponent.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void setupTree() {
  myTree.setCellRenderer(new NodeRenderer());
  myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
  myTree.setShowsRootHandles(true);
  registerPsiListener(myProject, this, this::queueUpdate);
  myProject.getMessageBus().connect(this).subscribe(UISettingsListener.TOPIC, o -> rebuild());

  if (showScrollToFromSourceActions()) {
    myAutoScrollToSourceHandler.install(myTree);
    myAutoScrollFromSourceHandler.install();
  }

  TreeUtil.installActions(getTree());

  new TreeSpeedSearch(getTree(), treePath -> {
    Object userObject = TreeUtil.getLastUserObject(treePath);
    return userObject != null ? FileStructurePopup.getSpeedSearchText(userObject) : null;
  });

  addTreeKeyListener();
  addTreeMouseListeners();
  restoreState();
}
 
Example 2
Source File: TreeState.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public ActionCallback expand(TreePath treePath) {
  NodeDescriptor desc = TreeUtil.getLastUserObject(NodeDescriptor.class, treePath);
  if (desc == null) return ActionCallback.REJECTED;
  Object element = myBuilder.getTreeStructureElement(desc);
  ActionCallback result = new ActionCallback();
  myBuilder.expand(element, result.createSetDoneRunnable());

  return result;
}
 
Example 3
Source File: StructureViewComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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 4
Source File: ProjectViewImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static SelectionInfo create(final AbstractProjectViewPane viewPane) {
  List<Object> selectedElements = Collections.emptyList();
  if (viewPane != null) {
    final TreePath[] selectionPaths = viewPane.getSelectionPaths();
    if (selectionPaths != null) {
      selectedElements = new ArrayList<>();
      for (TreePath path : selectionPaths) {
        NodeDescriptor descriptor = TreeUtil.getLastUserObject(NodeDescriptor.class, path);
        if (descriptor != null) selectedElements.add(descriptor.getElement());
      }
    }
  }
  return new SelectionInfo(selectedElements.toArray());
}
 
Example 5
Source File: AbstractProjectViewPane.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
protected <T extends NodeDescriptor> List<T> getSelectedNodes(@Nonnull Class<T> nodeClass) {
  TreePath[] paths = getSelectionPaths();
  if (paths == null) return Collections.emptyList();
  final ArrayList<T> result = new ArrayList<>();
  for (TreePath path : paths) {
    T userObject = TreeUtil.getLastUserObject(nodeClass, path);
    if (userObject != null) {
      result.add(userObject);
    }
  }
  return result;
}
 
Example 6
Source File: ProjectViewTree.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public final int getToggleClickCount() {
  int count = super.getToggleClickCount();
  TreePath path = getSelectionPath();
  if (path != null) {
    NodeDescriptor descriptor = TreeUtil.getLastUserObject(NodeDescriptor.class, path);
    if (descriptor != null && !descriptor.expandOnDoubleClick()) {
      LOG.debug("getToggleClickCount: -1 for ", descriptor.getClass().getName());
      return -1;
    }
  }
  return count;
}
 
Example 7
Source File: FileStructurePopup.java    From consulo with Apache License 2.0 5 votes vote down vote up
@TestOnly
public AsyncPromise<Void> rebuildAndUpdate() {
  AsyncPromise<Void> result = new AsyncPromise<>();
  TreeVisitor visitor = path -> {
    AbstractTreeNode node = TreeUtil.getLastUserObject(AbstractTreeNode.class, path);
    if (node != null) node.update();
    return TreeVisitor.Action.CONTINUE;
  };
  rebuild(false).onProcessed(ignore1 -> myAsyncTreeModel.accept(visitor).onProcessed(ignore2 -> result.setResult(null)));
  return result;
}
 
Example 8
Source File: AbstractProjectViewPane.java    From consulo with Apache License 2.0 4 votes vote down vote up
public final NodeDescriptor getSelectedDescriptor() {
  return TreeUtil.getLastUserObject(NodeDescriptor.class, getSelectedPath());
}