Statistics
| Revision:

root / org.gvsig.wfs.app / trunk / org.gvsig.wfs.app / org.gvsig.wfs.app.mainplugin / src / main / java / org / gvsig / wfs / gui / panels / WFSParamsPanel.java @ 112

History | View | Annotate | Download (29 KB)

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

    
3
import java.awt.Container;
4
import java.util.List;
5

    
6
import javax.swing.JTabbedPane;
7

    
8
import org.cresques.cts.IProjection;
9
import org.geotools.filter.AbstractFilter;
10
import org.gvsig.andami.PluginServices;
11
import org.gvsig.app.gui.ILayerPanel;
12
import org.gvsig.app.gui.WizardPanel;
13
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
14
import org.gvsig.fmap.crs.CRSFactory;
15
import org.gvsig.fmap.dal.DALLocator;
16
import org.gvsig.fmap.dal.DataManager;
17
import org.gvsig.fmap.dal.DataStore;
18
import org.gvsig.fmap.dal.DataStoreParameters;
19
import org.gvsig.fmap.dal.exception.DataException;
20
import org.gvsig.fmap.dal.exception.InitializeException;
21
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
22
import org.gvsig.fmap.dal.serverexplorer.wfs.WFSServerExplorer;
23
import org.gvsig.fmap.dal.store.wfs.WFSStoreParameters;
24
import org.gvsig.fmap.dal.store.wfs.WFSStoreProvider;
25
import org.gvsig.fmap.geom.Geometry;
26
import org.gvsig.fmap.geom.primitive.Envelope;
27
import org.gvsig.fmap.mapcontext.MapContextLocator;
28
import org.gvsig.fmap.mapcontext.MapContextManager;
29
import org.gvsig.fmap.mapcontext.ViewPort;
30
import org.gvsig.fmap.mapcontext.exceptions.CreateLayerException;
31
import org.gvsig.fmap.mapcontext.layers.FLayer;
32
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
33
import org.gvsig.gui.beans.panelGroup.exceptions.EmptyPanelGroupException;
34
import org.gvsig.gui.beans.panelGroup.exceptions.EmptyPanelGroupGUIException;
35
import org.gvsig.gui.beans.panelGroup.exceptions.ListCouldntAddPanelException;
36
import org.gvsig.gui.beans.panelGroup.loaders.IPanelGroupLoader;
37
import org.gvsig.gui.beans.panelGroup.panels.AbstractPanel;
38
import org.gvsig.gui.beans.panelGroup.panels.IPanel;
39
import org.gvsig.gui.beans.panelGroup.tabbedPanel.TabbedPanel;
40
import org.gvsig.remoteclient.wfs.filters.filterencoding.FilterEncoding;
41
import org.gvsig.remoteclient.wfs.schema.XMLNameSpace;
42
import org.gvsig.tools.dynobject.DynObject;
43
import org.gvsig.wfs.gui.panels.model.WFSSelectedFeature;
44
import org.gvsig.wfs.gui.panels.model.WFSSelectedFeatureManager;
45
import org.gvsig.wfs.gui.wizards.WFSWizard;
46
import org.slf4j.Logger;
47
import org.slf4j.LoggerFactory;
48

    
49

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

    
227
/**
228
 * <p>Container of the WFS panels, that works as a {@linkplain TabbedPanel TabbedPanel}.</p>
229
 *
230
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
231
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
232
 */
