Search in sources :

Example 16 with ProjectViewNode

use of com.intellij.ide.projectView.ProjectViewNode in project intellij-community by JetBrains.

the class TodoTreeBuilder method validateNode.

@Override
protected boolean validateNode(final Object child) {
    if (child instanceof ProjectViewNode) {
        final ProjectViewNode projectViewNode = (ProjectViewNode) child;
        projectViewNode.update();
        if (projectViewNode.getValue() == null) {
            return false;
        }
    }
    return true;
}
Also used : ProjectViewNode(com.intellij.ide.projectView.ProjectViewNode)

Example 17 with ProjectViewNode

use of com.intellij.ide.projectView.ProjectViewNode in project intellij-community by JetBrains.

the class ClassesTreeStructureProvider method modify.

@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
    ArrayList<AbstractTreeNode> result = new ArrayList<>();
    for (final AbstractTreeNode child : children) {
        Object o = child.getValue();
        if (o instanceof PsiClassOwner && !(o instanceof ServerPageFile)) {
            final ViewSettings settings1 = ((ProjectViewNode) parent).getSettings();
            final PsiClassOwner classOwner = (PsiClassOwner) o;
            final VirtualFile file = classOwner.getVirtualFile();
            if (!(classOwner instanceof PsiCompiledElement)) {
                //do not show duplicated items if jar file contains classes and sources
                final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
                if (file != null && fileIndex.isInLibrarySource(file)) {
                    final PsiElement originalElement = classOwner.getOriginalElement();
                    if (originalElement instanceof PsiFile) {
                        PsiFile classFile = (PsiFile) originalElement;
                        final VirtualFile virtualClassFile = classFile.getVirtualFile();
                        if (virtualClassFile != null && fileIndex.isInLibraryClasses(virtualClassFile) && !classOwner.getManager().areElementsEquivalent(classOwner, classFile) && classOwner.getManager().areElementsEquivalent(classOwner.getContainingDirectory(), classFile.getContainingDirectory())) {
                            continue;
                        }
                    }
                }
            }
            if (fileInRoots(file)) {
                PsiClass[] classes = ApplicationManager.getApplication().runReadAction(new Computable<PsiClass[]>() {

                    @Override
                    public PsiClass[] compute() {
                        try {
                            return classOwner.getClasses();
                        } catch (IndexNotReadyException e) {
                            return PsiClass.EMPTY_ARRAY;
                        }
                    }
                });
                if (classes.length == 1 && !(classes[0] instanceof SyntheticElement) && (file == null || file.getNameWithoutExtension().equals(classes[0].getName()))) {
                    result.add(new ClassTreeNode(myProject, classes[0], settings1));
                } else {
                    result.add(new PsiClassOwnerTreeNode(classOwner, settings1));
                }
                continue;
            }
        }
        result.add(child);
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) ViewSettings(com.intellij.ide.projectView.ViewSettings) ClassTreeNode(com.intellij.ide.projectView.impl.nodes.ClassTreeNode) ProjectViewNode(com.intellij.ide.projectView.ProjectViewNode) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ProjectViewNode (com.intellij.ide.projectView.ProjectViewNode)17 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)9 NotNull (org.jetbrains.annotations.NotNull)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 PsiFile (com.intellij.psi.PsiFile)6 ArrayList (java.util.ArrayList)5 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)5 TreePath (javax.swing.tree.TreePath)3 Project (com.intellij.openapi.project.Project)2 PsiElement (com.intellij.psi.PsiElement)2 List (java.util.List)2 Nullable (org.jetbrains.annotations.Nullable)2 IdeBundle (com.intellij.ide.IdeBundle)1 BaseProjectTreeBuilder (com.intellij.ide.projectView.BaseProjectTreeBuilder)1 PresentationData (com.intellij.ide.projectView.PresentationData)1 ProjectView (com.intellij.ide.projectView.ProjectView)1 TreeStructureProvider (com.intellij.ide.projectView.TreeStructureProvider)1 ViewSettings (com.intellij.ide.projectView.ViewSettings)1 AbstractProjectTreeStructure (com.intellij.ide.projectView.impl.AbstractProjectTreeStructure)1 ProjectAbstractTreeStructureBase (com.intellij.ide.projectView.impl.ProjectAbstractTreeStructureBase)1