001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.client.gui.property;
019:
020: import java.util.Iterator;
021: import java.util.Map;
022:
023: import javax.swing.table.AbstractTableModel;
024:
025: import de.finix.contelligent.client.base.ComponentProperty;
026: import de.finix.contelligent.client.base.ContelligentComponent;
027: import de.finix.contelligent.client.base.TypeProperty;
028: import de.finix.contelligent.client.i18n.Resources;
029: import de.finix.contelligent.client.util.SortableTableModel;
030:
031: public class PropertyTableModel extends AbstractTableModel implements
032: SortableTableModel {
033:
034: public PropertyTableModel(ContelligentComponent component,
035: String visibleGroup) {
036: this .component = component;
037: this .visibleGroup = visibleGroup;
038: updateData();
039: }
040:
041: protected Object[][] getDataArray() {
042: return data;
043: }
044:
045: public boolean isColumnSortable(int column) {
046: return true;
047: }
048:
049: public String getComparable(Object o, int column) {
050:
051: if (column == 0) {
052: ComponentProperty property = (ComponentProperty) o;
053: return property.getName();
054: } else if (column == 1) {
055: ComponentProperty property = (ComponentProperty) o;
056: return property.getValue();
057: } else {
058: return o.toString();
059: }
060: }
061:
062: public void updateData() {
063: Map properties = component.getProperties();
064: int visibleProperties = 0;
065: for (Iterator i = properties.values().iterator(); i.hasNext();) {
066: ComponentProperty property = (ComponentProperty) i.next();
067: TypeProperty typeProperty = property.getTypeProperty();
068: if (visibleGroup == null
069: || typeProperty.isGroup(visibleGroup)) {
070: visibleProperties++;
071: }
072: }
073:
074: data = new Object[visibleProperties][2];
075: int i = 0;
076: for (Iterator j = properties.values().iterator(); j.hasNext();) {
077: ComponentProperty property = (ComponentProperty) j.next();
078: TypeProperty typeProperty = property.getTypeProperty();
079: if (visibleGroup == null
080: || typeProperty.isGroup(visibleGroup)) {
081: data[i][0] = property;
082: data[i][1] = property;
083: i++;
084: }
085: }
086: }
087:
088: public int getColumnCount() {
089: return columnNames.length;
090: }
091:
092: public int getRowCount() {
093: return data.length;
094: }
095:
096: public String getColumnName(int col) {
097: return columnNames[col];
098: }
099:
100: public Object getValueAt(int row, int col) {
101: return data[row][col];
102: }
103:
104: public Class getColumnClass(int c) {
105: return getValueAt(0, c).getClass();
106: }
107:
108: public boolean isCellEditable(int row, int col) {
109: // Note that the data/cell address is constant,
110: // no matter where the cell appears onscreen.
111:
112: if (col == 1) {
113: return editable;
114: }
115: return false;
116: }
117:
118: public void setValueAt(Object value, int row, int col) {
119: component.setModified(true);
120: data[row][col] = value;
121: fireTableCellUpdated(row, 0);
122: fireTableCellUpdated(row, 1);
123: }
124:
125: public void setEditable(boolean editable) {
126: this .editable = editable;
127: }
128:
129: private boolean editable = false;
130:
131: private ContelligentComponent component;
132:
133: private Object[][] data;
134:
135: private String[] columnNames = {
136: Resources.getLocalString("property"),
137: Resources.getLocalString("value") };
138:
139: private String visibleGroup;
140: }
|