1 package com
.intellij
.ide
.projectView
.impl
.nodes
;
3 import com
.intellij
.ide
.IdeBundle
;
4 import com
.intellij
.ide
.projectView
.PresentationData
;
5 import com
.intellij
.ide
.projectView
.ProjectViewNode
;
6 import com
.intellij
.ide
.projectView
.ViewSettings
;
7 import com
.intellij
.ide
.util
.treeView
.AbstractTreeNode
;
8 import com
.intellij
.openapi
.project
.Project
;
9 import com
.intellij
.openapi
.projectRoots
.Sdk
;
10 import com
.intellij
.openapi
.roots
.JdkOrderEntry
;
11 import com
.intellij
.openapi
.roots
.LibraryOrderEntry
;
12 import com
.intellij
.openapi
.roots
.OrderEntry
;
13 import com
.intellij
.openapi
.roots
.OrderRootType
;
14 import com
.intellij
.openapi
.roots
.ui
.configuration
.ProjectSettingsService
;
15 import com
.intellij
.openapi
.util
.IconLoader
;
16 import com
.intellij
.openapi
.util
.io
.FileUtil
;
17 import com
.intellij
.openapi
.util
.text
.StringUtil
;
18 import com
.intellij
.openapi
.vfs
.VfsUtil
;
19 import com
.intellij
.openapi
.vfs
.VirtualFile
;
20 import org
.jetbrains
.annotations
.NotNull
;
23 import java
.util
.ArrayList
;
24 import java
.util
.Collection
;
25 import java
.util
.List
;
27 public class NamedLibraryElementNode
extends ProjectViewNode
<NamedLibraryElement
>{
28 private static final Icon GENERIC_JDK_ICON
= IconLoader
.getIcon("/general/jdk.png");
29 private static final Icon LIB_ICON_OPEN
= IconLoader
.getIcon("/nodes/ppLibOpen.png");
30 private static final Icon LIB_ICON_CLOSED
= IconLoader
.getIcon("/nodes/ppLibClosed.png");
32 public NamedLibraryElementNode(Project project
, NamedLibraryElement value
, ViewSettings viewSettings
) {
33 super(project
, value
, viewSettings
);
36 public NamedLibraryElementNode(final Project project
, final Object value
, final ViewSettings viewSettings
) {
37 this(project
, (NamedLibraryElement
)value
, viewSettings
);
41 public Collection
<AbstractTreeNode
> getChildren() {
42 final List
<AbstractTreeNode
> children
= new ArrayList
<AbstractTreeNode
>();
43 LibraryGroupNode
.addLibraryChildren(getValue().getOrderEntry(), children
, getProject(), this);
47 public String
getTestPresentation() {
48 return "Library: " + getValue().getName();
51 private static Icon
getJdkIcon(JdkOrderEntry entry
, boolean isExpanded
) {
52 final Sdk jdk
= entry
.getJdk();
54 return GENERIC_JDK_ICON
;
56 return isExpanded? jdk
.getSdkType().getIconForExpandedTreeNode() : jdk
.getSdkType().getIcon();
59 public String
getName() {
60 return getValue().getName();
63 public boolean contains(@NotNull VirtualFile file
) {
64 return orderEntryContainsFile(getValue().getOrderEntry(), file
);
67 private static boolean orderEntryContainsFile(OrderEntry orderEntry
, VirtualFile file
) {
68 for(OrderRootType rootType
: OrderRootType
.getAllTypes()) {
69 if (containsFileInOrderType(orderEntry
, rootType
, file
)) return true;
74 private static boolean containsFileInOrderType(final OrderEntry orderEntry
, final OrderRootType orderType
, final VirtualFile file
) {
75 if (!orderEntry
.isValid()) return false;
76 VirtualFile
[] files
= orderEntry
.getFiles(orderType
);
77 for (VirtualFile virtualFile
: files
) {
78 boolean ancestor
= VfsUtil
.isAncestor(virtualFile
, file
, false);
79 if (ancestor
) return true;
84 public void update(PresentationData presentation
) {
85 presentation
.setPresentableText(getValue().getName());
86 final OrderEntry orderEntry
= getValue().getOrderEntry();
87 presentation
.setOpenIcon(orderEntry
instanceof JdkOrderEntry ?
getJdkIcon((JdkOrderEntry
)orderEntry
, true) : LIB_ICON_OPEN
);
88 presentation
.setClosedIcon(orderEntry
instanceof JdkOrderEntry ?
getJdkIcon((JdkOrderEntry
)orderEntry
, false) : LIB_ICON_CLOSED
);
89 if (orderEntry
instanceof JdkOrderEntry
) {
90 final JdkOrderEntry jdkOrderEntry
= (JdkOrderEntry
)orderEntry
;
91 final Sdk projectJdk
= jdkOrderEntry
.getJdk();
92 if (projectJdk
!= null) { //jdk not specified
93 presentation
.setLocationString(FileUtil
.toSystemDependentName(projectJdk
.getHomePath()));
98 protected String
getToolTip() {
99 OrderEntry orderEntry
= getValue().getOrderEntry();
100 return orderEntry
instanceof JdkOrderEntry ? IdeBundle
.message("node.projectview.jdk") : StringUtil
.capitalize(IdeBundle
.message("node.projectview.library", ((LibraryOrderEntry
)orderEntry
).getLibraryLevel()));
103 public void navigate(final boolean requestFocus
) {
104 ProjectSettingsService
.getInstance(myProject
).openProjectLibrarySettings(getValue());
107 public boolean canNavigate() {