Statistics
| Revision:

root / trunk / extensions / extDataLocator / src / com / iver / gvsig / datalocator / gui / DataSelectionPanel.java @ 37907

History | View | Annotate | Download (26.6 KB)

1
/*
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.FlowLayout;
47
import java.awt.event.ItemListener;
48
import java.util.Comparator;
49
import java.util.TreeSet;
50
import java.util.Vector;
51
import java.util.prefs.Preferences;
52

    
53
import javax.swing.DefaultComboBoxModel;
54
import javax.swing.JCheckBox;
55
import javax.swing.JComboBox;
56
import javax.swing.JDialog;
57
import javax.swing.JLabel;
58
import javax.swing.JPanel;
59

    
60
import org.gvsig.gui.beans.swing.JButton;
61

    
62
import com.hardcode.driverManager.DriverLoadException;
63
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
64
import com.hardcode.gdbms.engine.data.DataSource;
65
import com.hardcode.gdbms.engine.data.DataSourceFactory;
66
import com.hardcode.gdbms.engine.instruction.EvaluationException;
67
import com.hardcode.gdbms.engine.instruction.IncompatibleTypesException;
68
import com.hardcode.gdbms.engine.instruction.SemanticException;
69
import com.hardcode.gdbms.engine.values.BooleanValue;
70
import com.hardcode.gdbms.engine.values.NullValue;
71
import com.hardcode.gdbms.engine.values.Value;
72
import com.hardcode.gdbms.parser.ParseException;
73
import com.iver.andami.PluginServices;
74
import com.iver.andami.ui.mdiManager.IWindow;
75
import com.iver.andami.ui.mdiManager.IWindowListener;
76
import com.iver.andami.ui.mdiManager.SingletonWindow;
77
import com.iver.andami.ui.mdiManager.WindowInfo;
78
import com.iver.cit.gvsig.exceptions.visitors.VisitorException;
79
import com.iver.cit.gvsig.fmap.MapContext;
80
import com.iver.cit.gvsig.fmap.layers.CancelationException;
81
import com.iver.cit.gvsig.fmap.layers.FBitSet;
82
import com.iver.cit.gvsig.fmap.layers.FLayer;
83
import com.iver.cit.gvsig.fmap.layers.FLayers;
84
import com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent;
85
import com.iver.cit.gvsig.fmap.layers.LayerCollectionListener;
86
import com.iver.cit.gvsig.fmap.layers.LayerPositionEvent;
87
import com.iver.cit.gvsig.fmap.layers.LayersIterator;
88
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
89
import com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection;
90
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable;
91
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData;
92
import com.iver.cit.gvsig.fmap.operations.strategies.SelectedZoomVisitor;
93
import com.iver.gvsig.datalocator.DataLocatorExtension;
94

    
95
/**
96
 * @author jmorell
97
 */
