Search in sources :

Example 11 with ProjectViewNode

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

the class ProjectViewTestUtil method collect.

public static void collect(AbstractTreeNode node, MultiValuesMap<VirtualFile, AbstractTreeNode> map, final AbstractTreeStructure structure, Function<AbstractTreeNode, VirtualFile[]> converterFunction) {
    Object[] kids = structure.getChildElements(node);
    for (Object kid1 : kids) {
        ProjectViewNode kid = (ProjectViewNode) kid1;
        final VirtualFile[] files = getFiles(kid, converterFunction);
        for (VirtualFile vFile : files) {
            map.put(vFile, kid);
            ProjectViewNode eachParent = (ProjectViewNode) kid.getParent();
            while (eachParent != null) {
                map.put(vFile, eachParent);
                eachParent = (ProjectViewNode) eachParent.getParent();
            }
        }
        collect(kid, map, structure, converterFunction);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectViewNode(com.intellij.ide.projectView.ProjectViewNode)

Example 12 with ProjectViewNode

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

the class ProjectTreeBuilder method updateNodesContaining.

private void updateNodesContaining(@NotNull Collection<VirtualFile> filesToRefresh, @NotNull DefaultMutableTreeNode rootNode) {
    if (!(rootNode.getUserObject() instanceof ProjectViewNode))
        return;
    ProjectViewNode node = (ProjectViewNode) rootNode.getUserObject();
    Collection<VirtualFile> containingFiles = null;
    for (VirtualFile virtualFile : filesToRefresh) {
        if (!virtualFile.isValid()) {
            // file must be deleted
            addSubtreeToUpdate(rootNode);
            return;
        }
        if (node.contains(virtualFile)) {
            if (containingFiles == null)
                containingFiles = new SmartList<>();
            containingFiles.add(virtualFile);
        }
    }
    if (containingFiles != null) {
        updateNode(rootNode);
        Enumeration children = rootNode.children();
        while (children.hasMoreElements()) {
            DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement();
            updateNodesContaining(containingFiles, child);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Enumeration(java.util.Enumeration) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ProjectViewNode(com.intellij.ide.projectView.ProjectViewNode) SmartList(com.intellij.util.SmartList)

Example 13 with ProjectViewNode

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

the class ClassNameConvertor 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 aChildren : children) {
        ProjectViewNode treeNode = (ProjectViewNode) aChildren;
        Object o = treeNode.getValue();
        if (o instanceof PsiFile && ((PsiFile) o).getVirtualFile().getExtension().equals("java")) {
            final String name = ((PsiFile) o).getName();
            ProjectViewNode viewNode = new ProjectViewNode<PsiFile>(myProject, (PsiFile) o, settings) {

                @Override
                @NotNull
                public Collection<AbstractTreeNode> getChildren() {
                    return Collections.emptyList();
                }

                @Override
                public String toTestString(Queryable.PrintInfo printInfo) {
                    return super.toTestString(printInfo) + " converted";
                }

                @Override
                public String getTestPresentation() {
                    return name + " converted";
                }

                @Override
                public boolean contains(@NotNull VirtualFile file) {
                    return false;
                }

                @Override
                public void update(PresentationData presentation) {
                }
            };
            result.add(viewNode);
        } else {
            result.add(treeNode);
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PresentationData(com.intellij.ide.projectView.PresentationData) ProjectViewNode(com.intellij.ide.projectView.ProjectViewNode) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with ProjectViewNode

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

the class TreeFileChooserDialog method calcSelectedClass.

private PsiFile calcSelectedClass() {
    if (myTabbedPane.getSelectedIndex() == 1) {
        return (PsiFile) myGotoByNamePanel.getChosenElement();
    } else {
        final TreePath path = myTree.getSelectionPath();
        if (path == null)
            return null;
        final DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
        final Object userObject = node.getUserObject();
        if (!(userObject instanceof ProjectViewNode))
            return null;
        ProjectViewNode pvNode = (ProjectViewNode) userObject;
        VirtualFile vFile = pvNode.getVirtualFile();
        if (vFile != null && !vFile.isDirectory()) {
            return PsiManager.getInstance(myProject).findFile(vFile);
        }
        return null;
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ProjectViewNode(com.intellij.ide.projectView.ProjectViewNode) PsiFile(com.intellij.psi.PsiFile)

Example 15 with ProjectViewNode

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

the class ModuleGroupNode method getRoots.

@NotNull
@Override
public Collection<VirtualFile> getRoots() {
    Collection<AbstractTreeNode> children = getChildren();
    Set<VirtualFile> result = new HashSet<>();
    for (AbstractTreeNode each : children) {
        if (each instanceof ProjectViewNode) {
            result.addAll(((ProjectViewNode) each).getRoots());
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectViewNode(com.intellij.ide.projectView.ProjectViewNode) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) 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