root / trunk / extensions / extDataLocator / src / com / iver / gvsig / datalocator / gui / DataSelectionPanel.java @ 6877
History | View | Annotate | Download (27.1 KB)
1 | 2257 | jmorell | /*
|
---|---|---|---|
2 | * Created on 22-jun-2005
|
||
3 | *
|
||
4 | * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
5 | *
|
||
6 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
7 | *
|
||
8 | * This program is free software; you can redistribute it and/or
|
||
9 | * modify it under the terms of the GNU General Public License
|
||
10 | * as published by the Free Software Foundation; either version 2
|
||
11 | * of the License, or (at your option) any later version.
|
||
12 | *
|
||
13 | * This program is distributed in the hope that it will be useful,
|
||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
16 | * GNU General Public License for more details.
|
||
17 | *
|
||
18 | * You should have received a copy of the GNU General Public License
|
||
19 | * along with this program; if not, write to the Free Software
|
||
20 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
21 | *
|
||
22 | * For more information, contact:
|
||
23 | *
|
||
24 | * Generalitat Valenciana
|
||
25 | * Conselleria d'Infraestructures i Transport
|
||
26 | * Av. Blasco Ib??ez, 50
|
||
27 | * 46010 VALENCIA
|
||
28 | * SPAIN
|
||
29 | *
|
||
30 | * +34 963862235
|
||
31 | * gvsig@gva.es
|
||
32 | * www.gvsig.gva.es
|
||
33 | *
|
||
34 | * or
|
||
35 | *
|
||
36 | * IVER T.I. S.A
|
||
37 | * Salamanca 50
|
||
38 | * 46005 Valencia
|
||
39 | * Spain
|
||
40 | *
|
||
41 | * +34 963163400
|
||
42 | * dac@iver.es
|
||
43 | */
|
||
44 | package com.iver.gvsig.datalocator.gui; |
||
45 | |||
46 | import java.awt.event.ItemListener; |
||
47 | 2557 | jmorell | import java.io.IOException; |
48 | 2257 | jmorell | |
49 | import java.util.Comparator; |
||
50 | import java.util.TreeSet; |
||
51 | import java.util.Vector; |
||
52 | import java.util.prefs.Preferences; |
||
53 | |||
54 | import javax.swing.JPanel; |
||
55 | |||
56 | 2557 | jmorell | import com.hardcode.driverManager.DriverLoadException; |
57 | 2257 | jmorell | import com.hardcode.gdbms.engine.data.DataSource; |
58 | 2557 | jmorell | import com.hardcode.gdbms.engine.data.DataSourceFactory; |
59 | import com.hardcode.gdbms.engine.instruction.EvaluationException; |
||
60 | 2257 | jmorell | import com.hardcode.gdbms.engine.instruction.IncompatibleTypesException; |
61 | 2557 | jmorell | import com.hardcode.gdbms.engine.instruction.SemanticException; |
62 | 2257 | jmorell | import com.hardcode.gdbms.engine.values.BooleanValue; |
63 | import com.hardcode.gdbms.engine.values.Value; |
||
64 | 2557 | jmorell | import com.hardcode.gdbms.parser.ParseException; |
65 | 2257 | jmorell | import com.iver.andami.PluginServices; |
66 | 5750 | fjp | import com.iver.andami.plugins.Extension; |
67 | 2276 | jmorell | import com.iver.andami.ui.mdiManager.SingletonView; |
68 | 6877 | cesar | import com.iver.andami.ui.mdiManager.IWindow; |
69 | 2257 | jmorell | import com.iver.andami.ui.mdiManager.ViewInfo; |
70 | 2276 | jmorell | import com.iver.andami.ui.mdiManager.ViewListener; |
71 | 2257 | jmorell | import com.iver.cit.gvsig.fmap.DriverException; |
72 | import com.iver.cit.gvsig.fmap.FMap; |
||
73 | 2276 | jmorell | import com.iver.cit.gvsig.fmap.layers.CancelationException; |
74 | 2257 | jmorell | import com.iver.cit.gvsig.fmap.layers.FBitSet; |
75 | import com.iver.cit.gvsig.fmap.layers.FLayer; |
||
76 | import com.iver.cit.gvsig.fmap.layers.FLayers; |
||
77 | 2399 | jmorell | import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
78 | 2276 | jmorell | import com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent; |
79 | import com.iver.cit.gvsig.fmap.layers.LayerCollectionListener; |
||
80 | import com.iver.cit.gvsig.fmap.layers.LayerPositionEvent; |
||
81 | 2257 | jmorell | import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
82 | import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable; |
||
83 | import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData; |
||
84 | import com.iver.cit.gvsig.fmap.operations.strategies.SelectedZoomVisitor; |
||
85 | import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
||
86 | 5750 | fjp | import com.iver.gvsig.datalocator.DataLocatorExtension; |
87 | 2257 | jmorell | |
88 | import javax.swing.DefaultComboBoxModel; |
||
89 | import javax.swing.JComboBox; |
||
90 | import javax.swing.JDialog; |
||
91 | import javax.swing.JLabel; |
||
92 | import javax.swing.JButton; |
||
93 | 5750 | fjp | import javax.swing.JCheckBox; |
94 | 2276 | jmorell | |
95 | 2257 | jmorell | /**
|
96 | * @author jmorell
|
||
97 | */
|
||
98 | 6877 | cesar | public class DataSelectionPanel extends JPanel implements IWindow, ViewListener, SingletonView { |
99 | 2276 | jmorell | |
100 | 2399 | jmorell | /**
|
101 | *
|
||
102 | */
|
||
103 | private static final long serialVersionUID = 1L; |
||
104 | private JComboBox jComboBox = null; |
||
105 | 2276 | jmorell | private JLabel jLabel = null; // @jve:decl-index=0:visual-constraint="597,16" |
106 | private JLabel jLabel1 = null; // @jve:decl-index=0:visual-constraint="873,44" |
||
107 | 2257 | jmorell | private JComboBox jComboBox1 = null; |
108 | 2276 | jmorell | private JLabel jLabel2 = null; // @jve:decl-index=0:visual-constraint="847,16" |
109 | 2257 | jmorell | private JComboBox jComboBox2 = null; |
110 | private ViewInfo viewInfo = null; |
||
111 | private JButton jButton = null; |
||
112 | private JButton jButton1 = null; |
||
113 | private FLayer layerToZoom = null; |
||
114 | private int fieldToZoomIndex = 0; |
||
115 | private Value itemToZoom = null; |
||
116 | private FMap mapContext = null; |
||
117 | private Preferences prefUsuario = null; |
||
118 | 2276 | jmorell | private LayersListener layersListener = null; |
119 | 2399 | jmorell | private Vector vectorialLayers = null; |
120 | 5750 | fjp | private JCheckBox jChkBoxOpenFirstTime = null; |
121 | 2276 | jmorell | |
122 | 2257 | jmorell | /**
|
123 | * This method initializes
|
||
124 | *
|
||
125 | */
|
||
126 | 5750 | fjp | public DataSelectionPanel(FMap mapContext) {
|
127 | 2257 | jmorell | super();
|
128 | this.mapContext = mapContext;
|
||
129 | 5750 | fjp | prefUsuario = Preferences.userRoot();
|
130 | 2399 | jmorell | initializeVectorialLayers(); |
131 | initializeLayerToZoom(); |
||
132 | 2282 | jmorell | initializeFieldToZoomIndex(); |
133 | initialize(); |
||
134 | 5750 | fjp | |
135 | int userOpen = prefUsuario.getInt("gvSIG.DataLocator.open_first_time", -1); |
||
136 | if (userOpen == 1) |
||
137 | getJChkBoxOpenFirstTime().setSelected(true);
|
||
138 | 2282 | jmorell | } |
139 | 2399 | jmorell | private void initializeVectorialLayers() { |
140 | vectorialLayers = new Vector(); |
||
141 | for (int i=0;i<mapContext.getLayers().getLayersCount();i++) { |
||
142 | if (mapContext.getLayers().getLayer(i) instanceof FLyrVect) vectorialLayers.add(mapContext.getLayers().getLayer(i)); |
||
143 | } |
||
144 | } |
||
145 | 5750 | fjp | private void initializeLayerToZoom() { |
146 | 2257 | jmorell | String layerName = prefUsuario.get("LAYERNAME_FOR_DATA_LOCATION", ""); |
147 | 2399 | jmorell | if (layerName.equals("")) layerToZoom = (FLayer)vectorialLayers.get(0); |
148 | boolean layerFound = false; |
||
149 | for (int i=0;i<vectorialLayers.size();i++) { |
||
150 | if (((FLayer)vectorialLayers.get(i)).getName().equals(layerName)) {
|
||
151 | layerFound = true;
|
||
152 | layerToZoom = (FLayer)vectorialLayers.get(i); |
||
153 | break;
|
||
154 | } |
||
155 | 2257 | jmorell | } |
156 | 2399 | jmorell | if (!layerFound) layerToZoom = (FLayer)vectorialLayers.get(0); |
157 | 5750 | fjp | prefUsuario.put("LAYERNAME_FOR_DATA_LOCATION", layerToZoom.getName());
|
158 | |||
159 | 2282 | jmorell | } |
160 | private void initializeFieldToZoomIndex() { |
||
161 | 2257 | jmorell | fieldToZoomIndex = prefUsuario.getInt("FIELDINDEX_FOR_DATA_LOCATION", 0); |
162 | 2276 | jmorell | AlphanumericData lyr = (AlphanumericData)layerToZoom; |
163 | DataSource ds;
|
||
164 | try {
|
||
165 | ds = lyr.getRecordset(); |
||
166 | if (fieldToZoomIndex > (ds.getFieldCount()-1)) fieldToZoomIndex = 0; |
||
167 | } catch (DriverException e) {
|
||
168 | // TODO Auto-generated catch block
|
||
169 | e.printStackTrace(); |
||
170 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
||
171 | // TODO Auto-generated catch block
|
||
172 | e.printStackTrace(); |
||
173 | } |
||
174 | 2257 | jmorell | } |
175 | /**
|
||
176 | * This method initializes this
|
||
177 | *
|
||
178 | * @return void
|
||
179 | */
|
||
180 | private void initialize() { |
||
181 | jLabel2 = new JLabel(); |
||
182 | jLabel1 = new JLabel(); |
||
183 | jLabel = new JLabel(); |
||
184 | this.setLayout(null); |
||
185 | 2447 | jmorell | this.setSize(286, 161); |
186 | 2276 | jmorell | jLabel.setBounds(6, 6, 43, 23); |
187 | 2484 | jmorell | jLabel.setText(PluginServices.getText(this,"Capa") + ":"); |
188 | 2276 | jmorell | jLabel1.setBounds(6, 34, 43, 23); |
189 | 2484 | jmorell | jLabel1.setText(PluginServices.getText(this,"Campo") + ":"); |
190 | 2276 | jmorell | jLabel2.setBounds(6, 61, 43, 23); |
191 | 2484 | jmorell | jLabel2.setText(PluginServices.getText(this,"Valor") + ":"); |
192 | 2257 | jmorell | this.add(getJComboBox(), null); |
193 | this.add(jLabel, null); |
||
194 | this.add(jLabel1, null); |
||
195 | this.add(getJComboBox1(), null); |
||
196 | this.add(jLabel2, null); |
||
197 | this.add(getJComboBox2(), null); |
||
198 | this.add(getJButton(), null); |
||
199 | this.add(getJButton1(), null); |
||
200 | 5750 | fjp | this.add(getJChkBoxOpenFirstTime(), null); |
201 | 2276 | jmorell | layersListener = new LayersListener(mapContext.getLayers());
|
202 | mapContext.getLayers().addLayerCollectionListener(layersListener); |
||
203 | 2257 | jmorell | } |
204 | 2282 | jmorell | private String[] getLayerNames() { |
205 | 2399 | jmorell | String[] layerNames = new String[vectorialLayers.size()]; |
206 | for (int i=0;i<vectorialLayers.size();i++) { |
||
207 | layerNames[i] = ((FLayer)vectorialLayers.get(i)).getName(); |
||
208 | 2282 | jmorell | } |
209 | return layerNames;
|
||
210 | } |
||
211 | private String[] getFieldNames() { |
||
212 | AlphanumericData lyr = (AlphanumericData)layerToZoom; |
||
213 | DataSource ds;
|
||
214 | String[] fieldNames = null; |
||
215 | try {
|
||
216 | ds = lyr.getRecordset(); |
||
217 | fieldNames = new String[ds.getFieldCount()]; |
||
218 | for (int i = 0; i < ds.getFieldCount(); i++) { |
||
219 | fieldNames[i] = ds.getFieldName(i); |
||
220 | } |
||
221 | } catch (DriverException e) {
|
||
222 | // TODO Auto-generated catch block
|
||
223 | e.printStackTrace(); |
||
224 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
||
225 | // TODO Auto-generated catch block
|
||
226 | e.printStackTrace(); |
||
227 | } |
||
228 | return fieldNames;
|
||
229 | } |
||
230 | private Value[] getNewValues() { |
||
231 | AlphanumericData lyr = (AlphanumericData)layerToZoom; |
||
232 | DataSource ds;
|
||
233 | Value[] newValues = null; |
||
234 | try {
|
||
235 | ds = lyr.getRecordset(); |
||
236 | 2557 | jmorell | String sql = "select * from " + ds.getName() + " where " + ds.getFieldName(fieldToZoomIndex) + " is not null;"; |
237 | 2681 | jmorell | ds = ds.getDataSourceFactory().executeSQL(sql, DataSourceFactory.AUTOMATIC_OPENING); |
238 | 2282 | jmorell | Value[] values = new Value[(int)ds.getRowCount()]; |
239 | for (int i=0;i<ds.getRowCount();i++) { |
||
240 | Value value = ds.getFieldValue(i, fieldToZoomIndex); |
||
241 | values[i] = value; |
||
242 | } |
||
243 | //Quitar los nombres repetidos y ordenarlos
|
||
244 | TreeSet treeSet = new TreeSet(new Comparator() { |
||
245 | public int compare(Object o1, Object o2) { |
||
246 | Value v1 = (Value) o1; |
||
247 | Value v2 = (Value) o2; |
||
248 | try {
|
||
249 | if (((BooleanValue)v1.less(v2)).getValue()){
|
||
250 | return -1; |
||
251 | }else if (((BooleanValue)v1.greater(v2)).getValue()){ |
||
252 | return 1; |
||
253 | }else{
|
||
254 | return 0; |
||
255 | } |
||
256 | } catch (IncompatibleTypesException e) {
|
||
257 | throw new RuntimeException(e); |
||
258 | } |
||
259 | } |
||
260 | }); |
||
261 | for (int i=0;i<values.length;i++) { |
||
262 | treeSet.add(values[i]); |
||
263 | } |
||
264 | newValues = (Value[])treeSet.toArray(new Value[0]); |
||
265 | } catch (DriverException ee) {
|
||
266 | // TODO Auto-generated catch block
|
||
267 | ee.printStackTrace(); |
||
268 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException eee) {
|
||
269 | // TODO Auto-generated catch block
|
||
270 | eee.printStackTrace(); |
||
271 | 2557 | jmorell | } catch (ParseException e) { |
272 | // TODO Auto-generated catch block
|
||
273 | e.printStackTrace(); |
||
274 | } catch (DriverLoadException e) {
|
||
275 | // TODO Auto-generated catch block
|
||
276 | e.printStackTrace(); |
||
277 | } catch (SemanticException e) {
|
||
278 | // TODO Auto-generated catch block
|
||
279 | e.printStackTrace(); |
||
280 | } catch (IOException e) { |
||
281 | // TODO Auto-generated catch block
|
||
282 | e.printStackTrace(); |
||
283 | } catch (EvaluationException e) {
|
||
284 | // TODO Auto-generated catch block
|
||
285 | e.printStackTrace(); |
||
286 | 2282 | jmorell | } |
287 | return newValues;
|
||
288 | } |
||
289 | 2276 | jmorell | private class LayersListener implements LayerCollectionListener { |
290 | public LayersListener(FLayers layers){
|
||
291 | } |
||
292 | /* (non-Javadoc)
|
||
293 | * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdded(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
||
294 | */
|
||
295 | public void layerAdded(LayerCollectionEvent e) { |
||
296 | 2399 | jmorell | initializeVectorialLayers(); |
297 | ((ChangeLayerToZoomItemListener)jComboBox.getItemListeners()[0]).setLayers(vectorialLayers);
|
||
298 | 2276 | jmorell | jComboBox.removeAllItems(); |
299 | 2282 | jmorell | DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getLayerNames()); |
300 | 2276 | jmorell | jComboBox.setModel(defaultModel); |
301 | jComboBox.setSelectedItem(layerToZoom.getName()); |
||
302 | } |
||
303 | /* (non-Javadoc)
|
||
304 | * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoved(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
||
305 | */
|
||
306 | public void layerRemoved(LayerCollectionEvent e) { |
||
307 | 2399 | jmorell | initializeVectorialLayers(); |
308 | ((ChangeLayerToZoomItemListener)jComboBox.getItemListeners()[0]).setLayers(vectorialLayers);
|
||
309 | if (vectorialLayers.size()>0) { |
||
310 | 2276 | jmorell | jComboBox.removeAllItems(); |
311 | 2399 | jmorell | String[] layerNames = new String[vectorialLayers.size()]; |
312 | 2276 | jmorell | boolean currentLayerRemoved = true; |
313 | 2399 | jmorell | for (int i=0;i<vectorialLayers.size();i++) { |
314 | layerNames[i] = ((FLayer)vectorialLayers.get(i)).getName(); |
||
315 | 2276 | jmorell | if (layerToZoom.getName().equals(layerNames[i])) currentLayerRemoved = false; |
316 | } |
||
317 | DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(layerNames); |
||
318 | jComboBox.setModel(defaultModel); |
||
319 | if (currentLayerRemoved) {
|
||
320 | 2399 | jmorell | layerToZoom = ((FLayer)vectorialLayers.get(0));
|
321 | 2282 | jmorell | defaultModel = new DefaultComboBoxModel(getFieldNames()); |
322 | jComboBox1.setModel(defaultModel); |
||
323 | fieldToZoomIndex = 0;
|
||
324 | jComboBox1.setSelectedIndex(fieldToZoomIndex); |
||
325 | defaultModel = new DefaultComboBoxModel(getNewValues()); |
||
326 | jComboBox2.setModel(defaultModel); |
||
327 | itemToZoom = getNewValues()[0];
|
||
328 | jComboBox2.setSelectedItem(itemToZoom); |
||
329 | 2276 | jmorell | } |
330 | jComboBox.setSelectedItem(layerToZoom.getName()); |
||
331 | }else {
|
||
332 | if (PluginServices.getMainFrame() == null) |
||
333 | ((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
||
334 | else
|
||
335 | PluginServices.getMDIManager().closeView(DataSelectionPanel.this); |
||
336 | } |
||
337 | } |
||
338 | /* (non-Javadoc)
|
||
339 | * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoved(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
|
||
340 | */
|
||
341 | public void layerMoved(LayerPositionEvent e) { |
||
342 | 2278 | jmorell | // TODO Auto-generated method stub
|
343 | |||
344 | 2276 | jmorell | } |
345 | /* (non-Javadoc)
|
||
346 | * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdding(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
||
347 | */
|
||
348 | public void layerAdding(LayerCollectionEvent e) throws CancelationException { |
||
349 | // TODO Auto-generated method stub
|
||
350 | |||
351 | } |
||
352 | /* (non-Javadoc)
|
||
353 | * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoving(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
|
||
354 | */
|
||
355 | public void layerMoving(LayerPositionEvent e) throws CancelationException { |
||
356 | // TODO Auto-generated method stub
|
||
357 | |||
358 | } |
||
359 | /* (non-Javadoc)
|
||
360 | * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoving(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
||
361 | */
|
||
362 | public void layerRemoving(LayerCollectionEvent e) throws CancelationException { |
||
363 | // TODO Auto-generated method stub
|
||
364 | |||
365 | } |
||
366 | /* (non-Javadoc)
|
||
367 | * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#activationChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
||
368 | */
|
||
369 | public void activationChanged(LayerCollectionEvent e) throws CancelationException { |
||
370 | // TODO Auto-generated method stub
|
||
371 | |||
372 | } |
||
373 | /* (non-Javadoc)
|
||
374 | * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#visibilityChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
||
375 | */
|
||
376 | public void visibilityChanged(LayerCollectionEvent e) throws CancelationException { |
||
377 | // TODO Auto-generated method stub
|
||
378 | |||
379 | } |
||
380 | } |
||
381 | 2257 | jmorell | /* (non-Javadoc)
|
382 | * @see com.iver.andami.ui.mdiManager.View#getViewInfo()
|
||
383 | */
|
||
384 | public ViewInfo getViewInfo() {
|
||
385 | if (viewInfo == null) { |
||
386 | 5750 | fjp | viewInfo=new ViewInfo(ViewInfo.MODELESSDIALOG | ViewInfo.PALETTE);
|
387 | 2484 | jmorell | viewInfo.setTitle(PluginServices.getText(this,"Localizador_por_atributo")); |
388 | 5750 | fjp | viewInfo.setHeight(getPreferredSize().height); |
389 | viewInfo.setWidth(getPreferredSize().width); |
||
390 | 2257 | jmorell | } |
391 | return viewInfo;
|
||
392 | } |
||
393 | /**
|
||
394 | * This method initializes jComboBox
|
||
395 | *
|
||
396 | * @return javax.swing.JComboBox
|
||
397 | */
|
||
398 | private JComboBox getJComboBox() { |
||
399 | if (jComboBox == null) { |
||
400 | 2399 | jmorell | jComboBox = new JComboBox(); |
401 | DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getLayerNames()); |
||
402 | jComboBox.setModel(defaultModel); |
||
403 | 2276 | jmorell | jComboBox.setBounds(54, 6, 218, 23); |
404 | 2257 | jmorell | jComboBox.setSelectedItem(layerToZoom.getName()); |
405 | 2399 | jmorell | ChangeLayerToZoomItemListener changeLayerToZoomItemListener = new ChangeLayerToZoomItemListener(vectorialLayers);
|
406 | 2257 | jmorell | jComboBox.addItemListener(changeLayerToZoomItemListener); |
407 | } |
||
408 | return jComboBox;
|
||
409 | } |
||
410 | private class ChangeLayerToZoomItemListener implements ItemListener { |
||
411 | 2399 | jmorell | private Vector layers; |
412 | public ChangeLayerToZoomItemListener(Vector layers) { |
||
413 | 2257 | jmorell | this.layers = layers;
|
414 | } |
||
415 | 2276 | jmorell | public void itemStateChanged(java.awt.event.ItemEvent e) { |
416 | if (jComboBox.getItemCount()>0) { |
||
417 | 2399 | jmorell | for (int i=0;i<layers.size();i++) { |
418 | if (((FLayer)layers.get(i)).getName().equals((String)jComboBox.getSelectedItem())) { |
||
419 | layerToZoom = (FLayer)layers.get(i); |
||
420 | break;
|
||
421 | } |
||
422 | } |
||
423 | 2276 | jmorell | fieldToZoomIndex = 0;
|
424 | prefUsuario.put("LAYERNAME_FOR_DATA_LOCATION", (String)jComboBox.getSelectedItem()); |
||
425 | 2282 | jmorell | DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getFieldNames()); |
426 | jComboBox1.setModel(defaultModel); |
||
427 | defaultModel = new DefaultComboBoxModel(getNewValues()); |
||
428 | jComboBox2.setModel(defaultModel); |
||
429 | jComboBox2.setSelectedIndex(0);
|
||
430 | itemToZoom = getNewValues()[0];
|
||
431 | 2276 | jmorell | } |
432 | 2257 | jmorell | } |
433 | 2399 | jmorell | /**
|
434 | * @param layers The layers to set.
|
||
435 | */
|
||
436 | public void setLayers(Vector layers) { |
||
437 | this.layers = layers;
|
||
438 | } |
||
439 | 2257 | jmorell | } |
440 | /**
|
||
441 | * This method initializes jComboBox1
|
||
442 | *
|
||
443 | * @return javax.swing.JComboBox
|
||
444 | */
|
||
445 | private JComboBox getJComboBox1() { |
||
446 | if (jComboBox1 == null) { |
||
447 | 2399 | jmorell | jComboBox1 = new JComboBox(); |
448 | DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getFieldNames()); |
||
449 | jComboBox1.setModel(defaultModel); |
||
450 | 2276 | jmorell | jComboBox1.setBounds(54, 34, 218, 23); |
451 | 2257 | jmorell | jComboBox1.setSelectedIndex(fieldToZoomIndex); |
452 | 2399 | jmorell | ChangeFieldItemListener changeFieldItemListener = new ChangeFieldItemListener(vectorialLayers);
|
453 | 2257 | jmorell | jComboBox1.addItemListener(changeFieldItemListener); |
454 | } |
||
455 | return jComboBox1;
|
||
456 | } |
||
457 | private class ChangeFieldItemListener implements ItemListener { |
||
458 | 2399 | jmorell | public ChangeFieldItemListener(Vector layers) { |
459 | 2257 | jmorell | } |
460 | 2557 | jmorell | public void itemStateChanged(java.awt.event.ItemEvent itemEvent) { |
461 | 2257 | jmorell | String fieldToZoom = ((String)jComboBox1.getSelectedItem()); |
462 | AlphanumericData lyr = (AlphanumericData)layerToZoom; |
||
463 | DataSource ds;
|
||
464 | try {
|
||
465 | ds = lyr.getRecordset(); |
||
466 | for (int i=0;i<ds.getFieldCount();i++) { |
||
467 | String fieldNamei = ds.getFieldName(i);
|
||
468 | if (fieldToZoom.equals(fieldNamei)) {
|
||
469 | fieldToZoomIndex = i; |
||
470 | prefUsuario.putInt("FIELDINDEX_FOR_DATA_LOCATION", i);
|
||
471 | } |
||
472 | } |
||
473 | 2557 | jmorell | String sql = "select * from " + ds.getName() + " where " + ds.getFieldName(fieldToZoomIndex) + " is not null;"; |
474 | 2681 | jmorell | ds = ds.getDataSourceFactory().executeSQL(sql, DataSourceFactory.AUTOMATIC_OPENING); |
475 | 2257 | jmorell | Value[] values = new Value[(int)ds.getRowCount()]; |
476 | for (int i=0;i<ds.getRowCount();i++) { |
||
477 | Value value = ds.getFieldValue(i, fieldToZoomIndex); |
||
478 | 2557 | jmorell | values[i] = value; |
479 | 2257 | jmorell | } |
480 | 2276 | jmorell | //Quitar los nombres repetidos y ordenarlos
|
481 | TreeSet treeSet = new TreeSet(new Comparator() { |
||
482 | public int compare(Object o1, Object o2) { |
||
483 | Value v1 = (Value) o1; |
||
484 | Value v2 = (Value) o2; |
||
485 | try {
|
||
486 | if (((BooleanValue)v1.less(v2)).getValue()){
|
||
487 | return -1; |
||
488 | }else if (((BooleanValue)v1.greater(v2)).getValue()){ |
||
489 | return 1; |
||
490 | }else{
|
||
491 | return 0; |
||
492 | } |
||
493 | } catch (IncompatibleTypesException e) {
|
||
494 | throw new RuntimeException(e); |
||
495 | } |
||
496 | } |
||
497 | }); |
||
498 | for (int i=0;i<values.length;i++) { |
||
499 | treeSet.add(values[i]); |
||
500 | } |
||
501 | Value[] newValues = (Value[])treeSet.toArray(new Value[0]); |
||
502 | DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(newValues); |
||
503 | 2257 | jmorell | jComboBox2.setModel(defaultModel); |
504 | 2557 | jmorell | if (newValues.length>0) jComboBox2.setSelectedIndex(0); |
505 | if (newValues.length>0) { |
||
506 | itemToZoom = newValues[0];
|
||
507 | } else {
|
||
508 | itemToZoom = null;
|
||
509 | } |
||
510 | 2257 | jmorell | } catch (DriverException ee) {
|
511 | // TODO Auto-generated catch block
|
||
512 | ee.printStackTrace(); |
||
513 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException eee) {
|
||
514 | // TODO Auto-generated catch block
|
||
515 | eee.printStackTrace(); |
||
516 | 2557 | jmorell | } catch (ParseException e) { |
517 | // TODO Auto-generated catch block
|
||
518 | e.printStackTrace(); |
||
519 | } catch (DriverLoadException e) {
|
||
520 | // TODO Auto-generated catch block
|
||
521 | e.printStackTrace(); |
||
522 | } catch (SemanticException e) {
|
||
523 | // TODO Auto-generated catch block
|
||
524 | e.printStackTrace(); |
||
525 | } catch (IOException e) { |
||
526 | // TODO Auto-generated catch block
|
||
527 | e.printStackTrace(); |
||
528 | } catch (EvaluationException e) {
|
||
529 | // TODO Auto-generated catch block
|
||
530 | e.printStackTrace(); |
||
531 | 2257 | jmorell | } |
532 | } |
||
533 | } |
||
534 | /**
|
||
535 | * This method initializes jComboBox2
|
||
536 | *
|
||
537 | * @return javax.swing.JComboBox
|
||
538 | */
|
||
539 | private JComboBox getJComboBox2() { |
||
540 | if (jComboBox2 == null) { |
||
541 | 2399 | jmorell | jComboBox2 = new JComboBox(); |
542 | DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getNewValues()); |
||
543 | jComboBox2.setModel(defaultModel); |
||
544 | 2282 | jmorell | jComboBox2.setSelectedIndex(-1);
|
545 | 2276 | jmorell | jComboBox2.setBounds(54, 61, 218, 23); |
546 | 2399 | jmorell | ChangeItemToZoomItemListener changeItemToZoomItemListener = new ChangeItemToZoomItemListener(vectorialLayers);
|
547 | 2257 | jmorell | jComboBox2.addItemListener(changeItemToZoomItemListener); |
548 | } |
||
549 | return jComboBox2;
|
||
550 | } |
||
551 | private class ChangeItemToZoomItemListener implements ItemListener { |
||
552 | 2399 | jmorell | private Vector layers; |
553 | public ChangeItemToZoomItemListener(Vector layers) { |
||
554 | 2257 | jmorell | this.layers = layers;
|
555 | } |
||
556 | public void itemStateChanged(java.awt.event.ItemEvent e) { |
||
557 | 2399 | jmorell | for (int i=0;i<layers.size();i++) { |
558 | if (((FLayer)layers.get(i)).getName().equals((String)jComboBox.getSelectedItem())) { |
||
559 | layerToZoom = (FLayer)layers.get(i); |
||
560 | break;
|
||
561 | } |
||
562 | } |
||
563 | 2257 | jmorell | itemToZoom = ((Value)jComboBox2.getSelectedItem()); |
564 | } |
||
565 | } |
||
566 | /**
|
||
567 | * This method initializes jButton
|
||
568 | *
|
||
569 | * @return javax.swing.JButton
|
||
570 | */
|
||
571 | private JButton getJButton() { |
||
572 | if (jButton == null) { |
||
573 | jButton = new JButton(); |
||
574 | 5750 | fjp | jButton.setBounds(8, 121, 128, 23); |
575 | 2484 | jmorell | jButton.setText(PluginServices.getText(this,"Zoom")); |
576 | 2257 | jmorell | jButton.addActionListener(new java.awt.event.ActionListener() {
|
577 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
578 | 2276 | jmorell | if (jComboBox2.getSelectedIndex()!=-1) { |
579 | AlphanumericData lyr = (AlphanumericData)layerToZoom; |
||
580 | DataSource ds;
|
||
581 | Vector indices = new Vector(); |
||
582 | try {
|
||
583 | ds = lyr.getRecordset(); |
||
584 | 5750 | fjp | Selectable selectable = (Selectable)ds; |
585 | FBitSet fBitSet = selectable.getSelection(); |
||
586 | |||
587 | 2276 | jmorell | for (int i=0;i<ds.getRowCount();i++) { |
588 | Value value = ds.getFieldValue(i, fieldToZoomIndex); |
||
589 | if (((BooleanValue)itemToZoom.equals(value)).getValue()) {
|
||
590 | indices.add(new Integer(i)); |
||
591 | fBitSet.set(i); |
||
592 | } |
||
593 | } |
||
594 | 5750 | fjp | selectable.setSelection(fBitSet); |
595 | SelectedZoomVisitor visitor = new SelectedZoomVisitor();
|
||
596 | ((VectorialData)layerToZoom).process(visitor); |
||
597 | mapContext.getViewPort().setExtent(visitor.getSelectBound()); |
||
598 | selectable.clearSelection(); |
||
599 | |||
600 | 2276 | jmorell | } catch (DriverException ee) {
|
601 | // TODO Auto-generated catch block
|
||
602 | ee.printStackTrace(); |
||
603 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException eee) {
|
||
604 | // TODO Auto-generated catch block
|
||
605 | eee.printStackTrace(); |
||
606 | } catch (IncompatibleTypesException eeee) {
|
||
607 | // TODO Auto-generated catch block
|
||
608 | eeee.printStackTrace(); |
||
609 | 5750 | fjp | } catch (VisitException e2) {
|
610 | // TODO Auto-generated catch block
|
||
611 | e2.printStackTrace(); |
||
612 | } |
||
613 | 2557 | jmorell | } else if (itemToZoom == null) { |
614 | System.out.println("Localizador por atributo: El campo valor debe tener elementos no nulos para hacer el Zoom."); |
||
615 | } else {
|
||
616 | 2276 | jmorell | System.out.println("Localizador por atributo: El campo valor debe estar inicializado antes de hacer Zoom."); |
617 | } |
||
618 | 2257 | jmorell | } |
619 | }); |
||
620 | } |
||
621 | return jButton;
|
||
622 | } |
||
623 | /**
|
||
624 | * This method initializes jButton1
|
||
625 | *
|
||
626 | * @return javax.swing.JButton
|
||
627 | */
|
||
628 | private JButton getJButton1() { |
||
629 | if (jButton1 == null) { |
||
630 | jButton1 = new JButton(); |
||
631 | 5750 | fjp | jButton1.setBounds(141, 121, 128, 23); |
632 | 2484 | jmorell | jButton1.setText(PluginServices.getText(this,"Salir")); |
633 | 2257 | jmorell | jButton1.addActionListener(new java.awt.event.ActionListener() {
|
634 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
635 | if (PluginServices.getMainFrame() == null) |
||
636 | ((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
||
637 | else
|
||
638 | PluginServices.getMDIManager().closeView(DataSelectionPanel.this); |
||
639 | } |
||
640 | }); |
||
641 | } |
||
642 | return jButton1;
|
||
643 | } |
||
644 | 2276 | jmorell | /* (non-Javadoc)
|
645 | * @see com.iver.andami.ui.mdiManager.ViewListener#viewActivated()
|
||
646 | */
|
||
647 | public void viewActivated() { |
||
648 | // TODO Auto-generated method stub
|
||
649 | |||
650 | } |
||
651 | /* (non-Javadoc)
|
||
652 | * @see com.iver.andami.ui.mdiManager.ViewListener#viewClosed()
|
||
653 | */
|
||
654 | public void viewClosed() { |
||
655 | mapContext.getLayers().removeLayerCollectionListener(layersListener); |
||
656 | 5750 | fjp | // Guardamos la posici?n en las preferencias del usuario.
|
657 | ViewInfo vi = PluginServices.getMDIManager().getViewInfo(this);
|
||
658 | prefUsuario.putInt("gvSIG.DataLocator.x", vi.getX());
|
||
659 | prefUsuario.putInt("gvSIG.DataLocator.y", vi.getY());
|
||
660 | prefUsuario.putInt("gvSIG.DataLocator.w", vi.getWidth());
|
||
661 | prefUsuario.putInt("gvSIG.DataLocator.h", vi.getHeight());
|
||
662 | 2276 | jmorell | } |
663 | /* (non-Javadoc)
|
||
664 | * @see com.iver.andami.ui.mdiManager.SingletonView#getViewModel()
|
||
665 | */
|
||
666 | public Object getViewModel() { |
||
667 | // Debe devolver una cadena. Mirar Console del CorePlugin
|
||
668 | return "DataSelectionPanel"; |
||
669 | } |
||
670 | 5750 | fjp | /**
|
671 | * This method initializes jChkBoxOpenFirstTime
|
||
672 | *
|
||
673 | * @return javax.swing.JCheckBox
|
||
674 | */
|
||
675 | private JCheckBox getJChkBoxOpenFirstTime() { |
||
676 | if (jChkBoxOpenFirstTime == null) { |
||
677 | jChkBoxOpenFirstTime = new JCheckBox(); |
||
678 | jChkBoxOpenFirstTime.setBounds(new java.awt.Rectangle(71,89,179,23)); |
||
679 | jChkBoxOpenFirstTime.setText(PluginServices.getText(this, "open_first_time")); |
||
680 | jChkBoxOpenFirstTime.addActionListener(new java.awt.event.ActionListener() {
|
||
681 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
682 | System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed() |
||
683 | if (jChkBoxOpenFirstTime.isSelected())
|
||
684 | { |
||
685 | prefUsuario.putInt("gvSIG.DataLocator.open_first_time",1); |
||
686 | } |
||
687 | else
|
||
688 | { |
||
689 | prefUsuario.putInt("gvSIG.DataLocator.open_first_time",0); |
||
690 | } |
||
691 | } |
||
692 | }); |
||
693 | } |
||
694 | return jChkBoxOpenFirstTime;
|
||
695 | } |
||
696 | 2257 | jmorell | } // @jve:decl-index=0:visual-constraint="10,10" |