01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.client.modules.preferences;
19:
20: import java.util.prefs.BackingStoreException;
21: import java.util.prefs.Preferences;
22:
23: import javax.swing.table.AbstractTableModel;
24:
25: import de.finix.contelligent.client.i18n.Resources;
26: import de.finix.contelligent.client.util.ExceptionDialog;
27:
28: public class PreferencesTableModel extends AbstractTableModel {
29:
30: private boolean editable = true;
31:
32: private Object[][] data;
33:
34: private String[] columnNames = { Resources.getLocalString("name"),
35: Resources.getLocalString("value") };
36:
37: private Preferences preferences;
38:
39: public PreferencesTableModel(Preferences preferences) {
40: this .preferences = preferences;
41: updateData();
42: }
43:
44: public void updateData() {
45: try {
46: String[] keys = preferences.keys();
47: data = new Object[keys.length][2];
48: for (int i = 0; i < keys.length; i++) {
49: data[i][0] = keys[i];
50: data[i][1] = preferences.get(keys[i], Resources
51: .getLocalString("not_available"));
52: }
53: } catch (BackingStoreException e) {
54: ExceptionDialog.show(e);
55: }
56: }
57:
58: public int getColumnCount() {
59: return columnNames.length;
60: }
61:
62: public int getRowCount() {
63: return data.length;
64: }
65:
66: public String getColumnName(int col) {
67: return columnNames[col];
68: }
69:
70: public Object getValueAt(int row, int col) {
71: return data[row][col];
72: }
73:
74: public Class getColumnClass(int c) {
75: return getValueAt(0, c).getClass();
76: }
77:
78: public boolean isCellEditable(int row, int col) {
79: // Note that the data/cell address is constant,
80: // no matter where the cell appears onscreen.
81:
82: if (col == 1) {
83: return editable;
84: }
85: return false;
86: }
87:
88: public void setValueAt(Object value, int row, int col) {
89: data[row][col] = value;
90: fireTableCellUpdated(row, 1);
91: preferences.put((String) data[row][0], (String) value);
92: }
93:
94: public void setEditable(boolean editable) {
95: this.editable = editable;
96: }
97: }
|