98
public class DataSelectionPanel extends JPanel implements IWindow, IWindowListener, SingletonWindow {
99

    
100
        /**
101
     *
102
     */
103
    private static final long serialVersionUID = 1L;
104
    private JComboBox jComboBox = null;
105
        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
        private JComboBox jComboBox1 = null;
108
        private JLabel jLabel2 = null;  //  @jve:decl-index=0:visual-constraint="847,16"
109
        private JComboBox jComboBox2 = null;
110
    private WindowInfo 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 MapContext mapContext = null;
117
        private Preferences prefUsuario = null;
118
        private Vector layersListenerList = new Vector();
119
    private Vector vectorialLayers = null;
120
        private JCheckBox jChkBoxOpenFirstTime = null;
121
        private JPanel jPanelButtons = null;
122

    
123
        /**
124
         * This method initializes
125
         *
126
         */
127
        public DataSelectionPanel(MapContext mapContext) {
128
                super();
129
                this.mapContext = mapContext;
130
                prefUsuario = Preferences.userRoot();
131
                initializeVectorialLayers();
132
        initializeLayerToZoom();
133
                initializeFieldToZoomIndex();
134
        initialize();
135

    
136
        int userOpen = prefUsuario.getInt("gvSIG.DataLocator.open_first_time", -1);
137
        if (userOpen == 1)
138
                getJChkBoxOpenFirstTime().setSelected(true);
139
        }
140
    private void initializeVectorialLayers() {
141
            unregisterLayersListener();
142
        vectorialLayers = new Vector();
143
        LayersIterator iter = DataLocatorExtension.newValidLayersIterator(mapContext.getLayers());
144

    
145

    
146
        while (iter.hasNext()) {
147
                vectorialLayers.add(iter.nextLayer());
148
        }
149

    
150
        registerLayersListener();
151
    }
152
        private void initializeLayerToZoom() {
153
                String layerName = prefUsuario.get("LAYERNAME_FOR_DATA_LOCATION", "");
154
        if (layerName.equals("")) layerToZoom = (FLayer)vectorialLayers.get(0);
155
        boolean layerFound = false;
156
        for (int i=0;i<vectorialLayers.size();i++) {
157
            if (((FLayer)vectorialLayers.get(i)).getName().equals(layerName)) {
158
                layerFound = true;
159
                layerToZoom = (FLayer)vectorialLayers.get(i);
160
                break;
161
            }
162
        }
163
        if (!layerFound) layerToZoom = (FLayer)vectorialLayers.get(0);
164
        prefUsuario.put("LAYERNAME_FOR_DATA_LOCATION", layerToZoom.getName());
165

    
166
        }
167
        private void initializeFieldToZoomIndex() {
168
        fieldToZoomIndex = prefUsuario.getInt("FIELDINDEX_FOR_DATA_LOCATION", 0);
169
                AlphanumericData lyr = (AlphanumericData)layerToZoom;
170
                DataSource ds;
171
        try {
172
            ds = lyr.getRecordset();
173
            if (fieldToZoomIndex > (ds.getFieldCount()-1)) {
174
                    fieldToZoomIndex = 0;
175
            } else if (ds.getFieldCount() == 0) {
176
                    fieldToZoomIndex = -1;
177
            }
178
        } catch (ReadDriverException e) {
179
                fieldToZoomIndex = -1;
180
            e.printStackTrace();
181
                }
182
        }
183
        /**
184
         * This method initializes this
185
         *
186
         * @return void
187
         */
188
        private void initialize() {
189
        jLabel2 = new JLabel();
190
        jLabel1 = new JLabel();
191
        jLabel = new JLabel();
192
        this.setLayout(null);
193
        this.setSize(350, 161);
194
        jLabel.setBounds(6, 6, 80, 23);
195
        jLabel.setText(PluginServices.getText(this,"Capa") + ":");
196
        jLabel1.setBounds(6, 34, 80, 23);
197
        jLabel1.setText(PluginServices.getText(this,"Campo") + ":");
198
        jLabel2.setBounds(6, 61, 80, 23);
199
        jLabel2.setText(PluginServices.getText(this,"Valor") + ":");
200
        this.add(getJComboBox(), null);
201
        this.add(jLabel, null);
202
        this.add(jLabel1, null);
203
        this.add(getJComboBox1(), null);
204
        this.add(jLabel2, null);
205
        this.add(getJComboBox2(), null);
206

    
207
        jPanelButtons = new JPanel();
208
        FlowLayout flowLayor = new FlowLayout(FlowLayout.RIGHT);
209
        flowLayor.setHgap(5);
210

    
211
        jPanelButtons.setLayout(flowLayor);
212
        jPanelButtons.setBounds(15,121,335,35);
213
        jPanelButtons.add(getJButton(), null);
214
        jPanelButtons.add(getJButton1(), null);
215

    
216
        this.add(jPanelButtons);
217

    
218
        this.add(getJChkBoxOpenFirstTime(), null);
219

    
220

    
221
        }
222
        private void registerLayersListener() {
223
                int i,j;
224
                FLayer layer;
225
                LayersListener listener;
226
                boolean found;
227
                for (i=0;i< vectorialLayers.size();i++) {
228
                        found = false;
229
                        layer = ((FLayer)vectorialLayers.get(i));
230
                        for (j=0;j < layersListenerList.size(); j++) {
231
                                listener = (LayersListener)layersListenerList.get(j);
232
                                if ( layer.getParentLayer() == listener.getLayerCollection()) {
233
                                        found = true;
234
                                        break;
235
                                }
236
                        }
237
                        if (!found) {
238
                                listener = new LayersListener(layer.getParentLayer());
239
                                layer.getParentLayer().addLayerCollectionListener(listener);
240
                                layersListenerList.add(listener);
241
                        }
242

    
243
                }
244
        }
245

    
246

    
247
        private void unregisterLayersListener() {
248
                int i;
249
                LayersListener listener;
250
                for (i=0;i<layersListenerList.size();i++) {
251
                        listener = (LayersListener)layersListenerList.get(i);
252
                        listener.getLayerCollection().removeLayerCollectionListener(listener);
253
                }
254
        }
255

    
256
        private String[] getLayerNames() {
257
                String[] layerNames = new String[vectorialLayers.size()];
258
            for (int i=0;i<vectorialLayers.size();i++) {
259
                layerNames[i] = ((FLayer)vectorialLayers.get(i)).getName();
260
            }
261
            return layerNames;
262
        }
263
        private String[] getFieldNames() {
264
                AlphanumericData lyr = (AlphanumericData)layerToZoom;
265
                DataSource ds;
266
        String[] fieldNames = null;
267
                try {
268
            ds = lyr.getRecordset();
269
                        fieldNames = new String[ds.getFieldCount()];
270
                        for (int i = 0; i < ds.getFieldCount(); i++) {
271
                                fieldNames[i] = ds.getFieldName(i);
272
                        }
273
        } catch (ReadDriverException e) {
274
                        // TODO Auto-generated catch block
275
                        e.printStackTrace();
276
                }
277
                return fieldNames;
278
        }
279
        private Value[] getNewValues() {
280
                AlphanumericData lyr = (AlphanumericData)layerToZoom;
281
                DataSource ds;
282
                Value[] newValues = null;
283
                if (fieldToZoomIndex < 0)
284
                        return null;
285
                try {                        
286
            ds = lyr.getRecordset();
287
            ds.start();
288
//            String sql = "select " + ds.getFieldName(fieldToZoomIndex) + " from " + ds.getName() + " where " + ds.getFieldName(fieldToZoomIndex) + " is not null;";
289
//            ds = ds.getDataSourceFactory().executeSQL(sql, DataSourceFactory.AUTOMATIC_OPENING);
290
//
291
                        //Quitar los nombres repetidos y ordenarlos
292
                        TreeSet treeSet = new TreeSet(new Comparator() {
293
                public int compare(Object o1, Object o2) {
294
                    Value v1 = (Value) o1;
295
                    Value v2 = (Value) o2;
296
                    try {
297
                        if (((BooleanValue)v1.less(v2)).getValue()){
298
                            return -1;
299
                        }else if (((BooleanValue)v1.greater(v2)).getValue()){
300
                            return 1;
301
                        }else{
302
                            return 0;
303
                        }
304
                    } catch (IncompatibleTypesException e) {
305
                        throw new RuntimeException(e);
306
                    }
307
                }
308
            });
309
                        for (int i=0;i<ds.getRowCount();i++) {
310
                            Value value = ds.getFieldValue(i, fieldToZoomIndex);
311
                            if (value instanceof NullValue)
312
                                    continue;
313
                            treeSet.add(value);
314
                        }
315
                        ds.stop();
316
                        newValues = (Value[])treeSet.toArray(new Value[0]);
317
//        } catch (ParseException e) {
318
//            // TODO Auto-generated catch block
319
//            e.printStackTrace();
320
//        } catch (DriverLoadException e) {
321
//            // TODO Auto-generated catch block
322
//            e.printStackTrace();
323
//        } catch (SemanticException e) {
324
//            // Seguramente hemos guardado una capa o un campo que no se encuentran. Ponemos el campo a -1 (la capa se queda la primera activa).
325
//            e.printStackTrace();
326
//            this.fieldToZoomIndex = -1;
327
//            return null;
328
//        } catch (EvaluationException e) {
329
//            // TODO Auto-generated catch block
330
//            e.printStackTrace();
331
        } catch (ReadDriverException e) {
332
                        // TODO Auto-generated catch block
333
                        e.printStackTrace();
334
                }
335
        return newValues;
336
        }
337
        private class LayersListener implements LayerCollectionListener {
338
                private LayerCollection theLayerCollection;
339
            public LayersListener(FLayers layers){
340
                    theLayerCollection = layers;
341
            }
342

    
343
            public LayerCollection getLayerCollection() {
344
                    return theLayerCollection;
345
            }
346
        /* (non-Javadoc)
347
         * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdded(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
348
         */
349
        public void layerAdded(LayerCollectionEvent e) {
350
            initializeVectorialLayers();
351
            ((ChangeLayerToZoomItemListener)jComboBox.getItemListeners()[0]).setLayers(vectorialLayers);
352
            jComboBox.removeAllItems();
353
                    DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getLayerNames());
354
                    jComboBox.setModel(defaultModel);
355
                        jComboBox.setSelectedItem(layerToZoom.getName());
356
        }
357
        /* (non-Javadoc)
358
         * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoved(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
359
         */
360
        public void layerRemoved(LayerCollectionEvent e) {
361
            initializeVectorialLayers();
362
            ((ChangeLayerToZoomItemListener)jComboBox.getItemListeners()[0]).setLayers(vectorialLayers);
363
                    if (vectorialLayers.size()>0) {
364
                    jComboBox.removeAllItems();
365
                                String[] layerNames = new String[vectorialLayers.size()];
366
                            boolean currentLayerRemoved = true;
367
                                for (int i=0;i<vectorialLayers.size();i++) {
368
                                layerNames[i] = ((FLayer)vectorialLayers.get(i)).getName();
369
                                if (layerToZoom.getName().equals(layerNames[i])) currentLayerRemoved = false;
370
                            }
371
                            DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(layerNames);
372
                            jComboBox.setModel(defaultModel);
373
                            if (currentLayerRemoved) {
374
                                layerToZoom = ((FLayer)vectorialLayers.get(0));
375
                                    defaultModel = new DefaultComboBoxModel(getFieldNames());
376
                                jComboBox1.setModel(defaultModel);
377
                                fieldToZoomIndex = 0;
378
                                jComboBox1.setSelectedIndex(fieldToZoomIndex);
379
                                Value[] values =getNewValues();
380
                                    defaultModel = new DefaultComboBoxModel(values);
381
                                    jComboBox2.setModel(defaultModel);
382
                                    if (values != null) {
383
                                            itemToZoom = getNewValues()[0];
384
                                            jComboBox2.setSelectedItem(itemToZoom);
385
                                    }else {
386
                                            itemToZoom = null;
387
                                    }
388

    
389
                            }
390
                            jComboBox.setSelectedItem(layerToZoom.getName());
391
                    }else {
392
                    if (PluginServices.getMainFrame() == null)
393
                            ((JDialog) (getParent().getParent().getParent().getParent())).dispose();
394
                    else
395
                            PluginServices.getMDIManager().closeWindow(DataSelectionPanel.this);
396
                    }
397
        }
398
        /* (non-Javadoc)
399
         * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoved(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
400
         */
401
        public void layerMoved(LayerPositionEvent e) {
402
            // TODO Auto-generated method stub
403

    
404
        }
405
        /* (non-Javadoc)
406
         * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdding(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
407
         */
408
        public void layerAdding(LayerCollectionEvent e) throws CancelationException {
409
            // TODO Auto-generated method stub
410

    
411
        }
412
        /* (non-Javadoc)
413
         * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoving(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
414
         */
415
        public void layerMoving(LayerPositionEvent e) throws CancelationException {
416
            // TODO Auto-generated method stub
417

    
418
        }
419
        /* (non-Javadoc)
420
         * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoving(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
421
         */
422
        public void layerRemoving(LayerCollectionEvent e) throws CancelationException {
423
            // TODO Auto-generated method stub
424

    
425
        }
426
        /* (non-Javadoc)
427
         * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#activationChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
428
         */
429
        public void activationChanged(LayerCollectionEvent e) throws CancelationException {
430
            // TODO Auto-generated method stub
431

    
432
        }
433
        /* (non-Javadoc)
434
         * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#visibilityChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
435
         */
436
        public void visibilityChanged(LayerCollectionEvent e) throws CancelationException {
437
            // TODO Auto-generated method stub
438

    
439
        }
440
        }