233
public class WFSParamsPanel extends TabbedPanel implements ILayerPanel {
234
        private static final long serialVersionUID = 150328995058481516L;
235

    
236
        private static Logger logger = LoggerFactory.getLogger(WFSParamsPanel.class);
237

    
238
        private WFSServerExplorer serverExplorer = null;
239
        private WFSSelectedFeatureManager selectedFeatureManager = null;
240

    
241
        private static final MapContextManager MAP_CONTEXT_MANAGER = MapContextLocator.getMapContextManager();
242

    
243
        // Tab positions
244
        private int infoTabPosition = -1;
245
        private int featureTabPosition = -1;
246
        private int fieldsTabPosition = -1;
247
        private int optionsTabPosition = -1;
248
        // private int filterTabPosition = -1;
249
        private int areaTabPosition = -1;
250

    
251
        // Tabs
252
        private WFSInfoPanel infoPanel = null;
253
        private WFSSelectFeaturePanel featurePanel = null;
254
        private WFSSelectFieldsPanel fieldsPanel = null;
255
        private WFSOptionsPanel optionsPanel = null;
256
        // private WFSFilterPanel filterPanel = null;
257
        private WFSAreaPanel areaPanel = null;
258

    
259
        private String cacheSelected = null;
260

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

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

    
278
                this.setVisible(false);
279
        }
280

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

    
287
                if ((tabIndex - 1) < getPanelInGUICount()) {
288
                        int nextIndex = nextPageEnabled();
289

    
290
                        if (nextIndex > -1)
291
                                setSelectedIndex(nextIndex);
292
                }
293
        }
294

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

    
302
        /**
303
         * @see JTabbedPane#getSelectedIndex()
304
         */
305
        public int getSelectedIndex(){
306
                return this.getJTabbedPane().getSelectedIndex();
307
        }
308

    
309
        /**
310
         * @see JTabbedPane#setSelectedIndex(int)
311
         */
312
        public void setSelectedIndex(int index) {
313
                this.getJTabbedPane().setSelectedIndex(index);
314
        }
315

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

    
325
                if (infoTabPosition == -1)
326
                        return null;
327

    
328
                return (infoPanel = (WFSInfoPanel) values().toArray()[infoTabPosition]);
329
        }
330

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

    
340
                if (featureTabPosition == -1)
341
                        return null;
342

    
343
                return (featurePanel = (WFSSelectFeaturePanel) values().toArray()[featureTabPosition]);
344
        }
345

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

    
355
                if (fieldsTabPosition == -1)
356
                        return null;
357

    
358
                return (fieldsPanel = (WFSSelectFieldsPanel) values().toArray()[fieldsTabPosition]);
359
        }
360

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

    
370
                if (optionsTabPosition == -1)
371
                        return null;
372

    
373
                return (optionsPanel = (WFSOptionsPanel) values().toArray()[optionsTabPosition]);
374
        }
375

    
376
        /**
377
         * This method initializes filterPanel
378
         *
379
         * @return javax.swing.JPanel
380
         */
381

    
382
        /*
383
        public WFSFilterPanel getFilterPanel(){
384
                if (filterPanel != null)
385
                        return filterPanel;
386

387
                if (filterTabPosition == -1)
388
                        return null;
389

390
                return (filterPanel = (WFSFilterPanel) values().toArray()[filterTabPosition]);
391
        }
392
        */
393

    
394
        /**
395
         * This method initializes areaPanel
396
         *
397
         * @return javax.swing.JPanel
398
         */
399
        public WFSAreaPanel getAreaPanel() {
400
                if (areaPanel != null)
401
                        return areaPanel;
402

    
403
                if (areaTabPosition == -1)
404
                        return null;
405

    
406
                return (areaPanel = (WFSAreaPanel) values().toArray()[areaTabPosition]);
407
        }
408

    
409
        /**
410
         * Verifies that the selected parameters are enough to request
411
         * the coverage to the server.
412
         *
413
         * @return boolean <code>true</code> if its correctly configured;
414
         * otherwise returns <code>false</code>
415
         */
416
        public boolean isCorretlyConfigured() {
417

    
418
            if (featurePanel == null) {
419
                return false;
420
            }
421

    
422
            int n_sel = featurePanel.getSelectedFeaturesCount();
423
            return (n_sel > 0);
424
        }
425

    
426
        /**
427
         * Enable or disable the default tabs
428
         */
