Search in sources :

Example 6 with AbstractTreeNode

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

the class MvcProjectNode method getChildren.

@Override
@NotNull
public Collection<? extends AbstractTreeNode> getChildren() {
    List<Module> modules = MvcModuleStructureUtil.getAllModulesWithSupport(myProject, myDescriptor.getFramework());
    modules = myDescriptor.getFramework().reorderModulesForMvcView(modules);
    final ArrayList<AbstractTreeNode> nodes = new ArrayList<>();
    for (Module module : modules) {
        nodes.add(new MvcModuleNode(module, getSettings(), myDescriptor));
    }
    return nodes;
}
Also used : ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with AbstractTreeNode

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

the class MvcProjectViewPane method getSelectPath.

@Nullable
private static List<Object> getSelectPath(@NotNull Project project, @NotNull MvcFramework framework, VirtualFile file) {
    if (file == null) {
        return null;
    }
    final Module module = ModuleUtilCore.findModuleForFile(file, project);
    if (module == null || !framework.hasSupport(module)) {
        return null;
    }
    List<Object> result = new ArrayList<>();
    final MvcProjectViewPane view = getView(project, framework);
    if (view == null) {
        return null;
    }
    final MvcProjectNode root = (MvcProjectNode) view.getTreeBuilder().getTreeStructure().getRootElement();
    result.add(root);
    for (AbstractTreeNode moduleNode : root.getChildren()) {
        if (moduleNode.getValue() == module) {
            result.add(moduleNode);
            AbstractTreeNode<?> cur = moduleNode;
            path: while (true) {
                for (AbstractTreeNode descriptor : cur.getChildren()) {
                    if (descriptor instanceof AbstractFolderNode) {
                        final AbstractFolderNode folderNode = (AbstractFolderNode) descriptor;
                        final VirtualFile dir = folderNode.getVirtualFile();
                        if (dir != null && VfsUtilCore.isAncestor(dir, file, false)) {
                            cur = folderNode;
                            result.add(folderNode);
                            if (dir.equals(file)) {
                                return result;
                            }
                            continue path;
                        }
                    }
                    if (descriptor instanceof AbstractMvcPsiNodeDescriptor) {
                        if (file.equals(((AbstractMvcPsiNodeDescriptor) descriptor).getVirtualFile())) {
                            result.add(descriptor);
                            return result;
                        }
                    }
                }
                return null;
            }
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with AbstractTreeNode

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

the class AbstractFolderNode method getChildrenImpl.

@Override
@Nullable
protected Collection<AbstractTreeNode> getChildrenImpl() {
    final PsiDirectory directory = getPsiDirectory();
    if (!directory.isValid()) {
        return Collections.emptyList();
    }
    // scan folder's children
    final List<AbstractTreeNode> children = Arrays.stream(directory.getSubdirectories()).map(this::createFolderNode).collect(Collectors.toList());
    for (PsiFile file : directory.getFiles()) {
        processNotDirectoryFile(children, file);
    }
    return children;
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiFile(com.intellij.psi.PsiFile) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with AbstractTreeNode

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

the class CCTaskDirectoryNode method modifyChildNode.

@Nullable
@Override
public AbstractTreeNode modifyChildNode(AbstractTreeNode childNode) {
    AbstractTreeNode node = super.modifyChildNode(childNode);
    if (node != null) {
        return node;
    }
    Object value = childNode.getValue();
    if (value instanceof PsiElement) {
        PsiElement psiElement = (PsiElement) value;
        PsiFile psiFile = psiElement.getContainingFile();
        VirtualFile virtualFile = psiFile.getVirtualFile();
        if (virtualFile == null) {
            return null;
        }
        if (StudyUtils.isTaskDescriptionFile(virtualFile.getName())) {
            return null;
        }
        Course course = StudyTaskManager.getInstance(myProject).getCourse();
        if (course == null) {
            return null;
        }
        StudyLanguageManager manager = StudyUtils.getLanguageManager(course);
        if (manager == null) {
            return new CCStudentInvisibleFileNode(myProject, psiFile, myViewSettings);
        }
        if (!CCUtils.isTestsFile(myProject, virtualFile)) {
            return new CCStudentInvisibleFileNode(myProject, psiFile, myViewSettings);
        }
        if (!myTask.hasSubtasks()) {
            return new CCStudentInvisibleFileNode(myProject, psiFile, myViewSettings, getTestNodeName(manager, psiElement));
        }
        String testFileName = getTestNodeName(manager, psiElement);
        return isActiveSubtaskTest(virtualFile) ? new CCStudentInvisibleFileNode(myProject, psiFile, myViewSettings, testFileName) : null;
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiFile(com.intellij.psi.PsiFile) Course(com.jetbrains.edu.learning.courseFormat.Course) PsiElement(com.intellij.psi.PsiElement) StudyLanguageManager(com.jetbrains.edu.learning.StudyLanguageManager) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with AbstractTreeNode

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

the class PackageUtil method createPackageViewChildrenOnFiles.

@NotNull
public static Collection<AbstractTreeNode> createPackageViewChildrenOnFiles(@NotNull List<VirtualFile> sourceRoots, @NotNull Project project, @NotNull ViewSettings settings, @Nullable Module module, final boolean inLibrary) {
    final PsiManager psiManager = PsiManager.getInstance(project);
    final List<AbstractTreeNode> children = new ArrayList<>();
    final Set<PsiPackage> topLevelPackages = new HashSet<>();
    for (final VirtualFile root : sourceRoots) {
        final PsiDirectory directory = psiManager.findDirectory(root);
        if (directory == null) {
            continue;
        }
        final PsiPackage directoryPackage = JavaDirectoryService.getInstance().getPackage(directory);
        if (directoryPackage == null || isPackageDefault(directoryPackage)) {
            // add subpackages
            final PsiDirectory[] subdirectories = directory.getSubdirectories();
            for (PsiDirectory subdirectory : subdirectories) {
                final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(subdirectory);
                if (aPackage != null && !isPackageDefault(aPackage)) {
                    topLevelPackages.add(aPackage);
                }
            }
            // add non-dir items
            children.addAll(ProjectViewDirectoryHelper.getInstance(project).getDirectoryChildren(directory, settings, false));
        } else {
            topLevelPackages.add(directoryPackage);
        }
    }
    for (final PsiPackage topLevelPackage : topLevelPackages) {
        addPackageAsChild(children, topLevelPackage, module, settings, inLibrary);
    }
    return children;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) 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