Search in sources :

Example 6 with PsiDirectoryNode

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

the class ResourceMergerTreeStructureProvider method modify.

@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
    if (!ApplicationManager.getApplication().isInternal()) {
        return children;
    }
    if (parent instanceof PsiDirectoryNode) {
        PsiDirectory directory = ((PsiDirectoryNode) parent).getValue();
        if (!directory.getName().equals("res")) {
            return children;
        }
        Module module = ModuleUtil.findModuleForPsiElement(directory);
        AndroidFacet facet = AndroidFacet.getInstance(module);
        if (facet == null) {
            return children;
        }
        return mergeResourceDirectories(children, settings);
    }
    return children;
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) PsiDirectoryNode(com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with PsiDirectoryNode

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

the class AndroidTreeStructureProvider method modify.

@Override
@NotNull
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
    Project project = parent.getProject();
    if (project != null && AndroidProjectInfo.getInstance(project).requiresAndroidModel()) {
        if (parent instanceof NamedLibraryElementNode) {
            NamedLibraryElement value = ((NamedLibraryElementNode) parent).getValue();
            LibraryOrSdkOrderEntry orderEntry = value.getOrderEntry();
            if (orderEntry instanceof JdkOrderEntry) {
                Sdk sdk = ((JdkOrderEntry) orderEntry).getJdk();
                if (sdk.getSdkType() instanceof JavaSdk) {
                    List<AbstractTreeNode> newChildren = Lists.newArrayList();
                    for (AbstractTreeNode child : children) {
                        if (isRtJar(child)) {
                            newChildren.add(child);
                        }
                    }
                    if (!newChildren.isEmpty()) {
                        myEventDispatcher.getMulticaster().nodeChanged(parent, newChildren);
                        return newChildren;
                    }
                }
            }
        } else if (isRtJar(parent)) {
            List<AbstractTreeNode> newChildren = Lists.newArrayList();
            for (AbstractTreeNode child : children) {
                if (child instanceof PsiDirectoryNode) {
                    VirtualFile file = ((PsiDirectoryNode) child).getVirtualFile();
                    if (file != null && ("java".equals(file.getName()) || "javax".equals(file.getName()))) {
                        newChildren.add(child);
                    }
                }
            }
            if (!newChildren.isEmpty()) {
                myEventDispatcher.getMulticaster().nodeChanged(parent, newChildren);
                return newChildren;
            }
        }
    }
    return children;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) NamedLibraryElement(com.intellij.ide.projectView.impl.nodes.NamedLibraryElement) JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) LibraryOrSdkOrderEntry(com.intellij.openapi.roots.LibraryOrSdkOrderEntry) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) List(java.util.List) PsiDirectoryNode(com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) NamedLibraryElementNode(com.intellij.ide.projectView.impl.nodes.NamedLibraryElementNode) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with PsiDirectoryNode

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

the class BuildNodeDecorator method decorate.

@Override
public void decorate(ProjectViewNode node, PresentationData data) {
    if (!(node instanceof PsiDirectoryNode)) {
        return;
    }
    final PsiDirectoryNode psiDirectoryNode = (PsiDirectoryNode) node;
    PsiDirectory directory = psiDirectoryNode.getValue();
    if (directory == null || !directory.isValid()) {
        return;
    }
    final Project project = directory.getProject();
    if (!ProjectFacetManager.getInstance(project).hasFacets(AndroidFacet.ID)) {
        return;
    }
    // If the build dir is inside the module's content root, ProjectRootsUtil.isModuleContentRoot will return false. The reason is that when
    // we set up the project during a sync, we don't create additional content roots if the build dir is inside the module.
    final VirtualFile folder = directory.getVirtualFile();
    if (!ProjectRootsUtil.isModuleContentRoot(folder, project)) {
        return;
    }
    Object parentValue = psiDirectoryNode.getParent().getValue();
    if (!(parentValue instanceof Module)) {
        return;
    }
    Module module = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(folder);
    if (module == null) {
        return;
    }
    AndroidProject androidProject = GradleUtil.getAndroidProject(module);
    if (androidProject == null) {
        return;
    }
    File buildFolderPath = androidProject.getBuildFolder();
    File folderPath = VfsUtilCore.virtualToIoFile(folder);
    if (FileUtil.filesEqual(buildFolderPath, folderPath)) {
        data.clearText();
        data.addText(folder.getName(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AndroidProject(com.android.builder.model.AndroidProject) Project(com.intellij.openapi.project.Project) PsiDirectory(com.intellij.psi.PsiDirectory) PsiDirectoryNode(com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode) AndroidProject(com.android.builder.model.AndroidProject) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 9 with PsiDirectoryNode

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

the class ResourceMergerTreeStructureProvider method mergeResourceDirectories.

private static Collection<AbstractTreeNode> mergeResourceDirectories(Collection<AbstractTreeNode> children, ViewSettings settings) {
    List<AbstractTreeNode> result = new ArrayList<AbstractTreeNode>();
    Map<ResourceFolderType, ResourceDirectoryNode> resourceDirectories = new HashMap<ResourceFolderType, ResourceDirectoryNode>();
    for (AbstractTreeNode child : children) {
        if (!(child instanceof PsiDirectoryNode)) {
            result.add(child);
            continue;
        }
        PsiDirectoryNode directoryNode = (PsiDirectoryNode) child;
        PsiDirectory directory = directoryNode.getValue();
        ResourceFolderType type = ResourceFolderType.getFolderType(directory.getName());
        if (type == null) {
            result.add(child);
            continue;
        }
        ResourceDirectoryNode node = resourceDirectories.get(type);
        if (node == null || !directory.getName().contains("-")) {
            node = new ResourceDirectoryNode(directoryNode.getProject(), directoryNode, settings);
            resourceDirectories.put(type, node);
        }
    }
    for (ResourceDirectoryNode node : resourceDirectories.values()) {
        node.collectChildren();
        result.add(node);
    }
    return result;
}
Also used : HashMap(com.intellij.util.containers.HashMap) ResourceFolderType(com.android.resources.ResourceFolderType) PsiDirectory(com.intellij.psi.PsiDirectory) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiDirectoryNode(com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)

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

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