429
        public void enableDefaultTabs(boolean isEnabled) {
430
                if (fieldsTabPosition != -1)
431
                        setEnabledAt(fieldsTabPosition, isEnabled);
432

    
433
                /*
434
                if (filterTabPosition != -1)
435
                        setEnabledAt(filterTabPosition, isEnabled);
436
                        */
437

    
438
                if (areaTabPosition != -1)
439
                        setEnabledAt(areaTabPosition, isEnabled);
440
        }
441

    
442
        /*
443
         * (non-Javadoc)
444
         * @see org.gvsig.gui.beans.panelGroup.tabbedPanel.TabbedPanel#loadPanel(org.gvsig.gui.beans.panelGroup.panels.IPanel)
445
         */
446
        protected void loadPanel(IPanel panel) {
447
                super.loadPanel(panel);
448

    
449
                if (((AbstractPanel)panel).getClass() ==  WFSInfoPanel.class) {
450
                        infoTabPosition = getPanelInGUICount() - 1;
451
                        return;
452
                }
453

    
454
                if (((AbstractPanel)panel).getClass() ==  WFSSelectFeaturePanel.class) {
455
                        featureTabPosition = getPanelInGUICount() - 1;
456
                        return;
457
                }
458

    
459
                if (((AbstractPanel)panel).getClass() ==  WFSSelectFieldsPanel.class) {
460
                        fieldsTabPosition = getPanelInGUICount() - 1;
461
                        return;
462
                }
463

    
464
                if (((AbstractPanel)panel).getClass() ==  WFSOptionsPanel.class) {
465
                        optionsTabPosition = getPanelInGUICount() - 1;
466
                        return;
467
                }
468

    
469
                /*
470
                if (((AbstractPanel)panel).getClass() ==  WFSFilterPanel.class) {
471
                        filterTabPosition = getPanelInGUICount() - 1;
472
                        return;
473
                }
474
                */
475

    
476
                if (((AbstractPanel)panel).getClass() ==  WFSAreaPanel.class) {
477
                        areaTabPosition = getPanelInGUICount() - 1;
478
                        return;
479
                }
480
        }
481

    
482
        /**
483
         * Refresh all the panels with the WFS capabilities information.
484
         */
485
        public void refreshCapabilitiesInfo(){
486
                WFSSelectedFeature selectedFeature = getFeaturesPanel().getSelectedFeature();
487
                if (selectedFeature != null) {
488
                        selectedFeature.setSelectedFields(getFieldsPanel().getSelectedFields());
489
                } else {
490
                        getFeaturesPanel().refresh(null);
491
                }
492
                serverExplorer.setUserName(getOptionsPanel().getUserName());
493
                serverExplorer.setMaxFeatures(getOptionsPanel().getBuffer());
494
                serverExplorer.setTimeOut(getOptionsPanel().getTimeout());
495

    
496
                getInfoPanel().refresh(selectedFeature);
497
        }
498

    
499
        /**
500
         * Gets the information used to add or load a WFS layer.
501
         *
502
         * @return information used to add or load a WFS layer
503
         */
504
        public WFSServerExplorer getServerExplorer() {
505
                return serverExplorer;
506
        }
507

    
508
        /**
509
         * Sets the information used to add or load a WFS layer.
510
         *
511
         * @param wizardData information used to add or load a WFS layer
512
         */
513
        public void setServerExplorer(WFSServerExplorer serverExplorer) {
514
                this.serverExplorer = serverExplorer;
515
                this.selectedFeatureManager =
516
                        WFSSelectedFeatureManager.getInstance(serverExplorer);
517
        }
518

    
519
        /**
520
         * Returns the next enabled tab's index, or -1 if there isn't any.
521
         *
522
         * @return The index or -1 if there is no one.
523
         */
524
        public int nextPageEnabled() {
525
                int currentPage = getSelectedIndex();
526
                int nPages = getPanelInGUICount();
527

    
528
                if (currentPage == nPages)
529
                        return -1;
530

    
531
                for (int i = currentPage + 1; i < nPages; i++){
532
                        if (getJTabbedPane().isEnabledAt(i)){
533
                                return i;
534
                        }
535
                }
536

    
537
                return -1;
538
        }