441
    /* (non-Javadoc)
442
     * @see com.iver.andami.ui.mdiManager.View#getViewInfo()
443
     */
444
    public WindowInfo getWindowInfo() {
445
        if (viewInfo == null) {
446
            viewInfo=new WindowInfo(WindowInfo.MODELESSDIALOG | WindowInfo.PALETTE);
447
            viewInfo.setTitle(PluginServices.getText(this,"Localizador_por_atributo"));
448
            viewInfo.setHeight(getPreferredSize().height);
449
            viewInfo.setWidth(getPreferredSize().width);
450
        }
451
        return viewInfo;
452
    }
453
        /**
454
         * This method initializes jComboBox
455
         *
456
         * @return javax.swing.JComboBox
457
         */
458
        private JComboBox getJComboBox() {
459
                if (jComboBox == null) {
460
                        jComboBox = new JComboBox();
461
            DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getLayerNames());
462
            jComboBox.setModel(defaultModel);
463
                        jComboBox.setBounds(90, 6, 250, 23);
464
                        jComboBox.setSelectedItem(layerToZoom.getName());
465
                        ChangeLayerToZoomItemListener changeLayerToZoomItemListener = new ChangeLayerToZoomItemListener(vectorialLayers);
466
                        jComboBox.addItemListener(changeLayerToZoomItemListener);
467
                }
