01: package net.sourceforge.squirrel_sql.plugins.codecompletion.prefs;
02:
03: import javax.swing.table.DefaultTableModel;
04: import java.util.Arrays;
05: import java.util.ArrayList;
06:
07: public class PrefixesTableModel extends DefaultTableModel {
08: private static final long serialVersionUID = 1L;
09:
10: private ArrayList<PrefixedConfig> _data = new ArrayList<PrefixedConfig>();
11:
12: public PrefixesTableModel(PrefixedConfig[] prefixedConfigs) {
13: _data.addAll(Arrays.asList(prefixedConfigs));
14:
15: }
16:
17: public Object getValueAt(int row, int column) {
18: PrefixedConfig buf = _data.get(row);
19:
20: if (0 == column) {
21: return buf.getPrefix();
22: } else {
23: return ConfigCboItem.getItemForConfig(buf
24: .getCompletionConfig());
25: }
26: }
27:
28: public void setValueAt(Object aValue, int row, int column) {
29: PrefixedConfig buf = _data.get(row);
30:
31: if (0 == column) {
32: buf.setPrefix(null == aValue ? "" : aValue.toString());
33: } else {
34: buf.setCompletionConfig(((ConfigCboItem) aValue)
35: .getCompletionConfig());
36: }
37:
38: fireTableCellUpdated(row, column);
39: }
40:
41: public void addNewConfig() {
42: _data.add(new PrefixedConfig());
43: fireTableRowsInserted(_data.size() - 1, _data.size() - 1);
44: }
45:
46: public int getRowCount() {
47: if (null == _data) {
48: return 0;
49: } else {
50: return _data.size();
51: }
52: }
53:
54: public void removeRows(int[] selRows) {
55: ArrayList<PrefixedConfig> toRemove = new ArrayList<PrefixedConfig>(
56: selRows.length);
57:
58: for (int i = 0; i < selRows.length; i++) {
59: toRemove.add(_data.get(selRows[i]));
60: }
61: _data.removeAll(toRemove);
62:
63: for (int i = 0; i < selRows.length; i++) {
64: fireTableRowsDeleted(selRows[i], selRows[i]);
65: }
66: }
67:
68: public PrefixedConfig[] getData() {
69: return _data.toArray(new PrefixedConfig[_data.size()]);
70: }
71: }
|