Search in sources :

Example 46 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 47 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)

Example 48 with AbstractTreeNode

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

the class BaseProjectTreeBuilder method _select.

private void _select(final Object element, final VirtualFile file, final boolean requestFocus, final Condition<AbstractTreeNode> nonStopCondition, final ActionCallback result, @NotNull final ProgressIndicator indicator, @Nullable final Ref<Object> virtualSelectTarget, final FocusRequestor focusRequestor, final boolean isSecondAttempt) {
    final AbstractTreeNode alreadySelected = alreadySelectedNode(element);
    final Runnable onDone = () -> {
        if (requestFocus && virtualSelectTarget == null && getUi().isReady()) {
            focusRequestor.requestFocus(getTree(), true);
        }
        result.setDone();
    };
    final Condition<AbstractTreeNode> condition = abstractTreeNode -> !result.isProcessed() && nonStopCondition.value(abstractTreeNode);
    if (alreadySelected == null) {
        expandPathTo(file, (AbstractTreeNode) getTreeStructure().getRootElement(), element, condition, indicator, virtualSelectTarget).doWhenDone(new Consumer<AbstractTreeNode>() {

            @Override
            public void consume(AbstractTreeNode node) {
                if (virtualSelectTarget == null) {
                    select(node, onDone);
                } else {
                    onDone.run();
                }
            }
        }).doWhenRejected(() -> {
            if (isSecondAttempt) {
                result.setRejected();
            } else {
                _select(file, file, requestFocus, nonStopCondition, result, indicator, virtualSelectTarget, focusRequestor, true);
            }
        });
    } else if (virtualSelectTarget == null) {
        scrollTo(alreadySelected, onDone);
    } else {
        onDone.run();
    }
}
Also used : com.intellij.openapi.util(com.intellij.openapi.util) UiActivityMonitor(com.intellij.ide.UiActivityMonitor) Arrays(java.util.Arrays) StatusBarProgress(com.intellij.openapi.progress.util.StatusBarProgress) VirtualFile(com.intellij.openapi.vfs.VirtualFile) TreeNode(javax.swing.tree.TreeNode) AbstractTreeBuilder(com.intellij.ide.util.treeView.AbstractTreeBuilder) FocusRequestor(com.intellij.openapi.wm.FocusRequestor) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Progressive(com.intellij.openapi.progress.Progressive) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) FavoritesTreeNodeDescriptor(com.intellij.ide.favoritesTreeView.FavoritesTreeNodeDescriptor) TreePath(javax.swing.tree.TreePath) UiActivity(com.intellij.ide.UiActivity) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) AbstractTreeStructure(com.intellij.ide.util.treeView.AbstractTreeStructure) Registry(com.intellij.openapi.util.registry.Registry) PsiDirectory(com.intellij.psi.PsiDirectory) ObjectUtils(com.intellij.util.ObjectUtils) AbstractTreeUpdater(com.intellij.ide.util.treeView.AbstractTreeUpdater) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) Consumer(com.intellij.util.Consumer) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) javax.swing(javax.swing) Consumer(com.intellij.util.Consumer) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode)

Example 49 with AbstractTreeNode

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

the class BaseProjectTreeBuilder method expandPathTo.

@NotNull
private AsyncResult<AbstractTreeNode> expandPathTo(final VirtualFile file, @NotNull final AbstractTreeNode root, final Object element, @NotNull final Condition<AbstractTreeNode> nonStopCondition, @NotNull final ProgressIndicator indicator, @Nullable final Ref<Object> target) {
    final AsyncResult<AbstractTreeNode> async = new AsyncResult<>();
    if (root.canRepresent(element)) {
        if (target == null) {
            expand(root, () -> async.setDone(root));
        } else {
            target.set(root);
            async.setDone(root);
        }
        return async;
    }
    if (!canExpandPathTo(root, element)) {
        async.setRejected();
        return async;
    }
    if (root instanceof ProjectViewNode && file != null && !((ProjectViewNode) root).contains(file)) {
        async.setRejected();
        return async;
    }
    if (target == null) {
        expand(root, () -> {
            indicator.checkCanceled();
            final DefaultMutableTreeNode rootNode = getNodeForElement(root);
            if (rootNode != null) {
                final List<AbstractTreeNode> kids = collectChildren(rootNode);
                expandChild(kids, 0, nonStopCondition, file, element, async, indicator, target);
            } else {
                async.setRejected();
            }
        });
    } else {
        if (indicator.isCanceled()) {
            async.setRejected();
        } else {
            final DefaultMutableTreeNode rootNode = getNodeForElement(root);
            final ArrayList<AbstractTreeNode> kids = new ArrayList<>();
            if (rootNode != null && getTree().isExpanded(new TreePath(rootNode.getPath()))) {
                kids.addAll(collectChildren(rootNode));
            } else {
                List<Object> list = Arrays.asList(getTreeStructure().getChildElements(root));
                for (Object each : list) {
                    kids.add((AbstractTreeNode) each);
                }
            }
            yield(() -> {
                if (isDisposed())
                    return;
                expandChild(kids, 0, nonStopCondition, file, element, async, indicator, target);
            });
        }
    }
    return async;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) NotNull(org.jetbrains.annotations.NotNull)

Example 50 with AbstractTreeNode

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

the class StructureViewModuleNode method getChildren.

@Override
@NotNull
public Collection<AbstractTreeNode> getChildren() {
    final Module module = getValue();
    if (module == null) {
        // just deleted a module from project view
        return Collections.emptyList();
    }
    final List<AbstractTreeNode> children = new ArrayList<>(2);
    children.add(new LibraryGroupNode(getProject(), new LibraryGroupElement(module), getSettings()) {

        @Override
        public boolean isAlwaysExpand() {
            return true;
        }
    });
    children.add(new ModuleListNode(getProject(), module, getSettings()));
    return children;
}
Also used : ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)150 NotNull (org.jetbrains.annotations.NotNull)69 ArrayList (java.util.ArrayList)51 VirtualFile (com.intellij.openapi.vfs.VirtualFile)40 Project (com.intellij.openapi.project.Project)33 PsiFile (com.intellij.psi.PsiFile)30 Module (com.intellij.openapi.module.Module)27 PsiDirectory (com.intellij.psi.PsiDirectory)25 PsiElement (com.intellij.psi.PsiElement)16 Nullable (org.jetbrains.annotations.Nullable)15 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)14 ProjectViewNode (com.intellij.ide.projectView.ProjectViewNode)10 PsiDirectoryNode (com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)9 PsiManager (com.intellij.psi.PsiManager)9 List (java.util.List)9 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