1 package com
.intellij
.openapi
.roots
.ui
.configuration
.packaging
;
3 import com
.intellij
.openapi
.module
.Module
;
4 import com
.intellij
.openapi
.project
.ProjectBundle
;
5 import com
.intellij
.openapi
.roots
.*;
6 import com
.intellij
.openapi
.roots
.impl
.OrderEntryUtil
;
7 import com
.intellij
.openapi
.roots
.impl
.libraries
.LibraryImpl
;
8 import com
.intellij
.openapi
.roots
.libraries
.Library
;
9 import com
.intellij
.openapi
.roots
.libraries
.LibraryTable
;
10 import com
.intellij
.openapi
.roots
.ui
.util
.OrderEntryCellAppearanceUtils
;
11 import com
.intellij
.openapi
.vfs
.VirtualFile
;
12 import com
.intellij
.ui
.ColoredTreeCellRenderer
;
13 import com
.intellij
.ui
.SimpleTextAttributes
;
14 import com
.intellij
.util
.Icons
;
15 import com
.intellij
.packaging
.impl
.ui
.LibraryElementPresentation
;
16 import org
.jetbrains
.annotations
.NotNull
;
18 import java
.util
.List
;
19 import java
.util
.ArrayList
;
20 import java
.util
.Collection
;
25 public class PackagingEditorUtil
{
26 private PackagingEditorUtil() {
29 public static void renderLibraryNode(final ColoredTreeCellRenderer renderer
, final Library library
,
30 final SimpleTextAttributes mainAttributes
, final SimpleTextAttributes commentAttributes
) {
31 String name
= library
.getName();
33 renderer
.setIcon(Icons
.LIBRARY_ICON
);
34 renderer
.append(name
, mainAttributes
);
35 renderer
.append(LibraryElementPresentation
.getLibraryTableComment(library
), commentAttributes
);
38 VirtualFile
[] files
= library
.getFiles(OrderRootType
.CLASSES
);
39 if (files
.length
> 0) {
40 VirtualFile file
= files
[0];
41 renderer
.setIcon(file
.getIcon());
42 renderer
.append(file
.getName(), mainAttributes
);
43 renderer
.append(LibraryElementPresentation
.getLibraryTableComment(library
), commentAttributes
);
46 OrderEntryCellAppearanceUtils
.forLibrary(library
).customize(renderer
);
51 public static void renderLibraryFile(final ColoredTreeCellRenderer renderer
, final Library library
, final VirtualFile file
,
52 final SimpleTextAttributes mainAttributes
, final SimpleTextAttributes commentAttributes
) {
53 renderer
.setIcon(file
.getIcon());
54 renderer
.append(file
.getName(), mainAttributes
);
55 String name
= library
.getName();
56 LibraryTable table
= library
.getTable();
58 StringBuilder comment
= new StringBuilder();
59 comment
.append(" ('").append(name
).append("' ");
60 comment
.append(LibraryElementPresentation
.getLibraryTableDisplayName(library
));
62 renderer
.append(comment
.toString(), commentAttributes
);
64 else if (table
== null) {
65 Module module
= ((LibraryImpl
)library
).getModule();
68 comment
= " (" + LibraryElementPresentation
.getLibraryTableDisplayName(library
) + ")";
71 comment
= " " + ProjectBundle
.message("node.text.library.of.module", module
.getName());
73 renderer
.append(comment
, commentAttributes
);
77 public static String
getLibraryDescription(final @NotNull Library library
) {
78 String name
= library
.getName();
79 VirtualFile
[] files
= library
.getFiles(OrderRootType
.CLASSES
);
81 return "'" + name
+ "' " + LibraryElementPresentation
.getLibraryTableDisplayName(library
);
83 else if (files
.length
> 0) {
84 Module module
= ((LibraryImpl
)library
).getModule();
85 final String description
;
87 description
= "(" + LibraryElementPresentation
.getLibraryTableDisplayName(library
) + ")";
90 description
= ProjectBundle
.message("node.text.library.of.module", module
.getName());
92 return files
[0].getName() + " " + description
;
95 return ProjectBundle
.message("library.empty.item");
99 public static String
getLibraryItemText(final @NotNull Library library
, final boolean includeTableName
) {
100 String name
= library
.getName();
101 VirtualFile
[] files
= library
.getFiles(OrderRootType
.CLASSES
);
103 return name
+ (includeTableName ? LibraryElementPresentation
.getLibraryTableComment(library
) : "");
105 else if (files
.length
> 0) {
106 return files
[0].getName() + (includeTableName ? LibraryElementPresentation
.getLibraryTableComment(library
) : "");
109 return ProjectBundle
.message("library.empty.item");
113 public static List
<Module
> getModulesFromDependentOrderEntries(final @NotNull ModuleRootModel rootModel
) {
114 List
<Module
> moduleList
= new ArrayList
<Module
>();
115 Collection
<OrderEntry
> orderEntries
= OrderEntryUtil
.getDependentOrderEntries(rootModel
);
116 for (OrderEntry orderEntry
: orderEntries
) {
117 if (orderEntry
instanceof ModuleOrderEntry
) {
118 Module module
= ((ModuleOrderEntry
)orderEntry
).getModule();
119 if (module
!= null) {
120 moduleList
.add(module
);
128 public static List
<Library
> getLibrariesFromDependentOrderEntries(final @NotNull ModuleRootModel rootModel
) {
129 List
<Library
> libraries
= new ArrayList
<Library
>();
130 for (OrderEntry orderEntry
: OrderEntryUtil
.getDependentOrderEntries(rootModel
)) {
131 if (orderEntry
instanceof LibraryOrderEntry
) {
132 Library library
= ((LibraryOrderEntry
)orderEntry
).getLibrary();
133 if (library
!= null) {
134 libraries
.add(library
);