Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extDataLocator / src / com / iver / gvsig / datalocator / gui / DataSelectionPanel.java @ 24989

History | View | Annotate | Download (27.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.Value;
71
import com.hardcode.gdbms.parser.ParseException;
72
import com.iver.andami.PluginServices;
73
import com.iver.andami.ui.mdiManager.IWindow;
74
import com.iver.andami.ui.mdiManager.IWindowListener;
75
import com.iver.andami.ui.mdiManager.SingletonWindow;
76
import com.iver.andami.ui.mdiManager.WindowInfo;
77
import com.iver.cit.gvsig.exceptions.visitors.VisitorException;
78
import com.iver.cit.gvsig.fmap.MapContext;
79
import com.iver.cit.gvsig.fmap.layers.CancelationException;
80
import com.iver.cit.gvsig.fmap.layers.FBitSet;
81
import com.iver.cit.gvsig.fmap.layers.FLayer;
82
import com.iver.cit.gvsig.fmap.layers.FLayers;
83
import com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent;
84
import com.iver.cit.gvsig.fmap.layers.LayerCollectionListener;
85
import com.iver.cit.gvsig.fmap.layers.LayerPositionEvent;
86
import com.iver.cit.gvsig.fmap.layers.LayersIterator;
87
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
88
import com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection;
89
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable;
90
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData;
91
import com.iver.cit.gvsig.fmap.operations.strategies.SelectedZoomVisitor;
92
import com.iver.gvsig.datalocator.DataLocatorExtension;
93

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

    
99
        /**
100
     *
101
     */
102
    private static final long serialVersionUID = 1L;
103
    private JComboBox jComboBox = null;
104
        private JLabel jLabel = null;  //  @jve:decl-index=0:visual-constraint="597,16"
105
        private JLabel jLabel1 = null;  //  @jve:decl-index=0:visual-constraint="873,44"
106
        private JComboBox jComboBox1 = null;
107
        private JLabel jLabel2 = null;  //  @jve:decl-index=0:visual-constraint="847,16"
108
        private JComboBox jComboBox2 = null;
109
    private WindowInfo viewInfo = null;
110
        private JButton jButton = null;
111
        private JButton jButton1 = null;
112
        private FLayer layerToZoom = null;
113
        private int fieldToZoomIndex = 0;
114
        private Value itemToZoom = null;
115
        private MapContext mapContext = null;
116
        private Preferences prefUsuario = null;
117
        private Vector layersListenerList = new Vector();
118
    private Vector vectorialLayers = null;
119
        private JCheckBox jChkBoxOpenFirstTime = null;
120
        private JPanel jPanelButtons = null;
121

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

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

    
144

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

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

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

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

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

    
215
        this.add(jPanelButtons);
216

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

    
219

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

    
242
                }
243
        }
244

    
245

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

    
255
        private String[] getLayerNames() {
256
                String[] layerNames = new String[vectorialLayers.size()];
257
            for (int i=0;i<vectorialLayers.size();i++) {
258
                layerNames[i] = ((FLayer)vectorialLayers.get(i)).getName();
259
            }
260
            return layerNames;
261
        }
262
        private String[] getFieldNames() {
263
                AlphanumericData lyr = (AlphanumericData)layerToZoom;
264
                DataSource ds;
265
        String[] fieldNames = null;
266
                try {
267
            ds = lyr.getRecordset();
268
                        fieldNames = new String[ds.getFieldCount()];
269
                        for (int i = 0; i < ds.getFieldCount(); i++) {
270
                                fieldNames[i] = ds.getFieldName(i);
271
                        }
272
        } catch (ReadDriverException e) {
273
                        // TODO Auto-generated catch block
274
                        e.printStackTrace();
275
                }
276
                return fieldNames;
277
        }
278
        private Value[] getNewValues() {
279
                AlphanumericData lyr = (AlphanumericData)layerToZoom;
280
                DataSource ds;
281
                Value[] newValues = null;
282
                if (fieldToZoomIndex < 0)
283
                        return null;
284
                try {
285
            ds = lyr.getRecordset();
286
            String sql = "select " + ds.getFieldName(fieldToZoomIndex) + " from " + ds.getName() + " where " + ds.getFieldName(fieldToZoomIndex) + " is not null;";
287
            ds = ds.getDataSourceFactory().executeSQL(sql, DataSourceFactory.AUTOMATIC_OPENING);
288

    
289
                        //Quitar los nombres repetidos y ordenarlos
290
                        TreeSet treeSet = new TreeSet(new Comparator() {
291
                public int compare(Object o1, Object o2) {
292
                    Value v1 = (Value) o1;
293
                    Value v2 = (Value) o2;
294
                    try {
295
                        if (((BooleanValue)v1.less(v2)).getValue()){
296
                            return -1;
297
                        }else if (((BooleanValue)v1.greater(v2)).getValue()){
298
                            return 1;
299
                        }else{
300
                            return 0;
301
                        }
302
                    } catch (IncompatibleTypesException e) {
303
                        throw new RuntimeException(e);
304
                    }
305
                }
306
            });
307
                        for (int i=0;i<ds.getRowCount();i++) {
308
                            Value value = ds.getFieldValue(i, 0);
309
                            treeSet.add(value);
310
                        }
311
                        newValues = (Value[])treeSet.toArray(new Value[0]);
312
        } catch (ParseException e) {
313
            // TODO Auto-generated catch block
314
            e.printStackTrace();
315
        } catch (DriverLoadException e) {
316
            // TODO Auto-generated catch block
317
            e.printStackTrace();
318
        } catch (SemanticException e) {
319
            // TODO Auto-generated catch block
320
            e.printStackTrace();
321
        } catch (EvaluationException e) {
322
            // TODO Auto-generated catch block
323
            e.printStackTrace();
324
        } catch (ReadDriverException e) {
325
                        // TODO Auto-generated catch block
326
                        e.printStackTrace();
327
                }
328
        return newValues;
329
        }
