Search in sources :

Example 1 with LibraryOrSdkOrderEntry

use of com.intellij.openapi.roots.LibraryOrSdkOrderEntry 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 LibraryOrSdkOrderEntry

use of com.intellij.openapi.roots.LibraryOrSdkOrderEntry 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

NamedLibraryElement (com.intellij.ide.projectView.impl.nodes.NamedLibraryElement)2 NamedLibraryElementNode (com.intellij.ide.projectView.impl.nodes.NamedLibraryElementNode)2 Sdk (com.intellij.openapi.projectRoots.Sdk)2 JdkOrderEntry (com.intellij.openapi.roots.JdkOrderEntry)2 LibraryOrSdkOrderEntry (com.intellij.openapi.roots.LibraryOrSdkOrderEntry)2 PsiDirectoryNode (com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)1 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)1 Project (com.intellij.openapi.project.Project)1 JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)1 SdkTypeId (com.intellij.openapi.projectRoots.SdkTypeId)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PythonSdkType (com.jetbrains.python.sdk.PythonSdkType)1 List (java.util.List)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1