2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com
.intellij
.ide
.util
;
19 import com
.intellij
.openapi
.module
.Module
;
20 import com
.intellij
.openapi
.module
.ModuleUtil
;
21 import com
.intellij
.openapi
.roots
.*;
22 import com
.intellij
.openapi
.util
.IconLoader
;
23 import com
.intellij
.openapi
.vfs
.VirtualFile
;
24 import com
.intellij
.psi
.PsiElement
;
25 import com
.intellij
.psi
.PsiFile
;
26 import com
.intellij
.util
.ui
.UIUtil
;
31 public class PsiElementModuleRenderer
extends DefaultListCellRenderer
{
32 private static final Icon TEST_ICON
= IconLoader
.getIcon("/nodes/testSourceFolder.png");
33 private static final Icon LIB_ICON
= IconLoader
.getIcon("/nodes/ppLibClosed.png");
35 private String myText
;
37 public Component
getListCellRendererComponent(
42 boolean cellHasFocus
) {
43 final Component listCellRendererComponent
= super.getListCellRendererComponent(list
, value
, index
, isSelected
,
45 customizeCellRenderer(value
, index
, isSelected
, cellHasFocus
);
46 return listCellRendererComponent
;
49 public String
getText() {
53 protected void customizeCellRenderer(
59 if (value
instanceof PsiElement
) {
60 PsiElement element
= (PsiElement
)value
;
61 if (element
.isValid()) {
62 PsiFile psiFile
= element
.getContainingFile();
63 Module module
= ModuleUtil
.findModuleForPsiElement(element
);
64 final ProjectFileIndex fileIndex
= ProjectRootManager
.getInstance(element
.getProject()).getFileIndex();
66 boolean inTestSource
= false;
67 if (psiFile
!= null) {
68 VirtualFile vFile
= psiFile
.getVirtualFile();
70 inTestSource
= fileIndex
.isInTestSourceContent(vFile
);
73 myText
= module
.getName();
78 setIcon(module
.getModuleType().getNodeIcon(false));
81 if (psiFile
!= null) {
82 VirtualFile vFile
= psiFile
.getVirtualFile();
84 final boolean isInLibraries
= fileIndex
.isInLibrarySource(vFile
) || fileIndex
.isInLibraryClasses(vFile
);
87 for (OrderEntry order
: fileIndex
.getOrderEntriesForFile(vFile
)) {
88 if (order
instanceof LibraryOrderEntry
|| order
instanceof JdkOrderEntry
) {
89 myText
= order
.getPresentableName();
94 setIcon(IconUtilEx.getEmptyIcon(false));
95 setText(value.toString());
106 setIcon(IconUtilEx.getEmptyIcon(false));
107 setText(value == null ? "" : value.toString());
110 setBorder(BorderFactory
.createEmptyBorder(0, 0, 0, 2));
111 setHorizontalTextPosition(SwingConstants
.LEFT
);
112 setBackground(selected ? UIUtil
.getListSelectionBackground() : UIUtil
.getListBackground());
113 setForeground(selected ? UIUtil
.getListSelectionForeground() : UIUtil
.getInactiveTextColor());