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.
18 * Created by IntelliJ IDEA.
23 package com
.intellij
.openapi
.roots
.ui
.configuration
;
25 import com
.intellij
.openapi
.module
.Module
;
26 import com
.intellij
.openapi
.roots
.LibraryOrderEntry
;
27 import com
.intellij
.openapi
.roots
.ModifiableRootModel
;
28 import com
.intellij
.openapi
.roots
.OrderEntry
;
29 import com
.intellij
.openapi
.roots
.libraries
.Library
;
30 import com
.intellij
.openapi
.util
.Comparing
;
31 import com
.intellij
.ui
.BooleanTableCellRenderer
;
32 import com
.intellij
.ui
.OrderPanel
;
35 import javax
.swing
.table
.DefaultTableCellRenderer
;
41 public class LibraryDependantsPanel
extends OrderPanel
<ModifiableRootModel
> {
42 private final Library myLibrary
;
44 public LibraryDependantsPanel(final Library library
) {
45 super(ModifiableRootModel
.class, true);
47 getEntryTable().setDefaultRenderer(ModifiableRootModel
.class, new DefaultTableCellRenderer(){
48 public Component
getTableCellRendererComponent(JTable table
, Object value
, boolean isSelected
, boolean hasFocus
, int row
, int column
) {
49 final Component cellRendererComponent
= super.getTableCellRendererComponent(table
, value
, isSelected
, hasFocus
, row
, column
);
50 if (value
instanceof ModifiableRootModel
){
51 final ModifiableRootModel model
= (ModifiableRootModel
)value
;
52 final Module module
= model
.getModule();
53 setText(module
.getName());
54 setIcon(module
.getModuleType().getNodeIcon(false));
56 return cellRendererComponent
;
59 getEntryTable().setDefaultRenderer(Boolean
.class, new BooleanTableCellRenderer());
61 setBorder(BorderFactory
.createTitledBorder("Used In"));
65 public boolean isCheckable(final ModifiableRootModel entry
) {
69 public boolean isChecked(final ModifiableRootModel model
) {
70 final OrderEntry
[] entries
= model
.getOrderEntries();
71 for (OrderEntry entry
: entries
) {
72 if (entry
instanceof LibraryOrderEntry
) {
73 final LibraryOrderEntry libraryOrderEntry
= (LibraryOrderEntry
)entry
;
74 if (Comparing
.equal(libraryOrderEntry
.getLibrary(), myLibrary
)) {
82 public void setChecked(final ModifiableRootModel model
, final boolean checked
) {
84 model
.addLibraryEntry(myLibrary
);
87 final OrderEntry
[] entries
= model
.getOrderEntries();
88 for (OrderEntry entry
: entries
) {
89 if (entry
instanceof LibraryOrderEntry
) {
90 final LibraryOrderEntry libraryOrderEntry
= (LibraryOrderEntry
)entry
;
91 if (Comparing
.equal(libraryOrderEntry
.getLibrary(), myLibrary
)) {
92 model
.removeOrderEntry(libraryOrderEntry
);