Search in sources :

Example 16 with PsiDirectoryNode

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

the class AndroidViewProjectNode method getChildren.

@NotNull
@Override
public Collection<? extends AbstractTreeNode> getChildren() {
    Project project = getProject();
    assert project != null;
    ViewSettings settings = getSettings();
    // add a node for every module
    // TODO: make this conditional on getSettings().isShowModules(), otherwise collapse them all at the root
    List<Module> modules = Arrays.asList(ModuleManager.getInstance(project).getModules());
    List<AbstractTreeNode> children = Lists.newArrayListWithExpectedSize(modules.size());
    for (Module module : modules) {
        if (isRootModuleWithNoSources(module)) {
            // If we detect such a module, then we don't show it..
            continue;
        }
        AndroidFacet androidFacet = AndroidFacet.getInstance(module);
        NdkFacet ndkFacet = NdkFacet.getInstance(module);
        if (androidFacet != null && androidFacet.getAndroidModel() != null) {
            children.add(new AndroidModuleNode(project, module, settings, myProjectViewPane));
        } else if (ndkFacet != null && ndkFacet.getNdkModuleModel() != null) {
            children.add(new NdkModuleNode(project, module, settings));
        } else {
            children.add(new NonAndroidModuleNode(project, module, settings));
        }
    }
    // are still visible. See https://code.google.com/p/android/issues/detail?id=76564
    if (children.isEmpty() && isBuildWithGradle(project) && GradleSyncState.getInstance(project).lastSyncFailed()) {
        PsiDirectory dir = PsiManager.getInstance(project).findDirectory(project.getBaseDir());
        if (dir != null) {
            children.add(new PsiDirectoryNode(project, dir, settings));
        }
    }
    if (isBuildWithGradle(project)) {
        children.add(new AndroidBuildScriptsGroupNode(project, settings));
    }
    ExternalBuildFilesGroupNode externalBuildFilesNode = new ExternalBuildFilesGroupNode(project, settings);
    if (!externalBuildFilesNode.getChildren().isEmpty()) {
        children.add(externalBuildFilesNode);
    }
    return children;
}
Also used : ViewSettings(com.intellij.ide.projectView.ViewSettings) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiDirectoryNode(com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode) NdkFacet(com.android.tools.idea.gradle.project.facet.ndk.NdkFacet) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Project(com.intellij.openapi.project.Project) PsiDirectory(com.intellij.psi.PsiDirectory) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 17 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)

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