packaging editor test
[fedora-idea.git] / source / com / intellij / openapi / roots / ui / configuration / packaging / LibraryNode.java
blob7cb659ce56fcc723a4e52285a1528c9235defa5e
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;
16 /**
17 * @author nik
19 class LibraryNode extends LibraryNodeBase {
20 LibraryNode(final LibraryLink libraryLink, PackagingArtifact owner) {
21 super(owner, libraryLink);
24 @NotNull
25 public String getOutputFileName() {
26 return myLibraryLink.getPresentableName();
29 public double getWeight() {
30 return PackagingNodeWeights.LIBRARY;
33 @Override
34 public String getSearchName() {
35 Library library = myLibraryLink.getLibrary();
36 if (library == null) {
37 return myLibraryLink.getPresentableName();
39 String name = library.getName();
40 if (name != null) {
41 return name;
43 VirtualFile[] files = library.getFiles(OrderRootType.CLASSES);
44 if (files.length > 0) {
45 return files[0].getName();
47 return super.getSearchName();
50 @Override
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);
61 else {
62 String name = library.getName();
63 if (name != null) {
64 renderer.setIcon(Icons.LIBRARY_ICON);
65 renderer.append(name, getMainAttributes());
66 renderer.append(getLibraryTableComment(library), getCommentAttributes());
68 else {
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());
76 else {
77 CellAppearanceUtils.forLibrary(library).customize(renderer);
84 private static String getLibraryTableComment(final Library library) {
85 LibraryTable libraryTable = library.getTable();
86 String displayName;
87 if (libraryTable != null) {
88 displayName = libraryTable.getPresentation().getDisplayName(false);
90 else {
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() {
99 return true;