330
        private class LayersListener implements LayerCollectionListener {
331
                private LayerCollection theLayerCollection;
332
            public LayersListener(FLayers layers){
333
                    theLayerCollection = layers;
334
            }
335

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

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

    
397
        }
398
        /* (non-Javadoc)
399
         * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdding(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
400
         */
401
        public void layerAdding(LayerCollectionEvent e) throws CancelationException {
402
            // TODO Auto-generated method stub
403

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

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

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

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

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

    
641
                                                    for (int i=0;i<ds.getRowCount();i++) {
642
                                                        Value value = ds.getFieldValue(i, fieldToZoomIndex);
643
                                                        if (((BooleanValue)itemToZoom.equals(value)).getValue()) {
644
                                                            indices.add(new Integer(i));
645
                                                            fBitSet.set(i);
646
                                                        }
647
                                                    }
648
                                                        selectable.setSelection(fBitSet);
649
                                                        SelectedZoomVisitor visitor = new SelectedZoomVisitor();
650
                                ((VectorialData)layerToZoom).process(visitor);
651
                                            mapContext.getViewPort().setExtent(visitor.getSelectBound());
652
                                            selectable.clearSelection();
653

    
654
                                    } catch (IncompatibleTypesException eeee) {
655
                                // TODO Auto-generated catch block
656
                                eeee.printStackTrace();
657
                            } catch (ReadDriverException e1) {
658
                                                        // TODO Auto-generated catch block
659
                                                        e1.printStackTrace();
660
                                                } catch (VisitorException e1) {
661
                                                        // TODO Auto-generated catch block
662
                                                        e1.printStackTrace();
663
                                                }
664
                    } else if (itemToZoom == null) {
665
                        System.out.println("Localizador por atributo: El campo valor debe tener elementos no nulos para hacer el Zoom.");
666
                    } else {
667
                                        System.out.println("Localizador por atributo: El campo valor debe estar inicializado antes de hacer Zoom.");
668
                                    }
669
                                }
670
                        });
671
                }
672
                return jButton;
673
        }
674
        /**
675
         * This method initializes jButton1
676
         *
677
         * @return javax.swing.JButton
678
         */
679
        private JButton getJButton1() {
680
                if (jButton1 == null) {
681
                        jButton1 = new JButton();
682
                        //jButton1.setBounds(141, 121, 128, 23);
683
                        jButton1.setText(PluginServices.getText(this,"Salir"));
684
                        jButton1.addActionListener(new java.awt.event.ActionListener() {
685
                                public void actionPerformed(java.awt.event.ActionEvent e) {
686
                            if (PluginServices.getMainFrame() == null)
687
                                    ((JDialog) (getParent().getParent().getParent().getParent())).dispose();
688
                            else
689
                                    PluginServices.getMDIManager().closeWindow(DataSelectionPanel.this);
690
                                }
691
                        });
692
                }
693
                return jButton1;
694
        }
695
    /* (non-Javadoc)
696
     * @see com.iver.andami.ui.mdiManager.ViewListener#viewActivated()
697
     */
698
    public void windowActivated() {
699
        // TODO Auto-generated method stub
700

    
701
    }
702
    /* (non-Javadoc)
703
     * @see com.iver.andami.ui.mdiManager.ViewListener#viewClosed()
704
     */
705
    public void windowClosed() {
706
                unregisterLayersListener();
707
                // Guardamos la posici?n en las preferencias del usuario.
708
                WindowInfo vi = PluginServices.getMDIManager().getWindowInfo(this);
709
                prefUsuario.putInt("gvSIG.DataLocator.x", vi.getX());
710
                prefUsuario.putInt("gvSIG.DataLocator.y", vi.getY());
711
                prefUsuario.putInt("gvSIG.DataLocator.w", vi.getWidth());
712
                prefUsuario.putInt("gvSIG.DataLocator.h", vi.getHeight());
713
    }
714
    /* (non-Javadoc)
715
     * @see com.iver.andami.ui.mdiManager.SingletonView#getViewModel()
716
     */
717
    public Object getWindowModel() {
718
        // Debe devolver una cadena. Mirar Console del CorePlugin
719
        return "DataSelectionPanel";
720
    }
721
        /**
722
         * This method initializes jChkBoxOpenFirstTime
723
         *
724
         * @return javax.swing.JCheckBox
725
         */
726
        private JCheckBox getJChkBoxOpenFirstTime() {
727
                if (jChkBoxOpenFirstTime == null) {
728
                        jChkBoxOpenFirstTime = new JCheckBox();
729
                        jChkBoxOpenFirstTime.setBounds(new java.awt.Rectangle(90,89,179,23));
730
                        jChkBoxOpenFirstTime.setText(PluginServices.getText(this, "open_first_time"));
731
                        jChkBoxOpenFirstTime.addActionListener(new java.awt.event.ActionListener() {
732
                                public void actionPerformed(java.awt.event.ActionEvent e) {
733
                                        System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
734
                                        if (jChkBoxOpenFirstTime.isSelected())
735
                                        {
736
                                                prefUsuario.putInt("gvSIG.DataLocator.open_first_time",1);
737
                                        }
738
                                        else
739
                                        {
740
                                                prefUsuario.putInt("gvSIG.DataLocator.open_first_time",0);
741
                                        }
742
                                }
743
                        });
744
                }
745
                return jChkBoxOpenFirstTime;
746
        }
747
        @Override
748
        public Object getWindowProfile() {
749
                return WindowInfo.TOOL_PROFILE;
750
        }
751
}  //  @jve:decl-index=0:visual-constraint="10,10"