468
                return jComboBox;
469
        }
470
        private class ChangeLayerToZoomItemListener implements ItemListener {
471
            private Vector layers;
472
            public ChangeLayerToZoomItemListener(Vector layers) {
473
                this.layers = layers;
474
            }
475
                public void itemStateChanged(java.awt.event.ItemEvent e) {
476
                    if (jComboBox.getItemCount()>0) {
477
                for (int i=0;i<layers.size();i++) {
478
                    if (((FLayer)layers.get(i)).getName().equals((String)jComboBox.getSelectedItem())) {
479
                        layerToZoom = (FLayer)layers.get(i);
480
                        break;
481
                    }
482
                }
483
                            fieldToZoomIndex = 0;
484
                                prefUsuario.put("LAYERNAME_FOR_DATA_LOCATION", (String)jComboBox.getSelectedItem());
485
                        DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getFieldNames());
486
                        jComboBox1.setModel(defaultModel);
487
                        Value[] values =getNewValues();
488
                        defaultModel = new DefaultComboBoxModel(values);
489
                            jComboBox2.setModel(defaultModel);
490
                            if ( values != null) {
491
                                    jComboBox2.setSelectedIndex(0);
492
                                    itemToZoom = values[0];
493
                            } else {
494
                                    itemToZoom = null;
495
                            }
496
                    }
497
                }
