use of javax.swing.table.TableCellEditor in project intellij-community by JetBrains.
the class OptionTableWithPreviewPanel method createOptionsTree.
protected TreeTable createOptionsTree(CodeStyleSettings settings) {
DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
Map<String, DefaultMutableTreeNode> groupsMap = new THashMap<>();
List<Option> sorted = sortOptions(ContainerUtil.concat(myOptions, myCustomOptions));
for (Option each : sorted) {
if (!(myCustomOptions.contains(each) || myAllowedOptions.contains(each.field.getName()) || myShowAllStandardOptions))
continue;
String group = each.groupName;
MyTreeNode newNode = new MyTreeNode(each, each.title, settings);
DefaultMutableTreeNode groupNode = groupsMap.get(group);
if (groupNode != null) {
groupNode.add(newNode);
} else {
String groupName;
if (group == null) {
groupName = each.title;
groupNode = newNode;
} else {
groupName = group;
groupNode = new DefaultMutableTreeNode(groupName);
groupNode.add(newNode);
}
groupsMap.put(groupName, groupNode);
rootNode.add(groupNode);
}
}
ListTreeTableModel model = new ListTreeTableModel(rootNode, COLUMNS);
TreeTable treeTable = new TreeTable(model) {
@Override
public TreeTableCellRenderer createTableRenderer(TreeTableModel treeTableModel) {
TreeTableCellRenderer tableRenderer = super.createTableRenderer(treeTableModel);
UIUtil.setLineStyleAngled(tableRenderer);
tableRenderer.setRootVisible(false);
tableRenderer.setShowsRootHandles(true);
return tableRenderer;
}
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
TreePath treePath = getTree().getPathForRow(row);
if (treePath == null)
return super.getCellRenderer(row, column);
Object node = treePath.getLastPathComponent();
@SuppressWarnings("unchecked") TableCellRenderer renderer = COLUMNS[column].getRenderer(node);
return renderer == null ? super.getCellRenderer(row, column) : renderer;
}
@Override
public TableCellEditor getCellEditor(int row, int column) {
TreePath treePath = getTree().getPathForRow(row);
if (treePath == null)
return super.getCellEditor(row, column);
Object node = treePath.getLastPathComponent();
@SuppressWarnings("unchecked") TableCellEditor editor = COLUMNS[column].getEditor(node);
return editor == null ? super.getCellEditor(row, column) : editor;
}
};
new TreeTableSpeedSearch(treeTable).setComparator(new SpeedSearchComparator(false));
treeTable.setRootVisible(false);
final JTree tree = treeTable.getTree();
tree.setCellRenderer(myTitleRenderer);
tree.setShowsRootHandles(true);
//myTreeTable.setRowHeight(new JComboBox(new String[]{"Sample Text"}).getPreferredSize().height);
treeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
treeTable.setTableHeader(null);
TreeUtil.expandAll(tree);
treeTable.getColumnModel().getSelectionModel().setAnchorSelectionIndex(1);
treeTable.getColumnModel().getSelectionModel().setLeadSelectionIndex(1);
int maxWidth = tree.getPreferredScrollableViewportSize().width + 10;
final TableColumn titleColumn = treeTable.getColumnModel().getColumn(0);
titleColumn.setPreferredWidth(maxWidth);
titleColumn.setMinWidth(maxWidth);
titleColumn.setMaxWidth(maxWidth);
titleColumn.setResizable(false);
//final TableColumn levelColumn = treeTable.getColumnModel().getColumn(1);
//TODO[max]: better preffered size...
//TODO[kb]: Did I fixed it by making the last column floating?
//levelColumn.setPreferredWidth(valueSize.width);
//levelColumn.setMaxWidth(valueSize.width);
//levelColumn.setMinWidth(valueSize.width);
//levelColumn.setResizable(false);
final Dimension valueSize = new JLabel(ApplicationBundle.message("option.table.sizing.text")).getPreferredSize();
treeTable.setPreferredScrollableViewportSize(new Dimension(maxWidth + valueSize.width + 10, 20));
return treeTable;
}
use of javax.swing.table.TableCellEditor in project intellij-community by JetBrains.
the class EncapsulateFieldsDialog method createTable.
private JComponent createTable() {
myTableModel = new MyTableModel();
myTable = new JBTable(myTableModel);
myTable.setSurrendersFocusOnKeystroke(true);
MyTableRenderer renderer = new MyTableRenderer();
TableColumnModel columnModel = myTable.getColumnModel();
columnModel.getColumn(CHECKED_COLUMN).setCellRenderer(new BooleanTableCellRenderer());
columnModel.getColumn(FIELD_COLUMN).setCellRenderer(renderer);
columnModel.getColumn(GETTER_COLUMN).setCellRenderer(renderer);
columnModel.getColumn(SETTER_COLUMN).setCellRenderer(renderer);
TableUtil.setupCheckboxColumn(columnModel.getColumn(CHECKED_COLUMN));
myTable.setPreferredScrollableViewportSize(new Dimension(550, myTable.getRowHeight() * 12));
myTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTable);
// JLabel label = new JLabel("Fields to Encapsulate");
// CompTitledBorder titledBorder = new CompTitledBorder(label);
JPanel panel = new JPanel(new BorderLayout());
Border border = IdeBorderFactory.createTitledBorder(RefactoringBundle.message("encapsulate.fields.fields.to.encapsulate.border.title"), false);
panel.setBorder(border);
panel.add(scrollPane);
// make ESC and ENTER work when focus is in the table
myTable.registerKeyboardAction(new ActionListener() {
public void actionPerformed(ActionEvent e) {
TableCellEditor editor = myTable.getCellEditor();
if (editor != null) {
editor.cancelCellEditing();
} else {
doCancelAction();
}
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
// make SPACE check/uncheck selected rows
@NonNls InputMap inputMap = myTable.getInputMap();
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "enable_disable");
@NonNls ActionMap actionMap = myTable.getActionMap();
actionMap.put("enable_disable", new AbstractAction() {
public void actionPerformed(ActionEvent e) {
if (myTable.isEditing())
return;
int[] rows = myTable.getSelectedRows();
if (rows.length > 0) {
boolean valueToBeSet = false;
for (int row : rows) {
if (!myCheckedMarks[row]) {
valueToBeSet = true;
break;
}
}
for (int row : rows) {
myCheckedMarks[row] = valueToBeSet;
}
myTableModel.fireTableRowsUpdated(rows[0], rows[rows.length - 1]);
TableUtil.selectRows(myTable, rows);
}
}
});
// make ENTER work when the table has focus
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "invokeImpl");
actionMap.put("invokeImpl", new AbstractAction() {
public void actionPerformed(ActionEvent e) {
TableCellEditor editor = myTable.getCellEditor();
if (editor != null) {
editor.stopCellEditing();
} else {
clickDefaultButton();
}
}
});
return panel;
}
use of javax.swing.table.TableCellEditor in project intellij-community by JetBrains.
the class ImportLayoutPanel method createTableForPackageEntries.
public static JBTable createTableForPackageEntries(final PackageEntryTable packageTable, final ImportLayoutPanel panel) {
final String[] names = { ApplicationBundle.message("listbox.import.package"), ApplicationBundle.message("listbox.import.with.subpackages") };
// Create a model of the data.
TableModel dataModel = new AbstractTableModel() {
public int getColumnCount() {
return names.length + (panel.areStaticImportsEnabled() ? 1 : 0);
}
public int getRowCount() {
return packageTable.getEntryCount();
}
@Nullable
public Object getValueAt(int row, int col) {
PackageEntry entry = packageTable.getEntryAt(row);
if (entry == null || !isCellEditable(row, col))
return null;
col += panel.areStaticImportsEnabled() ? 0 : 1;
if (col == 0) {
return entry.isStatic();
}
if (col == 1) {
return entry.getPackageName();
}
if (col == 2) {
return entry.isWithSubpackages();
}
throw new IllegalArgumentException(String.valueOf(col));
}
public String getColumnName(int column) {
if (panel.areStaticImportsEnabled() && column == 0)
return "Static";
column -= panel.areStaticImportsEnabled() ? 1 : 0;
return names[column];
}
public Class getColumnClass(int col) {
col += panel.areStaticImportsEnabled() ? 0 : 1;
if (col == 0) {
return Boolean.class;
}
if (col == 1) {
return String.class;
}
if (col == 2) {
return Boolean.class;
}
throw new IllegalArgumentException(String.valueOf(col));
}
public boolean isCellEditable(int row, int col) {
PackageEntry packageEntry = packageTable.getEntryAt(row);
return !packageEntry.isSpecial();
}
public void setValueAt(Object aValue, int row, int col) {
PackageEntry packageEntry = packageTable.getEntryAt(row);
col += panel.areStaticImportsEnabled() ? 0 : 1;
if (col == 0) {
PackageEntry newPackageEntry = new PackageEntry((Boolean) aValue, packageEntry.getPackageName(), packageEntry.isWithSubpackages());
packageTable.setEntryAt(newPackageEntry, row);
} else if (col == 1) {
PackageEntry newPackageEntry = new PackageEntry(packageEntry.isStatic(), ((String) aValue).trim(), packageEntry.isWithSubpackages());
packageTable.setEntryAt(newPackageEntry, row);
} else if (col == 2) {
PackageEntry newPackageEntry = new PackageEntry(packageEntry.isStatic(), packageEntry.getPackageName(), ((Boolean) aValue).booleanValue());
packageTable.setEntryAt(newPackageEntry, row);
} else {
throw new IllegalArgumentException(String.valueOf(col));
}
}
};
// Create the table
final JBTable result = new JBTable(dataModel);
result.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
resizeColumns(packageTable, result, panel.areStaticImportsEnabled());
TableCellEditor editor = result.getDefaultEditor(String.class);
if (editor instanceof DefaultCellEditor) {
((DefaultCellEditor) editor).setClickCountToStart(1);
}
TableCellEditor beditor = result.getDefaultEditor(Boolean.class);
beditor.addCellEditorListener(new CellEditorListener() {
public void editingStopped(ChangeEvent e) {
if (panel.areStaticImportsEnabled()) {
// add/remove static keyword
result.repaint();
}
}
public void editingCanceled(ChangeEvent e) {
}
});
return result;
}
use of javax.swing.table.TableCellEditor in project intellij-community by JetBrains.
the class TableUtil method stopEditing.
public static void stopEditing(@NotNull JTable table) {
if (table.isEditing()) {
final TableCellEditor cellEditor = table.getCellEditor();
if (cellEditor != null) {
cellEditor.stopCellEditing();
}
int row = table.getSelectedRow();
int column = table.getSelectedColumn();
if (row >= 0 && column >= 0) {
TableCellEditor editor = table.getCellEditor(row, column);
if (editor != null) {
editor.stopCellEditing();
//Object value = editor.getCellEditorValue();
//
//table.setValueAt(value, row, column);
}
}
}
}
use of javax.swing.table.TableCellEditor in project intellij-community by JetBrains.
the class UiUtils method editTableCell.
private static void editTableCell(final ListTable table, final int row, final int column) {
final ListSelectionModel selectionModel = table.getSelectionModel();
selectionModel.setSelectionInterval(row, row);
EventQueue.invokeLater(() -> {
final ListWrappingTableModel tableModel = table.getModel();
IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
IdeFocusManager.getGlobalInstance().requestFocus(table, true);
});
final Rectangle rectangle = table.getCellRect(row, column, true);
table.scrollRectToVisible(rectangle);
table.editCellAt(row, column);
final TableCellEditor editor = table.getCellEditor();
final Component component = editor.getTableCellEditorComponent(table, tableModel.getValueAt(row, column), true, row, column);
IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
IdeFocusManager.getGlobalInstance().requestFocus(component, true);
});
});
}
Aggregations