Search in sources :

Example 56 with AbstractTreeNode

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

the class ModuleGroupNode method getChildren.

@Override
@NotNull
public Collection<AbstractTreeNode> getChildren() {
    ModuleGrouper grouper = ModuleGrouper.instanceFor(getProject());
    final Collection<ModuleGroup> childGroups = getValue().childGroups(grouper);
    final List<AbstractTreeNode> result = new ArrayList<>();
    for (final ModuleGroup childGroup : childGroups) {
        result.add(createModuleGroupNode(childGroup));
    }
    Collection<Module> modules = getValue().modulesInGroup(grouper, false);
    try {
        for (Module module : modules) {
            result.add(createModuleNode(module));
        }
    } catch (Exception e) {
        LOG.error(e);
    }
    return result;
}
Also used : ModuleGrouper(com.intellij.openapi.module.ModuleGrouper) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) ModuleGroup(com.intellij.ide.projectView.impl.ModuleGroup) Module(com.intellij.openapi.module.Module) InvocationTargetException(java.lang.reflect.InvocationTargetException) NotNull(org.jetbrains.annotations.NotNull)

Example 57 with AbstractTreeNode

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

the class ProjectViewDirectoryHelper method getDirectoryChildren.

@NotNull
public Collection<AbstractTreeNode> getDirectoryChildren(final PsiDirectory psiDirectory, final ViewSettings settings, final boolean withSubDirectories, @Nullable PsiFileSystemItemFilter filter) {
    final List<AbstractTreeNode> children = new ArrayList<>();
    final Project project = psiDirectory.getProject();
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    final Module module = fileIndex.getModuleForFile(psiDirectory.getVirtualFile());
    final ModuleFileIndex moduleFileIndex = module == null ? null : ModuleRootManager.getInstance(module).getFileIndex();
    if (!settings.isFlattenPackages() || skipDirectory(psiDirectory)) {
        processPsiDirectoryChildren(psiDirectory, directoryChildrenInProject(psiDirectory, settings), children, fileIndex, null, settings, withSubDirectories, filter);
    } else {
        // source directory in "flatten packages" mode
        final PsiDirectory parentDir = psiDirectory.getParentDirectory();
        if (parentDir == null || skipDirectory(parentDir) && withSubDirectories) {
            addAllSubpackages(children, psiDirectory, moduleFileIndex, settings, filter);
        }
        if (withSubDirectories) {
            PsiDirectory[] subdirs = psiDirectory.getSubdirectories();
            for (PsiDirectory subdir : subdirs) {
                if (!skipDirectory(subdir) || filter != null && !filter.shouldShow(subdir)) {
                    continue;
                }
                VirtualFile directoryFile = subdir.getVirtualFile();
                if (Registry.is("ide.hide.excluded.files")) {
                    if (fileIndex.isExcluded(directoryFile))
                        continue;
                } else {
                    if (FileTypeRegistry.getInstance().isFileIgnored(directoryFile))
                        continue;
                }
                children.add(new PsiDirectoryNode(project, subdir, settings, filter));
            }
        }
        processPsiDirectoryChildren(psiDirectory, psiDirectory.getFiles(), children, fileIndex, moduleFileIndex, settings, withSubDirectories, filter);
    }
    return children;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 58 with AbstractTreeNode

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

the class PsiClassFavoriteNodeProvider method getFavoriteNodes.

@Override
public Collection<AbstractTreeNode> getFavoriteNodes(final DataContext context, final ViewSettings viewSettings) {
    final Project project = CommonDataKeys.PROJECT.getData(context);
    if (project == null)
        return null;
    PsiElement[] elements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(context);
    if (elements == null) {
        final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(context);
        if (element != null) {
            elements = new PsiElement[] { element };
        }
    }
    if (elements != null) {
        final Collection<AbstractTreeNode> result = new ArrayList<>();
        for (PsiElement element : elements) {
            if (element instanceof PsiClass && checkClassUnderSources(element, project)) {
                result.add(new ClassSmartPointerNode(project, element, viewSettings));
            }
        }
        return result.isEmpty() ? null : result;
    }
    return null;
}
Also used : Project(com.intellij.openapi.project.Project) ClassSmartPointerNode(com.intellij.ide.favoritesTreeView.smartPointerPsiNodes.ClassSmartPointerNode) ArrayList(java.util.ArrayList) PsiClass(com.intellij.psi.PsiClass) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiElement(com.intellij.psi.PsiElement)

Example 59 with AbstractTreeNode

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

the class PsiFieldFavoriteNodeProvider method getFavoriteNodes.

@Override
public Collection<AbstractTreeNode> getFavoriteNodes(final DataContext context, final ViewSettings viewSettings) {
    final Project project = CommonDataKeys.PROJECT.getData(context);
    if (project == null)
        return null;
    PsiElement[] elements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(context);
    if (elements == null) {
        final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(context);
        if (element != null) {
            elements = new PsiElement[] { element };
        }
    }
    if (elements != null) {
        final Collection<AbstractTreeNode> result = new ArrayList<>();
        for (PsiElement element : elements) {
            if (element instanceof PsiField) {
                result.add(new FieldSmartPointerNode(project, element, viewSettings));
            }
        }
        return result.isEmpty() ? null : result;
    }
    return null;
}
Also used : Project(com.intellij.openapi.project.Project) FieldSmartPointerNode(com.intellij.ide.favoritesTreeView.smartPointerPsiNodes.FieldSmartPointerNode) PsiField(com.intellij.psi.PsiField) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiElement(com.intellij.psi.PsiElement)

Example 60 with AbstractTreeNode

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

the class PsiPackageFavoriteNodeProvider method getFavoriteNodes.

@Override
public Collection<AbstractTreeNode> getFavoriteNodes(final DataContext context, final ViewSettings viewSettings) {
    final Project project = CommonDataKeys.PROJECT.getData(context);
    if (project == null)
        return null;
    PsiElement[] elements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(context);
    if (elements == null) {
        final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(context);
        if (element != null) {
            elements = new PsiElement[] { element };
        }
    }
    final Collection<AbstractTreeNode> result = new ArrayList<>();
    if (elements != null) {
        for (PsiElement element : elements) {
            if (element instanceof PsiPackage) {
                final PsiPackage psiPackage = (PsiPackage) element;
                final PsiDirectory[] directories = psiPackage.getDirectories();
                if (directories.length > 0) {
                    final VirtualFile firstDir = directories[0].getVirtualFile();
                    final boolean isLibraryRoot = ProjectRootsUtil.isLibraryRoot(firstDir, project);
                    final PackageElement packageElement = new PackageElement(LangDataKeys.MODULE.getData(context), psiPackage, isLibraryRoot);
                    result.add(new PackageElementNode(project, packageElement, viewSettings));
                }
            }
        }
        return result.isEmpty() ? null : result;
    }
    final String currentViewId = ProjectView.getInstance(project).getCurrentViewId();
    final Module[] modules = LangDataKeys.MODULE_CONTEXT_ARRAY.getData(context);
    if (modules != null) {
        for (Module module : modules) {
            if (PackageViewPane.ID.equals(currentViewId)) {
                result.add(new PackageViewModuleNode(project, module, viewSettings));
            } else {
                result.add(new ProjectViewModuleNode(project, module, viewSettings));
            }
        }
    } else {
        final ModuleGroup[] data = ModuleGroup.ARRAY_DATA_KEY.getData(context);
        if (data != null) {
            for (ModuleGroup moduleGroup : data) {
                if (PackageViewPane.ID.equals(currentViewId)) {
                    result.add(new PackageViewModuleGroupNode(project, moduleGroup, viewSettings));
                } else {
                    result.add(new ProjectViewModuleGroupNode(project, moduleGroup, viewSettings));
                }
            }
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiPackage(com.intellij.psi.PsiPackage) ModuleGroup(com.intellij.ide.projectView.impl.ModuleGroup) Project(com.intellij.openapi.project.Project) PsiDirectory(com.intellij.psi.PsiDirectory) Module(com.intellij.openapi.module.Module) PsiElement(com.intellij.psi.PsiElement)

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