01: package vicazh.hyperpool.stream;
02:
03: import java.util.*;
04: import javax.swing.table.*;
05:
06: /**
07: * The list selector table model
08: *
09: * @author Victor Zhigunov
10: * @version 0.4.0
11: */
12: public class ISelectorModel extends AbstractTableModel {
13: private Object name;
14:
15: private Object index;
16:
17: private List<Object> data;
18:
19: /**
20: * @param name
21: * column name for data name
22: * @param index
23: * column name for index
24: * @param data
25: * data list
26: */
27: public ISelectorModel(Object name, Object index, List<Object> data) {
28: this .name = name;
29: this .index = index;
30: this .data = data;
31: }
32:
33: private IListSelector selector;
34:
35: public void setSelector(IListSelector selector) {
36: this .selector = selector;
37: }
38:
39: public void setValueAt(Object aValue, int row, int column) {
40: Object o = data.get(row);
41: int i = selector.getIndex(o);
42: List<List<Object>> list = selector.getList();
43: switch (column) {
44: case 0:
45: data.set(row, aValue);
46: if (selector.getDef() == i)
47: break;
48: List<Object> l = list.get(i);
49: l.set(l.indexOf(o), aValue);
50: break;
51: case 1:
52: if (selector.getDef() != i)
53: list.get(i).remove(o);
54: int j = selector.getGroup().getObjects().indexOf(aValue);
55: if (j != selector.getDef())
56: list.get(j).add(o);
57: break;
58: }
59: selector.setList(list);
60: }
61:
62: public Object getValueAt(int row, int column) {
63: Object o = data.get(row);
64: switch (column) {
65: case 0:
66: return o;
67: case 1:
68: return selector.getGroup().getObjects().get(
69: selector.getIndex(o));
70: }
71: return null;
72: }
73:
74: public int getRowCount() {
75: return data.size();
76: }
77:
78: public int getColumnCount() {
79: return 2;
80: }
81:
82: public String getColumnName(int columnIndex) {
83: switch (columnIndex) {
84: case 0:
85: return name.toString();
86: case 1:
87: return index.toString();
88: }
89: return null;
90: }
91:
92: public boolean isCellEditable(int row, int column) {
93: return true;
94: }
95: }
|