Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extWFS2 / src / org / gvsig / wfs / gui / panels / WFSParamsPanel.java @ 34026

History | View | Annotate | Download (27.6 KB)

1
package org.gvsig.wfs.gui.panels;
2

    
3
import java.awt.Container;
4

    
5
import javax.swing.JOptionPane;
6
import javax.swing.JTabbedPane;
7

    
8
import org.cresques.cts.IProjection;
9

    
10
import org.gvsig.andami.PluginServices;
11
import org.gvsig.app.gui.ILayerPanel;
12
import org.gvsig.app.gui.WizardPanel;
13
import org.gvsig.fmap.crs.CRSFactory;
14
import org.gvsig.fmap.dal.DALLocator;
15
import org.gvsig.fmap.dal.DataManager;
16
import org.gvsig.fmap.dal.DataStoreParameters;
17
import org.gvsig.fmap.dal.exception.DataException;
18
import org.gvsig.fmap.dal.exception.InitializeException;
19
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
20
import org.gvsig.fmap.dal.serverexplorer.wfs.WFSServerExplorer;
21
import org.gvsig.fmap.dal.store.wfs.WFSStoreParameters;
22
import org.gvsig.fmap.dal.store.wfs.WFSStoreProvider;
23
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
24
import org.gvsig.fmap.mapcontext.layers.FLayer;
25
import org.gvsig.fmap.mapcontext.layers.LayerFactory;
26
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
27
import org.gvsig.gui.beans.panelGroup.PanelGroupManager;
28
import org.gvsig.gui.beans.panelGroup.exceptions.EmptyPanelGroupException;
29
import org.gvsig.gui.beans.panelGroup.exceptions.EmptyPanelGroupGUIException;
30
import org.gvsig.gui.beans.panelGroup.exceptions.ListCouldntAddPanelException;
31
import org.gvsig.gui.beans.panelGroup.loaders.IPanelGroupLoader;
32
import org.gvsig.gui.beans.panelGroup.panels.AbstractPanel;
33
import org.gvsig.gui.beans.panelGroup.panels.IPanel;
34
import org.gvsig.gui.beans.panelGroup.tabbedPanel.TabbedPanel;
35
import org.gvsig.remoteclient.wfs.WFSStatus;
36
import org.gvsig.tools.dynobject.DynObject;
37
import org.gvsig.wfs.gui.panels.model.WFSSelectedFeature;
38
import org.gvsig.wfs.gui.panels.model.WFSSelectedFeatureManager;
39
import org.gvsig.wfs.gui.wizards.WFSWizard;
40

    
41

    
42
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
43
 *
44
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
45
 *
46
 * This program is free software; you can redistribute it and/or
47
 * modify it under the terms of the GNU General Public License
48
 * as published by the Free Software Foundation; either version 2
49
 * of the License, or (at your option) any later version.
50
 *
51
 * This program is distributed in the hope that it will be useful,
52
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
53
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
54
 * GNU General Public License for more details.
55
 *
56
 * You should have received a copy of the GNU General Public License
57
 * along with this program; if not, write to the Free Software
58
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
59
 *
60
 * For more information, contact:
61
 *
62
 *  Generalitat Valenciana
63
 *   Conselleria d'Infraestructures i Transport
64
 *   Av. Blasco Ib??ez, 50
65
 *   46010 VALENCIA
66
 *   SPAIN
67
 *
68
 *      +34 963862235
69
 *   gvsig@gva.es
70
 *      www.gvsig.gva.es
71
 *
72
 *    or
73
 *
74
 *   IVER T.I. S.A
75
 *   Salamanca 50
76
 *   46005 Valencia
77
 *   Spain
78
 *
79
 *   +34 963163400
80
 *   dac@iver.es
81
 */
