Statistics
| Revision:

root / branches / v10 / extensions / extWFS2 / src / com / iver / cit / gvsig / gui / panels / WFSParamsPanel.java @ 9154

History | View | Annotate | Download (16.9 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.util.prefs.Preferences;
6

    
7
import javax.swing.JTabbedPane;
8

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

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

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

    
148
        /**
149
         * This method initializes jTabbedPane
150
         *
151
         * @return javax.swing.JTabbedPane
152
         */
153

    
154
        public WFSParamsPanel(){
155
                super();
156
                initialize();
157
        }
158
        /**
159
         * Returns the tab amount that the WFSParamsPanel currently have
160
         *
161
         * Devuelve el n?mero de solapas que tiene actualmente el WFSParamsPanel
162
         *
163
         * @return int
164
         */
165
        public int getNumTabs(){
166
                 return getJTabbedPane().getTabCount();
167
        }
168

    
169
        private void initialize() {
170
                this.setLayout(null);
171
                this.setVisible(false);
172
                this.setBounds(0, 0, 510, 427);
173
                this.add(getJTabbedPane(), null);
174
        }
175

    
176
        /**
177
         * Sets the focus to the tab next to the current one.
178
         *
179
         * Enfoca a la solapa siguiente a la actualmente enfocada del TabbedPane
180
         *
181
         */
182
        public void avanzaTab(){
183
            int currentPage = currentPage();
184
            int nPages = getNumTabs();
185
                if (nPages -1 > currentPage){
186
                        getJTabbedPane().setSelectedIndex(nextPageEnabled());
187
                }
188
        }
189

    
190
        /**
191
         * Sets the focus to the tab previous to the current one.
192
         *
193
         * Enfoca a la solapa anterior a la actualmente enfocada del TabbedPane
194
         *
195
         */
196
        public void retrocedeTab(){
197
                this.getJTabbedPane().setSelectedIndex(previousEnabledPage());
198
        }
199

    
200
        /**
201
         * Returns the current tab index.
202
         *
203
         * Devuelve el n?mero de solapa en que se encuentra
204
         *
205
         * @return
206
         */
207
        public int getIndiceSolapaActual(){
208
                return this.getJTabbedPane().getSelectedIndex();
209
        }
210

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

    
234
        private WFSInfoPanel getInfoPanel() {
235
                if (infoPanel==null) {
236
                        infoPanel = new WFSInfoPanel();
237
                        infoPanel.addFocusListener(new FocusListener() {
238
                                public void focusGained(java.awt.event.FocusEvent e) {
239
                                        refreshInfo();
240
                                }
241

    
242
                                private void refreshInfo() {
243
                                        WFSLayerNode selectedNode = featurePanel.getSelectedFeature();
244
                                        if (selectedNode != null){
245
                                                selectedNode.setSelectedFields(fieldsPanel.getSelectedFields());
246
                                        }
247
                                        data.setUserName(optionsPanel.getUserName());
248
                                        data.setBuffer(optionsPanel.getBuffer());
249
                                        data.setTimeOut(optionsPanel.getTimeout());
250
                                        infoPanel.refresh(data,selectedNode);
251
                                }
252

    
253
                                public void focusLost(FocusEvent e) {
254

    
255
                                }
256
                        });
257
                }
258
                return infoPanel;
259
        }
260

    
261
        /**
262
         *
263
         * @return the selected list
264
         */
265
        private Object getSelectedFeature() {
266
                return featurePanel.getSelectedFeature();
267
        }
268

    
269

    
270
        /**
271
         * This method initializes panelFeatures
272
         *
273
         * @return javax.swing.JPanel
274
         */
275
        private WFSSelectFeaturePanel getFeaturesPanel() {
276
                if (featurePanel == null) {
277
                        featurePanel = new WFSSelectFeaturePanel(this);
278
                        featurePanel.setLayout(null);
279
                }
280
                return featurePanel;
281
        }
282

    
283
        /**
284
         * This method initializes fieldsPanel
285
         *
286
         * @return javax.swing.JPanel
287
         */
288
        private WFSSelectAttributesPanel getAttributesPanel(){
289
                if (fieldsPanel == null) {
290
                        fieldsPanel = new WFSSelectAttributesPanel(this);
291
                        fieldsPanel.setLayout(null);
292
                }
293
                return fieldsPanel;
294
        }
295

    
296

    
297

    
298
        /**
299
         * This method initializes fieldsPanel
300
         *
301
         * @return javax.swing.JPanel
302
         */
303
        private WFSOptionsPanel getOptionsPanel(){
304
                if (optionsPanel == null) {
305
                        optionsPanel = new WFSOptionsPanel(this);
306
                        optionsPanel.setLayout(null);
307
                }
308
                return optionsPanel;
309
        }
310

    
311
        
312
        /**
313
         * This method initializes filterPanel
314
         * 
315
         * @return javax.swing.JPanel
316
         */
317
        private WFSFilterPanel getFilterPanel(){
318
                if (filterPanel == null) {
319
                        filterPanel = new WFSFilterPanel(this);
320
                        filterPanel.setVisible(true);
321
                        //filterPanel.setLayout(null);
322
                }
323
                return filterPanel;
324
        }
325
        
326
        /**
327
         * This method initializes areaPanel
328
         * 
329
         * @return javax.swing.JPanel
330
         */
331
        private WFSAreaPanel getAreaPanel(){
332
                if (areaPanel == null) {
333
                        areaPanel = new WFSAreaPanel(this);
334
                        areaPanel.setVisible(true);                        
335
                }
336
                return areaPanel;
337
        }
338

    
339
        /**
340
         * This method initializes formatPanel
341
         *
342
         * @return javax.swing.JPanel
343
         */
344
        private WFSFormatPanel getFormatPanel(){
345
                if (formatPanel == null) {
346
                        formatPanel = new WFSFormatPanel();
347
                        formatPanel.setLayout(null);
348
                }
349
                return formatPanel;
350
        }
351

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

    
369
        /**
370
         * Cleans up the wizard's components but the server's layers list.
371
         *
372
         * Limpia todos los componentes del wizard excepto la lista de capas del
373
         * servidor.
374
         */
375
        public void cleanupWizard() {
376
                jTabbedPane.setEnabledAt(indFields,false);
377
//                jTabbedPane.setEnabledAt(indFormat,false);
378
        }
379

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

    
402
        }
