Search in sources :

Example 41 with AbstractTreeNode

use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.

the class FavoritesTreeUtil method getLogicalPathTo.

/*private static int getIndex(Collection<AbstractTreeNode> children, AbstractTreeNode node) {
    int idx = 0;
    for (AbstractTreeNode child : children) {
      if (child == node) {
        return idx;
      }
      ++ idx;
    }
    assert false;
    return -1;
  }*/
public static List<AbstractTreeNode> getLogicalPathTo(List<AbstractTreeNode> result, TreePath selectionPath) {
    final Object component = selectionPath.getLastPathComponent();
    if (component instanceof DefaultMutableTreeNode) {
        final Object uo = ((DefaultMutableTreeNode) component).getUserObject();
        if (uo instanceof FavoritesTreeNodeDescriptor) {
            AbstractTreeNode treeNode = ((FavoritesTreeNodeDescriptor) uo).getElement();
            while ((!(treeNode instanceof FavoritesListNode)) && treeNode != null) {
                result.add(treeNode);
                treeNode = treeNode.getParent();
            }
            Collections.reverse(result);
            return result;
        }
    }
    return Collections.emptyList();
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode)

Example 42 with AbstractTreeNode

use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.

the class FavoritesTreeUtil method extractParentList.

@Nullable
public static FavoritesListNode extractParentList(FavoritesTreeNodeDescriptor descriptor) {
    final AbstractTreeNode node = descriptor.getElement();
    AbstractTreeNode current = node;
    while (current != null) {
        if (current instanceof FavoritesListNode) {
            return (FavoritesListNode) current;
        }
        current = current.getParent();
    }
    return null;
}
Also used : AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) Nullable(org.jetbrains.annotations.Nullable)

Example 43 with AbstractTreeNode

use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.

the class FavoritesViewTreeBuilder method findSmartFirstLevelNodeByElement.

@Nullable
DefaultMutableTreeNode findSmartFirstLevelNodeByElement(final Object element) {
    for (Object child : getRoot().getChildren()) {
        AbstractTreeNode favorite = (AbstractTreeNode) child;
        Object currentValue = favorite.getValue();
        if (currentValue instanceof SmartPsiElementPointer) {
            currentValue = ((SmartPsiElementPointer) favorite.getValue()).getElement();
        }
        /*else if (currentValue instanceof PsiJavaFile) {
        final PsiClass[] classes = ((PsiJavaFile)currentValue).getClasses();
        if (classes.length > 0) {
          currentValue = classes[0];
        }
      }*/
        if (Comparing.equal(element, currentValue)) {
            final DefaultMutableTreeNode nodeWithObject = findFirstLevelNodeWithObject((DefaultMutableTreeNode) getTree().getModel().getRoot(), favorite);
            if (nodeWithObject != null) {
                return nodeWithObject;
            }
        }
    }
    return null;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) SmartPsiElementPointer(com.intellij.psi.SmartPsiElementPointer) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) Nullable(org.jetbrains.annotations.Nullable)

Example 44 with AbstractTreeNode

use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.

the class BaseProjectTreeBuilder method expandChild.

private void expandChild(@NotNull final List<AbstractTreeNode> kids, int i, @NotNull final Condition<AbstractTreeNode> nonStopCondition, final VirtualFile file, final Object element, @NotNull final AsyncResult<AbstractTreeNode> async, @NotNull final ProgressIndicator indicator, final Ref<Object> virtualSelectTarget) {
    while (i < kids.size()) {
        final AbstractTreeNode eachKid = kids.get(i);
        final boolean[] nodeWasCollapsed = { true };
        final DefaultMutableTreeNode nodeForElement = getNodeForElement(eachKid);
        if (nodeForElement != null) {
            nodeWasCollapsed[0] = getTree().isCollapsed(new TreePath(nodeForElement.getPath()));
        }
        if (nonStopCondition.value(eachKid)) {
            final AsyncResult<AbstractTreeNode> result = expandPathTo(file, eachKid, element, nonStopCondition, indicator, virtualSelectTarget);
            result.doWhenDone(new Consumer<AbstractTreeNode>() {

                @Override
                public void consume(AbstractTreeNode abstractTreeNode) {
                    indicator.checkCanceled();
                    async.setDone(abstractTreeNode);
                }
            });
            if (!result.isProcessed()) {
                final int next = i + 1;
                result.doWhenRejected(() -> {
                    indicator.checkCanceled();
                    if (nodeWasCollapsed[0] && virtualSelectTarget == null) {
                        collapseChildren(eachKid, null);
                    }
                    expandChild(kids, next, nonStopCondition, file, element, async, indicator, virtualSelectTarget);
                });
                return;
            } else {
                if (result.isRejected()) {
                    indicator.checkCanceled();
                    if (nodeWasCollapsed[0] && virtualSelectTarget == null) {
                        collapseChildren(eachKid, null);
                    }
                    i++;
                } else {
                    return;
                }
            }
        } else {
            //filter tells us to stop here (for instance, in case of module nodes)
            break;
        }
    }
    async.setRejected();
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode)

Example 45 with AbstractTreeNode

use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.

the class BaseProjectTreeBuilder method collectChildren.

@NotNull
private static List<AbstractTreeNode> collectChildren(@NotNull DefaultMutableTreeNode node) {
    int childCount = node.getChildCount();
    List<AbstractTreeNode> result = new ArrayList<>(childCount);
    for (int i = 0; i < childCount; i++) {
        TreeNode childAt = node.getChildAt(i);
        DefaultMutableTreeNode defaultMutableTreeNode = (DefaultMutableTreeNode) childAt;
        if (defaultMutableTreeNode.getUserObject() instanceof AbstractTreeNode) {
            AbstractTreeNode treeNode = (AbstractTreeNode) defaultMutableTreeNode.getUserObject();
            result.add(treeNode);
        } else if (defaultMutableTreeNode.getUserObject() instanceof FavoritesTreeNodeDescriptor) {
            AbstractTreeNode treeNode = ((FavoritesTreeNodeDescriptor) defaultMutableTreeNode.getUserObject()).getElement();
            result.add(treeNode);
        }
    }
    return result;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeNode(javax.swing.tree.TreeNode) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) FavoritesTreeNodeDescriptor(com.intellij.ide.favoritesTreeView.FavoritesTreeNodeDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)154 NotNull (org.jetbrains.annotations.NotNull)69 ArrayList (java.util.ArrayList)52 VirtualFile (com.intellij.openapi.vfs.VirtualFile)43 Project (com.intellij.openapi.project.Project)36 PsiFile (com.intellij.psi.PsiFile)31 Module (com.intellij.openapi.module.Module)29 PsiDirectory (com.intellij.psi.PsiDirectory)27 PsiElement (com.intellij.psi.PsiElement)17 Nullable (org.jetbrains.annotations.Nullable)15 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)14 PsiManager (com.intellij.psi.PsiManager)11 ProjectViewNode (com.intellij.ide.projectView.ProjectViewNode)10 PsiDirectoryNode (com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)10 List (java.util.List)10 PresentationData (com.intellij.ide.projectView.PresentationData)6 ViewSettings (com.intellij.ide.projectView.ViewSettings)6 PsiFileNode (com.intellij.ide.projectView.impl.nodes.PsiFileNode)6 NamedLibraryElement (com.intellij.ide.projectView.impl.nodes.NamedLibraryElement)5 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)5