Search in sources :

Example 1 with NamedLibraryElementNode

use of com.intellij.ide.projectView.impl.nodes.NamedLibraryElementNode in project android by JetBrains.

the class AndroidTreeStructureProvider method modify.

@Override
@NotNull
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
    Project project = parent.getProject();
    if (project != null && AndroidProjectInfo.getInstance(project).requiresAndroidModel()) {
        if (parent instanceof NamedLibraryElementNode) {
            NamedLibraryElement value = ((NamedLibraryElementNode) parent).getValue();
            LibraryOrSdkOrderEntry orderEntry = value.getOrderEntry();
            if (orderEntry instanceof JdkOrderEntry) {
                Sdk sdk = ((JdkOrderEntry) orderEntry).getJdk();
                if (sdk.getSdkType() instanceof JavaSdk) {
                    List<AbstractTreeNode> newChildren = Lists.newArrayList();
                    for (AbstractTreeNode child : children) {
                        if (isRtJar(child)) {
                            newChildren.add(child);
                        }
                    }
                    if (!newChildren.isEmpty()) {
                        myEventDispatcher.getMulticaster().nodeChanged(parent, newChildren);
                        return newChildren;
                    }
                }
            }
        } else if (isRtJar(parent)) {
            List<AbstractTreeNode> newChildren = Lists.newArrayList();
            for (AbstractTreeNode child : children) {
                if (child instanceof PsiDirectoryNode) {
                    VirtualFile file = ((PsiDirectoryNode) child).getVirtualFile();
                    if (file != null && ("java".equals(file.getName()) || "javax".equals(file.getName()))) {
                        newChildren.add(child);
                    }
                }
            }
            if (!newChildren.isEmpty()) {
                myEventDispatcher.getMulticaster().nodeChanged(parent, newChildren);
                return newChildren;
            }
        }
    }
    return children;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) NamedLibraryElement(com.intellij.ide.projectView.impl.nodes.NamedLibraryElement) JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) LibraryOrSdkOrderEntry(com.intellij.openapi.roots.LibraryOrSdkOrderEntry) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) List(java.util.List) PsiDirectoryNode(com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) NamedLibraryElementNode(com.intellij.ide.projectView.impl.nodes.NamedLibraryElementNode) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with NamedLibraryElementNode

use of com.intellij.ide.projectView.impl.nodes.NamedLibraryElementNode 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 3 with NamedLibraryElementNode

use of com.intellij.ide.projectView.impl.nodes.NamedLibraryElementNode 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 4 with NamedLibraryElementNode

use of com.intellij.ide.projectView.impl.nodes.NamedLibraryElementNode in project intellij-community by JetBrains.

the class PyTreeStructureProvider method getPythonSdk.

@Nullable
private static Sdk getPythonSdk(@NotNull AbstractTreeNode node) {
    if (node instanceof NamedLibraryElementNode) {
        final NamedLibraryElement value = ((NamedLibraryElementNode) node).getValue();
        if (value != null) {
            final LibraryOrSdkOrderEntry entry = value.getOrderEntry();
            if (entry instanceof JdkOrderEntry) {
                final Sdk sdk = ((JdkOrderEntry) entry).getJdk();
                final SdkTypeId type = sdk.getSdkType();
                if (type instanceof PythonSdkType) {
                    return sdk;
                }
            }
        }
    }
    return null;
}
Also used : NamedLibraryElement(com.intellij.ide.projectView.impl.nodes.NamedLibraryElement) JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) LibraryOrSdkOrderEntry(com.intellij.openapi.roots.LibraryOrSdkOrderEntry) Sdk(com.intellij.openapi.projectRoots.Sdk) SdkTypeId(com.intellij.openapi.projectRoots.SdkTypeId) PythonSdkType(com.jetbrains.python.sdk.PythonSdkType) NamedLibraryElementNode(com.intellij.ide.projectView.impl.nodes.NamedLibraryElementNode) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

NamedLibraryElementNode (com.intellij.ide.projectView.impl.nodes.NamedLibraryElementNode)4 NamedLibraryElement (com.intellij.ide.projectView.impl.nodes.NamedLibraryElement)3 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)3 Sdk (com.intellij.openapi.projectRoots.Sdk)3 NotNull (org.jetbrains.annotations.NotNull)3 ExternalLibrariesNode (com.intellij.ide.projectView.impl.nodes.ExternalLibrariesNode)2 PsiDirectoryNode (com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)2 Project (com.intellij.openapi.project.Project)2 JdkOrderEntry (com.intellij.openapi.roots.JdkOrderEntry)2 LibraryOrSdkOrderEntry (com.intellij.openapi.roots.LibraryOrSdkOrderEntry)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 ArrayList (java.util.ArrayList)2 FlexCompositeSdk (com.intellij.lang.javascript.flex.projectStructure.FlexCompositeSdk)1 JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)1 SdkTypeId (com.intellij.openapi.projectRoots.SdkTypeId)1 HashSet (com.intellij.util.containers.hash.HashSet)1 DartUrlResolver (com.jetbrains.lang.dart.util.DartUrlResolver)1 PythonSdkType (com.jetbrains.python.sdk.PythonSdkType)1 List (java.util.List)1 Nullable (org.jetbrains.annotations.Nullable)1