01: package abbot.editor;
02:
03: import javax.swing.table.*;
04: import java.util.*;
05:
06: import abbot.i18n.Strings;
07: import abbot.script.*;
08:
09: /** Provides a table model for ComponentReference attributes. */
10: public class ReferenceAttributeModel extends AbstractTableModel {
11: private ComponentReference reference;
12:
13: private static String[] COLUMN_NAMES = {
14: Strings.get("attribute.name"),
15: Strings.get("attribute.value") };
16:
17: public void setReference(ComponentReference ref) {
18: reference = ref;
19: fireTableDataChanged();
20: }
21:
22: public String getColumnName(int col) {
23: return COLUMN_NAMES[col];
24: }
25:
26: public int getRowCount() {
27: return reference == null ? 0 : reference.getAttributes()
28: .values().size();
29: }
30:
31: public int getColumnCount() {
32: return 2;
33: }
34:
35: public Object getValueAt(int row, int col) {
36: Map.Entry entry = (Map.Entry) reference.getAttributes()
37: .entrySet().toArray()[row];
38: return col == 0 ? entry.getKey() : entry.getValue();
39: }
40:
41: public void setValueAt(Object value, int row, int col) {
42: if (col == 1) {
43: String key = (String) getValueAt(row, 0);
44: reference.setAttribute(key, (String) value);
45: fireTableCellUpdated(row, col);
46: }
47: }
48:
49: public boolean isCellEditable(int row, int col) {
50: return col == 1;
51: }
52: }
|