@Override @Nullable protected ClasspathTableItem<?> createTableItem(final Library item) { // clear invalid order entry corresponding to added library if any final ModifiableRootModel rootModel = myClasspathPanel.getRootModel(); final OrderEntry[] orderEntries = rootModel.getOrderEntries(); for (OrderEntry orderEntry : orderEntries) { if (orderEntry instanceof LibraryOrderEntry) { final LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry) orderEntry; if (item.equals(libraryOrderEntry.getLibrary())) { return ClasspathTableItem.createItem(libraryOrderEntry, myContext); } String name = item.getName(); if (name != null && name.equals(libraryOrderEntry.getLibraryName())) { if (orderEntry.isValid()) { Messages.showErrorDialog( ProjectBundle.message("classpath.message.library.already.added", item.getName()), ProjectBundle.message("classpath.title.adding.dependency")); return null; } else { rootModel.removeOrderEntry(orderEntry); } } } } final LibraryOrderEntry orderEntry = rootModel.addLibraryEntry(item); DependencyScope defaultScope = getDefaultScope(item); if (defaultScope != null) { orderEntry.setScope(defaultScope); } return ClasspathTableItem.createItem(orderEntry, myContext); }
@Override protected void customizeCellRenderer( JTable table, Object value, boolean selected, boolean hasFocus, int row, int column) { setPaintFocusBorder(false); setFocusBorderAroundIcon(true); setBorder(NO_FOCUS_BORDER); if (value instanceof ClasspathTableItem<?>) { final ClasspathTableItem<?> tableItem = (ClasspathTableItem<?>) value; getCellAppearance(tableItem, myContext, selected).customize(this); setToolTipText(tableItem.getTooltipText()); } }
private static CellAppearanceEx getCellAppearance( final ClasspathTableItem<?> item, final StructureConfigurableContext context, final boolean selected) { final OrderEntryAppearanceService service = OrderEntryAppearanceService.getInstance(); final OrderEntry entry = item.getEntry(); assert entry != null : item; return service.forOrderEntry(context.getProject(), entry, selected); }
private void updateButtons() { final int[] selectedRows = myEntryTable.getSelectedRows(); boolean removeButtonEnabled = true; int minRow = myEntryTable.getRowCount() + 1; int maxRow = -1; for (final int selectedRow : selectedRows) { minRow = Math.min(minRow, selectedRow); maxRow = Math.max(maxRow, selectedRow); final ClasspathTableItem<?> item = myModel.getItemAt(selectedRow); if (!item.isRemovable()) { removeButtonEnabled = false; } } if (myRemoveButton != null) { myRemoveButton.setEnabled(removeButtonEnabled && selectedRows.length > 0); } ClasspathTableItem<?> selectedItem = selectedRows.length == 1 ? myModel.getItemAt(selectedRows[0]) : null; myEditButton.setEnabled(selectedItem != null && selectedItem.isEditable()); }
static CellAppearanceEx getCellAppearance( final ClasspathTableItem<?> item, final StructureConfigurableContext context, final boolean selected) { final OrderEntryAppearanceService service = OrderEntryAppearanceService.getInstance(); if (item instanceof InvalidJdkItem) { return service.forJdk(null, false, selected, true); } else { final OrderEntry entry = item.getEntry(); assert entry != null : item; return service.forOrderEntry(context.getProject(), entry, selected); } }
private void removeSelectedItems(final List removedRows) { if (removedRows.isEmpty()) { return; } for (final Object removedRow : removedRows) { final ClasspathTableItem<?> item = (ClasspathTableItem<?>) ((Object[]) removedRow)[ClasspathTableModel.ITEM_COLUMN]; final OrderEntry orderEntry = item.getEntry(); if (orderEntry == null) { continue; } getRootModel().removeOrderEntry(orderEntry); } final int[] selectedRows = myEntryTable.getSelectedRows(); myModel.fireTableDataChanged(); TableUtil.selectRows(myEntryTable, selectedRows); final StructureConfigurableContext context = ModuleStructureConfigurable.getInstance(myState.getProject()).getContext(); context .getDaemonAnalyzer() .queueUpdate(new ModuleProjectStructureElement(context, getRootModel().getModule())); }
@Override @Nullable public OrderEntry getSelectedEntry() { ClasspathTableItem<?> item = getSelectedItem(); return item != null ? item.getEntry() : null; }