2 * Copyright 2004-2005 Alexey Efimov
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.
16 package com.intellij.openapi.roots.ui.configuration.classpath;
18 import com.intellij.openapi.actionSystem.*;
19 import com.intellij.openapi.application.ApplicationManager;
20 import com.intellij.openapi.application.ex.ApplicationEx;
21 import com.intellij.openapi.diagnostic.Logger;
22 import com.intellij.openapi.module.Module;
23 import com.intellij.openapi.module.StdModuleTypes;
24 import com.intellij.openapi.project.Project;
25 import com.intellij.openapi.project.ProjectBundle;
26 import com.intellij.openapi.projectRoots.Sdk;
27 import com.intellij.openapi.roots.*;
28 import com.intellij.openapi.roots.libraries.Library;
29 import com.intellij.openapi.roots.libraries.LibraryTable;
30 import com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider;
31 import com.intellij.openapi.roots.ui.configuration.ModuleConfigurationState;
32 import com.intellij.openapi.roots.ui.configuration.ModulesProvider;
33 import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable;
34 import com.intellij.openapi.roots.ui.configuration.dependencyAnalysis.AnalyzeDependenciesDialog;
35 import com.intellij.openapi.roots.ui.configuration.libraryEditor.ChooseModulesDialog;
36 import com.intellij.openapi.roots.ui.configuration.libraryEditor.EditExistingLibraryDialog;
37 import com.intellij.openapi.roots.ui.configuration.projectRoot.FindUsagesInProjectStructureActionBase;
38 import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable;
39 import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
40 import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.LibraryProjectStructureElement;
41 import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ModuleProjectStructureElement;
42 import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement;
43 import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.SdkProjectStructureElement;
44 import com.intellij.openapi.roots.ui.util.CellAppearance;
45 import com.intellij.openapi.roots.ui.util.OrderEntryCellAppearanceUtils;
46 import com.intellij.openapi.ui.Messages;
47 import com.intellij.openapi.ui.popup.JBPopup;
48 import com.intellij.openapi.ui.popup.JBPopupFactory;
49 import com.intellij.openapi.ui.popup.PopupStep;
50 import com.intellij.openapi.ui.popup.util.BaseListPopupStep;
51 import com.intellij.openapi.wm.IdeFocusManager;
52 import com.intellij.ui.*;
53 import com.intellij.ui.awt.RelativePoint;
54 import com.intellij.util.EventDispatcher;
55 import com.intellij.util.ui.Table;
56 import org.jetbrains.annotations.NotNull;
59 import javax.swing.border.Border;
60 import javax.swing.event.ListSelectionEvent;
61 import javax.swing.event.ListSelectionListener;
62 import javax.swing.table.TableCellRenderer;
63 import javax.swing.table.TableColumn;
65 import java.awt.event.*;
66 import java.util.ArrayList;
67 import java.util.HashSet;
68 import java.util.List;
71 public class ClasspathPanelImpl extends JPanel implements ClasspathPanel {
72 private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.ui.configuration.classpath.ClasspathPanel");
74 private final Table myEntryTable;
75 private final ClasspathTableModel myModel;
76 private final EventDispatcher<OrderPanelListener> myListeners = EventDispatcher.create(OrderPanelListener.class);
77 private List<AddItemPopupAction<?>> myPopupActions = null;
78 private JButton myEditButton;
79 private final ModuleConfigurationState myState;
81 public ClasspathPanelImpl(ModuleConfigurationState state) {
82 super(new BorderLayout());
85 myModel = new ClasspathTableModel(state);
86 myEntryTable = new Table(myModel);
87 myEntryTable.setShowGrid(false);
88 myEntryTable.setDragEnabled(false);
89 myEntryTable.setShowHorizontalLines(false);
90 myEntryTable.setShowVerticalLines(false);
91 myEntryTable.setIntercellSpacing(new Dimension(0, 0));
93 myEntryTable.setDefaultRenderer(ClasspathTableItem.class, new TableItemRenderer());
94 myEntryTable.setDefaultRenderer(Boolean.class, new ExportFlagRenderer(myEntryTable.getDefaultRenderer(Boolean.class)));
96 JComboBox scopeEditor = new JComboBox(new EnumComboBoxModel<DependencyScope>(DependencyScope.class));
97 myEntryTable.setDefaultEditor(DependencyScope.class, new DefaultCellEditor(scopeEditor));
98 myEntryTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
100 new SpeedSearchBase<Table>(myEntryTable) {
101 public int getSelectedIndex() {
102 return myEntryTable.getSelectedRow();
106 protected int convertIndexToModel(int viewIndex) {
107 return myEntryTable.convertRowIndexToModel(viewIndex);
110 public Object[] getAllElements() {
111 final int count = myModel.getRowCount();
112 Object[] elements = new Object[count];
113 for (int idx = 0; idx < count; idx++) {
114 elements[idx] = myModel.getItemAt(idx);
119 public String getElementText(Object element) {
120 return getCellAppearance((ClasspathTableItem)element, false).getText();
123 public void selectElement(Object element, String selectedText) {
124 final int count = myModel.getRowCount();
125 for (int row = 0; row < count; row++) {
126 if (element.equals(myModel.getItemAt(row))) {
127 final int viewRow = myEntryTable.convertRowIndexToView(row);
128 myEntryTable.getSelectionModel().setSelectionInterval(viewRow, viewRow);
129 TableUtil.scrollSelectionToVisible(myEntryTable);
137 setFixedColumnWidth(ClasspathTableModel.EXPORT_COLUMN, ClasspathTableModel.EXPORT_COLUMN_NAME);
138 setFixedColumnWidth(ClasspathTableModel.SCOPE_COLUMN, DependencyScope.COMPILE.toString() + " "); // leave space for combobox border
140 myEntryTable.registerKeyboardAction(
141 new ActionListener() {
142 public void actionPerformed(ActionEvent e) {
143 final int[] selectedRows = myEntryTable.getSelectedRows();
144 boolean currentlyMarked = true;
145 for (final int selectedRow : selectedRows) {
146 final ClasspathTableItem item = myModel.getItemAt(myEntryTable.convertRowIndexToModel(selectedRow));
147 if (selectedRow < 0 || !item.isExportable()) {
150 currentlyMarked &= item.isExported();
152 for (final int selectedRow : selectedRows) {
153 myModel.getItemAt(myEntryTable.convertRowIndexToModel(selectedRow)).setExported(!currentlyMarked);
155 myModel.fireTableDataChanged();
156 TableUtil.selectRows(myEntryTable, selectedRows);
159 KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0),
163 add(ScrollPaneFactory.createScrollPane(myEntryTable), BorderLayout.CENTER);
164 add(createButtonsBlock(), BorderLayout.EAST);
166 if (myEntryTable.getRowCount() > 0) {
167 myEntryTable.getSelectionModel().setSelectionInterval(0,0);
170 myEntryTable.addMouseListener(new MouseAdapter() {
171 public void mouseClicked(MouseEvent e) {
172 if (e.getClickCount() == 2){
178 DefaultActionGroup actionGroup = new DefaultActionGroup();
179 final AnAction navigateAction = new AnAction(ProjectBundle.message("classpath.panel.navigate.action.text")) {
180 public void actionPerformed(AnActionEvent e) {
184 public void update(AnActionEvent e) {
185 final Presentation presentation = e.getPresentation();
186 presentation.setEnabled(false);
187 if (myEntryTable.getSelectedRowCount() != 1) return;
188 final OrderEntry entry = myModel.getItemAt(myEntryTable.getSelectedRow()).getEntry();
189 if (entry != null && entry.isValid()){
190 if (!(entry instanceof ModuleSourceOrderEntry)){
191 presentation.setEnabled(true);
196 navigateAction.registerCustomShortcutSet(ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_SOURCE).getShortcutSet(), myEntryTable);
197 actionGroup.add(navigateAction);
198 actionGroup.add(new MyFindUsagesAction());
199 PopupHandler.installPopupHandler(myEntryTable, actionGroup, ActionPlaces.UNKNOWN, ActionManager.getInstance());
202 private void setFixedColumnWidth(final int columnIndex, final String textToMeasure) {
203 final FontMetrics fontMetrics = myEntryTable.getFontMetrics(myEntryTable.getFont());
204 final int width = fontMetrics.stringWidth(" " + textToMeasure + " ") + 4;
205 final TableColumn checkboxColumn = myEntryTable.getTableHeader().getColumnModel().getColumn(columnIndex);
206 checkboxColumn.setWidth(width);
207 checkboxColumn.setPreferredWidth(width);
208 checkboxColumn.setMaxWidth(width);
209 checkboxColumn.setMinWidth(width);
212 private void navigate(boolean openLibraryEditor) {
213 final int selectedRow = myEntryTable.getSelectedRow();
214 final OrderEntry entry = myModel.getItemAt(selectedRow).getEntry();
215 final ProjectStructureConfigurable rootConfigurable = ProjectStructureConfigurable.getInstance(myState.getProject());
216 if (entry instanceof ModuleOrderEntry){
217 Module module = ((ModuleOrderEntry)entry).getModule();
218 if (module != null) {
219 rootConfigurable.select(module.getName(), null, true);
222 else if (entry instanceof LibraryOrderEntry){
223 if (!openLibraryEditor) {
224 rootConfigurable.select((LibraryOrderEntry)entry, true);
227 myEditButton.doClick();
230 else if (entry instanceof JdkOrderEntry) {
231 Sdk jdk = ((JdkOrderEntry)entry).getJdk();
233 rootConfigurable.select(jdk, true);
239 private JComponent createButtonsBlock() {
240 final boolean isAnalyzeShown = ((ApplicationEx)ApplicationManager.getApplication()).isInternal();
242 final JButton addButton = new JButton(ProjectBundle.message("button.add"));
243 final JButton removeButton = new JButton(ProjectBundle.message("button.remove"));
244 myEditButton = new JButton(ProjectBundle.message("button.edit"));
245 final JButton upButton = new JButton(ProjectBundle.message("button.move.up"));
246 final JButton downButton = new JButton(ProjectBundle.message("button.move.down"));
247 final JButton analyzeButton = isAnalyzeShown ? new JButton(ProjectBundle.message("classpath.panel.analyze")) : null;
249 final JPanel panel = new JPanel(new GridBagLayout());
250 panel.add(addButton, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 0, 0), 0, 0));
251 panel.add(removeButton, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 0, 0), 0, 0));
252 panel.add(myEditButton, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 0, 0), 0, 0));
253 panel.add(upButton, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 0, 0), 0, 0));
254 panel.add(downButton, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, isAnalyzeShown ? 0.0 : 0.1, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 0, 0), 0, 0));
255 if( isAnalyzeShown) {
256 panel.add(analyzeButton, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 0, 0), 0, 0));
259 myEntryTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
260 public void valueChanged(ListSelectionEvent e) {
261 if (e.getValueIsAdjusting()) {
264 final int[] selectedRows = myEntryTable.getSelectedRows();
265 boolean removeButtonEnabled = true;
266 int minRow = myEntryTable.getRowCount() + 1;
268 for (final int selectedRow : selectedRows) {
269 minRow = Math.min(minRow, selectedRow);
270 maxRow = Math.max(maxRow, selectedRow);
271 final ClasspathTableItem item = myModel.getItemAt(selectedRow);
272 if (!item.isRemovable()) {
273 removeButtonEnabled = false;
276 upButton.setEnabled(minRow > 0 && minRow < myEntryTable.getRowCount());
277 downButton.setEnabled(maxRow >= 0 && maxRow < myEntryTable.getRowCount() - 1);
278 removeButton.setEnabled(removeButtonEnabled);
279 ClasspathTableItem selectedItem = selectedRows.length == 1 ? myModel.getItemAt(selectedRows[0]) : null;
280 myEditButton.setEnabled(selectedItem != null && selectedItem.isEditable());
284 upButton.addActionListener(new ClasspathPanelAction(this) {
287 moveSelectedRows(-1);
290 downButton.addActionListener(new ClasspathPanelAction(this) {
293 moveSelectedRows(+1);
298 analyzeButton.addActionListener(new ClasspathPanelAction(this) {
301 AnalyzeDependenciesDialog.show(getRootModel().getModule());
306 addKeyboardShortcut(myEntryTable, removeButton, KeyEvent.VK_DELETE, 0);
307 addKeyboardShortcut(myEntryTable, addButton, KeyEvent.VK_INSERT, 0);
308 addKeyboardShortcut(myEntryTable, upButton, KeyEvent.VK_UP, KeyEvent.CTRL_DOWN_MASK);
309 addKeyboardShortcut(myEntryTable, downButton, KeyEvent.VK_DOWN, KeyEvent.CTRL_DOWN_MASK);
311 addButton.addActionListener(new ActionListener() {
313 public void actionPerformed(ActionEvent e) {
315 final JBPopup popup = JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<AddItemPopupAction<?>>(null, myPopupActions) {
317 public Icon getIconFor(AddItemPopupAction<?> aValue) {
318 return aValue.getIcon();
321 public boolean isMnemonicsNavigationEnabled() {
324 public PopupStep onChosen(final AddItemPopupAction<?> selectedValue, final boolean finalChoice) {
325 return doFinalStep(new Runnable() {
327 selectedValue.execute();
332 public String getTextFor(AddItemPopupAction<?> value) {
333 return "&" + value.getIndex() + " " + value.getTitle();
336 popup.showUnderneathOf(addButton);
340 removeButton.addActionListener(new ClasspathPanelAction(this) {
343 final List removedRows = TableUtil.removeSelectedItems(myEntryTable);
344 if (removedRows.isEmpty()) {
347 for (final Object removedRow : removedRows) {
348 final ClasspathTableItem item = (ClasspathTableItem)((Object[])removedRow)[ClasspathTableModel.ITEM_COLUMN];
349 final OrderEntry orderEntry = item.getEntry();
350 if (orderEntry == null) {
354 getRootModel().removeOrderEntry(orderEntry);
356 final int[] selectedRows = myEntryTable.getSelectedRows();
357 myModel.fireTableDataChanged();
358 TableUtil.selectRows(myEntryTable, selectedRows);
359 final StructureConfigurableContext context = ModuleStructureConfigurable.getInstance(myState.getProject()).getContext();
360 context.getDaemonAnalyzer().queueUpdate(new ModuleProjectStructureElement(context, getRootModel().getModule()));
364 myEditButton.addActionListener(new ActionListener() {
365 public void actionPerformed(final ActionEvent e) {
366 final int row = myEntryTable.getSelectedRow();
367 final ClasspathTableItem item = myModel.getItemAt(row);
368 final OrderEntry entry = item.getEntry();
369 if (!(entry instanceof LibraryOrderEntry)) return;
371 final Library library = ((LibraryOrderEntry)entry).getLibrary();
372 if (library == null) {
375 final LibraryTableModifiableModelProvider provider;
376 final LibraryTable table = library.getTable();
378 final LibraryTable moduleLibraryTable = getRootModel().getModuleLibraryTable();
379 provider = new LibraryTableModifiableModelProvider() {
380 public LibraryTable.ModifiableModel getModifiableModel() {
381 return moduleLibraryTable.getModifiableModel();
387 provider = ProjectStructureConfigurable.getInstance(myState.getProject()).getContext().createModifiableModelProvider(table.getTableLevel());
389 EditExistingLibraryDialog dialog = EditExistingLibraryDialog.createDialog(ClasspathPanelImpl.this, provider, library, myState.getProject());
390 dialog.addFileChooserContext(LangDataKeys.MODULE_CONTEXT, getRootModel().getModule());
392 myEntryTable.repaint();
393 ModuleStructureConfigurable.getInstance(myState.getProject()).getTree().repaint();
399 private static void addKeyboardShortcut(final JComponent target, final JButton button, final int keyEvent, final int modifiers) {
400 target.registerKeyboardAction(
401 new ActionListener() {
402 public void actionPerformed(ActionEvent e) {
403 if (button.isEnabled()) {
408 KeyStroke.getKeyStroke(keyEvent, modifiers),
414 public void runClasspathPanelAction(Runnable action) {
416 disableModelUpdate();
421 myEntryTable.requestFocus();
426 public void addItems(List<ClasspathTableItem> toAdd) {
427 for (ClasspathTableItem item : toAdd) {
428 myModel.addItem(item);
430 myModel.fireTableDataChanged();
431 final ListSelectionModel selectionModel = myEntryTable.getSelectionModel();
432 selectionModel.setSelectionInterval(myModel.getRowCount() - toAdd.size(), myModel.getRowCount() - 1);
433 TableUtil.scrollSelectionToVisible(myEntryTable);
435 final StructureConfigurableContext context = ModuleStructureConfigurable.getInstance(myState.getProject()).getContext();
436 context.getDaemonAnalyzer().queueUpdate(new ModuleProjectStructureElement(context, getRootModel().getModule()));
440 public ModifiableRootModel getRootModel() {
441 return myState.getRootModel();
445 public Project getProject() {
446 return myState.getProject();
450 public JComponent getComponent() {
454 public void rootsChanged() {
455 forceInitFromModel();
458 private void initPopupActions() {
459 if (myPopupActions == null) {
460 final StructureConfigurableContext context = ProjectStructureConfigurable.getInstance(myState.getProject()).getContext();
462 final List<AddItemPopupAction<?>> actions = new ArrayList<AddItemPopupAction<?>>();
463 actions.add(new AddSingleEntryModuleLibraryAction(this, actionIndex++));
464 actions.add(new AddLibraryAction(this, actionIndex++, ProjectBundle.message("classpath.add.library.action"), context));
465 actions.add(new AddItemPopupAction<Module>(this, actionIndex, ProjectBundle.message("classpath.add.module.dependency.action"),
466 StdModuleTypes.JAVA.getNodeIcon(false)) {
467 protected ClasspathTableItem createTableItem(final Module item) {
468 return ClasspathTableItem.createItem(getRootModel().addModuleOrderEntry(item));
470 protected ClasspathElementChooser<Module> createChooser() {
471 final List<Module> chooseItems = getDependencyModules();
472 if (chooseItems.isEmpty()) {
473 Messages.showMessageDialog(ClasspathPanelImpl.this, ProjectBundle.message("message.no.module.dependency.candidates"), getTitle(), Messages.getInformationIcon());
476 return new ModuleChooser(chooseItems, ProjectBundle.message("classpath.chooser.title.add.module.dependency"));
481 myPopupActions = actions;
486 private void enableModelUpdate() {
490 private void disableModelUpdate() {
494 public void addListener(OrderPanelListener listener) {
495 myListeners.addListener(listener);
498 public void removeListener(OrderPanelListener listener) {
499 myListeners.removeListener(listener);
502 private void moveSelectedRows(int increment) {
503 if (increment == 0) {
506 if (myEntryTable.isEditing()){
507 myEntryTable.getCellEditor().stopCellEditing();
509 final ListSelectionModel selectionModel = myEntryTable.getSelectionModel();
510 for(int row = increment < 0? 0 : myModel.getRowCount() - 1; increment < 0? row < myModel.getRowCount() : row >= 0; row +=
511 increment < 0? +1 : -1){
512 if (selectionModel.isSelectedIndex(row)) {
513 final int newRow = moveRow(row, increment);
514 selectionModel.removeSelectionInterval(row, row);
515 selectionModel.addSelectionInterval(newRow, newRow);
518 myModel.fireTableRowsUpdated(0, myModel.getRowCount() - 1);
519 Rectangle cellRect = myEntryTable.getCellRect(selectionModel.getMinSelectionIndex(), 0, true);
520 if (cellRect != null) {
521 myEntryTable.scrollRectToVisible(cellRect);
523 myEntryTable.repaint();
524 myListeners.getMulticaster().entryMoved();
527 public void selectOrderEntry(@NotNull OrderEntry entry) {
528 for (int row = 0; row < myModel.getRowCount(); row++) {
529 if (entry.getPresentableName().equals(myModel.getItemAt(row).getEntry().getPresentableName())) {
530 myEntryTable.getSelectionModel().setSelectionInterval(row, row);
531 TableUtil.scrollSelectionToVisible(myEntryTable);
534 IdeFocusManager.getInstance(myState.getProject()).requestFocus(myEntryTable, true);
537 private int moveRow(final int row, final int increment) {
538 int newIndex = Math.abs(row + increment) % myModel.getRowCount();
539 final ClasspathTableItem item = myModel.removeDataRow(row);
540 myModel.addItemAt(item, newIndex);
544 public void stopEditing() {
545 TableUtil.stopEditing(myEntryTable);
548 public List<OrderEntry> getEntries() {
549 final int count = myModel.getRowCount();
550 final List<OrderEntry> entries = new ArrayList<OrderEntry>(count);
551 for (int row = 0; row < count; row++) {
552 final OrderEntry entry = myModel.getItemAt(row).getEntry();
560 private int myInsideChange = 0;
561 public void initFromModel() {
562 if (myInsideChange == 0) {
563 forceInitFromModel();
567 public void forceInitFromModel() {
568 final int[] selection = myEntryTable.getSelectedRows();
571 myModel.fireTableDataChanged();
572 TableUtil.selectRows(myEntryTable, selection);
575 private List<Module> getDependencyModules() {
576 final int rowCount = myModel.getRowCount();
577 final Set<String> filtered = new HashSet<String>(rowCount);
578 for (int row = 0; row < rowCount; row++) {
579 final OrderEntry entry = myModel.getItemAt(row).getEntry();
580 if (entry instanceof ModuleOrderEntry) {
581 filtered.add(((ModuleOrderEntry)entry).getModuleName());
584 final ModulesProvider modulesProvider = myState.getModulesProvider();
585 final Module self = modulesProvider.getModule(getRootModel().getModule().getName());
586 filtered.add(self.getName());
588 final Module[] modules = modulesProvider.getModules();
589 final List<Module> elements = new ArrayList<Module>(modules.length);
590 for (final Module module : modules) {
591 if (!filtered.contains(module.getName())) {
592 elements.add(module);
599 private static CellAppearance getCellAppearance(final ClasspathTableItem item, final boolean selected) {
600 if (item instanceof InvalidJdkItem) {
601 return OrderEntryCellAppearanceUtils.forJdk(null, false, selected);
604 return OrderEntryCellAppearanceUtils.forOrderEntry(item.getEntry(), selected);
608 private static class TableItemRenderer extends ColoredTableCellRenderer {
609 private final Border NO_FOCUS_BORDER = BorderFactory.createEmptyBorder(1, 1, 1, 1);
611 protected void customizeCellRenderer(JTable table, Object value, boolean selected, boolean hasFocus, int row, int column) {
612 setPaintFocusBorder(false);
613 setFocusBorderAroundIcon(true);
614 setBorder(NO_FOCUS_BORDER);
615 if (value instanceof ClasspathTableItem) {
616 getCellAppearance((ClasspathTableItem)value, selected).customize(this);
621 private static class ExportFlagRenderer implements TableCellRenderer {
622 private final TableCellRenderer myDelegate;
623 private final JPanel myBlankPanel;
625 public ExportFlagRenderer(TableCellRenderer delegate) {
626 myDelegate = delegate;
627 myBlankPanel = new JPanel();
630 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
631 if (!table.isCellEditable(row, column)) {
632 myBlankPanel.setBackground(isSelected ? table.getSelectionBackground() : table.getBackground());
635 return myDelegate.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
639 private class ModuleChooser extends ChooseModulesDialog implements ClasspathElementChooser<Module> {
640 public ModuleChooser(final List<Module> items, final String title) {
641 super(ClasspathPanelImpl.this, items, title);
644 public void doChoose() {
648 public void dispose() {
653 private class MyFindUsagesAction extends FindUsagesInProjectStructureActionBase {
654 private MyFindUsagesAction() {
655 super(myEntryTable, myState.getProject());
658 protected boolean isEnabled() {
659 return getSelectedElement() != null;
662 protected ProjectStructureElement getSelectedElement() {
663 int row = myEntryTable.getSelectedRow();
664 if (0 <= row && row < myModel.getRowCount()) {
665 ClasspathTableItem item = myModel.getItemAt(row);
666 final OrderEntry entry = item.getEntry();
667 if (entry instanceof LibraryOrderEntry) {
668 final Library library = ((LibraryOrderEntry)entry).getLibrary();
669 if (library != null) {
670 return new LibraryProjectStructureElement(getContext(), library);
673 else if (entry instanceof ModuleOrderEntry) {
674 final Module module = ((ModuleOrderEntry)entry).getModule();
675 if (module != null) {
676 return new ModuleProjectStructureElement(getContext(), module);
679 else if (entry instanceof JdkOrderEntry) {
680 final Sdk jdk = ((JdkOrderEntry)entry).getJdk();
682 return new SdkProjectStructureElement(getContext(), jdk);
689 protected RelativePoint getPointToShowResults() {
690 Rectangle rect = myEntryTable.getCellRect(myEntryTable.getSelectedRow(), 1, false);
691 Point location = rect.getLocation();
692 location.y += rect.height;
693 return new RelativePoint(myEntryTable, location);