use of javax.swing.table.AbstractTableModel in project intellij-community by JetBrains.
the class ImportLayoutPanel method moveRowUp.
private void moveRowUp() {
int selected = myImportLayoutTable.getSelectedRow();
if (selected < 1) {
return;
}
TableUtil.stopEditing(myImportLayoutTable);
PackageEntry entry = myImportLayoutList.getEntryAt(selected);
PackageEntry previousEntry = myImportLayoutList.getEntryAt(selected - 1);
myImportLayoutList.setEntryAt(previousEntry, selected);
myImportLayoutList.setEntryAt(entry, selected - 1);
AbstractTableModel model = (AbstractTableModel) myImportLayoutTable.getModel();
model.fireTableRowsUpdated(selected - 1, selected);
myImportLayoutTable.setRowSelectionInterval(selected - 1, selected - 1);
}
use of javax.swing.table.AbstractTableModel 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.AbstractTableModel in project intellij-community by JetBrains.
the class PackagePanel method removeEntryFromPackages.
private static void removeEntryFromPackages(JBTable table, PackageEntryTable list) {
int selected = table.getSelectedRow();
if (selected < 0)
return;
TableUtil.stopEditing(table);
list.removeEntryAt(selected);
AbstractTableModel model = (AbstractTableModel) table.getModel();
model.fireTableRowsDeleted(selected, selected);
if (selected >= list.getEntryCount()) {
selected--;
}
if (selected >= 0) {
table.setRowSelectionInterval(selected, selected);
}
}
use of javax.swing.table.AbstractTableModel in project intellij-community by JetBrains.
the class CodeStyleImportsPanelBase method refreshTable.
private void refreshTable(final JBTable table, final PackageEntryTable packageTable) {
AbstractTableModel model = (AbstractTableModel) table.getModel();
table.createDefaultColumnsFromModel();
model.fireTableDataChanged();
ImportLayoutPanel.resizeColumns(packageTable, table, myImportLayoutPanel.areStaticImportsEnabled());
}
use of javax.swing.table.AbstractTableModel in project intellij-community by JetBrains.
the class EditMigrationDialog method edit.
private void edit() {
EditMigrationEntryDialog dialog = new EditMigrationEntryDialog(myProject);
int selected = myTable.getSelectedRow();
if (selected < 0)
return;
MigrationMapEntry entry = myMigrationMap.getEntryAt(selected);
dialog.setEntry(entry);
if (!dialog.showAndGet()) {
return;
}
dialog.updateEntry(entry);
AbstractTableModel model = (AbstractTableModel) myTable.getModel();
model.fireTableRowsUpdated(selected, selected);
}
Aggregations