Statistics
| Revision:

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

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

    
133
        /**
134
         * This method initializes jTabbedPane
135
         *
136
         * @return javax.swing.JTabbedPane
137
         */
138

    
139
        public WFSParamsPanel(){
140
                super();
141
                initialize();
142
        }
143
        /**
144
         * Returns the tab amount that the WFSParamsPanel currently have
145
         *
146
         * Devuelve el n?mero de solapas que tiene actualmente el WFSParamsPanel
147
         *
148
         * @return int
149
         */
150
        public int getNumTabs(){
151
                 return getJTabbedPane().getTabCount();
152
        }
153

    
154
        private void initialize() {
155
                this.setLayout(null);
156
                this.setVisible(false);
157
                this.setBounds(0, 0, 510, 427);
158
                this.add(getJTabbedPane(), null);
159
        }
160

    
161
        /**
162
         * Sets the focus to the tab next to the current one.
163
         *
164
         * Enfoca a la solapa siguiente a la actualmente enfocada del TabbedPane
165
         *
166
         */
167
        public void avanzaTab(){
168
            int currentPage = currentPage();
169
            int nPages = getNumTabs();
170
                if (nPages -1 > currentPage){
171
                        getJTabbedPane().setSelectedIndex(nextPageEnabled());
172
                }
173
        }
174

    
175
        /**
176
         * Sets the focus to the tab previous to the current one.
177
         *
178
         * Enfoca a la solapa anterior a la actualmente enfocada del TabbedPane
179
         *
180
         */
181
        public void retrocedeTab(){
182
                this.getJTabbedPane().setSelectedIndex(previousEnabledPage());
183
        }
184

    
185
        /**
186
         * Returns the current tab index.
187
         *
188
         * Devuelve el n?mero de solapa en que se encuentra
189
         *
190
         * @return
191
         */
192
        public int getIndiceSolapaActual(){
193
                return this.getJTabbedPane().getSelectedIndex();
194
        }
195

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

    
219
        private WFSInfoPanel getInfoPanel() {
220
                if (infoPanel==null) {
221
                        infoPanel = new WFSInfoPanel();
222
                        infoPanel.addFocusListener(new FocusListener() {
223
                                public void focusGained(java.awt.event.FocusEvent e) {
224
                                        refreshInfo();
225
                                }
226

    
227
                                private void refreshInfo() {
228
                                        WFSLayerNode selectedNode = featurePanel.getSelectedFeature();
229
                                        if (selectedNode != null){
230
                                                selectedNode.setSelectedFields(fieldsPanel.getSelectedFields());
231
                                        }
232
                                        data.setUserName(optionsPanel.getUserName());
233
                                        data.setBuffer(optionsPanel.getBuffer());
234
                                        data.setTimeOut(optionsPanel.getTimeout());
235
                                        infoPanel.refresh(data,selectedNode);
236
                                }
237

    
238
                                public void focusLost(FocusEvent e) {
239

    
240
                                }
241
                        });
242
                }
243
                return infoPanel;
244
        }
245

    
246
        /**
247
         *
248
         * @return the selected list
249
         */
250
        private Object getSelectedFeature() {
251
                return featurePanel.getSelectedFeature();
252
        }
253

    
254

    
255
        /**
256
         * This method initializes panelFeatures
257
         *
258
         * @return javax.swing.JPanel
259
         */
260
        private WFSSelectFeaturePanel getFeaturesPanel() {
261
                if (featurePanel == null) {
262
                        featurePanel = new WFSSelectFeaturePanel(this);
263
                        featurePanel.setLayout(null);
264
                }
265
                return featurePanel;
266
        }
267

    
268
        /**
269
         * This method initializes fieldsPanel
270
         *
271
         * @return javax.swing.JPanel
272
         */
273
        private WFSSelectAttributesPanel getAttributesPanel(){
274
                if (fieldsPanel == null) {
275
                        fieldsPanel = new WFSSelectAttributesPanel(this);
276
                        fieldsPanel.setLayout(null);
277
                }
278
                return fieldsPanel;
279
        }
280

    
281

    
282

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

    
296
        
297
        /**
298
         * This method initializes filterPanel
299
         * 
300
         * @return javax.swing.JPanel
301
         */
302
        private WFSFilterPanel getFilterPanel(){
303
                if (filterPanel == null) {
304
                        filterPanel = new WFSFilterPanel(this);
305
                        filterPanel.setVisible(true);
306
                        //filterPanel.setLayout(null);
307
                }
308
                return filterPanel;
309
        }
