Search in sources :

Example 6 with ProjectViewNode

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

the class GroupByTypeComparator method compare.

@Override
public int compare(NodeDescriptor descriptor1, NodeDescriptor descriptor2) {
    if (!isSortByType() && descriptor1 instanceof ProjectViewNode && ((ProjectViewNode) descriptor1).isSortByFirstChild()) {
        final Collection<AbstractTreeNode> children = ((ProjectViewNode) descriptor1).getChildren();
        if (!children.isEmpty()) {
            descriptor1 = children.iterator().next();
            descriptor1.update();
        }
    }
    if (!isSortByType() && descriptor2 instanceof ProjectViewNode && ((ProjectViewNode) descriptor2).isSortByFirstChild()) {
        final Collection<AbstractTreeNode> children = ((ProjectViewNode) descriptor2).getChildren();
        if (!children.isEmpty()) {
            descriptor2 = children.iterator().next();
            descriptor2.update();
        }
    }
    if (descriptor1 instanceof ProjectViewNode && descriptor2 instanceof ProjectViewNode) {
        final Project project = descriptor1.getProject();
        final ProjectView projectView = ProjectView.getInstance(project);
        ProjectViewNode node1 = (ProjectViewNode) descriptor1;
        ProjectViewNode node2 = (ProjectViewNode) descriptor2;
        if (isManualOrder()) {
            final Comparable key1 = node1.getManualOrderKey();
            final Comparable key2 = node2.getManualOrderKey();
            int result = compare(key1, key2);
            if (result != 0)
                return result;
        }
        boolean isFoldersOnTop = !(projectView instanceof ProjectViewImpl && !((ProjectViewImpl) projectView).isFoldersAlwaysOnTop());
        if (isFoldersOnTop) {
            int typeWeight1 = node1.getTypeSortWeight(isSortByType());
            int typeWeight2 = node2.getTypeSortWeight(isSortByType());
            if (typeWeight1 != 0 && typeWeight2 == 0) {
                return -1;
            }
            if (typeWeight1 == 0 && typeWeight2 != 0) {
                return 1;
            }
            if (typeWeight1 != 0 && typeWeight2 != typeWeight1) {
                return typeWeight1 - typeWeight2;
            }
        }
        if (isSortByType()) {
            final Comparable typeSortKey1 = node1.getTypeSortKey();
            final Comparable typeSortKey2 = node2.getTypeSortKey();
            int result = compare(typeSortKey1, typeSortKey2);
            if (result != 0)
                return result;
        } else {
            final Comparable typeSortKey1 = node1.getSortKey();
            final Comparable typeSortKey2 = node2.getSortKey();
            if (typeSortKey1 != null && typeSortKey2 != null) {
                int result = compare(typeSortKey1, typeSortKey2);
                if (result != 0)
                    return result;
            }
        }
        if (isAbbreviateQualifiedNames()) {
            String key1 = node1.getQualifiedNameSortKey();
            String key2 = node2.getQualifiedNameSortKey();
            if (key1 != null && key2 != null) {
                return naturalCompare(key1, key2);
            }
        }
    }
    if (descriptor1 == null)
        return -1;
    if (descriptor2 == null)
        return 1;
    return AlphaComparator.INSTANCE.compare(descriptor1, descriptor2);
}
Also used : Project(com.intellij.openapi.project.Project) ProjectViewNode(com.intellij.ide.projectView.ProjectViewNode) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) ProjectView(com.intellij.ide.projectView.ProjectView)

Example 7 with ProjectViewNode

use of com.intellij.ide.projectView.ProjectViewNode 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 8 with ProjectViewNode

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

the class Commander method syncViews.

public void syncViews() {
    final CommanderPanel activePanel;
    final CommanderPanel passivePanel;
    if (isLeftPanelActive()) {
        activePanel = myLeftPanel;
        passivePanel = myRightPanel;
    } else {
        activePanel = myRightPanel;
        passivePanel = myLeftPanel;
    }
    ProjectViewNode element = (ProjectViewNode) activePanel.getBuilder().getParentNode();
    passivePanel.getBuilder().enterElement(element);
}
Also used : ProjectViewNode(com.intellij.ide.projectView.ProjectViewNode)

Example 9 with ProjectViewNode

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

the class FlexTreeStructureProvider method modify.

@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
    List<AbstractTreeNode> result = new ArrayList<>();
    if (parent instanceof SwfQualifiedNamedElementNode || parent instanceof FlexFileNode) {
        if (((ProjectViewNode) parent).getSettings().isShowMembers()) {
            JSQualifiedNamedElement parentElement = getElement(parent);
            if (parentElement != null) {
                JSStructureViewElement structureViewElement = parentElement instanceof XmlBackedJSClassImpl ? new FlexStructureViewElement(((XmlBackedJSClassImpl) parentElement), (XmlFile) parentElement.getContainingFile(), false) : new JSStructureViewElement(parentElement, false, true);
                StructureViewTreeElement[] structureViewChildren = structureViewElement.getChildren();
                for (final StructureViewTreeElement structureViewChild : structureViewChildren) {
                    if (structureViewChild instanceof JSStructureViewElement) {
                        PsiElement childElement = ((JSStructureViewElement) structureViewChild).getValue();
                        result.add(new FlexClassMemberNode((JSElement) childElement, ((ProjectViewNode) parent).getSettings()));
                    } else {
                        result.add(new UnknownNode(parentElement.getProject(), structureViewChild, ((ProjectViewNode) parent).getSettings()));
                    }
                }
            }
        }
    } else {
        for (final AbstractTreeNode child : children) {
            Object o = child.getValue();
            if (o instanceof JSFileImpl && !(o instanceof PsiCompiledFile) && DialectDetector.isActionScript((PsiFile) o) || o instanceof XmlFile && JavaScriptSupportLoader.isFlexMxmFile((PsiFile) o)) {
                result.add(new FlexFileNode((PsiFile) o, ((ProjectViewNode) parent).getSettings()));
                continue;
            }
            result.add(child);
        }
    }
    return result;
}
Also used : XmlBackedJSClassImpl(com.intellij.lang.javascript.flex.XmlBackedJSClassImpl) XmlFile(com.intellij.psi.xml.XmlFile) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) JSStructureViewElement(com.intellij.lang.javascript.structureView.JSStructureViewElement) FlexStructureViewElement(com.intellij.lang.javascript.flex.presentation.FlexStructureViewProvider.FlexStructureViewElement) JSFileImpl(com.intellij.lang.javascript.psi.impl.JSFileImpl) ProjectViewNode(com.intellij.ide.projectView.ProjectViewNode) PsiCompiledFile(com.intellij.psi.PsiCompiledFile) JSElement(com.intellij.lang.javascript.psi.JSElement) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

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