539

    
540
        /**
541
         * Returns the index of the current tab.
542
         *
543
         * @return index of the current tab
544
         */
545
        public int currentPage() {
546
                return getSelectedIndex();
547
        }
548

    
549
        /**
550
         * Returns the index of the previous enabled tab.
551
         *
552
         * @return The index, or -1 if there is no one.
553
         */
554
        public int previousEnabledPage() {
555
                int currentPage = getSelectedIndex();
556

    
557
                if (currentPage == 0)
558
                        return -1;
559

    
560
                for (int i = currentPage - 1; i > -1; i--) {
561
                        if (isEnabledAt(i)) {
562
                                return i;
563
                        }
564
                }
565

    
566
                return -1;
567
        }
568

    
569
        /*
570
         *  (non-Javadoc)
571
         * @see com.iver.cit.gvsig.gui.WizardPanel#initWizard()
572
         */
573
        public void initWizard() {
574

    
575
        }
576

    
577
        /*
578
         *  (non-Javadoc)
579
         * @see com.iver.cit.gvsig.gui.WizardPanel#execute()
580
         */
581
        public void execute() {
582

    
583
        }
584

    
585
        /*
586
         *  (non-Javadoc)
587
         * @see com.iver.cit.gvsig.gui.ILayerPanel#getLayer()
588
         */
589
        public FLayer getLayer() {
590
            try {
591
                FLayer layer = (FLyrVect) createLayer();
592
                logger.warn("El flujo de la apliaci?n tal vez no deber?a haber pasado por aqu?.");
593
                return layer;
594
            } catch (CreateLayerException e) {
595
                // do nothing
596
            }
597
            return null;
598
        }
599

    
600
        public FLayer createLayer() throws CreateLayerException {
601
                try {
602
                    FLyrVect layerAux =
603
                        (FLyrVect)MAP_CONTEXT_MANAGER.createLayer(getFeaturesPanel().getLayerName(), getDataStoreParameters());
604

    
605
                        if((cacheSelected != null) && (!this.cacheSelected.equals(PluginServices.getText(this, "none")))){
606
                                layerAux.getFeatureStore().createCache(cacheSelected, getParameters(cacheSelected));
607
                        }
608
                        return layerAux;
609
                } catch (Exception e) {
610
                        logger.warn("Can't create layer.",e);
611
                        throw new CreateLayerException(getFeaturesPanel().getLayerName(), e);
612
                }
613

    
614
        }
615

    
616

    
617
         protected DynObject getParameters(String nameCacheProvider) throws DataException {
618
                 DataManager dataManager = DALLocator.getDataManager();
619
                 return dataManager.createCacheParameters(nameCacheProvider);
620
         }
621

    
622
        public WFSStoreParameters getDataStoreParameters() throws InitializeException, ProviderNotRegisteredException{
623
                DataManager dataManager = DALLocator.getDataManager();
624
                WFSStoreParameters parameters = (WFSStoreParameters) dataManager
625
                .createStoreParameters(WFSStoreProvider.NAME);
626
                refreshDataStoreParameters(parameters);
627
                return parameters;
628
        }
