Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extWFS2 / src / com / iver / cit / gvsig / gui / panels / WFSParamsPanel.java @ 8746

History | View | Annotate | Download (15.8 KB)

1
package com.iver.cit.gvsig.gui.panels;
2

    
3
import java.awt.event.FocusEvent;
4
import java.awt.event.FocusListener;
5
import java.io.ObjectInputStream.GetField;
6
import java.util.prefs.Preferences;
7

    
8
import javax.swing.JTabbedPane;
9

    
10
import org.gvsig.remoteClient.wfs.WFSStatus;
11

    
12
import com.iver.andami.PluginServices;
13
import com.iver.cit.gvsig.fmap.drivers.wfs.FMapWFSDriver;
14
import com.iver.cit.gvsig.fmap.layers.FLayer;
15
import com.iver.cit.gvsig.fmap.layers.FLyrWFS;
16
import com.iver.cit.gvsig.fmap.layers.WFSLayerNode;
17
import com.iver.cit.gvsig.gui.WizardPanel;
18
import com.iver.cit.gvsig.gui.wizards.WFSWizardData;
19
import com.iver.cit.gvsig.gui.wizards.WizardListener;
20
import com.iver.cit.gvsig.gui.wizards.WizardListenerSupport;
21

    
22
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
23
 *
24
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
25
 *
26
 * This program is free software; you can redistribute it and/or
27
 * modify it under the terms of the GNU General Public License
28
 * as published by the Free Software Foundation; either version 2
29
 * of the License, or (at your option) any later version.
30
 *
31
 * This program is distributed in the hope that it will be useful,
32
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
34
 * GNU General Public License for more details.
35
 *
36
 * You should have received a copy of the GNU General Public License
37
 * along with this program; if not, write to the Free Software
38
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
39
 *
40
 * For more information, contact:
41
 *
42
 *  Generalitat Valenciana
43
 *   Conselleria d'Infraestructures i Transport
44
 *   Av. Blasco Ib??ez, 50
45
 *   46010 VALENCIA
46
 *   SPAIN
47
 *
48
 *      +34 963862235
49
 *   gvsig@gva.es
50
 *      www.gvsig.gva.es
51
 *
52
 *    or
53
 *
54
 *   IVER T.I. S.A
55
 *   Salamanca 50
56
 *   46005 Valencia
57
 *   Spain
58
 *
59
 *   +34 963163400
60
 *   dac@iver.es
61
 */
62
/* CVS MESSAGES:
63
 *
64
 * $Id: WFSParamsPanel.java 8746 2006-11-14 13:45:49Z ppiqueras $
65
 * $Log$
66
 * Revision 1.20  2006-11-14 13:45:49  ppiqueras
67
 * A?adida peque?a funcionalidad:
68
 * Cuando se pulsa el bot?n "Aplicar", (al seleccionar un nuevo filtro), si el ?rbol de campos posee alguno seleccionado, actualiza los valores (con los nuevos), asociados a ?ste campo seleccionado.
69
 *
70
 * Revision 1.19  2006/10/27 12:10:02  ppiqueras
71
 * Nueva funcionalidad
72
 *
73
 * Revision 1.16  2006/10/23 07:37:04  jorpiell
74
 * Ya funciona el filterEncoding
75
 *
76
 * Revision 1.14  2006/10/13 13:05:32  ppiqueras
77
 * Permite el refrescado de datos del panel de filtrado sobre capa WFS.
78
 *
79
 * Revision 1.13  2006/10/10 12:55:06  jorpiell
80
 * Se ha a?adido el soporte de features complejas
81
 *
82
 * Revision 1.12  2006/10/02 09:17:48  jorpiell
83
 * A?adido el setCRS a la capa
84
 *
85
 * Revision 1.11  2006/09/29 13:02:38  ppiqueras
86
 * Filtro para WFS. De momento s?lo interfaz gr?fica.
87
 *
88
 * Revision 1.10  2006/07/21 11:50:31  jaume
89
 * improved appearance
90
 *
91
 * Revision 1.9  2006/06/21 12:35:45  jorpiell
92
 * Se ha a?adido la ventana de propiedades. Esto implica a?adir listeners por todos los paneles. Adem?s no se muestra la geomatr?a en la lista de atributos y se muestran ?nicamnete los que se van a descargar
93
 *
94
 * Revision 1.8  2006/06/15 07:50:58  jorpiell
95
 * A?adida la funcionalidad de reproyectar y hechos algunos cambios en la interfaz
96
 *
97
 * Revision 1.7  2006/05/25 16:22:47  jorpiell
98
 * Se limpia el panel cada vez que se conecta con un servidor distinto
99
 *
100
 * Revision 1.6  2006/05/25 16:01:43  jorpiell
101
 * Se ha a?adido la funcionalidad para eliminar el namespace de los tipos de atributos
102
 *
103
 * Revision 1.5  2006/05/25 10:31:06  jorpiell
104
 * Como ha cambiado la forma de mostrar las capas (una tabla, en lugar de una lista), los paneles han tenido que ser modificados
105
 *
106
 * Revision 1.4  2006/05/23 08:09:39  jorpiell
107
 * Se ha cambiado la forma en la que se leian los valores seleccionados en los paneles y se ha cambiado el comportamiento de los botones
108
 *
109
 * Revision 1.3  2006/05/19 12:57:08  jorpiell
110
 * Modificados algunos paneles
111
 *
112
 * Revision 1.2  2006/04/20 16:38:24  jorpiell
113
 * Ahora mismo ya se puede hacer un getCapabilities y un getDescribeType de la capa seleccionada para ver los atributos a dibujar. Queda implementar el panel de opciones y hacer el getFeature().
114
 *
115
 * Revision 1.1  2006/04/19 12:50:16  jorpiell
116
 * Primer commit de la aplicaci?n. Se puede hacer un getCapabilities y ver el mensaje de vienvenida del servidor
117
 *
118
 *
119
 */
