root / branches / v2_0_0_prep / extensions / extGeoDB / src / org / gvsig / geodb / vectorialdb / wizard / TablesListItem.java @ 38608
History | View | Annotate | Download (6.38 KB)
1 | 11971 | caballero | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2006 Prodevelop and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib??ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * Prodevelop Integraci?n de Tecnolog?as SL
|
||
34 | * Conde Salvatierra de ?lava , 34-10
|
||
35 | * 46004 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963 510 612
|
||
39 | * +34 963 510 968
|
||
40 | * gis@prodevelop.es
|
||
41 | * http://www.prodevelop.es
|
||
42 | */
|
||
43 | 29628 | jpiera | package org.gvsig.geodb.vectorialdb.wizard; |
44 | 11971 | caballero | |
45 | 21910 | vcaballero | import java.util.ArrayList; |
46 | 22135 | jmvivo | import java.util.Iterator; |
47 | 21910 | vcaballero | |
48 | 12826 | jaume | import javax.swing.JCheckBox; |
49 | |||
50 | 21910 | vcaballero | import org.cresques.cts.IProjection; |
51 | 37547 | jpiera | |
52 | 29628 | jpiera | import org.gvsig.andami.messages.NotificationManager; |
53 | import org.gvsig.app.addlayer.AddLayerDialog; |
||
54 | import org.gvsig.app.gui.panels.CRSSelectPanel; |
||
55 | 27917 | jmvivo | import org.gvsig.fmap.dal.exception.DataException; |
56 | 24759 | jmvivo | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
57 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
58 | 27909 | jmvivo | import org.gvsig.fmap.dal.serverexplorer.db.DBServerExplorer; |
59 | 27932 | jmvivo | import org.gvsig.fmap.dal.store.db.DBStoreParameters; |
60 | 21910 | vcaballero | |
61 | 11971 | caballero | |
62 | |||
63 | /**
|
||
64 | * Utility class that represents a table list item as a selectable check box.
|
||
65 | *
|
||
66 | * @author jldominguez
|
||
67 | *
|
||
68 | */
|
||
69 | public class TablesListItem extends JCheckBox { |
||
70 | 29199 | jmvivo | protected String tableName = ""; |
71 | 11971 | caballero | private UserSelectedFieldsPanel selectedFieldsPanel = null; |
72 | 29199 | jmvivo | protected WizardDB parent = null; |
73 | 11971 | caballero | private boolean activated = false; |
74 | 12844 | caballero | private CRSSelectPanel jPanelProj;
|
75 | 29199 | jmvivo | protected DBStoreParameters parameters;
|
76 | protected DBServerExplorer explorer;
|
||
77 | protected UserTableSettingsPanel tableSettingsPanel = null; |
||
78 | 11971 | caballero | |
79 | 27909 | jmvivo | public TablesListItem(DBServerExplorer explorer,
|
80 | 27932 | jmvivo | DBStoreParameters param, |
81 | 29199 | jmvivo | WizardDB _parent) { |
82 | 27932 | jmvivo | tableName = param.getTable(); |
83 | 22128 | vcaballero | setText(tableName); |
84 | 27932 | jmvivo | this.parameters = param;
|
85 | 22128 | vcaballero | this.explorer=explorer;
|
86 | 11971 | caballero | parent = _parent; |
87 | } |
||
88 | |||
89 | public void activate() { |
||
90 | activated = true;
|
||
91 | selectedFieldsPanel.loadValues(); |
||
92 | tableSettingsPanel.loadValues(); |
||
93 | } |
||
94 | |||
95 | public boolean isActivated() { |
||
96 | return activated;
|
||
97 | } |
||
98 | |||
99 | /**
|
||
100 | * Tells whether this item prevents the wizard from being in a valid final state.
|
||
101 | * @return whether this item prevents the wizard from being in a valid final state.
|
||
102 | */
|
||
103 | public boolean disturbsWizardValidity() { |
||
104 | if (isSelected()) {
|
||
105 | return (!hasValidValues());
|
||
106 | } |
||
107 | else {
|
||
108 | return false; |
||
109 | } |
||
110 | } |
||
111 | |||
112 | private boolean hasValidValues() { |
||
113 | return tableSettingsPanel.hasValidValues();
|
||
114 | } |
||
115 | |||
116 | public String toString() { |
||
117 | return tableName;
|
||
118 | } |
||
119 | |||
120 | public String getTableName() { |
||
121 | return tableName;
|
||
122 | } |
||
123 | |||
124 | public void setEnabledPanels(boolean b) { |
||
125 | selectedFieldsPanel.enableControls(b); |
||
126 | 22653 | vcaballero | tableSettingsPanel.enableAlphaControls(b); |
127 | 29199 | jmvivo | tableSettingsPanel.enableSpatialControls(b); |
128 | |||
129 | 11971 | caballero | } |
130 | |||
131 | 21910 | vcaballero | public UserSelectedFieldsPanel getUserSelectedFieldsPanel() {
|
132 | 11971 | caballero | if (selectedFieldsPanel == null) { |
133 | 22128 | vcaballero | FeatureType ft=null;
|
134 | try {
|
||
135 | 27917 | jmvivo | ft = explorer.getFeatureType(parameters); |
136 | } catch (DataException e) {
|
||
137 | NotificationManager.addError(e); |
||
138 | return null; |
||
139 | 22128 | vcaballero | } |
140 | 27953 | jmvivo | ArrayList<FeatureAttributeDescriptor> attList = new ArrayList<FeatureAttributeDescriptor>(); |
141 | 27909 | jmvivo | |
142 | 27953 | jmvivo | Iterator<FeatureAttributeDescriptor> iter = ft.iterator();
|
143 | while (iter.hasNext()) {
|
||
144 | attList.add(iter.next()); |
||
145 | } |
||
146 | 27909 | jmvivo | |
147 | 27953 | jmvivo | FeatureAttributeDescriptor[] allf = attList
|
148 | .toArray(new FeatureAttributeDescriptor[0]); |
||
149 | 27909 | jmvivo | |
150 | 27953 | jmvivo | |
151 | 29199 | jmvivo | selectedFieldsPanel = new UserSelectedFieldsPanel(allf, false, |
152 | 11971 | caballero | parent); |
153 | } |
||
154 | |||
155 | return selectedFieldsPanel;
|
||
156 | } |
||
157 | |||
158 | 29199 | jmvivo | public UserTableSettingsPanel getUserTableSettingsPanel() {
|
159 | if (tableSettingsPanel == null) { |
||
160 | 11971 | caballero | |
161 | 29199 | jmvivo | String[] ids = new String[0]; |
162 | FeatureType ft = null;
|
||
163 | 22135 | jmvivo | |
164 | 22128 | vcaballero | try {
|
165 | 27917 | jmvivo | ft = explorer.getFeatureType(parameters); |
166 | } catch (DataException e) {
|
||
167 | NotificationManager.addError(e); |
||
168 | return null; |
||
169 | 22128 | vcaballero | } |
170 | 22135 | jmvivo | |
171 | 29199 | jmvivo | ArrayList auxAll = new ArrayList(); |
172 | 22135 | jmvivo | ArrayList auxId = new ArrayList(); |
173 | 29199 | jmvivo | Iterator iter = ft.iterator();
|
174 | 22135 | jmvivo | while (iter.hasNext()) {
|
175 | 27723 | jmvivo | FeatureAttributeDescriptor dbattr = (FeatureAttributeDescriptor) iter |
176 | 22135 | jmvivo | .next(); |
177 | 29199 | jmvivo | if (dbattr.isPrimaryKey()) {
|
178 | 22135 | jmvivo | auxId.add(dbattr.getName()); |
179 | 29199 | jmvivo | } |
180 | auxAll.add(dbattr.getName()); |
||
181 | 22135 | jmvivo | |
182 | } |
||
183 | |||
184 | 29199 | jmvivo | if (auxId.size() > 0) { |
185 | StringBuilder strb = new StringBuilder(); |
||
186 | strb.append('{');
|
||
187 | for (int i = 0; i < auxId.size()-1; i++) { |
||
188 | 37547 | jpiera | strb.append(auxId.get(i)); |
189 | 29199 | jmvivo | strb.append(',');
|
190 | } |
||
191 | strb.append(auxId.get(auxId.size() - 1));
|
||
192 | 11971 | caballero | |
193 | 29199 | jmvivo | strb.append('}');
|
194 | if (auxId.size() == 1) { |
||
195 | auxAll.remove(auxId.get(0));
|
||
196 | } |
||
197 | auxAll.add(0, strb.toString());
|
||
198 | } |
||
199 | ids = (String[]) auxAll.toArray(new String[auxAll.size()]); |
||
200 | int ids_size = ids.length;
|
||
201 | FieldComboItem[] ids_ci = new FieldComboItem[ids_size]; |
||
202 | 11971 | caballero | |
203 | 29199 | jmvivo | for (int i = 0; i < ids_size; i++) { |
204 | 22135 | jmvivo | ids_ci[i] = new FieldComboItem(ids[i]);
|
205 | } |
||
206 | 11971 | caballero | |
207 | |||
208 | |||
209 | 29199 | jmvivo | tableSettingsPanel = new UserTableSettingsPanel(ids_ci, tableName,
|
210 | true, parent, getParameters());
|
||
211 | } |
||
212 | 11971 | caballero | |
213 | 29199 | jmvivo | return tableSettingsPanel;
|
214 | } |
||
215 | |||
216 | |||
217 | public IProjection currentProjection(String espView, |
||
218 | 12844 | caballero | FieldComboItem[] ids_ci, FieldComboItem[] geos_ci) { |
219 | 13541 | bsanchez | IProjection proj = AddLayerDialog.getLastProjection(); |
220 | 29199 | jmvivo | try {
|
221 | ArrayList list = new ArrayList(1); |
||
222 | list.add(espView); |
||
223 | FeatureType ft = null;
|
||
224 | 12844 | caballero | try {
|
225 | 29199 | jmvivo | ft = explorer.getFeatureType(parameters); |
226 | } catch (DataException e) {
|
||
227 | // TODO Auto-generated catch block
|
||
228 | e.printStackTrace(); |
||
229 | 12844 | caballero | } |
230 | 29199 | jmvivo | } catch (Exception e) { |
231 | NotificationManager.addInfo("Incorrect projection", e);
|
||
232 | } |
||
233 | return proj;
|
||
234 | 12844 | caballero | } |
235 | |||
236 | 23342 | jmvivo | public DBStoreParameters getParameters() {
|
237 | 22128 | vcaballero | return parameters;
|
238 | 22035 | vcaballero | } |
239 | 11971 | caballero | } |