629

    
630
        private void refreshDataStoreParameters(WFSStoreParameters parameters){
631
                WFSSelectedFeature selectedFeature = getSelectedFeature();
632
                parameters.setUrl(serverExplorer.getUrl());
633
                parameters.setFeatureType(selectedFeature.getNameSpace(),
634
                                selectedFeature.getName());
635
                parameters.setFields(getFieldsPanel().getSelectedFieldsAsString());
636
                parameters.setUser(getOptionsPanel().getUserName());
637
                parameters.setPassword(getOptionsPanel().getPassword());
638
                parameters.setMaxFeatures(getOptionsPanel().getBuffer());
639
                parameters.setTimeOut(getOptionsPanel().getTimeout());
640

    
641
                boolean useAxisOrderYX = getOptionsPanel().getUseAxisOrderYX();
642
                parameters.setUseAxisOrderYX(useAxisOrderYX);
643

    
644
                // MapServer no funciona con filtros por intersecci?n de pol?gonos
645

    
646
//                parameters.setFilterByAreaGeometry(getAreaPanel().getArea());
647
                Geometry area = getAreaPanel().getArea();
648
                if (area != null) {
649

    
650
                        Envelope envelope = area.getEnvelope();
651
                        parameters.setFilterByAreaEnvelope(envelope);
652
                }
653
                parameters.setFilterByAreaCrs(getOptionsPanel().getSRS());
654

    
655
                XMLNameSpace ns = selectedFeature.getWFSFeature().getNamespace();
656
                if (ns != null) {
657
                String ns_pre = ns.getPrefix();
658
                parameters.setDynValue(
659
                    WFSStoreParameters.DYNFIELDNAME_NAMESPACEPREFIX, ns_pre);
660
                }
661
                // serverExplorer.getServerExplorerProviderServices();
662

    
663
                parameters.setVersion(getOptionsPanel().getVersion());
664

    
665
                parameters.setFilterByAreaOperation(FilterEncoding.GEOMETRIC_OPERATOR_CONTAINS); //(int)AbstractFilter.GEOMETRY_INTERSECTS);
666
                parameters.setFilterByAreaAttribute(selectedFeature.getGeometryField().getName());
667
                // parameters.setFilterEncodingByAttribute(getFilterPanel().getQuery());
668
        }
669

    
670
    /**
671
     * Sets the forms from a
672
     */
673
    public void setDataStore(DataStore dataStore){
674
        WFSStoreParameters storeParameters =
675
            (WFSStoreParameters)dataStore.getParameters();
676
        WFSSelectedFeature selectedFeature =
677
            selectedFeatureManager.getFeatureInfo(storeParameters.getFeatureNamespace(),
678
                storeParameters.getFeatureType());
679
        getFeaturesPanel().setSelectedFeature(selectedFeature);
680
        getFieldsPanel().setSelectedFields(storeParameters.getFields());
681
        getOptionsPanel().setUserName(storeParameters.getUser());
682
        getOptionsPanel().setPassword(storeParameters.getPassword());
683
        getOptionsPanel().setBuffer(storeParameters.getMaxFeatures());
684
        getOptionsPanel().setTimeOut(storeParameters.getTimeOut());
685
        getAreaPanel().setArea(storeParameters.getFilterByAreaGeometry());
686

    
687
        getOptionsPanel().setSRS(storeParameters.getFilterByAreaCrs());
688
        getOptionsPanel().setVersion(storeParameters.getVersion());
689

    
690
        // getFilterPanel().setFilterExpressionIntoInterface(storeParameters.getFilterEncodingByAttribute());
691

    
692
        //The filter panel needs to store to update the attributes list
693
        // getFilterPanel().setDataStore(dataStore);
694
    }
695

    
696
    /**
697
     * Gets the node of the layer selected as a feature, with the selected fields and the filter defined.
698
     *
699
     * @return gets the node of the layer selected as a feature, with the selected fields and the filter defined
700
     */
701
    private WFSSelectedFeature getSelectedFeature(){
702
        WFSSelectedFeature selectedFeature = getFeaturesPanel().getSelectedFeature();
703
        selectedFeature.setSelectedFields(getFieldsPanel().getSelectedFields());
704
        // selectedFeature.setFilter(getFilterPanel().getQuery());
705
        return selectedFeature;
706
    }
707

    
708
        /**
709
         * @see WFSWizard#doClickOnNextButton()
710
         */
711
        public void doClickOnNextButton() {
712
                Object obj = this.getParent();
713

    
714
                if (obj == null)
715
                        return;
716

    
717
                // When we start to connect to a server -> the interface is the dialog WFSWizard
718
                if (obj instanceof WFSWizard)
719
                        ((WFSWizard)this.getParent()).doClickOnNextButton();
720
                else {
721
                        // When we are modifying a loaded layer -> the interface is the dialog WFSPropsDialog
722
                        this.advanceCurrentTab();
723
                }
724
        }
