Search in sources :

Example 11 with PsiDirectoryNode

use of com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode in project intellij-plugins by JetBrains.

the class DartTreeStructureProvider method modify.

@NotNull
public Collection<AbstractTreeNode> modify(@NotNull final AbstractTreeNode parentNode, @NotNull final Collection<AbstractTreeNode> children, final ViewSettings settings) {
    if (parentNode instanceof ExternalLibrariesNode) {
        return ContainerUtil.map(children, node -> {
            if (node instanceof NamedLibraryElementNode && (DartPackagesLibraryType.DART_PACKAGES_LIBRARY_NAME.equals(node.getName()) || DartSdk.DART_SDK_LIB_NAME.equals(node.getName()))) {
                final boolean isSdkRoot = DartSdk.DART_SDK_LIB_NAME.equals(node.getName());
                return new NamedLibraryElementNode(node.getProject(), ((NamedLibraryElementNode) node).getValue(), settings) {

                    @Override
                    public boolean canNavigate() {
                        return isSdkRoot;
                    }

                    @Override
                    public void navigate(boolean requestFocus) {
                        final Project project = getProject();
                        if (project != null) {
                            DartConfigurable.openDartSettings(project);
                        }
                    }
                };
            }
            return node;
        });
    }
    if (parentNode instanceof NamedLibraryElementNode && (DartPackagesLibraryType.DART_PACKAGES_LIBRARY_NAME.equals(parentNode.getName()) || DartSdk.DART_SDK_LIB_NAME.equals(parentNode.getName()))) {
        final boolean isSdkRoot = DartSdk.DART_SDK_LIB_NAME.equals(parentNode.getName());
        return ContainerUtil.map(children, node -> {
            final VirtualFile dir = node instanceof PsiDirectoryNode ? ((PsiDirectoryNode) node).getVirtualFile() : null;
            if (dir != null && dir.isInLocalFileSystem() && dir.isDirectory() && (isSdkRoot || "lib".equals(dir.getName()))) {
                return new DartSdkOrLibraryRootNode(node.getProject(), ((PsiDirectoryNode) node).getValue(), settings);
            }
            return node;
        });
    }
    // root/packages/ThisProject and root/packages/PathPackage folders are excluded in dart projects (see DartProjectComponent.excludeBuildAndPackagesFolders),
    // this provider adds location string tho these nodes in Project View like "ThisProject (ThisProject/lib)"
    final Project project = parentNode.getProject();
    final VirtualFile packagesDir = parentNode instanceof PsiDirectoryNode && project != null ? ((PsiDirectoryNode) parentNode).getVirtualFile() : null;
    final VirtualFile parentFolder = packagesDir != null && packagesDir.isDirectory() && PACKAGES_FOLDER_NAME.equals(packagesDir.getName()) ? packagesDir.getParent() : null;
    final VirtualFile pubspecYamlFile = parentFolder != null ? parentFolder.findChild(PUBSPEC_YAML) : null;
    if (pubspecYamlFile != null && !pubspecYamlFile.isDirectory()) {
        final ArrayList<AbstractTreeNode> modifiedChildren = new ArrayList<>(children);
        final DartUrlResolver resolver = DartUrlResolver.getInstance(project, pubspecYamlFile);
        resolver.processLivePackages((packageName, packageDir) -> {
            final VirtualFile folder = packagesDir.findChild(packageName);
            if (folder != null) {
                final AbstractTreeNode node = getFolderNode(children, folder);
                if (node == null) {
                    modifiedChildren.add(new SymlinkToLivePackageNode(project, packageName, packageDir));
                } else {
                    node.getPresentation().setLocationString(getPackageLocationString(packageDir));
                }
            }
        });
        return modifiedChildren;
    }
    return children;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ExternalLibrariesNode(com.intellij.ide.projectView.impl.nodes.ExternalLibrariesNode) ArrayList(java.util.ArrayList) DartUrlResolver(com.jetbrains.lang.dart.util.DartUrlResolver) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiDirectoryNode(com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode) NamedLibraryElementNode(com.intellij.ide.projectView.impl.nodes.NamedLibraryElementNode) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with PsiDirectoryNode

use of com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode in project intellij-community by JetBrains.

the class NestingTreeStructureProvider method modify.

@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull final AbstractTreeNode parent, @NotNull final Collection<AbstractTreeNode> children, final ViewSettings settings) {
    if (!(parent instanceof PsiDirectoryNode))
        return children;
    final Collection<NestingRule> rules = getNestingRules();
    if (rules.isEmpty())
        return children;
    final MultiMap<PsiFileNode, PsiFileNode> parentToChildren = calcParentToChildren(children, rules);
    if (parentToChildren.isEmpty())
        return children;
    // initial ArrayList size may be not exact, not a big problem
    final Collection<AbstractTreeNode> newChildren = new ArrayList<>(children.size() - parentToChildren.size());
    final Set<PsiFileNode> childrenToMoveDown = new THashSet<>(parentToChildren.values());
    for (AbstractTreeNode node : children) {
        if (!(node instanceof PsiFileNode)) {
            newChildren.add(node);
            continue;
        }
        if (childrenToMoveDown.contains(node)) {
            continue;
        }
        final Collection<PsiFileNode> childrenOfThisFile = parentToChildren.get((PsiFileNode) node);
        if (childrenOfThisFile.isEmpty()) {
            newChildren.add(node);
            continue;
        }
        newChildren.add(new NestingTreeNode((PsiFileNode) node, childrenOfThisFile));
    }
    return newChildren;
}
Also used : PsiFileNode(com.intellij.ide.projectView.impl.nodes.PsiFileNode) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiDirectoryNode(com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode) NestingTreeNode(com.intellij.ide.projectView.impl.nodes.NestingTreeNode) THashSet(gnu.trove.THashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with PsiDirectoryNode

use of com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode in project intellij-community by JetBrains.

the class AbstractProjectViewPSIPane method createComponent.

@Override
public JComponent createComponent() {
    if (myComponent != null)
        return myComponent;
    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(null);
    DefaultTreeModel treeModel = new DefaultTreeModel(rootNode);
    myTree = createTree(treeModel);
    enableDnD();
    myComponent = ScrollPaneFactory.createScrollPane(myTree);
    if (Registry.is("error.stripe.enabled")) {
        ErrorStripePainter painter = new ErrorStripePainter(true);
        Disposer.register(this, new TreeUpdater<ErrorStripePainter>(painter, myComponent, myTree) {

            @Override
            protected void update(ErrorStripePainter painter, int index, Object object) {
                if (object instanceof DefaultMutableTreeNode) {
                    DefaultMutableTreeNode node = (DefaultMutableTreeNode) object;
                    object = node.getUserObject();
                }
                if (object instanceof PsiDirectoryNode && !myTree.isCollapsed(index)) {
                    object = null;
                }
                super.update(painter, index, object);
            }

            @Override
            protected ErrorStripe getErrorStripe(Object object) {
                if (object instanceof PresentableNodeDescriptor) {
                    PresentableNodeDescriptor node = (PresentableNodeDescriptor) object;
                    PresentationData presentation = node.getPresentation();
                    TextAttributesKey key = presentation.getTextAttributesKey();
                    if (key != null) {
                        TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(key);
                        if (attributes != null && EffectType.WAVE_UNDERSCORE == attributes.getEffectType()) {
                            return ErrorStripe.create(attributes.getEffectColor(), 1);
                        }
                    }
                }
                return null;
            }
        });
    }
    myTreeStructure = createStructure();
    BaseProjectTreeBuilder treeBuilder = createBuilder(treeModel);
    installComparator(treeBuilder);
    setTreeBuilder(treeBuilder);
    initTree();
    Disposer.register(getTreeBuilder(), new UiNotifyConnector(myTree, new Activatable() {

        private boolean showing;

        @Override
        public void showNotify() {
            if (!showing) {
                showing = true;
                restoreExpandedPaths();
            }
        }

        @Override
        public void hideNotify() {
            if (showing) {
                showing = false;
                saveExpandedPaths();
            }
        }
    }));
    return myComponent;
}
Also used : ErrorStripe(com.intellij.ui.stripe.ErrorStripe) PresentableNodeDescriptor(com.intellij.ide.util.treeView.PresentableNodeDescriptor) PresentationData(com.intellij.ide.projectView.PresentationData) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Activatable(com.intellij.util.ui.update.Activatable) ErrorStripePainter(com.intellij.ui.stripe.ErrorStripePainter) PsiDirectoryNode(com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) UiNotifyConnector(com.intellij.util.ui.update.UiNotifyConnector) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) BaseProjectTreeBuilder(com.intellij.ide.projectView.BaseProjectTreeBuilder)

