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 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40559 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | *
|
||
6 | 40435 | jjdelcerro | * This program is free software; you can redistribute it and/or
|
7 | * modify it under the terms of the GNU General Public License
|
||
8 | 40559 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * of the License, or (at your option) any later version.
|
10 | 40559 | jjdelcerro | *
|
11 | 40435 | jjdelcerro | * 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 | 40559 | jjdelcerro | *
|
16 | 40435 | jjdelcerro | * 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 | 40559 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | 40435 | jjdelcerro | * MA 02110-1301, USA.
|
20 | 40559 | jjdelcerro | *
|
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 | 40435 | jjdelcerro | */
|
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 | 41056 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
33 | 40435 | jjdelcerro | import org.gvsig.i18n.Messages; |
34 | |||
35 | /**
|
||
36 | * TableModel to configure a ConfigurableFeatureTableModel.
|
||
37 | 41704 | fdiaz | *
|
38 | 40435 | jjdelcerro | * Allows to set Feature attributes as visible or not, and to set aliases for
|
39 | * the Feature attribute names.
|
||
40 | 41704 | fdiaz | *
|
41 | 40435 | jjdelcerro | * @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 | 43354 | jjdelcerro | 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 | 41707 | jjdelcerro | |
55 | private static final int COLUMN_COUNT = 7; |
||
56 | |||
57 | |||
58 | 40435 | jjdelcerro | |
59 | private ConfigurableFeatureTableModel configurable;
|
||
60 | |||
61 | public ConfigurationTableModel(ConfigurableFeatureTableModel configurable) {
|
||
62 | super();
|
||
63 | this.configurable = configurable;
|
||
64 | } |
||
65 | |||
66 | public int getColumnCount() { |
||
67 | 41704 | fdiaz | // 1: visibility, 2: field name, 3: alias, 4:Type, 5:size, 6:pattern
|
68 | 41707 | jjdelcerro | return COLUMN_COUNT;
|
69 | 40435 | jjdelcerro | } |
70 | |||
71 | public int getRowCount() { |
||
72 | return configurable.getOriginalColumnCount();
|
||
73 | } |
||
74 | |||
75 | public Object getValueAt(int rowIndex, int columnIndex) { |
||
76 | 41056 | jjdelcerro | FeatureAttributeDescriptor fad = null;
|
77 | 40435 | jjdelcerro | 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 | 41056 | jjdelcerro | 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 | 41707 | jjdelcerro | case PRECISION_COLUMN:
|
98 | fad = configurable.internalGetFeatureDescriptorForColumn(rowIndex); |
||
99 | if( fad == null ) { |
||
100 | return null; |
||
101 | } |
||
102 | return fad.getPrecision();
|
||
103 | 41704 | fdiaz | case PATTERN_COLUMN:
|
104 | return configurable.getFormattingPattern(name);
|
||
105 | 40435 | jjdelcerro | 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 | 41704 | fdiaz | case PATTERN_COLUMN:
|
121 | configurable.setFormattingPattern(name, (String) value);
|
||
122 | 40435 | jjdelcerro | } |
123 | } |
||
124 | 41704 | fdiaz | |
125 | 40435 | jjdelcerro | @Override
|
126 | public boolean isCellEditable(int rowIndex, int columnIndex) { |
||
127 | switch (columnIndex) {
|
||
128 | case VISIBILITY_COLUMN:
|
||
129 | case ALIAS_COLUMN:
|
||
130 | 41704 | fdiaz | case PATTERN_COLUMN:
|
131 | 40435 | jjdelcerro | 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 | 41056 | jjdelcerro | case TYPE_COLUMN:
|
145 | 41704 | fdiaz | case PATTERN_COLUMN:
|
146 | 40435 | jjdelcerro | return String.class; |
147 | 41056 | jjdelcerro | case SIZE_COLUMN:
|
148 | 41707 | jjdelcerro | case PRECISION_COLUMN:
|
149 | 41103 | jldominguez | /*
|
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 | 40435 | jjdelcerro | 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 | 42115 | mcompany | return Messages.getText("visible"); |
167 | 40435 | jjdelcerro | case NAME_COLUMN:
|
168 | 42115 | mcompany | return Messages.getText("name"); |
169 | 40435 | jjdelcerro | case ALIAS_COLUMN:
|
170 | 42115 | mcompany | return Messages.getText("alias"); |
171 | 41056 | jjdelcerro | case SIZE_COLUMN:
|
172 | 42115 | mcompany | return Messages.getText("size"); |
173 | 41707 | jjdelcerro | case PRECISION_COLUMN:
|
174 | 42115 | mcompany | return Messages.getText("precision"); |
175 | 41056 | jjdelcerro | case TYPE_COLUMN:
|
176 | 42115 | mcompany | return Messages.getText("type"); |
177 | 41704 | fdiaz | case PATTERN_COLUMN:
|
178 | 42115 | mcompany | return Messages.getText("pattern"); |
179 | 40435 | jjdelcerro | default:
|
180 | return ""; |
||
181 | } |
||
182 | } |
||
183 | |||
184 | public static int getVisibilityColumn() { |
||
185 | return VISIBILITY_COLUMN;
|
||
186 | } |
||
187 | 41704 | fdiaz | |
188 | 40435 | jjdelcerro | /**
|
189 | * Make current changes in configuration (visible columns and aliases)
|
||
190 | * as definitive.
|
||
191 | */
|
||
192 | public void acceptChanges() { |
||
193 | configurable.acceptChanges(); |
||
194 | } |
||
195 | 41704 | fdiaz | |
196 | 40435 | jjdelcerro | /**
|
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 | 43354 | jjdelcerro | |
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 | 40435 | jjdelcerro | } |