725

    
726
        /**
727
         * Selects the next tab
728
         */
729
        public void advanceCurrentTab() {
730
                int currentTabIndex = this.getJTabbedPane().getSelectedIndex();
731

    
732
                // Ensure we can select next tab
733
                if ((currentTabIndex != -1) && (currentTabIndex < (values().size() -1)))
734
                        setSelectedIndex(currentTabIndex + 1);
735
        }
736

    
737
        /**
738
         * Refreshes the data of the inner <code>WFSSelectFeaturePanel</code>.
739
         */
740
        public void refreshWFSSelectFeaturePanel() {
741
                WFSSelectFeaturePanel panel = getFeaturesPanel();
742

    
743
                if (panel != null) {
744
                        panel.refresh(null);
745
                }
746
        }
747

    
748
        /**
749
         * @return the selected projection
750
         */
751
        public IProjection getSelectedFeatureProjection(){
752
                WFSSelectedFeature selectedFeature = getSelectedFeature();
753
                if (selectedFeature.getSrs().size() > 0){
754
                        String crs = (String)selectedFeature.getSrs().get(0);
755
                        crs = getSRS(crs);
756
                        IProjection projection = CRSFactory.getCRS(crs);
757
                        if (projection != null){
758
                                return projection;
759
                        }
760
                }
761
                return null;
762
        }
763

    
764
        /**
765
         * Removing the URN prefix
766
         * @param srs
767
         * @return
768
         */
769
        private String getSRS(String srs){
770
                if (srs == null){
771
                        return null;
772
                }
773
                if (srs.startsWith("urn:x-ogc:def:crs:")){
774
                        String newString = srs.substring(srs.lastIndexOf(":") + 1, srs.length());
775
                        if (srs.indexOf("EPSG") > 0){
776
                                if (newString.indexOf("EPSG") < 0){
777
                                        newString = "EPSG:" + newString;
778
                                }
779
                        }
780
                        return newString;
781
                }
782
                if (srs.toLowerCase().startsWith("crs:")){
783
                        return srs.substring(4, srs.length());
784
                }
785
                return srs;
786
        }
787

    
788
        /**
789
         * Refresh all the panels every time that a different layer is selected. The info panel is refreshed every time the user
790
         * makes a click on it.
791
         *
792
         * @param selectedFeature the selected layer
793
         */
794
        public void refresh(WFSSelectedFeature selectedFeature, List vers_list){
795
                boolean hasFields = false;
796

    
797
                if (selectedFeature!=null){
798
                        //Update the layer information
799
                        selectedFeature = selectedFeatureManager.getFeatureInfo(selectedFeature.getNameSpace(),
800
                                        selectedFeature.getName());
801

    
802
                        // If there is no fields -> disable not necessary tabs
803
                        if (selectedFeature.getWFSFeature().getFieldSize() == 0) {
804
                                setApplicable(false);
805
                                hasFields = false;
806
                        }else{
807
                                getFieldsPanel().refresh(selectedFeature);
808
                                getOptionsPanel().refresh(selectedFeature);
809
                getOptionsPanel().refreshVersions(vers_list);
810
                                // getFilterPanel().refresh(selectedFeature);
811
                                getAreaPanel().refresh(selectedFeature);
812
                                hasFields = true;
813
                        }
814
                }
815

    
816
                enableDefaultTabs(hasFields);
817
        }
818

    
819
        /**
820
         * Changes the <i>enable</i> status of the "<i>apply</i>" button
821
         *
822
         * @param isApplicable the <i>enable</i> status of the "<i>apply</i>" button
823
         */
824
        public void setApplicable(boolean isApplicable){
825
                setEnabledApplyButton(isApplicable);
826
        }
827

    
828
        /*
829
         * (non-Javadoc)
830
         * @see org.gvsig.gui.beans.buttonspanel.IButtonsPanel#setEnabledApplyButton(boolean)
831
         */