310
        
311
        /**
312
         * This method initializes areaPanel
313
         * 
314
         * @return javax.swing.JPanel
315
         */
316
        private WFSAreaPanel getAreaPanel(){
317
                if (areaPanel == null) {
318
                        areaPanel = new WFSAreaPanel(this);
319
                        areaPanel.setVisible(true);                        
320
                }
321
                return areaPanel;
322
        }
323

    
324
        /**
325
         * This method initializes formatPanel
326
         *
327
         * @return javax.swing.JPanel
328
         */
329
        private WFSFormatPanel getFormatPanel(){
330
                if (formatPanel == null) {
331
                        formatPanel = new WFSFormatPanel();
332
                        formatPanel.setLayout(null);
333
                }
334
                return formatPanel;
335
        }
336

    
337
        /**
338
         * Verifies that the selected parameters are enough to request the coverage
339
         * to the server.
340
         *
341
         * Comprueba que los par?metros seleccionados son suficientes para pedir la
342
         * cobertura al servidor.
343
         *
344
         * @return boolean
345
         */
346
        public boolean isCorretlyConfigured() {
347
                if (featurePanel.getSelectedFeature()!= null){
348
                        return true;
349
                }else{
350
                        return false;
351
                }
352
        }
353

    
354
        /**
355
         * Cleans up the wizard's components but the server's layers list.
356
         *
357
         * Limpia todos los componentes del wizard excepto la lista de capas del
358
         * servidor.
359
         */
360
        public void cleanupWizard() {
361
                jTabbedPane.setEnabledAt(indFields,false);
362
//                jTabbedPane.setEnabledAt(indFormat,false);
363
        }
364

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

    
389
        }
390

    
391
        public void refreshInfo(WFSLayerNode feature){
392
                infoPanel.refresh(data,feature);
393
        }
394

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

    
411
        /**
412
         * Sets the wizard's data source
413
         *
414
         * Establece el origen de los datos del wizard
415
         * @param dataSource
416
         */
417
        public void setDataSource(WFSWizardData dataSource) {
418
                this.data = dataSource;
419

    
420
        }
421

    
422

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

    
444
    /**
445
     * Returns the index of the current tab.
446
     *
447
     * Devuelve el ?ndice de la p?gina actual del wizard.
448
     *
449
     * @return
450
     */
451
    public int currentPage() {
452
        return getJTabbedPane().getSelectedIndex();
453
    }
454

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

    
477
        public FMapWFSDriver getDriver() {
478
                return data.getDriver();
479
        }
480

    
481
        public void setListenerSupport(WizardListenerSupport support) {
482
                listenerSupport = support;
483
        }
484

    
485

    
486
        /*
487
         *  (non-Javadoc)
488
         * @see com.iver.cit.gvsig.gui.WizardPanel#initWizard()
489
         */
490
        public void initWizard() {
491

    
492
        }
493

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

    
500
        }
501

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

    
522
        private WFSLayerNode getLayerNode(){
523
                WFSLayerNode layerNode = getFeaturesPanel().getWFSLayerNode();
524
                layerNode.setSelectedFields(getAttributesPanel().getSelectedFields());
525
                layerNode.setFilter(getFilterPanel().getQuery());
526
                return layerNode;
527
        }
528

    
529

    
530
        public void setSelectedFeature(WFSLayerNode layerNode){
531
                getFeaturesPanel().setSelectedFeature(layerNode);
532
                getAttributesPanel().setSelectedFields(layerNode);
533
                getFilterPanel().setQuery(layerNode.getFilter());
534
        }        
535
        
536
        
537
        /**
538
         * @return Returns the data.
539
         */
540
        public WFSWizardData getData() {
541
                return data;
542
        }
543
        public void setLayerName(String name) {
544
                getFeaturesPanel().setLayerName(name);
545

    
546
        }
547

    
548
        public void addWizardListener(WizardListener listener) {
549
                listenerSupport.addWizardListener(listener);
550
        }
551

    
552
        public void isApplicable(boolean applicable){
553
                listenerSupport.callStateChanged(applicable);
554
        }
555

    
556

    
557
        public void setStatus(WFSStatus status) {
558
                getOptionsPanel().setStatus(status);
559
        }
560

    
561

    
562
}