use of com.intellij.ui.table.JBTable in project intellij-community by JetBrains.
the class TodoConfigurable method createComponent.
@Override
public JComponent createComponent() {
myPatternsTable = new JBTable(myPatternsModel);
myPatternsTable.getEmptyText().setText(IdeBundle.message("text.todo.no.patterns"));
TableColumn typeColumn = myPatternsTable.getColumnModel().getColumn(0);
int width = myPatternsTable.getFontMetrics(myPatternsTable.getFont()).stringWidth(myPatternsTable.getColumnName(0)) + 10;
typeColumn.setPreferredWidth(width);
typeColumn.setMaxWidth(width);
typeColumn.setMinWidth(width);
typeColumn.setCellRenderer(new IconTableCellRenderer<Icon>() {
@Nullable
@Override
protected Icon getIcon(@NotNull Icon value, JTable table, int row) {
return value;
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean selected, boolean focus, int row, int column) {
super.getTableCellRendererComponent(table, value, selected, focus, row, column);
setText("");
return this;
}
@Override
protected boolean isCenterAlignment() {
return true;
}
});
// Column "Case Sensitive"
TableColumn todoCaseSensitiveColumn = myPatternsTable.getColumnModel().getColumn(1);
width = myPatternsTable.getFontMetrics(myPatternsTable.getFont()).stringWidth(myPatternsTable.getColumnName(1)) + 10;
todoCaseSensitiveColumn.setPreferredWidth(width);
todoCaseSensitiveColumn.setMaxWidth(width);
todoCaseSensitiveColumn.setMinWidth(width);
todoCaseSensitiveColumn.setCellRenderer(new BooleanTableCellRenderer());
todoCaseSensitiveColumn.setCellEditor(new BooleanTableCellEditor());
// Column "Pattern"
TodoPatternTableCellRenderer todoPatternRenderer = new TodoPatternTableCellRenderer(myPatterns);
TableColumn patternColumn = myPatternsTable.getColumnModel().getColumn(2);
patternColumn.setCellRenderer(todoPatternRenderer);
JPanel patternsPanel = new JPanel(new BorderLayout());
patternsPanel.setBorder(IdeBorderFactory.createTitledBorder(IdeBundle.message("label.todo.patterns"), false));
patternsPanel.add(ToolbarDecorator.createDecorator(myPatternsTable).setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
stopEditing();
TodoPattern pattern = new TodoPattern(TodoAttributesUtil.createDefault());
PatternDialog dialog = new PatternDialog(myPanel, pattern);
if (!dialog.showAndGet()) {
return;
}
myPatterns.add(pattern);
int index = myPatterns.size() - 1;
myPatternsModel.fireTableRowsInserted(index, index);
myPatternsTable.getSelectionModel().setSelectionInterval(index, index);
myPatternsTable.scrollRectToVisible(myPatternsTable.getCellRect(index, 0, true));
}
}).setEditAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
editSelectedPattern();
}
}).setRemoveAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
stopEditing();
int selectedIndex = myPatternsTable.getSelectedRow();
if (selectedIndex < 0 || selectedIndex >= myPatternsModel.getRowCount()) {
return;
}
TodoPattern patternToBeRemoved = myPatterns.get(selectedIndex);
TableUtil.removeSelectedItems(myPatternsTable);
for (int i = 0; i < myFilters.size(); i++) {
TodoFilter filter = myFilters.get(i);
if (filter.contains(patternToBeRemoved)) {
filter.removeTodoPattern(patternToBeRemoved);
myFiltersModel.fireTableRowsUpdated(i, i);
}
}
}
}).disableUpDownActions().createPanel(), BorderLayout.CENTER);
// double click in "Patterns" table should also start editing of selected pattern
new DoubleClickListener() {
@Override
protected boolean onDoubleClick(MouseEvent e) {
editSelectedPattern();
return true;
}
}.installOn(myPatternsTable);
// Panel with filters
myFiltersTable = new JBTable(myFiltersModel);
myFiltersTable.getEmptyText().setText(IdeBundle.message("text.todo.no.filters"));
// Column "Name"
TableColumn nameColumn = myFiltersTable.getColumnModel().getColumn(0);
width = myPatternsTable.getColumnModel().getColumn(0).getPreferredWidth() + /*typeColumn*/
myPatternsTable.getColumnModel().getColumn(1).getPreferredWidth();
nameColumn.setPreferredWidth(width);
nameColumn.setMaxWidth(width);
nameColumn.setMinWidth(width);
nameColumn.setCellRenderer(new MyFilterNameTableCellRenderer());
JPanel filtersPanel = new JPanel(new BorderLayout());
filtersPanel.setBorder(IdeBorderFactory.createTitledBorder(IdeBundle.message("label.todo.filters"), false));
filtersPanel.add(ToolbarDecorator.createDecorator(myFiltersTable).setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
stopEditing();
TodoFilter filter = new TodoFilter();
FilterDialog dialog = new FilterDialog(myPanel, filter, -1, myFilters, myPatterns);
if (dialog.showAndGet()) {
myFilters.add(filter);
int index = myFilters.size() - 1;
myFiltersModel.fireTableRowsInserted(index, index);
myFiltersTable.getSelectionModel().setSelectionInterval(index, index);
myFiltersTable.scrollRectToVisible(myFiltersTable.getCellRect(index, 0, true));
}
}
}).setEditAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
editSelectedFilter();
}
}).setRemoveAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
stopEditing();
TableUtil.removeSelectedItems(myFiltersTable);
}
}).disableUpDownActions().createPanel());
new DoubleClickListener() {
@Override
protected boolean onDoubleClick(MouseEvent e) {
editSelectedFilter();
return true;
}
}.installOn(myFiltersTable);
myPanel = FormBuilder.createFormBuilder().addComponentFillVertically(patternsPanel, 0).addComponentFillVertically(filtersPanel, 0).getPanel();
return myPanel;
}
use of com.intellij.ui.table.JBTable in project intellij-community by JetBrains.
the class JBComboBoxTableCellEditorComponent method initAndShowPopup.
private void initAndShowPopup() {
myList.removeAll();
myList.setModel(JBList.createDefaultListModel(myOptions));
if (myRenderer != null) {
myList.setCellRenderer(myRenderer);
}
final Rectangle rect = myTable.getCellRect(myRow, myColumn, true);
Point point = new Point(rect.x, rect.y);
final boolean surrendersFocusOnKeystrokeOldValue = myTable instanceof JBTable ? ((JBTable) myTable).surrendersFocusOnKeyStroke() : myTable.getSurrendersFocusOnKeystroke();
final JBPopup popup = JBPopupFactory.getInstance().createListPopupBuilder(myList).setItemChoosenCallback(() -> {
myValue = myList.getSelectedValue();
final ActionEvent event = new ActionEvent(myList, ActionEvent.ACTION_PERFORMED, "elementChosen");
for (ActionListener listener : myListeners) {
listener.actionPerformed(event);
}
TableUtil.stopEditing(myTable);
// on Mac getCellEditorValue() called before myValue is set.
myTable.setValueAt(myValue, myRow, myColumn);
// force repaint
myTable.tableChanged(new TableModelEvent(myTable.getModel(), myRow));
}).setCancelCallback(() -> {
TableUtil.stopEditing(myTable);
return true;
}).addListener(new JBPopupAdapter() {
@Override
public void beforeShown(LightweightWindowEvent event) {
super.beforeShown(event);
myTable.setSurrendersFocusOnKeystroke(false);
}
@Override
public void onClosed(LightweightWindowEvent event) {
myTable.setSurrendersFocusOnKeystroke(surrendersFocusOnKeystrokeOldValue);
super.onClosed(event);
}
}).setMinSize(myWide ? new Dimension(((int) rect.getSize().getWidth()), -1) : null).createPopup();
popup.show(new RelativePoint(myTable, point));
}
use of com.intellij.ui.table.JBTable in project intellij-community by JetBrains.
the class ClassPatternsPanel method createTableForPatterns.
private JBTable createTableForPatterns() {
TableModel dataModel = new MyTableModel();
final JBTable result = new JBTable(dataModel);
result.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
result.getColumnModel().getColumn(2).setCellRenderer(new DefaultTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
final Component component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (value instanceof String && ((String) value).isEmpty()) {
setText("constructors");
setForeground(UIUtil.getInactiveTextColor());
} else if (value instanceof String) {
setText((String) value);
setForeground(UIUtil.getTableForeground(isSelected));
}
return component;
}
});
TableCellEditor editor = result.getDefaultEditor(String.class);
if (editor instanceof DefaultCellEditor) {
((DefaultCellEditor) editor).setClickCountToStart(1);
}
final TableColumn column = result.getTableHeader().getColumnModel().getColumn(0);
column.setResizable(false);
final int width = 15 + result.getTableHeader().getFontMetrics(result.getTableHeader().getFont()).stringWidth(result.getColumnName(0));
column.setMaxWidth(width);
column.setMinWidth(width);
return result;
}
use of com.intellij.ui.table.JBTable in project intellij-community by JetBrains.
the class ReplaceConstructorWithBuilderDialog method createTablePanel.
private JScrollPane createTablePanel() {
myTableModel = new MyTableModel();
myTable = new JBTable(myTableModel);
myTable.setSurrendersFocusOnKeystroke(true);
myTable.getTableHeader().setReorderingAllowed(false);
final TableColumnModel columnModel = myTable.getColumnModel();
columnModel.getColumn(SKIP_SETTER).setCellRenderer(new BooleanTableCellRenderer());
myTable.registerKeyboardAction(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final int[] selectedRows = myTable.getSelectedRows();
for (final int selectedRow : selectedRows) {
final ParameterData parameterData = myTableModel.getParamData(selectedRow);
if (parameterData.getDefaultValue() != null) {
parameterData.setInsertSetter(!parameterData.isInsertSetter());
}
}
TableUtil.selectRows(myTable, selectedRows);
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), JComponent.WHEN_FOCUSED);
myTable.setPreferredScrollableViewportSize(new Dimension(550, myTable.getRowHeight() * 12));
myTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
return ScrollPaneFactory.createScrollPane(myTable);
}
use of com.intellij.ui.table.JBTable in project intellij-community by JetBrains.
the class ProjectStartupConfigurable method createComponent.
@Nullable
@Override
public JComponent createComponent() {
myModel = new ProjectStartupTasksTableModel(RunManagerEx.getInstanceEx(myProject));
myTable = new JBTable(myModel);
myTable.getEmptyText().setText("Add run configurations with the + button");
new TableSpeedSearch(myTable);
DefaultCellEditor defaultEditor = (DefaultCellEditor) myTable.getDefaultEditor(Object.class);
defaultEditor.setClickCountToStart(1);
myTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
new DumbAwareAction() {
@Override
public void actionPerformed(AnActionEvent e) {
final int row = myTable.getSelectedRow();
if (row >= 0 && myModel.isCellEditable(row, ProjectStartupTasksTableModel.IS_SHARED_COLUMN)) {
myModel.setValueAt(!Boolean.TRUE.equals(myTable.getValueAt(row, ProjectStartupTasksTableModel.IS_SHARED_COLUMN)), row, ProjectStartupTasksTableModel.IS_SHARED_COLUMN);
}
}
}.registerCustomShortcutSet(new CustomShortcutSet(KeyEvent.VK_SPACE), myTable);
myTable.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() >= 2) {
editRunConfiguration();
}
}
});
installRenderers();
myDecorator = ToolbarDecorator.createDecorator(myTable).setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
selectAndAddConfiguration(button);
}
}).setEditAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
editRunConfiguration();
}
}).setEditActionUpdater(new AnActionButtonUpdater() {
@Override
public boolean isEnabled(AnActionEvent e) {
return myTable.getSelectedRow() >= 0;
}
}).disableUpAction().disableDownAction();
final JPanel tasksPanel = myDecorator.createPanel();
final JLabel label = new JLabel("Run tasks and tools via run configurations");
label.setForeground(UIUtil.getInactiveTextColor());
label.setHorizontalAlignment(SwingConstants.RIGHT);
final JPanel wrapper = new JPanel(new BorderLayout());
wrapper.add(new JLabel("To be started on project opening:"), BorderLayout.WEST);
wrapper.add(label, BorderLayout.EAST);
wrapper.setBorder(BorderFactory.createEmptyBorder(0, 0, UIUtil.DEFAULT_VGAP, 0));
final JPanel main = new JPanel(new BorderLayout());
main.add(wrapper, BorderLayout.NORTH);
main.add(tasksPanel, BorderLayout.CENTER);
return main;
}
Aggregations