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.modules.types;
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.Type;
026: import de.finix.contelligent.client.base.TypeProperty;
027: import de.finix.contelligent.client.i18n.Resources;
028: import de.finix.contelligent.client.util.SortableTableModel;
029:
030: public class TypeTableModel extends AbstractTableModel implements
031: SortableTableModel {
032:
033: private boolean editable = false;
034:
035: private Type type;
036:
037: private Object[][] data;
038:
039: private String[] columnNames = {
040: Resources.getLocalString("property"),
041: Resources.getLocalString("value"),
042: Resources.getLocalString("type"),
043: Resources.getLocalString("required"),
044: Resources.getLocalString("final"),
045: Resources.getLocalString("mode"),
046: Resources.getLocalString("group"),
047: Resources.getLocalString("constraints") };
048:
049: public TypeTableModel(Type type) {
050: this .type = type;
051: updateData();
052: }
053:
054: protected Object[][] getDataArray() {
055: return data;
056: }
057:
058: public boolean isColumnSortable(int column) {
059: // only first one makes sense...
060: return (column == 0);
061: }
062:
063: public String getComparable(Object o, int column) {
064: return o.toString();
065: }
066:
067: public void setType(Type type) {
068: this .type = type;
069: updateData();
070: fireTableDataChanged();
071: }
072:
073: public void updateData() {
074: if (type == null) {
075: data = new Object[0][8];
076: } else {
077: Map properties = type.getEffectivePropertyMap();
078:
079: data = new Object[properties.size()][8];
080:
081: int i = 0;
082: for (Iterator j = properties.values().iterator(); j
083: .hasNext();) {
084: TypeProperty property = (TypeProperty) j.next();
085: data[i][0] = property;
086: data[i][1] = property;
087: data[i][2] = property;
088: data[i][3] = property;
089: data[i][4] = property;
090: data[i][5] = property;
091: data[i][6] = property;
092: data[i][7] = property;
093: i++;
094: }
095: }
096: }
097:
098: public int getColumnCount() {
099: return columnNames.length;
100: }
101:
102: public int getRowCount() {
103: return data.length;
104: }
105:
106: public String getColumnName(int col) {
107: return columnNames[col];
108: }
109:
110: public Object getValueAt(int row, int col) {
111: return data[row][col];
112: }
113:
114: public Class getColumnClass(int c) {
115: return TypeProperty.class;
116: }
117:
118: public boolean isCellEditable(int row, int col) {
119: // Note that the data/cell address is constant,
120: // no matter where the cell appears onscreen.
121:
122: if (col == 1) {
123: return editable;
124: }
125: return false;
126: }
127:
128: public void setValueAt(Object value, int row, int col) {
129: data[row][col] = value;
130: fireTableCellUpdated(row, 0);
131: fireTableCellUpdated(row, 1);
132: }
133:
134: public void setEditable(boolean editable) {
135: this .editable = editable;
136: }
137:
138: public Type getType() {
139: return type;
140: }
141:
142: }
|