403

    
404
        public void refreshInfo(WFSLayerNode feature){
405
                infoPanel.refresh(data,feature);
406
        }
407

    
408
        /**
409
         * Sets the object that holds the wizard data.
410
         *
411
         * Establece el objeto que contiene los datos del wizard.
412
         *
413
         * @param data
414
         */
415
        public void setWizardData(WFSWizardData data) {
416
                this.data = data;
417
                //WFSLayerNode selectedNode = (WFSLayerNode)featurePanel.getSelectedFeature();
418
                featurePanel.setWizardData(data);
419
                data.setBuffer(optionsPanel.getBuffer());
420
                data.setTimeOut(optionsPanel.getTimeout());
421
                infoPanel.refresh(data,null);
422
        }
423

    
424
        /**
425
         * Sets the wizard's data source
426
         *
427
         * Establece el origen de los datos del wizard
428
         * @param dataSource
429
         */
430
        public void setDataSource(WFSWizardData dataSource) {
431
                this.data = dataSource;
432

    
433
        }
434

    
435

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

    
457
    /**
458
     * Returns the index of the current tab.
459
     *
460
     * Devuelve el ?ndice de la p?gina actual del wizard.
461
     *
462
     * @return
463
     */
464
    public int currentPage() {
465
        return getJTabbedPane().getSelectedIndex();
466
    }
467

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

    
490
        public FMapWFSDriver getDriver() {
491
                return data.getDriver();
492
        }
493

    
494
        public void setListenerSupport(WizardListenerSupport support) {
495
                listenerSupport = support;
496
        }
497

    
498

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

    
505
        }
506

    
507
        /*
508
         *  (non-Javadoc)
509
         * @see com.iver.cit.gvsig.gui.WizardPanel#execute()
510
         */
511
        public void execute() {
512

    
513
        }
514

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

    
535
        private WFSLayerNode getLayerNode(){
536
                WFSLayerNode layerNode = getFeaturesPanel().getWFSLayerNode();
537
                layerNode.setSelectedFields(getAttributesPanel().getSelectedFields());
538
                layerNode.setFilter(getFilterPanel().getQuery());
539
                return layerNode;
540
        }
541

    
542

    
543
        public void setSelectedFeature(WFSLayerNode layerNode){
544
                getFeaturesPanel().setSelectedFeature(layerNode);
545
                getAttributesPanel().setSelectedFields(layerNode);
546
                getFilterPanel().setQuery(layerNode.getFilter());
547
        }        
548
        
549
        
550
        /**
551
         * @return Returns the data.
552
         */
553
        public WFSWizardData getData() {
554
                return data;
555
        }
556
        public void setLayerName(String name) {
557
                getFeaturesPanel().setLayerName(name);
558

    
559
        }
560

    
561
        public void addWizardListener(WizardListener listener) {
562
                listenerSupport.addWizardListener(listener);
563
        }
564

    
565
        public void isApplicable(boolean applicable){
566
                listenerSupport.callStateChanged(applicable);
567
        }
568

    
569

    
570
        public void setStatus(WFSStatus status) {
571
                getOptionsPanel().setStatus(status);
572
                getFilterPanel().setQuery(status.getFilterQuery());
573
        }
574

    
575
        /**
576
         * 
577
         *
578
         */
579
        public void updateWFSFilterFieldValues()  {
580
                filterPanel.updateFieldValues();
581
        }
582
        
583
        /**
584
         * @see WFSFilterPanel#setWFSFilterPanelIsAsTabForWFSLayersLoad(boolean)
585
         */
586
        public void setWFSFilterPanelIsAsTabForWFSLayersLoad(boolean b) {
587
                this.getFilterPanel().setWFSFilterPanelIsAsTabForWFSLayersLoad(b);
588
        }
589
        
590
        /**
591
         * @see WFSFilterPanel#getWFSFilterPanelIsAsTabForWFSLayersLoad()
592
         */
593
        public boolean getWFSFilterPanelIsAsTabForWFSLayersLoad() {
594
                return this.getFilterPanel().getWFSFilterPanelIsAsTabForWFSLayersLoad();
595
        }
596
        
597
        /**
598
         * @see WFSSelectAttributesPanel#getAttributesSelectedOfSameLayerHasChanged()
599
         */
600
        public boolean getAttributesSelectedOfSameLayerHasChanged() {
601
                return this.getAttributesPanel().getAttributesSelectedOfSameLayerHasChanged();
602
        }
603
        
604
        /**
605
         * @see WFSSelectAttributesPanel#resetAttributesSelectedOfSameLayerHasChanged()
606
         */
607
        public void resetAttributesSelectedOfSameLayerHasChanged() {
608
                this.getAttributesPanel().resetAttributesSelectedOfSameLayerHasChanged();
609
        }
610
}