1 package com
.intellij
.openapi
.roots
.ui
.configuration
.packaging
;
3 import com
.intellij
.openapi
.deployment
.LibraryLink
;
4 import com
.intellij
.openapi
.module
.Module
;
5 import com
.intellij
.openapi
.roots
.OrderRootType
;
6 import com
.intellij
.openapi
.roots
.impl
.libraries
.LibraryImpl
;
7 import com
.intellij
.openapi
.roots
.libraries
.Library
;
8 import com
.intellij
.openapi
.roots
.libraries
.LibraryTable
;
9 import com
.intellij
.openapi
.roots
.ui
.util
.CellAppearanceUtils
;
10 import com
.intellij
.openapi
.vfs
.VirtualFile
;
11 import com
.intellij
.ui
.ColoredTreeCellRenderer
;
12 import com
.intellij
.ui
.SimpleTextAttributes
;
13 import com
.intellij
.util
.Icons
;
14 import org
.jetbrains
.annotations
.NotNull
;
19 class LibraryNode
extends LibraryNodeBase
{
20 LibraryNode(final LibraryLink libraryLink
, PackagingArtifact owner
) {
21 super(owner
, libraryLink
);
25 public String
getOutputFileName() {
26 return myLibraryLink
.getPresentableName();
29 public double getWeight() {
30 return PackagingNodeWeights
.LIBRARY
;
34 public String
getSearchName() {
35 Library library
= myLibraryLink
.getLibrary();
36 if (library
== null) {
37 return myLibraryLink
.getPresentableName();
39 String name
= library
.getName();
43 VirtualFile
[] files
= library
.getFiles(OrderRootType
.CLASSES
);
44 if (files
.length
> 0) {
45 return files
[0].getName();
47 return super.getSearchName();
51 public int compareTo(final PackagingTreeNode node
) {
52 return getSearchName().compareToIgnoreCase(node
.getSearchName());
55 public void render(final ColoredTreeCellRenderer renderer
) {
56 Library library
= myLibraryLink
.getLibrary();
57 if (library
== null) {
58 String libraryName
= myLibraryLink
.getPresentableName();
59 renderer
.append(libraryName
, SimpleTextAttributes
.ERROR_ATTRIBUTES
);
62 String name
= library
.getName();
64 renderer
.setIcon(Icons
.LIBRARY_ICON
);
65 renderer
.append(name
, getMainAttributes());
66 renderer
.append(getLibraryTableComment(library
), getCommentAttributes());
69 VirtualFile
[] files
= library
.getFiles(OrderRootType
.CLASSES
);
70 if (files
.length
> 0) {
71 VirtualFile file
= files
[0];
72 renderer
.setIcon(file
.getIcon());
73 renderer
.append(file
.getName(), getMainAttributes());
74 renderer
.append(getLibraryTableComment(library
), getCommentAttributes());
77 CellAppearanceUtils
.forLibrary(library
).customize(renderer
);
84 private static String
getLibraryTableComment(final Library library
) {
85 LibraryTable libraryTable
= library
.getTable();
87 if (libraryTable
!= null) {
88 displayName
= libraryTable
.getPresentation().getDisplayName(false);
91 Module module
= ((LibraryImpl
)library
).getModule();
92 String tableName
= PackagingEditorUtil
.getLibraryTableDisplayName(library
);
93 displayName
= module
!= null ?
"'" + module
.getName() + "' " + tableName
: tableName
;
95 return " (" + displayName
+ ")";
98 public boolean canNavigate() {