498
        /**
499
         * @param layers The layers to set.
500
         */
501
        public void setLayers(Vector layers) {
502
            this.layers = layers;
503
        }
504
        }
505
        /**
506
         * This method initializes jComboBox1
507
         *
508
         * @return javax.swing.JComboBox
509
         */
510
        private JComboBox getJComboBox1() {
511
                if (jComboBox1 == null) {
512
                        jComboBox1 = new JComboBox();
513
            DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getFieldNames());
514
            jComboBox1.setModel(defaultModel);
515
                        jComboBox1.setBounds(90, 34, 250, 23);
516
                        jComboBox1.setSelectedIndex(fieldToZoomIndex);
517
                        ChangeFieldItemListener changeFieldItemListener = new ChangeFieldItemListener(vectorialLayers);
518
                        jComboBox1.addItemListener(changeFieldItemListener);
519
                }
520
                return jComboBox1;
521
        }
522
        private class ChangeFieldItemListener implements ItemListener {
523
            public ChangeFieldItemListener(Vector layers) {
524
            }
525
                public void itemStateChanged(java.awt.event.ItemEvent itemEvent) {
526
                        String fieldToZoom = ((String)jComboBox1.getSelectedItem());
527
                        AlphanumericData lyr = (AlphanumericData)layerToZoom;
528
                        DataSource ds;
529
                        try {
530
                ds = lyr.getRecordset();
531
                            for (int i=0;i<ds.getFieldCount();i++) {
532
                                String fieldNamei = ds.getFieldName(i);
533
                                if (fieldToZoom.equals(fieldNamei)) {
534
                                    fieldToZoomIndex = i;
535
                                            prefUsuario.putInt("FIELDINDEX_FOR_DATA_LOCATION", i);
536
                                }
537
                            }
538
                            Value[] newValues = getNewValues();
539
                        DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(newValues);
540
                        jComboBox2.setModel(defaultModel);
541
                        if (newValues.length>0) jComboBox2.setSelectedIndex(0);
542
                if (newValues.length>0) {
543
                    itemToZoom = newValues[0];
544
                } else {
545
                    itemToZoom = null;
546
                }
547
//            } catch (ParseException e) {
548
//                // TODO Auto-generated catch block
549
//                e.printStackTrace();
550
//            } catch (DriverLoadException e) {
551
//                // TODO Auto-generated catch block
552
//                e.printStackTrace();
553
//            } catch (SemanticException e) {
554
//                // TODO Auto-generated catch block
555
//                e.printStackTrace();
556
//            }catch (EvaluationException e) {
557
//                // TODO Auto-generated catch block
558
//                e.printStackTrace();
559
            } catch (ReadDriverException e) {
560
                                // TODO Auto-generated catch block
561
                                e.printStackTrace();
562
                        }
563
                }
564
        }
