private JComponent getLibrariesTable() { myLibraryTableModel = new LibraryTableModel(); final JBTable librariesTable = new JBTable(myLibraryTableModel); librariesTable.setTableHeader(null); librariesTable.setDefaultRenderer(String.class, new MyPathRenderer()); librariesTable.setShowHorizontalLines(false); librariesTable.setShowVerticalLines(false); librariesTable.setAutoCreateRowSorter(false); librariesTable.setAutoscrolls(true); ToolbarDecorator decorator = ToolbarDecorator.createDecorator(librariesTable); decorator .setAddAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton anActionButton) { List<ModelRootDescriptor> modelRoots = new ArrayList<ModelRootDescriptor>( myJavaModuleFacet .getModule() .getModuleDescriptor() .getModelRootDescriptors()); StubRootChooser stubRootChooser = new StubRootChooser( modelRoots, (myJavaModuleFacet.getModule() instanceof Language ? true : false)); myLibraryTableModel.addAll(stubRootChooser.compute()); } }) .setRemoveAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton anActionButton) { TableUtil.removeSelectedItems(librariesTable); myLibraryTableModel.fireTableDataChanged(); } }); decorator.setToolbarBorder(IdeBorderFactory.createBorder()); decorator.setPreferredSize(new Dimension(500, 100)); JPanel table = decorator.createPanel(); table.setBorder( IdeBorderFactory.createTitledBorder( PropertiesBundle.message("mps.properties.configurable.module.javatab.librariesborder"), false)); return table; }
private JComponent getSourcePathsTable() { myPathsTableModel = new PathsTableModel(); final JBTable sourcePathTable = new JBTable(myPathsTableModel); sourcePathTable.setTableHeader(null); sourcePathTable.setDefaultRenderer(String.class, new MyPathRenderer()); sourcePathTable.setShowHorizontalLines(false); sourcePathTable.setShowVerticalLines(false); sourcePathTable.setAutoCreateRowSorter(false); sourcePathTable.setAutoscrolls(true); ToolbarDecorator decorator = ToolbarDecorator.createDecorator(sourcePathTable); decorator .setAddAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton anActionButton) { myPathsTableModel.add((new PathChooser()).compute()); } }) .setRemoveAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton anActionButton) { TableUtil.removeSelectedItems(sourcePathTable); myPathsTableModel.fireTableDataChanged(); } }); decorator.setToolbarBorder(IdeBorderFactory.createBorder()); decorator.setPreferredSize(new Dimension(500, 100)); JPanel table = decorator.createPanel(); table.setBorder( IdeBorderFactory.createTitledBorder( PropertiesBundle.message("mps.properties.configurable.module.javatab.sourcepathborder"), false)); return table; }
private ElementsChooser(@Nullable List<T> elements, boolean marked, boolean elementsCanBeMarked) { super(new BorderLayout()); myTableModel = new MyTableModel(elementsCanBeMarked); myTable = new Table(myTableModel); myTable.setShowGrid(false); myTable.setIntercellSpacing(new Dimension(0, 0)); myTable.setTableHeader(null); myTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); myTable.setColumnSelectionAllowed(false); JScrollPane pane = ScrollPaneFactory.createScrollPane(myTable); pane.setPreferredSize(new Dimension(100, 155)); int width = new JCheckBox().getPreferredSize().width; TableColumnModel columnModel = myTable.getColumnModel(); if (elementsCanBeMarked) { TableColumn checkMarkColumn = columnModel.getColumn(myTableModel.CHECK_MARK_COLUM_INDEX); checkMarkColumn.setPreferredWidth(width); checkMarkColumn.setMaxWidth(width); checkMarkColumn.setCellRenderer( new CheckMarkColumnCellRenderer(myTable.getDefaultRenderer(Boolean.class))); } columnModel .getColumn(myTableModel.ELEMENT_COLUMN_INDEX) .setCellRenderer(new MyElementColumnCellRenderer()); add(pane, BorderLayout.CENTER); myTable.registerKeyboardAction( new ActionListener() { public void actionPerformed(ActionEvent e) { final int[] selectedRows = myTable.getSelectedRows(); boolean currentlyMarked = true; for (int selectedRow : selectedRows) { currentlyMarked = myTableModel.isElementMarked(selectedRow); if (!currentlyMarked) { break; } } myTableModel.setMarked(selectedRows, !currentlyMarked); } }, KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), JComponent.WHEN_FOCUSED); final SpeedSearchBase<JBTable> speedSearch = new SpeedSearchBase<JBTable>(myTable) { public int getSelectedIndex() { return myTable.getSelectedRow(); } @Override protected int convertIndexToModel(int viewIndex) { return myTable.convertRowIndexToModel(viewIndex); } public Object[] getAllElements() { final int count = myTableModel.getRowCount(); Object[] elements = new Object[count]; for (int idx = 0; idx < count; idx++) { elements[idx] = myTableModel.getElementAt(idx); } return elements; } public String getElementText(Object element) { return getItemText((T) element); } public void selectElement(Object element, String selectedText) { final int count = myTableModel.getRowCount(); for (int row = 0; row < count; row++) { if (element.equals(myTableModel.getElementAt(row))) { final int viewRow = myTable.convertRowIndexToView(row); myTable.getSelectionModel().setSelectionInterval(viewRow, viewRow); TableUtil.scrollSelectionToVisible(myTable); break; } } } }; speedSearch.setComparator(new SpeedSearchBase.SpeedSearchComparator(false)); setElements(elements, marked); installActions(myTable); }