Search in sources :

Example 81 with AbstractTreeNode

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

the class NativeAndroidSourceDirectoryNode method getChildrenImpl.

@Override
public Collection<AbstractTreeNode> getChildrenImpl() {
    PsiDirectory psiDirectory = getValue();
    if (psiDirectory == null) {
        return ImmutableList.of();
    }
    Collection<AbstractTreeNode> directoryChildren = ProjectViewDirectoryHelper.getInstance(myProject).getDirectoryChildren(psiDirectory, getSettings(), true);
    List<AbstractTreeNode> result = Lists.newArrayList();
    for (AbstractTreeNode child : directoryChildren) {
        Object value = child.getValue();
        if (value instanceof PsiFile) {
            VirtualFile file = ((PsiFile) value).getVirtualFile();
            if ((mySourceFolders.contains(psiDirectory.getVirtualFile()) && myFileExtensions.contains(file.getExtension())) || mySourceFiles.contains(file)) {
                result.add(child);
            }
        } else if (value instanceof PsiDirectory) {
            VirtualFile dir = ((PsiDirectory) value).getVirtualFile();
            if (mySourceFolders.contains(dir) || mySourceFolders.contains(psiDirectory.getVirtualFile())) {
                result.add(new NativeAndroidSourceDirectoryNode(myProject, (PsiDirectory) value, getSettings(), myFileExtensions, ImmutableList.of(dir), ImmutableList.of()));
                continue;
            }
            List<VirtualFile> childDirs = Lists.newArrayList();
            for (VirtualFile sourceFolder : mySourceFolders) {
                if (VfsUtilCore.isAncestor(dir, sourceFolder, true)) {
                    childDirs.add(sourceFolder);
                }
            }
            List<VirtualFile> childFiles = Lists.newArrayList();
            for (VirtualFile file : mySourceFiles) {
                if (VfsUtilCore.isAncestor(dir, file, true)) {
                    childFiles.add(file);
                }
            }
            if (!childDirs.isEmpty() || !childFiles.isEmpty()) {
                result.add(new NativeAndroidSourceDirectoryNode(myProject, (PsiDirectory) value, getSettings(), myFileExtensions, childDirs, childFiles));
            }
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDirectory(com.intellij.psi.PsiDirectory) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiFile(com.intellij.psi.PsiFile) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList)

Example 82 with AbstractTreeNode

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

the class NdkModuleNode method getNativeSourceNodes.

@NotNull
public static Collection<AbstractTreeNode> getNativeSourceNodes(@NotNull Project project, @NotNull NdkModuleModel ndkModuleModel, @NotNull ViewSettings viewSettings) {
    NativeAndroidProject nativeAndroidProject = ndkModuleModel.getAndroidProject();
    Collection<String> sourceFileExtensions = nativeAndroidProject.getFileExtensions().keySet();
    NdkModuleModel.NdkVariant variant = ndkModuleModel.getSelectedVariant();
    Multimap<String, NativeArtifact> nativeLibraries = HashMultimap.create();
    for (NativeArtifact artifact : variant.getArtifacts()) {
        String artifactOutputFileName = artifact.getOutputFile().getName();
        nativeLibraries.put(artifactOutputFileName, artifact);
    }
    if (nativeLibraries.keySet().size() == 1) {
        return getSourceDirectoryNodes(project, nativeLibraries.values(), viewSettings, sourceFileExtensions);
    }
    List<AbstractTreeNode> children = Lists.newArrayList();
    for (String name : nativeLibraries.keySet()) {
        String nativeLibraryType = "";
        String nativeLibraryName = trimEnd(name, ".so");
        if (nativeLibraryName.length() < name.length()) {
            nativeLibraryType = "Shared Library";
        } else {
            nativeLibraryName = trimEnd(name, ".a");
            if (nativeLibraryName.length() < name.length()) {
                nativeLibraryType = "Static Library";
            }
        }
        nativeLibraryName = trimStart(nativeLibraryName, "lib");
        children.add(new NativeAndroidLibraryNode(project, nativeLibraryName, nativeLibraryType, nativeLibraries.get(name), viewSettings, sourceFileExtensions));
    }
    return children;
}
Also used : NativeAndroidProject(com.android.builder.model.NativeAndroidProject) NativeArtifact(com.android.builder.model.NativeArtifact) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) NdkModuleModel(com.android.tools.idea.gradle.project.model.NdkModuleModel) NotNull(org.jetbrains.annotations.NotNull)

Example 83 with AbstractTreeNode

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

the class DartTreeStructureProvider method modify.

@NotNull
public Collection<AbstractTreeNode> modify(@NotNull final AbstractTreeNode parentNode, @NotNull final Collection<AbstractTreeNode> children, final ViewSettings settings) {
    if (parentNode instanceof ExternalLibrariesNode) {
        return ContainerUtil.map(children, node -> {
            if (node instanceof NamedLibraryElementNode && (DartPackagesLibraryType.DART_PACKAGES_LIBRARY_NAME.equals(node.getName()) || DartSdk.DART_SDK_LIB_NAME.equals(node.getName()))) {
                final boolean isSdkRoot = DartSdk.DART_SDK_LIB_NAME.equals(node.getName());
                return new NamedLibraryElementNode(node.getProject(), ((NamedLibraryElementNode) node).getValue(), settings) {

                    @Override
                    public boolean canNavigate() {
                        return isSdkRoot;
                    }

                    @Override
                    public void navigate(boolean requestFocus) {
                        final Project project = getProject();
                        if (project != null) {
                            DartConfigurable.openDartSettings(project);
                        }
                    }
                };
            }
            return node;
        });
    }
    if (parentNode instanceof NamedLibraryElementNode && (DartPackagesLibraryType.DART_PACKAGES_LIBRARY_NAME.equals(parentNode.getName()) || DartSdk.DART_SDK_LIB_NAME.equals(parentNode.getName()))) {
        final boolean isSdkRoot = DartSdk.DART_SDK_LIB_NAME.equals(parentNode.getName());
        return ContainerUtil.map(children, node -> {
            final VirtualFile dir = node instanceof PsiDirectoryNode ? ((PsiDirectoryNode) node).getVirtualFile() : null;
            if (dir != null && dir.isInLocalFileSystem() && dir.isDirectory() && (isSdkRoot || "lib".equals(dir.getName()))) {
                return new DartSdkOrLibraryRootNode(node.getProject(), ((PsiDirectoryNode) node).getValue(), settings);
            }
            return node;
        });
    }
    // root/packages/ThisProject and root/packages/PathPackage folders are excluded in dart projects (see DartProjectComponent.excludeBuildAndPackagesFolders),
    // this provider adds location string tho these nodes in Project View like "ThisProject (ThisProject/lib)"
    final Project project = parentNode.getProject();
    final VirtualFile packagesDir = parentNode instanceof PsiDirectoryNode && project != null ? ((PsiDirectoryNode) parentNode).getVirtualFile() : null;
    final VirtualFile parentFolder = packagesDir != null && packagesDir.isDirectory() && PACKAGES_FOLDER_NAME.equals(packagesDir.getName()) ? packagesDir.getParent() : null;
    final VirtualFile pubspecYamlFile = parentFolder != null ? parentFolder.findChild(PUBSPEC_YAML) : null;
    if (pubspecYamlFile != null && !pubspecYamlFile.isDirectory()) {
        final ArrayList<AbstractTreeNode> modifiedChildren = new ArrayList<>(children);
        final DartUrlResolver resolver = DartUrlResolver.getInstance(project, pubspecYamlFile);
        resolver.processLivePackages((packageName, packageDir) -> {
            final VirtualFile folder = packagesDir.findChild(packageName);
            if (folder != null) {
                final AbstractTreeNode node = getFolderNode(children, folder);
                if (node == null) {
                    modifiedChildren.add(new SymlinkToLivePackageNode(project, packageName, packageDir));
                } else {
                    node.getPresentation().setLocationString(getPackageLocationString(packageDir));
                }
            }
        });
        return modifiedChildren;
    }
    return children;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ExternalLibrariesNode(com.intellij.ide.projectView.impl.nodes.ExternalLibrariesNode) ArrayList(java.util.ArrayList) DartUrlResolver(com.jetbrains.lang.dart.util.DartUrlResolver) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiDirectoryNode(com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode) NamedLibraryElementNode(com.intellij.ide.projectView.impl.nodes.NamedLibraryElementNode) NotNull(org.jetbrains.annotations.NotNull)

Example 84 with AbstractTreeNode

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

the class FlexCompositeSdkProjectViewStructureProvider method modify.

@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull final AbstractTreeNode parent, @NotNull final Collection<AbstractTreeNode> children, final ViewSettings settings) {
    if (!(parent instanceof ExternalLibrariesNode)) {
        return children;
    }
    Set<Sdk> processedSdks = new HashSet<>();
    Collection<AbstractTreeNode> result = new ArrayList<>();
    for (AbstractTreeNode child : children) {
        Object value = child.getValue();
        if (!(value instanceof NamedLibraryElement)) {
            result.add(child);
            continue;
        }
        NamedLibraryElement libraryElement = (NamedLibraryElement) value;
        OrderEntry orderEntry = libraryElement.getOrderEntry();
        if (!(orderEntry instanceof JdkOrderEntry)) {
            result.add(child);
            continue;
        }
        Sdk sdk = ((JdkOrderEntry) orderEntry).getJdk();
        if (!(sdk instanceof FlexCompositeSdk)) {
            result.add(child);
            continue;
        }
        Sdk[] sdks = ((FlexCompositeSdk) sdk).getSdks();
        for (Sdk individualSdk : sdks) {
            if (processedSdks.add(individualSdk)) {
                IndividualSdkOrderEntry entry = new IndividualSdkOrderEntry(individualSdk, orderEntry.getOwnerModule());
                result.add(new NamedLibraryElementNode(parent.getProject(), new NamedLibraryElement(null, entry), ((ExternalLibrariesNode) parent).getSettings()));
            }
        }
    }
    return result;
}
Also used : FlexCompositeSdk(com.intellij.lang.javascript.flex.projectStructure.FlexCompositeSdk) ExternalLibrariesNode(com.intellij.ide.projectView.impl.nodes.ExternalLibrariesNode) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) NamedLibraryElement(com.intellij.ide.projectView.impl.nodes.NamedLibraryElement) FlexCompositeSdk(com.intellij.lang.javascript.flex.projectStructure.FlexCompositeSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) HashSet(com.intellij.util.containers.hash.HashSet) NamedLibraryElementNode(com.intellij.ide.projectView.impl.nodes.NamedLibraryElementNode) NotNull(org.jetbrains.annotations.NotNull)