565
        /**
566
         * This method initializes jComboBox2
567
         *
568
         * @return javax.swing.JComboBox
569
         */
570
        private JComboBox getJComboBox2() {
571
                if (jComboBox2 == null) {
572
                        jComboBox2 = new JComboBox();
573
            DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getNewValues());
574
            jComboBox2.setModel(defaultModel);
575
                        jComboBox2.setSelectedIndex(-1);
576
                        jComboBox2.setBounds(90, 61, 250, 23);
577
                        ChangeItemToZoomItemListener changeItemToZoomItemListener = new ChangeItemToZoomItemListener(vectorialLayers);
578
                        jComboBox2.addItemListener(changeItemToZoomItemListener);
579
                }
580
                return jComboBox2;
581
        }
582
        private class ChangeItemToZoomItemListener implements ItemListener {
583
            private Vector layers;
584
            public ChangeItemToZoomItemListener(Vector layers) {
585
                this.layers = layers;
586
            }
587
                public void itemStateChanged(java.awt.event.ItemEvent e) {
588
            for (int i=0;i<layers.size();i++) {
589
                if (((FLayer)layers.get(i)).getName().equals((String)jComboBox.getSelectedItem())) {
590
                    layerToZoom = (FLayer)layers.get(i);
591
                    break;
592
                }
593
            }
594
                        itemToZoom = ((Value)jComboBox2.getSelectedItem());
595
                }
596
        }
597
        /**
598
         * This method initializes jButton
599
         *
600
         * @return javax.swing.JButton
601
         */
602
        private JButton getJButton() {
603
                if (jButton == null) {
604
                        jButton = new JButton();
605
                        //jButton.setBounds(8, 121, 128, 23);
606
                        jButton.setText(PluginServices.getText(this,"Zoom"));
607
                        jButton.addActionListener(new java.awt.event.ActionListener() {
608
                                public void actionPerformed(java.awt.event.ActionEvent e) {
609
                                        if (layerToZoom == null || fieldToZoomIndex < 0 || itemToZoom == null)
610
                                                return;
611
                                    if (jComboBox2.getSelectedIndex()!=-1) {
612
                                                AlphanumericData lyr = (AlphanumericData)layerToZoom;
613
                                                DataSource ds;
614
                                                Vector indices = new Vector();
615
                                                try {
616
                                        ds = lyr.getRecordset();
617
                                                        Selectable selectable = (Selectable)ds;
618
                                                        FBitSet fBitSet = selectable.getSelection();
619

    
620
                                                    for (int i=0;i<ds.getRowCount();i++) {
621
                                                        Value value = ds.getFieldValue(i, fieldToZoomIndex);
622
                                                        if (((BooleanValue)itemToZoom.equals(value)).getValue()) {
623
                                                            indices.add(new Integer(i));
624
                                                            fBitSet.set(i);
625
                                                        }
626
                                                    }
627
                                                        selectable.setSelection(fBitSet);
628
                                                        SelectedZoomVisitor visitor = new SelectedZoomVisitor();
629
                                ((VectorialData)layerToZoom).process(visitor);
630
                                            mapContext.getViewPort().setExtent(visitor.getSelectBound());
631
                                            selectable.clearSelection();
632

    
633
                                    } catch (IncompatibleTypesException eeee) {
634
                                // TODO Auto-generated catch block
635
                                eeee.printStackTrace();
636
                            } catch (ReadDriverException e1) {
637
                                                        // TODO Auto-generated catch block
638
                                                        e1.printStackTrace();
639
                                                } catch (VisitorException e1) {
640
                                                        // TODO Auto-generated catch block
641
                                                        e1.printStackTrace();
642
                                                }
643
                    } else if (itemToZoom == null) {
644
                        System.out.println("Localizador por atributo: El campo valor debe tener elementos no nulos para hacer el Zoom.");
645
                    } else {
646
                                        System.out.println("Localizador por atributo: El campo valor debe estar inicializado antes de hacer Zoom.");
647
                                    }
648
                                }
649
                        });
650
                }
651
                return jButton;
652
        }