120
/**
121
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
122
 */
123
public class WFSParamsPanel extends WizardPanel{
124
        private JTabbedPane jTabbedPane = null;  //  @jve:decl-index=0:visual-constraint="37,30"
125
        private WFSSelectFeaturePanel featurePanel = null;
126
        private WFSSelectAttributesPanel fieldsPanel = null;
127
        private WFSOptionsPanel optionsPanel = null;
128
        private WFSFormatPanel formatPanel = null;
129
        private WFSFilterPanel filterPanel = null;
130
        private WFSAreaPanel areaPanel = null;
131
        private WFSWizardData data;
132
        private WizardListenerSupport listenerSupport;
133
        public        static Preferences fPrefs = Preferences.userRoot().node( "gvsig.wcs-wizard" );
134
        private WFSInfoPanel infoPanel;
135
        private int indFields;
136
        private int indFormat;
137
        private int indFilter;
138
        private int indArea;
139
        
140

    
141
        /**
142
         * This method initializes jTabbedPane
143
         *
144
         * @return javax.swing.JTabbedPane
145
         */
146

    
147
        public WFSParamsPanel(){
148
                super();
149
                initialize();
150
        }
151
        /**
152
         * Returns the tab amount that the WFSParamsPanel currently have
153
         *
154
         * Devuelve el n?mero de solapas que tiene actualmente el WFSParamsPanel
155
         *
156
         * @return int
157
         */
158
        public int getNumTabs(){
159
                 return getJTabbedPane().getTabCount();
160
        }
161

    
162
        private void initialize() {
163
                this.setLayout(null);
164
                this.setVisible(false);
165
                this.setBounds(0, 0, 510, 427);
166
                this.add(getJTabbedPane(), null);
167
        }
168

    
169
        /**
170
         * Sets the focus to the tab next to the current one.
171
         *
172
         * Enfoca a la solapa siguiente a la actualmente enfocada del TabbedPane
173
         *
174
         */
175
        public void avanzaTab(){
176
            int currentPage = currentPage();
177
            int nPages = getNumTabs();
178
                if (nPages -1 > currentPage){
179
                        getJTabbedPane().setSelectedIndex(nextPageEnabled());
180
                }
181
        }
182

    
183
        /**
184
         * Sets the focus to the tab previous to the current one.
185
         *
186
         * Enfoca a la solapa anterior a la actualmente enfocada del TabbedPane
187
         *
188
         */
189
        public void retrocedeTab(){
190
                this.getJTabbedPane().setSelectedIndex(previousEnabledPage());
191
        }
192

    
193
        /**
194
         * Returns the current tab index.
195
         *
196
         * Devuelve el n?mero de solapa en que se encuentra
197
         *
198
         * @return
199
         */
200
        public int getIndiceSolapaActual(){
201
                return this.getJTabbedPane().getSelectedIndex();
202
        }
203

    
204
        public JTabbedPane getJTabbedPane() {
205
                if (jTabbedPane == null) {
206
                        jTabbedPane = new JTabbedPane();
207
                        jTabbedPane.setBounds(4, 4, 502, 415);
208
                        jTabbedPane.addTab(PluginServices.getText(this, "info"), null, getInfoPanel());
209
                        jTabbedPane.addTab(PluginServices.getText(this, "feature"), null, getFeaturesPanel(), null);
210
                        jTabbedPane.addTab(PluginServices.getText(this, "attributes"),null, getAttributesPanel(), null);
211
                        indFields = jTabbedPane.getTabCount() - 1;
212
                        jTabbedPane.setEnabledAt(indFields, false);
213
                        //jTabbedPane.addTab(PluginServices.getText(this,"formatos"),null,getFormatPanel(),null);
214
//                        indFormat = jTabbedPane.getTabCount() - 1;
215
//                        jTabbedPane.setEnabledAt(indFormat, false);
216
                        jTabbedPane.addTab(PluginServices.getText(this, "options"),null, getOptionsPanel(), null);
217
                        jTabbedPane.addTab(PluginServices.getText(this, "filter"),null, getFilterPanel(), null);
218
                        indFilter = jTabbedPane.getTabCount() - 1;
219
                        jTabbedPane.setEnabledAt(indFilter, false);
220
                        //jTabbedPane.addTab(PluginServices.getText(this, "area"),null, getAreaPanel(), null);
221
                        indArea = jTabbedPane.getTabCount() - 1;
222
                        jTabbedPane.setEnabledAt(indArea, false);
223
                }
224
                return jTabbedPane;
225
        }
226

    
227
        private WFSInfoPanel getInfoPanel() {
228
                if (infoPanel==null) {
229
                        infoPanel = new WFSInfoPanel();
230
                        infoPanel.addFocusListener(new FocusListener() {
231
                                public void focusGained(java.awt.event.FocusEvent e) {
232
                                        refreshInfo();
233
                                }
234

    
235
                                private void refreshInfo() {
236
                                        WFSLayerNode selectedNode = featurePanel.getSelectedFeature();
237
                                        if (selectedNode != null){
238
                                                selectedNode.setSelectedFields(fieldsPanel.getSelectedFields());
239
                                        }
240
                                        data.setUserName(optionsPanel.getUserName());
241
                                        data.setBuffer(optionsPanel.getBuffer());
242
                                        data.setTimeOut(optionsPanel.getTimeout());
243
                                        infoPanel.refresh(data,selectedNode);
244
                                }
245

    
246
                                public void focusLost(FocusEvent e) {
247

    
248
                                }
249
                        });
250
                }
251
                return infoPanel;
252
        }
253

    
254
        /**
255
         *
256
         * @return the selected list
257
         */
258
        private Object getSelectedFeature() {
259
                return featurePanel.getSelectedFeature();
260
        }
261

    
262

    
263
        /**
264
         * This method initializes panelFeatures
265
         *
266
         * @return javax.swing.JPanel
267
         */
268
        private WFSSelectFeaturePanel getFeaturesPanel() {
269
                if (featurePanel == null) {
270
                        featurePanel = new WFSSelectFeaturePanel(this);
271
                        featurePanel.setLayout(null);
272
                }
273
                return featurePanel;
274
        }
275

    
276
        /**
277
         * This method initializes fieldsPanel
278
         *
279
         * @return javax.swing.JPanel
280
         */
281
        private WFSSelectAttributesPanel getAttributesPanel(){
282
                if (fieldsPanel == null) {
283
                        fieldsPanel = new WFSSelectAttributesPanel(this);
284
                        fieldsPanel.setLayout(null);
285
                }
286
                return fieldsPanel;
287
        }
288

    
289

    
290

    
291
        /**
292
         * This method initializes fieldsPanel
293
         *
294
         * @return javax.swing.JPanel
295
         */
296
        private WFSOptionsPanel getOptionsPanel(){
297
                if (optionsPanel == null) {
298
                        optionsPanel = new WFSOptionsPanel(this);
299
                        optionsPanel.setLayout(null);
300
                }
301
                return optionsPanel;
302
        }
303

    
304
        
305
        /**
306
         * This method initializes filterPanel
307
         * 
308
         * @return javax.swing.JPanel
309
         */
310
        private WFSFilterPanel getFilterPanel(){
311
                if (filterPanel == null) {
312
                        filterPanel = new WFSFilterPanel(this);
313
                        filterPanel.setVisible(true);
314
                        //filterPanel.setLayout(null);
315
                }
316
                return filterPanel;
317
        }
318
        
319
        /**
320
         * This method initializes areaPanel
321
         * 
322
         * @return javax.swing.JPanel
323
         */
324
        private WFSAreaPanel getAreaPanel(){
325
                if (areaPanel == null) {
326
                        areaPanel = new WFSAreaPanel(this);
327
                        areaPanel.setVisible(true);                        
328
                }
329
                return areaPanel;
330
        }
331

    
332
        /**
333
         * This method initializes formatPanel
334
         *
335
         * @return javax.swing.JPanel
336
         */
337
        private WFSFormatPanel getFormatPanel(){
338
                if (formatPanel == null) {
339
                        formatPanel = new WFSFormatPanel();
340
                        formatPanel.setLayout(null);
341
                }
342
                return formatPanel;
343
        }
344

    
345
        /**
346
         * Verifies that the selected parameters are enough to request the coverage
347
         * to the server.
348
         *
349
         * Comprueba que los par?metros seleccionados son suficientes para pedir la
350
         * cobertura al servidor.
351
         *
352
         * @return boolean
353
         */
354
        public boolean isCorretlyConfigured() {
355
                if (featurePanel.getSelectedFeature()!= null){
356
                        return true;
357
                }else{
358
                        return false;
359
                }
360
        }
361

    
362
        /**
363
         * Cleans up the wizard's components but the server's layers list.
364
         *
365
         * Limpia todos los componentes del wizard excepto la lista de capas del
366
         * servidor.
367
         */
368
        public void cleanupWizard() {
369
                jTabbedPane.setEnabledAt(indFields,false);
370
//                jTabbedPane.setEnabledAt(indFormat,false);
371
        }
372

    
373
        /**
374
         * Refreshes the wizard components data each time a feature
375
         * is selected.
376
         *
377
         * Actualiza los datos de los componentes del wizard cada vez
378
         * que se selecciona una feature diferente.
379
         *
380
         * @param feature
381
         * Selected feature
382
         */
383
        public void refreshData(WFSLayerNode feature){
384
                if (feature != null){
385
                        feature = (WFSLayerNode)data.getFeatureInfo(feature.getName());
386
                        jTabbedPane.setEnabledAt(indFields,true);
387
                        jTabbedPane.setEnabledAt(indFilter,true);
388
                        jTabbedPane.setEnabledAt(indArea,true);
389
                        fieldsPanel.refresh(feature);
390
                        optionsPanel.refresh(feature);
391
                        filterPanel.refresh(feature);
392
                }
393
                listenerSupport.callStateChanged(isCorretlyConfigured());
394

    
395
        }
396

    
397
        public void refreshInfo(WFSLayerNode feature){
398
                infoPanel.refresh(data,feature);
399
        }
400

    
401
        /**
402
         * Sets the object that holds the wizard data.
403
         *
404
         * Establece el objeto que contiene los datos del wizard.
405
         *
406
         * @param data
407
         */
408
        public void setWizardData(WFSWizardData data) {
409
                this.data = data;
410
                //WFSLayerNode selectedNode = (WFSLayerNode)featurePanel.getSelectedFeature();
411
                featurePanel.setWizardData(data);
412
                data.setBuffer(optionsPanel.getBuffer());
413
                data.setTimeOut(optionsPanel.getTimeout());
414
                infoPanel.refresh(data,null);
415
        }
416

    
417
        /**
418
         * Sets the wizard's data source
419
         *
420
         * Establece el origen de los datos del wizard
421
         * @param dataSource
422
         */
423
        public void setDataSource(WFSWizardData dataSource) {
424
                this.data = dataSource;
425

    
426
        }
427

    
428

    
429
    /**
430
     * Returns the next enabled tab's index.
431
     *
432
     * Devuelve el ?ndicie de la siguiente pesta?a habilitada del wizard o -1 si no hay
433
     * ninguna.
434
     *
435
     * @return The index or -1 if there is no one.
436
     */
437
    public int nextPageEnabled() {
438
        int currentPage = currentPage();
439
        int nPages = getNumTabs();
440
        if (currentPage == nPages)
441
                return -1;
442
        for (int i=currentPage+1; i<nPages; i++){
443
            if (getJTabbedPane().isEnabledAt(i)){
444
                return i;
445
            }
446
        }
447
        return -1;
448
    }
449

    
450
    /**
451
     * Returns the index of the current tab.
452
     *
453
     * Devuelve el ?ndice de la p?gina actual del wizard.
454
     *
455
     * @return
456
     */
457
    public int currentPage() {
458
        return getJTabbedPane().getSelectedIndex();
459
    }
460

    
461
    /**
462
     * Returns the index of the previous enabled tab.
463
     *
464
     * Devuelve el ?ndice de la anterior p?gina habilitada del wizard o -1 si no hay
465
     * ninguna.
466
     *
467
     * @return The index, or -1 if there is no one.
468
     */
469
    public int previousEnabledPage() {
470
        int currentPage = currentPage();
471
        int j=0;
472
        if (currentPage == 0)
473
            j= -1;
474
        for (int i = currentPage-1; i>-1; i--){
475
            if (getJTabbedPane().isEnabledAt(i)){
476
                j= i;
477
                    break;
478
            }
479
        }
480
        return j;
481
    }
482

    
483
        public FMapWFSDriver getDriver() {
484
                return data.getDriver();
485
        }
486

    
487
        public void setListenerSupport(WizardListenerSupport support) {
488
                listenerSupport = support;
489
        }
490

    
491

    
492
        /*
493
         *  (non-Javadoc)
494
         * @see com.iver.cit.gvsig.gui.WizardPanel#initWizard()
495
         */
496
        public void initWizard() {
497

    
498
        }
499

    
500
        /*
501
         *  (non-Javadoc)
502
         * @see com.iver.cit.gvsig.gui.WizardPanel#execute()
503
         */
504
        public void execute() {
505

    
506
        }
507

    
508
        /*
509
         *  (non-Javadoc)
510
         * @see com.iver.cit.gvsig.gui.ILayerPanel#getLayer()
511
         */
512
        public FLayer getLayer() {
513
                FLyrWFS layer = new FLyrWFS();
514
                layer.setName(getFeaturesPanel().getLayerText());
515
                layer.setLayerName(getFeaturesPanel().getLayerName());
516
                layer.setWfsLayerNode(getLayerNode());
517
                layer.setFields(getAttributesPanel().getSelectedFields());
518
                layer.setUserName(getOptionsPanel().getUserName());
519
                layer.setPassword(getOptionsPanel().getPassword());
520
                layer.setNumfeatures(getOptionsPanel().getBuffer());
521
                layer.setTimeout(getOptionsPanel().getTimeout());
522
                layer.setSrs(getOptionsPanel().getSRS());
523
                layer.setAttributesQuery(getFilterPanel().getQuery());
524
                layer.setWfsDriver(data.getDriver());
525
                return layer;
526
        }
527

    
528
        private WFSLayerNode getLayerNode(){
529
                WFSLayerNode layerNode = getFeaturesPanel().getWFSLayerNode();
530
                layerNode.setSelectedFields(getAttributesPanel().getSelectedFields());
531
                layerNode.setFilter(getFilterPanel().getQuery());
532
                return layerNode;
533
        }
534

    
535

    
536
        public void setSelectedFeature(WFSLayerNode layerNode){
537
                getFeaturesPanel().setSelectedFeature(layerNode);
538
                getAttributesPanel().setSelectedFields(layerNode);
539
                getFilterPanel().setQuery(layerNode.getFilter());
540
        }        
541
        
542
        
543
        /**
544
         * @return Returns the data.
545
         */
546
        public WFSWizardData getData() {
547
                return data;
548
        }
549
        public void setLayerName(String name) {
550
                getFeaturesPanel().setLayerName(name);
551

    
552
        }
553

    
554
        public void addWizardListener(WizardListener listener) {
555
                listenerSupport.addWizardListener(listener);
556
        }
557

    
558
        public void isApplicable(boolean applicable){
559
                listenerSupport.callStateChanged(applicable);
560
        }
561

    
562

    
563
        public void setStatus(WFSStatus status) {
564
                getOptionsPanel().setStatus(status);
565
        }
566

    
567
        /**
568
         * 
569
         *
570
         */
571
        public void updateWFSFilterFieldValues()  {
572
                filterPanel.updateFieldValues();
573
        }
574
        
575
        /**
576
         * @see WFSFilterPanel#setWFSFilterPanelIsAsTabForWFSLayersLoad(boolean)
577
         */
578
        public void setWFSFilterPanelIsAsTabForWFSLayersLoad(boolean b) {
579
                this.filterPanel.setWFSFilterPanelIsAsTabForWFSLayersLoad(b);
580
        }        
581
}