Example 85 with AbstractTreeNode

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

the class SlicePanel method createTree.

@NotNull
private JTree createTree() {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    final Tree tree = new Tree(new DefaultTreeModel(root));
    tree.setOpaque(false);
    tree.setToggleClickCount(-1);
    SliceUsageCellRendererBase renderer = myProvider.getRenderer();
    renderer.setOpaque(false);
    tree.setCellRenderer(renderer);
    UIUtil.setLineStyleAngled(tree);
    tree.setRootVisible(false);
    tree.setShowsRootHandles(true);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setSelectionPath(new TreePath(root.getPath()));
    //ActionGroup group = (ActionGroup)ActionManager.getInstance().getAction(IdeActions.GROUP_METHOD_HIERARCHY_POPUP);
    //PopupHandler.installPopupHandler(tree, group, ActionPlaces.METHOD_HIERARCHY_VIEW_POPUP, ActionManager.getInstance());
    EditSourceOnDoubleClickHandler.install(tree);
    new TreeSpeedSearch(tree);
    TreeUtil.installActions(tree);
    ToolTipManager.sharedInstance().registerComponent(tree);
    myAutoScrollToSourceHandler.install(tree);
    tree.getSelectionModel().addTreeSelectionListener(e -> treeSelectionChanged());
    tree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (KeyEvent.VK_ENTER == e.getKeyCode()) {
                List<Navigatable> navigatables = getNavigatables();
                if (navigatables.isEmpty())
                    return;
                for (Navigatable navigatable : navigatables) {
                    if (navigatable instanceof AbstractTreeNode && ((AbstractTreeNode) navigatable).getValue() instanceof Usage) {
                        navigatable = (Usage) ((AbstractTreeNode) navigatable).getValue();
                    }
                    if (navigatable.canNavigateToSource()) {
                        navigatable.navigate(false);
                        if (navigatable instanceof Usage) {
                            ((Usage) navigatable).highlightInEditor();
                        }
                    }
                }
                e.consume();
            }
        }
    });
    tree.addTreeWillExpandListener(new TreeWillExpandListener() {

        @Override
        public void treeWillCollapse(TreeExpansionEvent event) {
        }

        @Override
        public void treeWillExpand(TreeExpansionEvent event) {
            TreePath path = event.getPath();
            SliceNode node = fromPath(path);
            node.calculateDupNode();
        }
    });
    return tree;
}
Also used : TreeWillExpandListener(javax.swing.event.TreeWillExpandListener) Usage(com.intellij.usages.Usage) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) KeyAdapter(java.awt.event.KeyAdapter) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) Navigatable(com.intellij.pom.Navigatable) KeyEvent(java.awt.event.KeyEvent) TreePath(javax.swing.tree.TreePath) Tree(com.intellij.ui.treeStructure.Tree) ArrayList(java.util.ArrayList) List(java.util.List) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)150 NotNull (org.jetbrains.annotations.NotNull)69 ArrayList (java.util.ArrayList)51 VirtualFile (com.intellij.openapi.vfs.VirtualFile)40 Project (com.intellij.openapi.project.Project)33 PsiFile (com.intellij.psi.PsiFile)30 Module (com.intellij.openapi.module.Module)27 PsiDirectory (com.intellij.psi.PsiDirectory)25 PsiElement (com.intellij.psi.PsiElement)16 Nullable (org.jetbrains.annotations.Nullable)15 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)14 ProjectViewNode (com.intellij.ide.projectView.ProjectViewNode)10 PsiDirectoryNode (com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)9 PsiManager (com.intellij.psi.PsiManager)9 List (java.util.List)9 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