832
        public void setEnabledApplyButton(boolean b) {
833
                super.setEnabledApplyButton(b);
834

    
835
                Container parent = getParent();
836

    
837
                if ((parent != null) && (parent instanceof WizardPanel))
838
                        ((WizardPanel)parent).callStateChanged(b);
839
        }
840

    
841
        /*
842
         * (non-Javadoc)
843
         * @see org.gvsig.gui.beans.panelGroup.AbstractPanelGroup#loadPanels(org.gvsig.gui.beans.panelGroup.loaders.IPanelGroupLoader)
844
         */
845
        public void loadPanels(IPanelGroupLoader loader) throws ListCouldntAddPanelException, EmptyPanelGroupException, EmptyPanelGroupGUIException {
846
                // This code will be executed when is creating the dialog of properties
847
                if (getReference() != null) {
848
                        FLyrVect lyr = (FLyrVect) getReference();
849

    
850
                        DataManager dataManager = DALLocator.getDataManager();
851
                        //Create the datastore parameters and fill them
852
                        WFSStoreParameters parameters;
853
                        try {
854
                                parameters = (WFSStoreParameters) dataManager
855
                                .createStoreParameters(WFSStoreProvider.NAME);
856
                                parameters.setUrl(serverExplorer.getUrl());
857
                                parameters.setVersion(serverExplorer.getVersion());
858
                                //parameters.setFeatureType(namespacePrefix, namespace, featureType);
859

    
860
                                //dataSource.setDriver(lyr.getWfsDriver());
861

    
862
                                //setServerExplorer(dataSource);
863

    
864
                                super.loadPanels(loader);
865

    
866
                                //                                HashMap<String, Object> info = lyr.getProperties();
867
                                //                                setSelectedFeature((WFSLayerNode)info.get("wfsLayerNode"));
868
                                //                                setStatus((WFSStatus)info.get("status"));
869
                                //                                setLayerName(lyr.getName());
870
                                //                                setVisible(true);
871
                                //                                refreshInfo();
872
                        } catch (InitializeException e) {
873
                                // TODO Auto-generated catch block
874
                                e.printStackTrace();
875
                        } catch (ProviderNotRegisteredException e) {
876
                                // TODO Auto-generated catch block
877
                                e.printStackTrace();
878
                        }
879
                        return;
880
                }
881

    
882
                // This will executed when is adding a new WFS layer:
883
                super.loadPanels(loader);
884
        }
885

    
886
        ///// BEGIN: METHODS FOR INITIALIZE THIS PANEL AS A COMPONENT OF A PROPERTIES DIALOG /////
887

    
888

    
889
        /**
890
         * @see WFSSelectFeaturePanel#setLayerName(String)
891
         */
892
        public void setLayerName(String name) {
893
                getFeaturesPanel().setLayerName(name);
894
        }
895

    
896
        /**
897
         * Updates the information stored at the wizard's data and <i>info</i> panel.
898
         */
899
        public void refreshInfo(){
900
                WFSSelectedFeature selectedFeature = getFeaturesPanel().getSelectedFeature();
901

    
902
                if (selectedFeature != null) {
903
                        selectedFeature.setSelectedFields(getFieldsPanel().getSelectedFields());
904
                }
905

    
906
                serverExplorer.setUserName(getOptionsPanel().getUserName());
907
                serverExplorer.setMaxFeatures(getOptionsPanel().getBuffer());
908
                serverExplorer.setTimeOut(getOptionsPanel().getTimeout());
909
                getInfoPanel().refresh(selectedFeature);
910
        }
911

    
912
        /**
913
         * @return the selectedFeatureManager
914
         */
915
        public WFSSelectedFeatureManager getSelectedFeatureManager() {
916
                return selectedFeatureManager;
917
        }
918

    
919
        public void setSelectedCache(String selectedCache) {
920
                this.cacheSelected = selectedCache;
921
        }
922
}