Example 14 with PsiDirectoryNode

use of com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode in project intellij-community by JetBrains.

the class PlatformProjectViewStructureProvider method modify.

@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull final AbstractTreeNode parent, @NotNull final Collection<AbstractTreeNode> children, final ViewSettings settings) {
    if (parent instanceof PsiDirectoryNode) {
        final VirtualFile vFile = ((PsiDirectoryNode) parent).getVirtualFile();
        if (vFile != null && Comparing.equal(ProjectFileIndex.SERVICE.getInstance(myProject).getContentRootForFile(vFile), vFile)) {
            final Collection<AbstractTreeNode> moduleChildren = ((PsiDirectoryNode) parent).getChildren();
            Collection<AbstractTreeNode> result = new ArrayList<>();
            for (AbstractTreeNode moduleChild : moduleChildren) {
                if (moduleChild instanceof PsiDirectoryNode) {
                    final PsiDirectory value = ((PsiDirectoryNode) moduleChild).getValue();
                    if (value.getName().equals(Project.DIRECTORY_STORE_FOLDER) && Registry.is("projectView.hide.dot.idea")) {
                        continue;
                    }
                }
                result.add(moduleChild);
            }
            return result;
        }
    }
    return children;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDirectory(com.intellij.psi.PsiDirectory) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiDirectoryNode(com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with PsiDirectoryNode

use of com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode in project intellij-community by JetBrains.

the class AbstractProjectViewPane method getSelectedDirectories.

@NotNull
public PsiDirectory[] getSelectedDirectories() {
    List<PsiDirectory> directories = ContainerUtil.newArrayList();
    for (PsiDirectoryNode node : getSelectedNodes(PsiDirectoryNode.class)) {
        PsiDirectory directory = node.getValue();
        if (directory != null) {
            directories.add(directory);
            Object parentValue = node.getParent().getValue();
            if (parentValue instanceof PsiDirectory && Registry.is("projectView.choose.directory.on.compacted.middle.packages")) {
                while (true) {
                    directory = directory.getParentDirectory();
                    if (directory == null || directory.equals(parentValue)) {
                        break;
                    }
                    directories.add(directory);
                }
            }
        }
    }
    if (!directories.isEmpty()) {
        return directories.toArray(new PsiDirectory[directories.size()]);
    }
    final PsiElement[] elements = getSelectedPSIElements();
    if (elements.length == 1) {
        final PsiElement element = elements[0];
        if (element instanceof PsiDirectory) {
            return new PsiDirectory[] { (PsiDirectory) element };
        } else if (element instanceof PsiDirectoryContainer) {
            return ((PsiDirectoryContainer) element).getDirectories();
        } else {
            final PsiFile containingFile = element.getContainingFile();
            if (containingFile != null) {
                final PsiDirectory psiDirectory = containingFile.getContainingDirectory();
                if (psiDirectory != null) {
                    return new PsiDirectory[] { psiDirectory };
                }
                final VirtualFile file = containingFile.getVirtualFile();
                if (file instanceof VirtualFileWindow) {
                    final VirtualFile delegate = ((VirtualFileWindow) file).getDelegate();
                    final PsiFile delegatePsiFile = containingFile.getManager().findFile(delegate);
                    if (delegatePsiFile != null && delegatePsiFile.getContainingDirectory() != null) {
                        return new PsiDirectory[] { delegatePsiFile.getContainingDirectory() };
                    }
                }
                return PsiDirectory.EMPTY_ARRAY;
            }
        }
    } else {
        final DefaultMutableTreeNode selectedNode = getSelectedNode();
        if (selectedNode != null) {
            return getSelectedDirectoriesInAmbiguousCase(selectedNode);
        }
    }
    return PsiDirectory.EMPTY_ARRAY;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) VirtualFileWindow(com.intellij.injected.editor.VirtualFileWindow) PsiDirectoryNode(com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiDirectoryNode (com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)17 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)9 PsiDirectory (com.intellij.psi.PsiDirectory)9 NotNull (org.jetbrains.annotations.NotNull)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 Project (com.intellij.openapi.project.Project)7 ArrayList (java.util.ArrayList)5 Module (com.intellij.openapi.module.Module)4 PsiFileNode (com.intellij.ide.projectView.impl.nodes.PsiFileNode)3 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)3 NamedLibraryElementNode (com.intellij.ide.projectView.impl.nodes.NamedLibraryElementNode)2 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)2 AndroidProject (com.android.builder.model.AndroidProject)1 ResourceFolderType (com.android.resources.ResourceFolderType)1 NdkFacet (com.android.tools.idea.gradle.project.facet.ndk.NdkFacet)1 TestArtifactSearchScopes (com.android.tools.idea.testartifacts.scopes.TestArtifactSearchScopes)1 BaseProjectTreeBuilder (com.intellij.ide.projectView.BaseProjectTreeBuilder)1 PresentationData (com.intellij.ide.projectView.PresentationData)1 ViewSettings (com.intellij.ide.projectView.ViewSettings)1 ExternalLibrariesNode (com.intellij.ide.projectView.impl.nodes.ExternalLibrariesNode)1