653
        /**
654
         * This method initializes jButton1
655
         *
656
         * @return javax.swing.JButton
657
         */
658
        private JButton getJButton1() {
659
                if (jButton1 == null) {
660
                        jButton1 = new JButton();
661
                        //jButton1.setBounds(141, 121, 128, 23);
662
                        jButton1.setText(PluginServices.getText(this,"Salir"));
663
                        jButton1.addActionListener(new java.awt.event.ActionListener() {
664
                                public void actionPerformed(java.awt.event.ActionEvent e) {
665
                            if (PluginServices.getMainFrame() == null)
666
                                    ((JDialog) (getParent().getParent().getParent().getParent())).dispose();
667
                            else
668
                                    PluginServices.getMDIManager().closeWindow(DataSelectionPanel.this);
669
                                }
670
                        });
671
                }
672
                return jButton1;
673
        }
674
    /* (non-Javadoc)
675
     * @see com.iver.andami.ui.mdiManager.ViewListener#viewActivated()
676
     */
677
    public void windowActivated() {
678
        // TODO Auto-generated method stub
679

    
680
    }
681
    /* (non-Javadoc)
682
     * @see com.iver.andami.ui.mdiManager.ViewListener#viewClosed()
683
     */
684
    public void windowClosed() {
685
                unregisterLayersListener();
686
                // Guardamos la posici?n en las preferencias del usuario.
687
                WindowInfo vi = PluginServices.getMDIManager().getWindowInfo(this);
688
                prefUsuario.putInt("gvSIG.DataLocator.x", vi.getX());
689
                prefUsuario.putInt("gvSIG.DataLocator.y", vi.getY());
690
                prefUsuario.putInt("gvSIG.DataLocator.w", vi.getWidth());
691
                prefUsuario.putInt("gvSIG.DataLocator.h", vi.getHeight());
692
                vi.setClosed(true);
693
    }
694
    /* (non-Javadoc)
695
     * @see com.iver.andami.ui.mdiManager.SingletonView#getViewModel()
696
     */
697
    public Object getWindowModel() {
698
        // Debe devolver una cadena. Mirar Console del CorePlugin
699
        return "DataSelectionPanel";
700
    }
701
        /**
702
         * This method initializes jChkBoxOpenFirstTime
703
         *
704
         * @return javax.swing.JCheckBox
705
         */
706
        private JCheckBox getJChkBoxOpenFirstTime() {
707
                if (jChkBoxOpenFirstTime == null) {
708
                        jChkBoxOpenFirstTime = new JCheckBox();
709
                        jChkBoxOpenFirstTime.setBounds(new java.awt.Rectangle(90,89,179,23));
710
                        jChkBoxOpenFirstTime.setText(PluginServices.getText(this, "open_first_time"));
711
                        jChkBoxOpenFirstTime.addActionListener(new java.awt.event.ActionListener() {
712
                                public void actionPerformed(java.awt.event.ActionEvent e) {
713
                                        System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
714
                                        if (jChkBoxOpenFirstTime.isSelected())
715
                                        {
716
                                                prefUsuario.putInt("gvSIG.DataLocator.open_first_time",1);
717
                                        }
718
                                        else
719
                                        {
720
                                                prefUsuario.putInt("gvSIG.DataLocator.open_first_time",0);
721
                                        }
722
                                }
723
                        });
724
                }
725
                return jChkBoxOpenFirstTime;
726
        }
727
        public Object getWindowProfile() {
728
                return WindowInfo.TOOL_PROFILE;
729
        }
730
}  //  @jve:decl-index=0:visual-constraint="10,10"