Search in sources :

Example 1 with AbstractTreeNode

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

the class ResourceBundleNode method getChildren.

@Override
@NotNull
public Collection<AbstractTreeNode> getChildren() {
    List<PropertiesFile> propertiesFiles = ObjectUtils.notNull(getValue()).getPropertiesFiles();
    Collection<AbstractTreeNode> children = new ArrayList<>();
    for (PropertiesFile propertiesFile : propertiesFiles) {
        AbstractTreeNode node = new PsiFileNode(myProject, propertiesFile.getContainingFile(), getSettings());
        children.add(node);
    }
    return children;
}
Also used : PsiFileNode(com.intellij.ide.projectView.impl.nodes.PsiFileNode) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with AbstractTreeNode

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

the class XsltTreeStructureProvider method modify.

@NotNull
@SuppressWarnings({ "RawUseOfParameterizedType", "unchecked" })
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
    Collection<AbstractTreeNode> l = children;
    int i = 0;
    for (AbstractTreeNode o : children) {
        if (o instanceof ProjectViewNode) {
            final ProjectViewNode node = (ProjectViewNode) o;
            final Object element = node.getValue();
            if (element instanceof PsiFile) {
                if (XsltSupport.isXsltFile((PsiFile) element)) {
                    if (l == children && l.getClass() != ArrayList.class) {
                        l = new ArrayList<>(children);
                    }
                    final XsltFileNode fileNode = new XsltFileNode(myProject, (PsiFile) element, settings);
                    ((List<AbstractTreeNode>) l).set(i, fileNode);
                }
            }
        }
        i++;
    }
    return l;
}
Also used : ProjectViewNode(com.intellij.ide.projectView.ProjectViewNode) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiFile(com.intellij.psi.PsiFile) ArrayList(java.util.ArrayList) List(java.util.List) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with AbstractTreeNode

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

the class StudyTreeStructureProvider method modify.

@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
    Project project = parent.getProject();
    if (project == null || !shouldModify(project)) {
        return children;
    }
    Course course = StudyTaskManager.getInstance(project).getCourse();
    if (course == null) {
        return children;
    }
    Collection<AbstractTreeNode> modifiedNodes = new ArrayList<>();
    for (AbstractTreeNode node : children) {
        if (parent instanceof ProjectViewProjectNode && node instanceof PsiDirectoryNode) {
            modifiedNodes.add(createCourseNode(project, node, settings, course));
            continue;
        }
        if (parent instanceof StudyDirectoryNode) {
            AbstractTreeNode modifiedNode = ((StudyDirectoryNode) parent).modifyChildNode(node);
            if (modifiedNode != null) {
                modifiedNodes.add(modifiedNode);
            }
        }
    }
    return modifiedNodes;
}
Also used : Project(com.intellij.openapi.project.Project) ProjectViewProjectNode(com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiDirectoryNode(com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode) Course(com.jetbrains.edu.learning.courseFormat.Course) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with AbstractTreeNode

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

the class FormMergerTreeStructureProvider method findFormsIn.

private static Collection<BasePsiNode<? extends PsiElement>> findFormsIn(Collection<AbstractTreeNode> children, List<PsiFile> forms) {
    if (children.isEmpty() || forms.isEmpty())
        return Collections.emptyList();
    ArrayList<BasePsiNode<? extends PsiElement>> result = new ArrayList<>();
    HashSet<PsiFile> psiFiles = new HashSet<>(forms);
    for (final AbstractTreeNode child : children) {
        if (child instanceof BasePsiNode) {
            //noinspection unchecked
            BasePsiNode<? extends PsiElement> treeNode = (BasePsiNode<? extends PsiElement>) child;
            //noinspection SuspiciousMethodCalls
            if (psiFiles.contains(treeNode.getValue()))
                result.add(treeNode);
        }
    }
    return result;
}
Also used : AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) BasePsiNode(com.intellij.ide.projectView.impl.nodes.BasePsiNode)

Example 5 with AbstractTreeNode

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

the class FormMergerTreeStructureProvider method modify.

@NotNull
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
    if (parent.getValue() instanceof Form)
        return children;
    // Optimization. Check if there are any forms at all.
    boolean formsFound = false;
    for (AbstractTreeNode node : children) {
        if (node.getValue() instanceof PsiFile) {
            PsiFile file = (PsiFile) node.getValue();
            if (file.getFileType() == StdFileTypes.GUI_DESIGNER_FORM) {
                formsFound = true;
                break;
            }
        }
    }
    if (!formsFound)
        return children;
    Collection<AbstractTreeNode> result = new LinkedHashSet<>(children);
    ProjectViewNode[] copy = children.toArray(new ProjectViewNode[children.size()]);
    for (ProjectViewNode element : copy) {
        PsiClass psiClass = null;
        if (element.getValue() instanceof PsiClass) {
            psiClass = (PsiClass) element.getValue();
        } else if (element.getValue() instanceof PsiClassOwner) {
            final PsiClass[] psiClasses = ((PsiClassOwner) element.getValue()).getClasses();
            if (psiClasses.length == 1) {
                psiClass = psiClasses[0];
            }
        }
        if (psiClass == null)
            continue;
        String qName = psiClass.getQualifiedName();
        if (qName == null)
            continue;
        List<PsiFile> forms;
        try {
            forms = FormClassIndex.findFormsBoundToClass(myProject, qName);
        } catch (ProcessCanceledException e) {
            continue;
        }
        Collection<BasePsiNode<? extends PsiElement>> formNodes = findFormsIn(children, forms);
        if (!formNodes.isEmpty()) {
            Collection<PsiFile> formFiles = convertToFiles(formNodes);
            Collection<BasePsiNode<? extends PsiElement>> subNodes = new ArrayList<>();
            //noinspection unchecked
            subNodes.add((BasePsiNode<? extends PsiElement>) element);
            subNodes.addAll(formNodes);
            result.add(new FormNode(myProject, new Form(psiClass, formFiles), settings, subNodes));
            result.remove(element);
            result.removeAll(formNodes);
        }
    }
    return result;
}
Also used : AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) BasePsiNode(com.intellij.ide.projectView.impl.nodes.BasePsiNode) ProjectViewNode(com.intellij.ide.projectView.ProjectViewNode) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) NotNull(org.jetbrains.annotations.NotNull)

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