Search in sources :

Example 11 with AbstractTreeNode

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

the class PackageViewPane method getSelectedPackageElement.

@Nullable
private PackageElement getSelectedPackageElement() {
    PackageElement result = null;
    final DefaultMutableTreeNode selectedNode = getSelectedNode();
    if (selectedNode != null) {
        Object o = selectedNode.getUserObject();
        if (o instanceof AbstractTreeNode) {
            Object selected = ((AbstractTreeNode) o).getValue();
            result = selected instanceof PackageElement ? (PackageElement) selected : null;
        }
    }
    return result;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PackageElement(com.intellij.ide.projectView.impl.nodes.PackageElement) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with AbstractTreeNode

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

the class PackageElementNode method getChildren.

@Override
@NotNull
public Collection<AbstractTreeNode> getChildren() {
    final PackageElement value = getValue();
    if (value == null)
        return Collections.emptyList();
    final List<AbstractTreeNode> children = new ArrayList<>();
    final Module module = value.getModule();
    final PsiPackage aPackage = value.getPackage();
    if (!getSettings().isFlattenPackages()) {
        final PsiPackage[] subpackages = PackageUtil.getSubpackages(aPackage, module, isLibraryElement());
        for (PsiPackage subpackage : subpackages) {
            PackageUtil.addPackageAsChild(children, subpackage, module, getSettings(), isLibraryElement());
        }
    }
    // process only files in package's directories
    final GlobalSearchScope scopeToShow = PackageUtil.getScopeToShow(aPackage.getProject(), module, isLibraryElement());
    PsiFile[] packageChildren = aPackage.getFiles(scopeToShow);
    for (PsiFile file : packageChildren) {
        if (file.getVirtualFile() != null) {
            children.add(new PsiFileNode(getProject(), file, getSettings()));
        }
    }
    return children;
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiPackage(com.intellij.psi.PsiPackage) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with AbstractTreeNode

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

the class SameNamesJoiner method modify.

@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
    if (parent instanceof JoinedNode)
        return children;
    ArrayList<AbstractTreeNode> result = new ArrayList<>();
    MultiValuesMap<Object, AbstractTreeNode> executed = new MultiValuesMap<>();
    for (Iterator<AbstractTreeNode> iterator = children.iterator(); iterator.hasNext(); ) {
        ProjectViewNode treeNode = (ProjectViewNode) iterator.next();
        Object o = treeNode.getValue();
        if (o instanceof PsiFile) {
            String name = ((PsiFile) o).getVirtualFile().getNameWithoutExtension();
            executed.put(name, treeNode);
        } else {
            executed.put(o, treeNode);
        }
    }
    Iterator<Object> keys = executed.keySet().iterator();
    while (keys.hasNext()) {
        Object each = keys.next();
        Collection<AbstractTreeNode> objects = executed.get(each);
        if (objects.size() > 1) {
            result.add(new JoinedNode(objects, new Joined(findPsiFileIn(objects))));
        } else if (objects.size() == 1) {
            result.add(objects.iterator().next());
        }
    }
    return result;
}
Also used : MultiValuesMap(com.intellij.openapi.util.MultiValuesMap) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) ProjectViewNode(com.intellij.ide.projectView.ProjectViewNode) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with AbstractTreeNode

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

the class JavaCoverageViewExtension method createTopLevelNodes.

@Override
public List<AbstractTreeNode> createTopLevelNodes() {
    final List<AbstractTreeNode> topLevelNodes = new ArrayList<>();
    final LinkedHashSet<PsiPackage> packages = new LinkedHashSet<>();
    final LinkedHashSet<PsiClass> classes = new LinkedHashSet<>();
    for (CoverageSuite suite : mySuitesBundle.getSuites()) {
        packages.addAll(((JavaCoverageSuite) suite).getCurrentSuitePackages(myProject));
        classes.addAll(((JavaCoverageSuite) suite).getCurrentSuiteClasses(myProject));
    }
    final Set<PsiPackage> packs = new HashSet<>();
    for (PsiPackage aPackage : packages) {
        final String qualifiedName = aPackage.getQualifiedName();
        for (PsiPackage psiPackage : packages) {
            if (psiPackage.getQualifiedName().startsWith(qualifiedName + ".")) {
                packs.add(psiPackage);
                break;
            }
        }
    }
    packages.removeAll(packs);
    for (PsiPackage aPackage : packages) {
        final GlobalSearchScope searchScope = mySuitesBundle.getSearchScope(myProject);
        if (aPackage.getClasses(searchScope).length != 0) {
            final CoverageListNode node = new CoverageListNode(myProject, aPackage, mySuitesBundle, myStateBean);
            topLevelNodes.add(node);
        }
        collectSubPackages(topLevelNodes, aPackage);
    }
    for (PsiClass aClass : classes) {
        topLevelNodes.add(new CoverageListNode(myProject, aClass, mySuitesBundle, myStateBean));
    }
    return topLevelNodes;
}
Also used : AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope)

Example 15 with AbstractTreeNode

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

the class DirectoryCoverageViewExtension method getChildrenNodes.

@Override
public List<AbstractTreeNode> getChildrenNodes(AbstractTreeNode node) {
    List<AbstractTreeNode> children = new ArrayList<>();
    if (node instanceof CoverageListNode) {
        final Object val = node.getValue();
        if (val instanceof PsiFile || val == null)
            return Collections.emptyList();
        final PsiDirectory psiDirectory = (PsiDirectory) val;
        final PsiDirectory[] subdirectories = ApplicationManager.getApplication().runReadAction(new Computable<PsiDirectory[]>() {

            @Override
            public PsiDirectory[] compute() {
                return psiDirectory.getSubdirectories();
            }
        });
        for (PsiDirectory subdirectory : subdirectories) {
            children.add(new CoverageListNode(myProject, subdirectory, mySuitesBundle, myStateBean));
        }
        final PsiFile[] psiFiles = ApplicationManager.getApplication().runReadAction(new Computable<PsiFile[]>() {

            @Override
            public PsiFile[] compute() {
                return psiDirectory.getFiles();
            }
        });
        for (PsiFile psiFile : psiFiles) {
            children.add(new CoverageListNode(myProject, psiFile, mySuitesBundle, myStateBean));
        }
        for (AbstractTreeNode childNode : children) {
            childNode.setParent(node);
        }
    }
    return children;
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiFile(com.intellij.psi.PsiFile)

Aggregations

AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)154 NotNull (org.jetbrains.annotations.NotNull)69 ArrayList (java.util.ArrayList)52 VirtualFile (com.intellij.openapi.vfs.VirtualFile)43 Project (com.intellij.openapi.project.Project)36 PsiFile (com.intellij.psi.PsiFile)31 Module (com.intellij.openapi.module.Module)29 PsiDirectory (com.intellij.psi.PsiDirectory)27 PsiElement (com.intellij.psi.PsiElement)17 Nullable (org.jetbrains.annotations.Nullable)15 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)14 PsiManager (com.intellij.psi.PsiManager)11 ProjectViewNode (com.intellij.ide.projectView.ProjectViewNode)10 PsiDirectoryNode (com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)10 List (java.util.List)10 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