Statistics
| Revision:

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

History | View | Annotate | Download (16 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 9018 2006-11-28 08:03:03Z jorpiell $
65
 * $Log$
66
 * Revision 1.10.2.4  2006-11-28 08:03:03  jorpiell
67
 * Se escribe el filtro al abrir la ventana
68
 *
69
 * Revision 1.10.2.3  2006/11/17 11:28:45  ppiqueras
70
 * Corregidos bugs y a?adida nueva funcionalidad.
71
 *
72
 * Revision 1.20  2006/11/14 13:45:49  ppiqueras
73
 * A?adida peque?a funcionalidad:
74
 * 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.
75
 *
76
 * Revision 1.19  2006/10/27 12:10:02  ppiqueras
77
 * Nueva funcionalidad
78
 *
79
 * Revision 1.16  2006/10/23 07:37:04  jorpiell
80
 * Ya funciona el filterEncoding
81
 *
82
 * Revision 1.14  2006/10/13 13:05:32  ppiqueras
83
 * Permite el refrescado de datos del panel de filtrado sobre capa WFS.
84
 *
85
 * Revision 1.13  2006/10/10 12:55:06  jorpiell
86
 * Se ha a?adido el soporte de features complejas
87
 *
88
 * Revision 1.12  2006/10/02 09:17:48  jorpiell
89
 * A?adido el setCRS a la capa
90
 *
91
 * Revision 1.11  2006/09/29 13:02:38  ppiqueras
92
 * Filtro para WFS. De momento s?lo interfaz gr?fica.
93
 *
94
 * Revision 1.10  2006/07/21 11:50:31  jaume
95
 * improved appearance
96
 *
97
 * Revision 1.9  2006/06/21 12:35:45  jorpiell
98
 * 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
99
 *
100
 * Revision 1.8  2006/06/15 07:50:58  jorpiell
101
 * A?adida la funcionalidad de reproyectar y hechos algunos cambios en la interfaz
102
 *
103
 * Revision 1.7  2006/05/25 16:22:47  jorpiell
104
 * Se limpia el panel cada vez que se conecta con un servidor distinto
105
 *
106
 * Revision 1.6  2006/05/25 16:01:43  jorpiell
107
 * Se ha a?adido la funcionalidad para eliminar el namespace de los tipos de atributos
108
 *
109
 * Revision 1.5  2006/05/25 10:31:06  jorpiell
110
 * Como ha cambiado la forma de mostrar las capas (una tabla, en lugar de una lista), los paneles han tenido que ser modificados
111
 *
112
 * Revision 1.4  2006/05/23 08:09:39  jorpiell
113
 * 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
114
 *
115
 * Revision 1.3  2006/05/19 12:57:08  jorpiell
116
 * Modificados algunos paneles
117
 *
118
 * Revision 1.2  2006/04/20 16:38:24  jorpiell
119
 * 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().
120
 *
121
 * Revision 1.1  2006/04/19 12:50:16  jorpiell
122
 * Primer commit de la aplicaci?n. Se puede hacer un getCapabilities y ver el mensaje de vienvenida del servidor
123
 *
124
 *
125
 */
126
/**
127
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
128
 */
129
public class WFSParamsPanel extends WizardPanel{
130
        private JTabbedPane jTabbedPane = null;  //  @jve:decl-index=0:visual-constraint="37,30"
131
        private WFSSelectFeaturePanel featurePanel = null;
132
        private WFSSelectAttributesPanel fieldsPanel = null;
133
        private WFSOptionsPanel optionsPanel = null;
134
        private WFSFormatPanel formatPanel = null;
135
        private WFSFilterPanel filterPanel = null;
136
        private WFSAreaPanel areaPanel = null;
137
        private WFSWizardData data;
138
        private WizardListenerSupport listenerSupport;
139
        public        static Preferences fPrefs = Preferences.userRoot().node( "gvsig.wcs-wizard" );
140
        private WFSInfoPanel infoPanel;
141
        private int indFields;
142
        private int indFormat;
143
        private int indFilter;
144
        private int indArea;
145
        
146

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

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

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

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

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

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

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

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

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

    
252
                                public void focusLost(FocusEvent e) {
253

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

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

    
268

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

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

    
295

    
296

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

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

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

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

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

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

    
401
        }
402

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

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

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

    
432
        }
433

    
434

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

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

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

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

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

    
497

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

    
504
        }
505

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

    
512
        }
513

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

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

    
541

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

    
558
        }
559

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

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

    
568

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

    
574
        /**
575
         * 
576
         *
577
         */
578
        public void updateWFSFilterFieldValues()  {
579
                filterPanel.updateFieldValues();
580
        }
581
        
582
        /**
583
         * @see WFSFilterPanel#setWFSFilterPanelIsAsTabForWFSLayersLoad(boolean)
584
         */
585
        public void setWFSFilterPanelIsAsTabForWFSLayersLoad(boolean b) {
586
                this.filterPanel.setWFSFilterPanelIsAsTabForWFSLayersLoad(b);
587
        }        
588
}