82
/* CVS MESSAGES:
83
 *
84
 * $Id: WFSParamsPanel.java 17736 2008-01-02 16:53:48Z ppiqueras $
85
 * $Log$
86
 * Revision 1.42  2007-09-19 16:14:50  jaume
87
 * removed unnecessary imports
88
 *
89
 * Revision 1.41  2007/06/26 09:33:54  jorpiell
90
 * Information tab refreshed
91
 *
92
 * Revision 1.40  2007/04/11 12:08:55  ppiqueras
93
 * Varios cambios:
94
 * - Corregida etiqueta "Campo"
95
 * - Cambiada actualizaci?n
96
 * - Corregido bug: actualizar ?rea visible despu?s de pulsar "Aplicar" en la interfaz gr?fica.
97
 *
98
 * Revision 1.39  2007/03/15 13:33:44  ppiqueras
99
 * Corregido bug de excepci?n que se lanzaba cuando se filtraba y no se pod?a cargar la capa.
100
 *
101
 * Revision 1.38  2007/03/05 13:49:42  ppiqueras
102
 * Si una capa WFS no tiene campos (y por tanto no tiene un campo obligatorio de tipo geometr?a), que avise al usuario y no permita que se intente cargar dicha capa.
103
 *
104
 * Revision 1.37  2007/03/01 13:12:09  ppiqueras
105
 * Mejorado el filtrado por ?rea.
106
 *
107
 * Revision 1.36  2007/02/22 12:30:59  ppiqueras
108
 * - Eliminado m?todo que sobraba.
109
 * - Mejorada la relaci?n con el panel del ?rea.
110
 * - A?adido JOptionPanel de aviso que no se aplicar? ?rea porque es incorrecta.
111
 *
112
 * Revision 1.35  2007/02/20 11:31:11  ppiqueras
113
 * Eliminados comentarios que sobraban.
114
 *
115
 * Revision 1.34  2007/02/19 11:44:42  jorpiell
116
 * A?adidos los filtros por ?rea
117
 *
118
 * Revision 1.33  2007/02/16 13:36:53  ppiqueras
119
 * Que el ?rea seleccionada en el panel WFSArea sea accesible una vez se va a aplicar.
120
 *
121
 * Revision 1.32  2007/02/12 11:37:00  ppiqueras
122
 * A?adidos comentarios y m?todo para refrescar el MapControl de la pesta?a del ?rea.
123
 *
124
 * Revision 1.31  2007/02/09 14:12:39  jorpiell
125
 * Soporte para WFS 1.1 y WFS-T
126
 *
127
 * Revision 1.30  2007/02/02 12:22:22  ppiqueras
128
 * Corregido alg?n bug.
129
 *
130
 * Revision 1.29  2007/01/08 09:37:39  ppiqueras
131
 * Eliminado comentario que sobraba
132
 *
133
 * Revision 1.28  2006/12/29 09:27:02  ppiqueras
134
 * Corregidos varios bugs:
135
 *
136
 * - Se ejecuta 2 veces "Aplicar" o "Aceptar" en los filtros WFS.
137
 * - Cuando se carga por primera vez una capa WFS, si se pone un
138
 * filtro incorrecto, se ignora el filtro (cargando toda la informaci?n posible de la capa, y borrando el texto de filtrado).
139
 *
140
 * Revision 1.27  2006/12/26 09:19:40  ppiqueras
141
 * Cambiado "atttibutes" en todas las aparaciones en atributos, m?todos, clases, paquetes o comentarios por "fields". (S?lo a aquellas que afectan a clases dentro del proyecto extWFS2).
142
 *
143
 * Revision 1.26  2006/12/20 14:22:06  ppiqueras
144
 * A?adido comentario
145
 *
146
 * Revision 1.25  2006/12/15 13:59:36  ppiqueras
147
 * -Permite que se almacenen y/o recojan todos los campos y valores conocidos de la capa actual.
148
 *
149
 * -Adem?s, control frentre a consultas de filtro err?neas, (esto a medias a?n).
150
 *
151
 * - Alg?n comentario m?s.
152
 *
153
 * Revision 1.24  2006/12/12 10:24:45  ppiqueras
154
 * Nueva funcionalidad: Pulsando doble 'click' sobre una capa de un servidor, se carga (igual que antes), pero adem?s se avanza a la siguiente pesta?a sin tener que pulsar el bot?n 'Siguiente'.
155
 *
156
 * Revision 1.23  2006/12/11 11:02:24  ppiqueras
157
 * Corregido bug -> que se mantenga la frase de filtrado
158
 *
159
 * Revision 1.22  2006/12/04 08:59:47  ppiqueras
160
 * Algunos bugs corregidos. A cambio hay 2 bugs relacionados que todav?a no han sido corregidos (ver PHPCollab) (los tiene asignados Jorge).
161
 *
162
 * Revision 1.21  2006/11/28 08:05:13  jorpiell
163
 * Se escribe la query en la pesta?a del filtro
164
 *
165
 * Revision 1.20  2006/11/14 13:45:49  ppiqueras
166
 * A?adida peque?a funcionalidad:
167
 * 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.
168
 *
169
 * Revision 1.19  2006/10/27 12:10:02  ppiqueras
170
 * Nueva funcionalidad
171
 *
172
 * Revision 1.16  2006/10/23 07:37:04  jorpiell
173
 * Ya funciona el filterEncoding
174
 *
175
 * Revision 1.14  2006/10/13 13:05:32  ppiqueras
176
 * Permite el refrescado de datos del panel de filtrado sobre capa WFS.
177
 *
178
 * Revision 1.13  2006/10/10 12:55:06  jorpiell
179
 * Se ha a?adido el soporte de features complejas
180
 *
181
 * Revision 1.12  2006/10/02 09:17:48  jorpiell
182
 * A?adido el setCRS a la capa
183
 *
184
 * Revision 1.11  2006/09/29 13:02:38  ppiqueras
185
 * Filtro para WFS. De momento s?lo interfaz gr?fica.
186
 *
187
 * Revision 1.10  2006/07/21 11:50:31  jaume
188
 * improved appearance
189
 *
190
 * Revision 1.9  2006/06/21 12:35:45  jorpiell
191
 * 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
192
 *
193
 * Revision 1.8  2006/06/15 07:50:58  jorpiell
194
 * A?adida la funcionalidad de reproyectar y hechos algunos cambios en la interfaz
195
 *
196
 * Revision 1.7  2006/05/25 16:22:47  jorpiell
197
 * Se limpia el panel cada vez que se conecta con un servidor distinto
198
 *
199
 * Revision 1.6  2006/05/25 16:01:43  jorpiell
200
 * Se ha a?adido la funcionalidad para eliminar el namespace de los tipos de atributos
201
 *
202
 * Revision 1.5  2006/05/25 10:31:06  jorpiell
203
 * Como ha cambiado la forma de mostrar las capas (una tabla, en lugar de una lista), los paneles han tenido que ser modificados
204
 *
205
 * Revision 1.4  2006/05/23 08:09:39  jorpiell
206
 * 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
207
 *
208
 * Revision 1.3  2006/05/19 12:57:08  jorpiell
209
 * Modificados algunos paneles
210
 *
211
 * Revision 1.2  2006/04/20 16:38:24  jorpiell
212
 * 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().
213
 *
214
 * Revision 1.1  2006/04/19 12:50:16  jorpiell
215
 * Primer commit de la aplicaci?n. Se puede hacer un getCapabilities y ver el mensaje de vienvenida del servidor
216
 *
217
 */
