svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extGeoDB / src / com / prodevelop / cit / gvsig / vectorialdb / wizard / TablesListItem.java @ 27723
History | View | Annotate | Download (7.12 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 | package com.prodevelop.cit.gvsig.vectorialdb.wizard; |
||
44 | |||
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 | 24984 | jmvivo | import org.gvsig.fmap.dal.DataTypes; |
52 | 24759 | jmvivo | import org.gvsig.fmap.dal.exception.ReadException; |
53 | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
||
54 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
55 | 22373 | jmvivo | import org.gvsig.fmap.data.feature.db.DBExplorer; |
56 | 23342 | jmvivo | import org.gvsig.fmap.data.feature.db.DBStoreParameters; |
57 | 21910 | vcaballero | import org.gvsig.fmap.mapcontrol.MapControl; |
58 | |||
59 | 12844 | caballero | import com.iver.andami.messages.NotificationManager; |
60 | 13541 | bsanchez | import com.iver.cit.gvsig.addlayer.AddLayerDialog; |
61 | 12844 | caballero | import com.iver.cit.gvsig.gui.panels.CRSSelectPanel; |
62 | 11971 | caballero | |
63 | |||
64 | /**
|
||
65 | * Utility class that represents a table list item as a selectable check box.
|
||
66 | *
|
||
67 | * @author jldominguez
|
||
68 | *
|
||
69 | */
|
||
70 | public class TablesListItem extends JCheckBox { |
||
71 | private String tableName = ""; |
||
72 | private UserSelectedFieldsPanel selectedFieldsPanel = null; |
||
73 | private UserTableSettingsPanel tableSettingsPanel = null; |
||
74 | private MapControl mc;
|
||
75 | private WizardVectorialDB parent = null; |
||
76 | private boolean activated = false; |
||
77 | 12844 | caballero | private CRSSelectPanel jPanelProj;
|
78 | 23342 | jmvivo | private DBStoreParameters parameters;
|
79 | 22128 | vcaballero | private DBExplorer explorer;
|
80 | 11971 | caballero | |
81 | 23342 | jmvivo | public TablesListItem(DBExplorer explorer, DBStoreParameters parameters,
|
82 | MapControl _mc, WizardVectorialDB _parent) { |
||
83 | 22128 | vcaballero | tableName = parameters.getTableName(); |
84 | setText(tableName); |
||
85 | this.parameters = parameters;
|
||
86 | this.explorer=explorer;
|
||
87 | 11971 | caballero | mc = _mc; |
88 | parent = _parent; |
||
89 | } |
||
90 | |||
91 | public void activate() { |
||
92 | activated = true;
|
||
93 | selectedFieldsPanel.loadValues(); |
||
94 | tableSettingsPanel.loadValues(); |
||
95 | } |
||
96 | |||
97 | public boolean isActivated() { |
||
98 | return activated;
|
||
99 | } |
||
100 | |||
101 | /**
|
||
102 | * Tells whether this item prevents the wizard from being in a valid final state.
|
||
103 | * @return whether this item prevents the wizard from being in a valid final state.
|
||
104 | */
|
||
105 | public boolean disturbsWizardValidity() { |
||
106 | if (isSelected()) {
|
||
107 | return (!hasValidValues());
|
||
108 | } |
||
109 | else {
|
||
110 | return false; |
||
111 | } |
||
112 | } |
||
113 | |||
114 | private boolean hasValidValues() { |
||
115 | return tableSettingsPanel.hasValidValues();
|
||
116 | } |
||
117 | |||
118 | public String toString() { |
||
119 | return tableName;
|
||
120 | } |
||
121 | |||
122 | public String getTableName() { |
||
123 | return tableName;
|
||
124 | } |
||
125 | |||
126 | public void setEnabledPanels(boolean b) { |
||
127 | selectedFieldsPanel.enableControls(b); |
||
128 | 22653 | vcaballero | tableSettingsPanel.enableSpatialControls(b); |
129 | tableSettingsPanel.enableAlphaControls(b); |
||
130 | 11971 | caballero | } |
131 | |||
132 | 21910 | vcaballero | public UserSelectedFieldsPanel getUserSelectedFieldsPanel() {
|
133 | 11971 | caballero | if (selectedFieldsPanel == null) { |
134 | 22128 | vcaballero | FeatureType ft=null;
|
135 | try {
|
||
136 | ft = explorer.getFeatureTypes(parameters)[0];
|
||
137 | } catch (ReadException e) {
|
||
138 | // TODO Auto-generated catch block
|
||
139 | e.printStackTrace(); |
||
140 | } |
||
141 | FeatureAttributeDescriptor[] allf=(FeatureAttributeDescriptor[])ft.toArray(new FeatureAttributeDescriptor[0]); |
||
142 | 21910 | vcaballero | selectedFieldsPanel = new UserSelectedFieldsPanel(allf, true, |
143 | 11971 | caballero | parent); |
144 | } |
||
145 | |||
146 | return selectedFieldsPanel;
|
||
147 | } |
||
148 | |||
149 | 21910 | vcaballero | public UserTableSettingsPanel getUserTableSettingsPanel(String espView) { |
150 | 11971 | caballero | if (tableSettingsPanel == null) { |
151 | |||
152 | String[] ids = new String[0]; |
||
153 | 22128 | vcaballero | FeatureType ft=null;
|
154 | 22135 | jmvivo | |
155 | 22128 | vcaballero | try {
|
156 | ft = explorer.getFeatureTypes(parameters)[0];
|
||
157 | } catch (ReadException e) {
|
||
158 | // TODO Auto-generated catch block
|
||
159 | e.printStackTrace(); |
||
160 | } |
||
161 | 22135 | jmvivo | |
162 | |||
163 | ids = ft.getFields(); |
||
164 | 11971 | caballero | |
165 | String[] geos = new String[0]; |
||
166 | 22135 | jmvivo | ArrayList auxGeo = new ArrayList(); |
167 | ArrayList auxId = new ArrayList(); |
||
168 | Iterator iter = ft.iterator();
|
||
169 | while (iter.hasNext()) {
|
||
170 | 27723 | jmvivo | FeatureAttributeDescriptor dbattr = (FeatureAttributeDescriptor) iter |
171 | 22135 | jmvivo | .next(); |
172 | 24984 | jmvivo | if (dbattr.getDataType() == DataTypes.GEOMETRY) {
|
173 | 22135 | jmvivo | auxGeo.add(dbattr.getName()); |
174 | } |
||
175 | 22653 | vcaballero | // if (dbattr.isPrimaryKey()) {
|
176 | 22135 | jmvivo | auxId.add(dbattr.getName()); |
177 | 22653 | vcaballero | // }
|
178 | 22135 | jmvivo | |
179 | } |
||
180 | |||
181 | geos = (String[]) auxGeo.toArray(new String[0]); |
||
182 | ids = (String[]) auxId.toArray(new String[0]); |
||
183 | 11971 | caballero | |
184 | int ids_size = ids.length;
|
||
185 | FieldComboItem[] ids_ci = new FieldComboItem[ids_size]; |
||
186 | |||
187 | 22135 | jmvivo | for (int i = 0; i < ids_size; i++) { |
188 | ids_ci[i] = new FieldComboItem(ids[i]);
|
||
189 | } |
||
190 | 11971 | caballero | |
191 | int geos_size = geos.length;
|
||
192 | FieldComboItem[] geos_ci = new FieldComboItem[geos_size]; |
||
193 | |||
194 | 22135 | jmvivo | for (int i = 0; i < geos_size; i++) { |
195 | geos_ci[i] = new FieldComboItem(geos[i]);
|
||
196 | } |
||
197 | 11971 | caballero | |
198 | tableSettingsPanel = new UserTableSettingsPanel(ids_ci, geos_ci,
|
||
199 | 12844 | caballero | tableName, mc, true, parent, projectionPanel(espView,ids_ci,geos_ci));
|
200 | 11971 | caballero | } |
201 | |||
202 | return tableSettingsPanel;
|
||
203 | } |
||
204 | 12844 | caballero | public CRSSelectPanel projectionPanel(String espView, |
205 | FieldComboItem[] ids_ci, FieldComboItem[] geos_ci) { |
||
206 | 13541 | bsanchez | IProjection proj = AddLayerDialog.getLastProjection(); |
207 | 12844 | caballero | try {
|
208 | 21910 | vcaballero | ArrayList list=new ArrayList(1); |
209 | list.add(espView); |
||
210 | 22128 | vcaballero | FeatureType ft=null;
|
211 | try {
|
||
212 | ft = explorer.getFeatureTypes(parameters)[0];
|
||
213 | } catch (ReadException e) {
|
||
214 | // TODO Auto-generated catch block
|
||
215 | e.printStackTrace(); |
||
216 | } |
||
217 | ft.setAllSRS(list); |
||
218 | 12844 | caballero | } catch (Exception e) { |
219 | NotificationManager.addInfo("Incorrect projection", e);
|
||
220 | } |
||
221 | return getJPanelProj(proj);
|
||
222 | } |
||
223 | private CRSSelectPanel getJPanelProj(IProjection proj) {
|
||
224 | jPanelProj = CRSSelectPanel.getPanel(proj); |
||
225 | |||
226 | jPanelProj.setTransPanelActive(true);
|
||
227 | 13040 | caballero | jPanelProj.setBounds(new java.awt.Rectangle(210, 22, 280, 32)); |
228 | 12844 | caballero | jPanelProj.setPreferredSize(new java.awt.Dimension(448,35)); |
229 | jPanelProj.addActionListener(new java.awt.event.ActionListener() {
|
||
230 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
231 | if (jPanelProj.isOkPressed()) {
|
||
232 | 13541 | bsanchez | AddLayerDialog.setLastProjection(jPanelProj.getCurProj()); |
233 | 12844 | caballero | } |
234 | } |
||
235 | }); |
||
236 | |||
237 | return jPanelProj;
|
||
238 | } |
||
239 | 23342 | jmvivo | public DBStoreParameters getParameters() {
|
240 | 22128 | vcaballero | return parameters;
|
241 | 22035 | vcaballero | } |
242 | 11971 | caballero | } |