JBTable (final PackageEntryTable packageTable, final ImportLayoutPanel panel) { final String[] names = { JavaBundle.message("listbox.import.package"), JavaBundle.message("listbox.import.with.subpackages"), }; // Create a model of the data. TableModel dataModel = new AbstractTableModel() { @Override public int getColumnCount() { return names.length + (panel.areStaticImportsEnabled() ? 1 : 0); } @Override public int getRowCount() { return packageTable.getEntryCount(); } @Override @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)); } @Override public String getColumnName(int column) { if (panel.areStaticImportsEnabled() && column == 0) return JavaBundle.message("listbox.import.static"); column -= panel.areStaticImportsEnabled() ? 1 : 0; return names[column]; } @Override 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)); } @Override public boolean isCellEditable(int row, int col) { PackageEntry packageEntry = packageTable.getEntryAt(row); return !packageEntry.isSpecial(); } @Override 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.setShowGrid(false); 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() { @Override public void editingStopped(ChangeEvent e) { if (panel.areStaticImportsEnabled()) { result.repaint(); // add/remove static keyword } } @Override public void editingCanceled(ChangeEvent e) { } }); return result; }