218

    
219
/**
220
 * <p>Container of the WFS panels, that works as a {@linkplain TabbedPanel TabbedPanel}.</p>
221
 *
222
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
223
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
224
 */
225
public class WFSParamsPanel extends TabbedPanel implements ILayerPanel {
226
        private static final long serialVersionUID = 150328995058481516L;
227

    
228
        private WFSServerExplorer serverExplorer = null;
229
        private WFSSelectedFeatureManager selectedFeatureManager = null;
230

    
231
        // Tab positions
232
        private int infoTabPosition = -1;
233
        private int featureTabPosition = -1;
234
        private int fieldsTabPosition = -1;
235
        private int optionsTabPosition = -1;
236
        private int filterTabPosition = -1;
237
        private int areaTabPosition = -1;
238

    
239
        // Tabs
240
        private WFSInfoPanel infoPanel = null;
241
        private WFSSelectFeaturePanel featurePanel = null;
242
        private WFSSelectFieldsPanel fieldsPanel = null;
243
        private WFSOptionsPanel optionsPanel = null;
244
        private WFSFilterPanel filterPanel = null;
245
        private WFSAreaPanel areaPanel = null;
246

    
247
        private FLyrVect layer;
248
        private String cacheSelected = null;
249

    
250
        static {
251
                // Registers this class as a "PanelGroup" type
252
                PanelGroupManager.getManager().registerPanelGroup(WFSParamsPanel.class);
253

    
254
                // Sets this class as the default "PanelGroup" type
255
                PanelGroupManager.getManager().setDefaultType(WFSParamsPanel.class);
256
        }
257

    
258
        /**
259
         * This method initializes jTabbedPane
260
         *
261
         * @return javax.swing.JTabbedPane
262
         */
263
        public WFSParamsPanel(Object reference) {
264
                super(reference);
265
                initialize();
266
        }
267

    
268
        /*
269
         * (non-Javadoc)
270
         * @see org.gvsig.gui.beans.panelGroup.tabbedPanel.TabbedPanel#initialize()
271
         */
272
        protected void initialize() {
273
                super.initialize();
274

    
275
                this.setVisible(false);
276
        }
277

    
278
        /**
279
         * Sets the focus to the next tab of the current one.
280
         */
281
        public void goToNextTab() {
282
                int tabIndex = getSelectedIndex();
283

    
284
                if ((tabIndex - 1) < getPanelInGUICount()) {
285
                        int nextIndex = nextPageEnabled();
286

    
287
                        if (nextIndex > -1)
288
                                setSelectedIndex(nextIndex);
289
                }
290
        }
291

    
292
        /**
293
         * Sets the focus to the tab previous to the current one.
294
         */
295
        public void goToPreviousTab(){
296
                setSelectedIndex(previousEnabledPage());
297
        }
298

    
299
        /**
300
         * @see JTabbedPane#getSelectedIndex()
301
         */
302
        public int getSelectedIndex(){
303
                return this.getJTabbedPane().getSelectedIndex();
304
        }
305

    
306
        /**
307
         * @see JTabbedPane#setSelectedIndex(int)
308
         */
309
        public void setSelectedIndex(int index) {
310
                this.getJTabbedPane().setSelectedIndex(index);
311
        }
312

    
313
        /**
314
         * This method initializes infoPanel
315
         * 
316
         * @return the information panel
317
         */
318
        public WFSInfoPanel getInfoPanel() {
319
                if (infoPanel != null)
320
                        return infoPanel;
321

    
322
                if (infoTabPosition == -1)
323
                        return null;
324

    
325
                return (infoPanel = (WFSInfoPanel) values().toArray()[infoTabPosition]);
326
        }
327

    
328
        /**
329
         * This method initializes featurePanel
330
         *
331
         * @return javax.swing.JPanel
332
         */
333
        public WFSSelectFeaturePanel getFeaturesPanel() {
334
                if (featurePanel != null)
335
                        return featurePanel;
336

    
337
                if (featureTabPosition == -1)
338
                        return null;
339

    
340
                return (featurePanel = (WFSSelectFeaturePanel) values().toArray()[featureTabPosition]);
341
        }
342

    
343
        /**
344
         * This method initializes fieldsPanel
345
         *
346
         * @return javax.swing.JPanel
347
         */
348
        public WFSSelectFieldsPanel getFieldsPanel() {
349
                if (fieldsPanel != null)
350
                        return fieldsPanel;
351

    
352
                if (fieldsTabPosition == -1)
353
                        return null;
354

    
355
                return (fieldsPanel = (WFSSelectFieldsPanel) values().toArray()[fieldsTabPosition]);
356
        }
357

    
358
        /**
359
         * This method initializes optionsPanel
360
         *
361
         * @return javax.swing.JPanel
362
         */
363
        public WFSOptionsPanel getOptionsPanel() {
364
                if (optionsPanel != null)
365
                        return optionsPanel;
366

    
367
                if (optionsTabPosition == -1)
368
                        return null;
369

    
370
                return (optionsPanel = (WFSOptionsPanel) values().toArray()[optionsTabPosition]);
371
        }
372

    
373
        /**
374
         * This method initializes filterPanel
375
         * 
376
         * @return javax.swing.JPanel
377
         */
378
        public WFSFilterPanel getFilterPanel(){
379
                if (filterPanel != null)
380
                        return filterPanel;
381

    
382
                if (filterTabPosition == -1)
383
                        return null;
384

    
385
                return (filterPanel = (WFSFilterPanel) values().toArray()[filterTabPosition]);
386
        }
387

    
388
        /**
389
         * This method initializes areaPanel
390
         * 
391
         * @return javax.swing.JPanel
392
         */
393
        public WFSAreaPanel getAreaPanel() {
394
                if (areaPanel != null)
395
                        return areaPanel;
396

    
397
                if (areaTabPosition == -1)
398
                        return null;
399

    
400
                return (areaPanel = (WFSAreaPanel) values().toArray()[areaTabPosition]);
401
        }
402

    
403
        /**
404
         * Verifies that the selected parameters are enough to request the coverage to the server.
405
         * 
406
         * @return boolean <code>true</code> if its correctly configured; otherwise returns <code>false</code>
407
         */
408
        public boolean isCorretlyConfigured() {
409
                if (featureTabPosition == -1) {
410
                        return false;
411
                } else {
412
                        return true;
413
                }
414
        }
415

    
416
        /**
417
         * Enable or disable the default tabs
418
         */
419
        public void enableDefaultTabs(boolean isEnabled) {
420
                if (fieldsTabPosition != -1)
421
                        setEnabledAt(fieldsTabPosition, isEnabled);
422

    
423
                if (filterTabPosition != -1)
424
                        setEnabledAt(filterTabPosition, isEnabled);
425

    
426
                if (areaTabPosition != -1)
427
                        setEnabledAt(areaTabPosition, isEnabled);
428
        }
429

    
430
        /*
431
         * (non-Javadoc)
432
         * @see org.gvsig.gui.beans.panelGroup.tabbedPanel.TabbedPanel#loadPanel(org.gvsig.gui.beans.panelGroup.panels.IPanel)
433
         */
434
        protected void loadPanel(IPanel panel) {
435
                super.loadPanel(panel);
436

    
437
                if (((AbstractPanel)panel).getClass() ==  WFSInfoPanel.class) {
438
                        infoTabPosition = getPanelInGUICount() - 1;
439
                        return;
440
                }
441

    
442
                if (((AbstractPanel)panel).getClass() ==  WFSSelectFeaturePanel.class) {
443
                        featureTabPosition = getPanelInGUICount() - 1;
444
                        return;
445
                }
446

    
447
                if (((AbstractPanel)panel).getClass() ==  WFSSelectFieldsPanel.class) {
448
                        fieldsTabPosition = getPanelInGUICount() - 1;
449
                        return;
450
                }
451

    
452
                if (((AbstractPanel)panel).getClass() ==  WFSOptionsPanel.class) {
453
                        optionsTabPosition = getPanelInGUICount() - 1;
454
                        return;
455
                }
456

    
457
                if (((AbstractPanel)panel).getClass() ==  WFSFilterPanel.class) {
458
                        filterTabPosition = getPanelInGUICount() - 1;
459
                        return;
460
                }
461

    
462
                if (((AbstractPanel)panel).getClass() ==  WFSAreaPanel.class) {
463
                        areaTabPosition = getPanelInGUICount() - 1;
464
                        return;
465
                }
466
        }
467

    
468
        /**
469
         * Refresh all the panels with the WFS capabilities information.
470
         */
471
        public void refreshCapabilitiesInfo(){
472
                WFSSelectedFeature selectedFeature = getFeaturesPanel().getSelectedFeature();
473
                if (selectedFeature != null) {
474
                        selectedFeature.setSelectedFields(getFieldsPanel().getSelectedFields());
475
                } else {
476
                        getFeaturesPanel().refresh(null);
477
                }
478
                serverExplorer.setUserName(getOptionsPanel().getUserName());
479
                serverExplorer.setMaxFeatures(getOptionsPanel().getBuffer());
480
                serverExplorer.setTimeOut(getOptionsPanel().getTimeout());
481

    
482
                getInfoPanel().refresh(selectedFeature);
483
        }
484

    
485
        /**
486
         * Gets the information used to add or load a WFS layer.
487
         * 
488
         * @return information used to add or load a WFS layer
489
         */
490
        public WFSServerExplorer getServerExplorer() {
491
                return serverExplorer;
492
        }
493

    
494
        /**
495
         * Sets the information used to add or load a WFS layer.
496
         *
497
         * @param wizardData information used to add or load a WFS layer
498
         */
499
        public void setServerExplorer(WFSServerExplorer serverExplorer) {
500
                this.serverExplorer = serverExplorer;
501
                this.selectedFeatureManager = 
502
                        WFSSelectedFeatureManager.getInstance(serverExplorer);
503
        }
504

    
505
        /**
506
         * Returns the next enabled tab's index, or -1 if there isn't any.
507
         *
508
         * @return The index or -1 if there is no one.
509
         */
510
        public int nextPageEnabled() {
511
                int currentPage = getSelectedIndex();
512
                int nPages = getPanelInGUICount();
513

    
514
                if (currentPage == nPages)
515
                        return -1;
516

    
517
                for (int i = currentPage + 1; i < nPages; i++){
518
                        if (getJTabbedPane().isEnabledAt(i)){
519
                                return i;
520
                        }
521
                }
522

    
523
                return -1;
524
        }
525

    
526
        /**
527
         * Returns the index of the current tab.
528
         *
529
         * @return index of the current tab
530
         */
531
        public int currentPage() {
532
                return getSelectedIndex();
533
        }
534

    
535
        /**
536
         * Returns the index of the previous enabled tab.
537
         *
538
         * @return The index, or -1 if there is no one.
539
         */
540
        public int previousEnabledPage() {
541
                int currentPage = getSelectedIndex();
542

    
543
                if (currentPage == 0)
544
                        return -1;
545

    
546
                for (int i = currentPage - 1; i > -1; i--) {
547
                        if (isEnabledAt(i)) {
548
                                return i;
549
                        }
550
                }
551

    
552
                return -1;
553
        }
554

    
555
        /*
556
         *  (non-Javadoc)
557
         * @see com.iver.cit.gvsig.gui.WizardPanel#initWizard()
558
         */
559
        public void initWizard() {
560

    
561
        }
562

    
563
        /*
564
         *  (non-Javadoc)
565
         * @see com.iver.cit.gvsig.gui.WizardPanel#execute()
566
         */
567
        public void execute() {
568

    
569
        }
570

    
571
        /*
572
         *  (non-Javadoc)
573
         * @see com.iver.cit.gvsig.gui.ILayerPanel#getLayer()
574
         */
575
        public FLayer getLayer() {
576
                if (layer == null) {
577
                        try {
578
                                FLyrVect layerAux = (FLyrVect)LayerFactory.getInstance().createLayer(
579
                                                getFeaturesPanel().getLayerName(),
580
                                                getDataStoreParameters());
581
                                if(!this.cacheSelected.equals(PluginServices.getText(this, "none"))){
582
                                        layerAux.getFeatureStore().createCache(cacheSelected, getParameters(cacheSelected));
583
                                }
584
                                return layerAux;
585
                        } catch (InitializeException e1) {
586
                                e1.printStackTrace();
587
                        } catch (ProviderNotRegisteredException e1) {
588
                                e1.printStackTrace();
589
                        } catch (LoadLayerException e1) {
590
                                e1.printStackTrace();
591
                        } catch (DataException e) {
592
                                e.printStackTrace();
593
                        }
594
                }
595

    
596
                return layer;
597
        }
598
        
599
         protected DynObject getParameters(String nameCacheProvider) throws DataException {
600
                 DataManager dataManager = DALLocator.getDataManager();
601
                 return dataManager.createCacheParameters(nameCacheProvider);
602
         }
603

    
604
        public void setLayer(FLyrVect layer){
605
                this.layer = layer;
606
        }
607

    
608
        public DataStoreParameters getDataStoreParameters() throws InitializeException, ProviderNotRegisteredException{
609
                DataManager dataManager = DALLocator.getDataManager();
610
                WFSStoreParameters parameters = (WFSStoreParameters) dataManager
611
                .createStoreParameters(WFSStoreProvider.NAME);
612
                refreshDataStoreParameters(parameters);
613
                return parameters;
614
        }
615

    
616
        public void refreshDataStoreParameters(WFSStoreParameters parameters){
617
                WFSSelectedFeature selectedFeature = getSelectedFeature();
618
                parameters.setUrl(serverExplorer.getUrl());
619
                parameters.setVersion(serverExplorer.getVersion());
620
                parameters.setFeatureType(selectedFeature.getNameSpace(),
621
                                selectedFeature.getName());
622
                parameters.setFields(getFieldsPanel().getSelectedFieldsAsString());
623
                parameters.setUser(getOptionsPanel().getUserName());
624
                parameters.setPassword(getOptionsPanel().getPassword());
625
                parameters.setMaxFeatures(getOptionsPanel().getBuffer());
626
                parameters.setTimeOut(getOptionsPanel().getTimeout());
627
                //                parameters.setFilterByArea(getAreaPanel().getArea(),
628
                //                                "the_geom",
629
                //                                getOptionsPanel().getSRS(),
630
                //                                AFilter.GEOMETRIC_OPERATOR_INTERSECT);                
631
                //                parameters.setFilterByAttribute(getFilterPanel().getFilterExpressionFromInterface());
632
        }        
633

    
634
        /**
635
         * @see WFSWizard#doClickOnNextButton()
636
         */
637
        public void doClickOnNextButton() {
638
                Object obj = this.getParent();
639

    
640
                if (obj == null)
641
                        return;
642

    
643
                // When we start to connect to a server -> the interface is the dialog WFSWizard
644
                if (obj instanceof WFSWizard)
645
                        ((WFSWizard)this.getParent()).doClickOnNextButton();
646
                else {
647
                        // When we are modifying a loaded layer -> the interface is the dialog WFSPropsDialog
648
                        this.advanceCurrentTab();
649
                }
650
        }
651

    
652
        /**
653
         * Selects the next tab
654
         */
655
        public void advanceCurrentTab() {
656
                int currentTabIndex = this.getJTabbedPane().getSelectedIndex();
657

    
658
                // Ensure we can select next tab
659
                if ((currentTabIndex != -1) && (currentTabIndex < (values().size() -1)))
660
                        setSelectedIndex(currentTabIndex + 1);
661
        }
662

    
663
        /**
664
         * Refreshes the data of the inner <code>WFSSelectFeaturePanel</code>.
665
         */
666
        public void refreshWFSSelectFeaturePanel() {
667
                WFSSelectFeaturePanel panel = getFeaturesPanel();
668

    
669
                if (panel != null) {
670
                        panel.refresh(null);
671
                }
672
        }
673

    
674
        /**
675
         * Gets the node of the layer selected as a feature, with the selected fields and the filter defined.
676
         * 
677
         * @return gets the node of the layer selected as a feature, with the selected fields and the filter defined
678
         */
679
        private WFSSelectedFeature getSelectedFeature(){
680
                WFSSelectedFeature selectedFeature = getFeaturesPanel().getSelectedFeature();
681
                selectedFeature.setSelectedFields(getFieldsPanel().getSelectedFields());
682

    
683
                // If the query is incorrect -> no query (no filter)
684
                String query = getFilterPanel().getQuery();
685
                if (query == null) {
686
                        selectedFeature.setFilter("");
687

    
688
                        // Removes filter expression from the JTextArea
689
                        getFilterPanel().removeFilterExpression();
690

    
691
                        // Notify to user that no filter will be applied
692
                        JOptionPane.showMessageDialog(null, PluginServices.getText(null, "no_filter_will_be_applied_in_the_load_of_the_layer"), PluginServices.getText(null, "warning"), JOptionPane.WARNING_MESSAGE);
693
                }
694
                else {
695
                        selectedFeature.setFilter(query);
696
                }
697
                return selectedFeature;
698
        }
699

    
700
        /**
701
         * @return the selected projection
702
         */
703
        public IProjection getSelectedFeatureProjection(){
704
                WFSSelectedFeature selectedFeature = getSelectedFeature();
705
                if (selectedFeature.getSrs().size() > 0){
706
                        String crs = (String)selectedFeature.getSrs().get(0);
707
                        crs = getSRS(crs);
708
                        IProjection projection = CRSFactory.getCRS(crs);
709
                        if (projection != null){
710
                                return projection;
711
                        }
712
                }
713
                return null;
714
        }
715

    
716
        /**
717
         * Removing the URN prefix
718
         * @param srs
719
         * @return
720
         */
721
        private String getSRS(String srs){
722
                if (srs == null){
723
                        return null;
724
                }
725
                if (srs.startsWith("urn:x-ogc:def:crs:")){
726
                        String newString = srs.substring(srs.lastIndexOf(":") + 1, srs.length());
727
                        if (srs.indexOf("EPSG") > 0){
728
                                if (newString.indexOf("EPSG") < 0){
729
                                        newString = "EPSG:" + newString;
730
                                }
731
                        }
732
                        return newString;                        
733
                }
734
                if (srs.toLowerCase().startsWith("crs:")){
735
                        return srs.substring(4, srs.length());
736
                }
737
                return srs;
738
        }
739

    
740
        /**
741
         * Refresh all the panels every time that a different layer is selected. The info panel is refreshed every time the user 
742
         * makes a click on it.
743
         * 
744
         * @param selectedFeature the selected layer
745
         */
746
        public void refresh(WFSSelectedFeature selectedFeature){
747
                boolean hasFields = false;
748

    
749
                if (selectedFeature!=null){
750
                        //Update the layer information
751
                        selectedFeature = selectedFeatureManager.getFeatureInfo(selectedFeature.getNameSpace(),
752
                                        selectedFeature.getName());
753

    
754
                        // If there is no fields -> disable not necessary tabs
755
                        if (selectedFeature.getWFSFeature().getFieldSize() == 0) {
756
                                setApplicable(false);
757
                                hasFields = false;
758
                        }else{        
759
                                getFieldsPanel().refresh(selectedFeature);                        
760
                                getOptionsPanel().refresh(selectedFeature);
761
                                getFilterPanel().refresh(selectedFeature);
762
                                getAreaPanel().refresh(selectedFeature);
763
                                hasFields = true;
764
                        }
765
                }
766

    
767
                enableDefaultTabs(hasFields);
768
        }
769

    
770
        /**
771
         * Changes the <i>enable</i> status of the "<i>apply</i>" button
772
         * 
773
         * @param isApplicable the <i>enable</i> status of the "<i>apply</i>" button
774
         */
775
        public void setApplicable(boolean isApplicable){
776
                setEnabledApplyButton(isApplicable);
777
        }
778

    
779
        /*
780
         * (non-Javadoc)
781
         * @see org.gvsig.gui.beans.buttonspanel.IButtonsPanel#setEnabledApplyButton(boolean)
782
         */
783
        public void setEnabledApplyButton(boolean b) {
784
                super.setEnabledApplyButton(b);
785

    
786
                Container parent = getParent();
787

    
788
                if ((parent != null) && (parent instanceof WizardPanel))
789
                        ((WizardPanel)parent).callStateChanged(b);
790
        }
791

    
792
        /*
793
         * (non-Javadoc)
794
         * @see org.gvsig.gui.beans.panelGroup.AbstractPanelGroup#loadPanels(org.gvsig.gui.beans.panelGroup.loaders.IPanelGroupLoader)
795
         */
796
        public void loadPanels(IPanelGroupLoader loader) throws ListCouldntAddPanelException, EmptyPanelGroupException, EmptyPanelGroupGUIException {
797
                // This code will be executed when is creating the dialog of properties
798
                if (getReference() != null) {
799
                        FLyrVect lyr = (FLyrVect) getReference();
800

    
801
                        DataManager dataManager = DALLocator.getDataManager();
802
                        //Create the datastore parameters and fill them
803
                        WFSStoreParameters parameters;
804
                        try {
805
                                parameters = (WFSStoreParameters) dataManager
806
                                .createStoreParameters(WFSStoreProvider.NAME);
807
                                parameters.setUrl(serverExplorer.getUrl());
808
                                parameters.setVersion(serverExplorer.getVersion());
809
                                //parameters.setFeatureType(namespacePrefix, namespace, featureType);
810

    
811
                                //dataSource.setDriver(lyr.getWfsDriver());
812

    
813
                                //setServerExplorer(dataSource);
814

    
815
                                super.loadPanels(loader);
816

    
817
                                //                                HashMap<String, Object> info = lyr.getProperties();
818
                                //                                setSelectedFeature((WFSLayerNode)info.get("wfsLayerNode"));
819
                                //                                setStatus((WFSStatus)info.get("status"));
820
                                //                                setLayerName(lyr.getName());
821
                                //                                setVisible(true);
822
                                //                                refreshInfo();
823
                        } catch (InitializeException e) {
824
                                // TODO Auto-generated catch block
825
                                e.printStackTrace();
826
                        } catch (ProviderNotRegisteredException e) {
827
                                // TODO Auto-generated catch block
828
                                e.printStackTrace();
829
                        }                        
830
                        return;
831
                }
832

    
833
                // This will executed when is adding a new WFS layer:
834
                super.loadPanels(loader);
835
        }
836

    
837
        ///// BEGIN: METHODS FOR INITIALIZE THIS PANEL AS A COMPONENT OF A PROPERTIES DIALOG /////
838

    
839
        /**
840
         * Sets the selected feature.
841
         * 
842
         * @param selectedFeature node of the selected feature
843
         */
844
        public void setSelectedFeature(WFSSelectedFeature selectedFeature){
845
                getFeaturesPanel().setSelectedFeature(selectedFeature);
846
                getFieldsPanel().setSelectedFields(selectedFeature);
847
                getFilterPanel().refresh(selectedFeature);
848
        }
849
        
850
           public void setSelectedFeature(WFSSelectedFeature selectedFeature, FLyrVect layer){
851
                setSelectedFeature(selectedFeature);
852
                getFilterPanel().setSelectedLayer(layer);
853
            }
854

    
855
        /**
856
         * Sets the status of the options and filter panels.
857
         * 
858
         * @param status the status of the options and filter panels
859
         */
860
        public void setStatus(WFSStatus status) {
861
                getOptionsPanel().setStatus(status);
862
                getFilterPanel().setFilterExpressionIntoInterface(status.getFilterByAttribute());
863
        }
864

    
865
        /**
866
         * @see WFSSelectFeaturePanel#setLayerName(String)
867
         */
868
        public void setLayerName(String name) {
869
                getFeaturesPanel().setLayerName(name);
870
        }
871

    
872
        /**
873
         * Updates the information stored at the wizard's data and <i>info</i> panel.
874
         */
875
        public void refreshInfo(){
876
                WFSSelectedFeature selectedFeature = getFeaturesPanel().getSelectedFeature();
877

    
878
                if (selectedFeature != null) {
879
                        selectedFeature.setSelectedFields(getFieldsPanel().getSelectedFields());
880
                }
881

    
882
                serverExplorer.setUserName(getOptionsPanel().getUserName());
883
                serverExplorer.setMaxFeatures(getOptionsPanel().getBuffer());
884
                serverExplorer.setTimeOut(getOptionsPanel().getTimeout());
885
                getInfoPanel().refresh(selectedFeature);
886
        }
887

    
888
        /**
889
         * @return the selectedFeatureManager
890
         */
891
        public WFSSelectedFeatureManager getSelectedFeatureManager() {
892
                return selectedFeatureManager;
893
        }
894

    
895
        public void setSelectedCache(String selectedCache) {
896
                this.cacheSelected = selectedCache;
897
        }        
898
}