svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.fmap.control / src / main / java / org / gvsig / fmap / mapcontrol / dal / feature / swing / table / ConfigurationTableModel.java @ 43354
History | View | Annotate | Download (6.46 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
/*
|
25 |
* AUTHORS (In addition to CIT):
|
26 |
* 2008 {DiSiD Technologies} {Create a JTable TableModel for a FeatureQuery}
|
27 |
*/
|
28 |
package org.gvsig.fmap.mapcontrol.dal.feature.swing.table; |
29 |
|
30 |
import javax.swing.table.AbstractTableModel; |
31 |
|
32 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
33 |
import org.gvsig.i18n.Messages; |
34 |
|
35 |
/**
|
36 |
* TableModel to configure a ConfigurableFeatureTableModel.
|
37 |
*
|
38 |
* Allows to set Feature attributes as visible or not, and to set aliases for
|
39 |
* the Feature attribute names.
|
40 |
*
|
41 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
|
42 |
*/
|
43 |
public class ConfigurationTableModel extends AbstractTableModel { |
44 |
|
45 |
private static final long serialVersionUID = -825156698327593853L; |
46 |
|
47 |
public static final int VISIBILITY_COLUMN = 0; |
48 |
public static final int NAME_COLUMN = 1; |
49 |
public static final int ALIAS_COLUMN = 2; |
50 |
public static final int TYPE_COLUMN = 3; |
51 |
public static final int SIZE_COLUMN = 4; |
52 |
public static final int PRECISION_COLUMN = 5; |
53 |
public static final int PATTERN_COLUMN = 6; |
54 |
|
55 |
private static final int COLUMN_COUNT = 7; |
56 |
|
57 |
|
58 |
|
59 |
private ConfigurableFeatureTableModel configurable;
|
60 |
|
61 |
public ConfigurationTableModel(ConfigurableFeatureTableModel configurable) {
|
62 |
super();
|
63 |
this.configurable = configurable;
|
64 |
} |
65 |
|
66 |
public int getColumnCount() { |
67 |
// 1: visibility, 2: field name, 3: alias, 4:Type, 5:size, 6:pattern
|
68 |
return COLUMN_COUNT;
|
69 |
} |
70 |
|
71 |
public int getRowCount() { |
72 |
return configurable.getOriginalColumnCount();
|
73 |
} |
74 |
|
75 |
public Object getValueAt(int rowIndex, int columnIndex) { |
76 |
FeatureAttributeDescriptor fad = null;
|
77 |
String name = configurable.getOriginalColumnName(rowIndex);
|
78 |
switch (columnIndex) {
|
79 |
case VISIBILITY_COLUMN:
|
80 |
return configurable.isVisible(name);
|
81 |
case NAME_COLUMN:
|
82 |
return name;
|
83 |
case ALIAS_COLUMN:
|
84 |
return configurable.getAliasForColumn(name);
|
85 |
case TYPE_COLUMN:
|
86 |
fad = configurable.internalGetFeatureDescriptorForColumn(rowIndex); |
87 |
if( fad == null ) { |
88 |
return null; |
89 |
} |
90 |
return fad.getDataType().getName();
|
91 |
case SIZE_COLUMN:
|
92 |
fad = configurable.internalGetFeatureDescriptorForColumn(rowIndex); |
93 |
if( fad == null ) { |
94 |
return null; |
95 |
} |
96 |
return fad.getSize();
|
97 |
case PRECISION_COLUMN:
|
98 |
fad = configurable.internalGetFeatureDescriptorForColumn(rowIndex); |
99 |
if( fad == null ) { |
100 |
return null; |
101 |
} |
102 |
return fad.getPrecision();
|
103 |
case PATTERN_COLUMN:
|
104 |
return configurable.getFormattingPattern(name);
|
105 |
default:
|
106 |
return null; |
107 |
} |
108 |
} |
109 |
|
110 |
@Override
|
111 |
public void setValueAt(Object value, int rowIndex, int columnIndex) { |
112 |
String name = configurable.getOriginalColumnName(rowIndex);
|
113 |
switch (columnIndex) {
|
114 |
case VISIBILITY_COLUMN:
|
115 |
configurable.setVisible(name, Boolean.TRUE.equals(value));
|
116 |
break;
|
117 |
case ALIAS_COLUMN:
|
118 |
configurable.setAlias(name, (String) value);
|
119 |
break;
|
120 |
case PATTERN_COLUMN:
|
121 |
configurable.setFormattingPattern(name, (String) value);
|
122 |
} |
123 |
} |
124 |
|
125 |
@Override
|
126 |
public boolean isCellEditable(int rowIndex, int columnIndex) { |
127 |
switch (columnIndex) {
|
128 |
case VISIBILITY_COLUMN:
|
129 |
case ALIAS_COLUMN:
|
130 |
case PATTERN_COLUMN:
|
131 |
return true; |
132 |
default:
|
133 |
return false; |
134 |
} |
135 |
} |
136 |
|
137 |
@Override
|
138 |
public Class<?> getColumnClass(int columnIndex) { |
139 |
switch (columnIndex) {
|
140 |
case VISIBILITY_COLUMN:
|
141 |
return Boolean.class; |
142 |
case NAME_COLUMN:
|
143 |
case ALIAS_COLUMN:
|
144 |
case TYPE_COLUMN:
|
145 |
case PATTERN_COLUMN:
|
146 |
return String.class; |
147 |
case SIZE_COLUMN:
|
148 |
case PRECISION_COLUMN:
|
149 |
/*
|
150 |
* We must use Integer.class instead of int.class
|
151 |
* because int.class does not have a registered
|
152 |
* renderer and its parent class is 'null', so we
|
153 |
* have no renderer for it
|
154 |
*/
|
155 |
return Integer.class; |
156 |
default:
|
157 |
return Object.class; |
158 |
} |
159 |
|
160 |
} |
161 |
|
162 |
@Override
|
163 |
public String getColumnName(int columnIndex) { |
164 |
switch (columnIndex) {
|
165 |
case VISIBILITY_COLUMN:
|
166 |
return Messages.getText("visible"); |
167 |
case NAME_COLUMN:
|
168 |
return Messages.getText("name"); |
169 |
case ALIAS_COLUMN:
|
170 |
return Messages.getText("alias"); |
171 |
case SIZE_COLUMN:
|
172 |
return Messages.getText("size"); |
173 |
case PRECISION_COLUMN:
|
174 |
return Messages.getText("precision"); |
175 |
case TYPE_COLUMN:
|
176 |
return Messages.getText("type"); |
177 |
case PATTERN_COLUMN:
|
178 |
return Messages.getText("pattern"); |
179 |
default:
|
180 |
return ""; |
181 |
} |
182 |
} |
183 |
|
184 |
public static int getVisibilityColumn() { |
185 |
return VISIBILITY_COLUMN;
|
186 |
} |
187 |
|
188 |
/**
|
189 |
* Make current changes in configuration (visible columns and aliases)
|
190 |
* as definitive.
|
191 |
*/
|
192 |
public void acceptChanges() { |
193 |
configurable.acceptChanges(); |
194 |
} |
195 |
|
196 |
/**
|
197 |
* Cancel current changes in configuration (visible columns and aliases)
|
198 |
* and return to previous status.
|
199 |
*/
|
200 |
public void cancelChanges() { |
201 |
configurable.cancelChanges(); |
202 |
} |
203 |
|
204 |
public String getFormattingPattern(String columnName) { |
205 |
return configurable.getFormattingPattern(columnName);
|
206 |
} |
207 |
|
208 |
public void setFormattingPattern(String columnName, String pattern) { |
209 |
configurable.setFormattingPattern(columnName, pattern); |
210 |
} |
211 |
} |