Statistics
| Revision:

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

History | View | Annotate | Download (10.4 KB)

1
package com.iver.cit.gvsig.gui.panels;
2

    
3
import java.awt.Dimension;
4
import java.awt.geom.Rectangle2D;
5

    
6
import javax.swing.JOptionPane;
7

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

    
10
import com.iver.andami.PluginServices;
11
import com.iver.cit.gvsig.fmap.drivers.wfs.FMapWFSDriver;
12
import com.iver.cit.gvsig.fmap.layers.FLyrWFS;
13
import com.iver.cit.gvsig.fmap.layers.WFSLayerNode;
14
import com.iver.cit.gvsig.gui.wizards.WFSWizardData;
15

    
16

    
17
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
18
 *
19
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
20
 *
21
 * This program is free software; you can redistribute it and/or
22
 * modify it under the terms of the GNU General Public License
23
 * as published by the Free Software Foundation; either version 2
24
 * of the License, or (at your option) any later version.
25
 *
26
 * This program is distributed in the hope that it will be useful,
27
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29
 * GNU General Public License for more details.
30
 *
31
 * You should have received a copy of the GNU General Public License
32
 * along with this program; if not, write to the Free Software
33
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
34
 *
35
 * For more information, contact:
36
 *
37
 *  Generalitat Valenciana
38
 *   Conselleria d'Infraestructures i Transport
39
 *   Av. Blasco Ib??ez, 50
40
 *   46010 VALENCIA
41
 *   SPAIN
42
 *
43
 *      +34 963862235
44
 *   gvsig@gva.es
45
 *      www.gvsig.gva.es
46
 *
47
 *    or
48
 *
49
 *   IVER T.I. S.A
50
 *   Salamanca 50
51
 *   46005 Valencia
52
 *   Spain
53
 *
54
 *   +34 963163400
55
 *   dac@iver.es
56
 */
57
/* CVS MESSAGES:
58
 *
59
 * $Id$
60
 * $Log$
61
 *
62
 */
63
/**
64
 * This class contains the objects (panels) that
65
 * are used to establish a WFS connection.
66
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
67
 */
68
public class WFSParamsPanelData {
69
        //All the panels
70
        private WFSSelectFeaturePanel featurePanel = null;
71
        private WFSSelectFieldsPanel fieldsPanel = null;
72
        private WFSOptionsPanel optionsPanel = null;
73
        private WFSFilterPanel filterPanel = null;
74
        private WFSAreaPanel areaPanel = null;
75
        private WFSInfoPanel infoPanel;
76
        //The wizard
77
        private WFSWizardData wizardData = null;
78
        //The panel that contains all the panels
79
        private WFSParamsPanel panel = null;
80
        //The driver
81
        private FMapWFSDriver driver = null;
82

    
83
        public WFSParamsPanelData(WFSParamsPanel panel) {
84
                super();
85
                this.panel = panel;
86
        }
87

    
88
        public WFSParamsPanelData() {
89
                super();                
90
        }
91

    
92
        /**
93
         * Update the WFS status
94
         * @param status
95
         */
96
        public void updateStatus(WFSStatus status) {
97
                getInfoPanel().updateStatus(status);
98
                getFeaturePanel().updateStatus(status);
99
                getFieldsPanel().updateStatus(status);
100
                getOptionsPanel().setStatus(status);                
101
                getFilterPanel().setFilterExpressionIntoInterface(status.getFilterVisualText());
102
                getAreaPanel().updateStatus(status);
103
        }
104

    
105
        /**
106
         * Refresh all the panels every time that a different layer
107
         * is selected. The info panel is refreshed every time the user 
108
         * makes a click on it.
109
         * @param layer
110
         * The selected layer
111
         */
112
        public void refresh(WFSLayerNode layer){
113
                boolean hasFields = false;
114

    
115
                if (layer!=null){
116
                //Update the layer information
117
                        layer = (WFSLayerNode)wizardData.getFeatureInfo(layer.getName(), layer.getNameSpace());
118
                        // If there is no fields -> disable not necessary tabs
119
                        if (layer.getFields().size() == 0) {
120
                                isApplicable(false);
121
                                hasFields = false;
122
                        }else{        
123
                                fieldsPanel.refresh(layer);                        
124
                                optionsPanel.refresh(layer);
125
                                filterPanel.refresh(layer);
126
                                areaPanel.refresh(layer);
127
                                hasFields = true;
128
                        }
129
                }
130
                if (panel != null){
131
                        panel.enableDefaultTabs(hasFields);
132
                        panel.getListenerSupport().callStateChanged(isCorretlyConfigured());
133
                }
134
        }
135

    
136
        /**
137
         * Refresh all the panels with the WFS capabilities 
138
         * information
139
         */
140
        public void refreshCapabilitiesInfo(){
141
                WFSLayerNode selectedNode = featurePanel.getWFSLayerNode();
142
                if (selectedNode != null){
143
                        selectedNode.setSelectedFields(fieldsPanel.getSelectedFields());
144
                }else{
145
                        featurePanel.refresh(null);
146
                }
147
                wizardData.setUserName(getOptionsPanel().getUserName());
148
                wizardData.setBuffer(getOptionsPanel().getBuffer());
149
                wizardData.setTimeOut(getOptionsPanel().getTimeout());
150
                infoPanel.refresh(selectedNode);
151
        }                
152

    
153
        /**
154
         * Sets the parent panel apply button active
155
         * @param isApplicable
156
         */
157
        public void isApplicable(boolean isApplicable){
158
                if (panel != null){
159
                        panel.isApplicable(isApplicable);
160
                }        
161
                getFeaturePanel().getPanelGroup().setEnabledApplyButton(isApplicable);
162
        }
163

    
164
        /**
165
         * @return the featurePanel
166
         */
167
        public WFSSelectFeaturePanel getFeaturePanel() {
168
                if (featurePanel == null) {
169
                        featurePanel = new WFSSelectFeaturePanel();
170
                        featurePanel.setParamsPanelData(this);
171
                        featurePanel.setVisible(true);
172
                }
173
                return featurePanel;
174
        }
175

    
176
        /**
177
         * @param featurePanel the featurePanel to set
178
         */
179
        public void setFeaturePanel(WFSSelectFeaturePanel featurePanel) {
180
                this.featurePanel = featurePanel;
181
        }
182

    
183
        /**
184
         * @return the fieldsPanel
185
         */
186
        public WFSSelectFieldsPanel getFieldsPanel() {
187
                if (fieldsPanel == null) {
188
                        fieldsPanel = new WFSSelectFieldsPanel();
189
                        fieldsPanel.setParamsPanelData(this);
190
                        fieldsPanel.setVisible(true);
191
                }
192
                return fieldsPanel;
193
        }
194

    
195
        /**
196
         * @param fieldsPanel the fieldsPanel to set
197
         */
198
        public void setFieldsPanel(WFSSelectFieldsPanel fieldsPanel) {
199
                this.fieldsPanel = fieldsPanel;
200
        }
201

    
202
        /**
203
         * @return the optionsPanel
204
         */
205
        public WFSOptionsPanel getOptionsPanel() {
206
                if (optionsPanel == null) {
207
                        optionsPanel = new WFSOptionsPanel();
208
                        optionsPanel.setParamsPanelData(this);
209
                        optionsPanel.setVisible(true);
210
                }
211
                return optionsPanel;
212
        }
213

    
214
        /**
215
         * @param optionsPanel the optionsPanel to set
216
         */
217
        public void setOptionsPanel(WFSOptionsPanel optionsPanel) {
218
                this.optionsPanel = optionsPanel;
219
        }
220

    
221
        /**
222
         * @return the filterPanel
223
         */
224
        public WFSFilterPanel getFilterPanel() {
225
                if (filterPanel == null) {
226
                        filterPanel = new WFSFilterPanel();
227
                        filterPanel.setParamsPanelData(this);
228
                        filterPanel.setVisible(true);                        
229
                }
230
                return filterPanel;
231
        }
232

    
233
        /**
234
         * @param filterPanel the filterPanel to set
235
         */
236
        public void setFilterPanel(WFSFilterPanel filterPanel) {
237
                this.filterPanel = filterPanel;
238
        }
239

    
240
        /**
241
         * @return the areaPanel
242
         */
243
        public WFSAreaPanel getAreaPanel() {
244
                if (areaPanel == null) {
245
                        areaPanel = new WFSAreaPanel();
246
                        areaPanel.setParamsPanelData(this);
247
                        areaPanel.setVisible(true);                        
248
                }
249
                return areaPanel;
250
        }
251

    
252
        /**
253
         * @param areaPanel the areaPanel to set
254
         */
255
        public void setAreaPanel(WFSAreaPanel areaPanel) {
256
                this.areaPanel = areaPanel;
257
        }
258

    
259
        /**
260
         * @return the infoPanel
261
         */
262
        public WFSInfoPanel getInfoPanel() {
263
                if (infoPanel==null) {
264
                        infoPanel = new WFSInfoPanel();        
265
                        infoPanel.setParamsPanelData(this);
266
                        infoPanel.setVisible(true);
267
                }
268
                return infoPanel;
269
        }
270

    
271
        /**
272
         * @param infoPanel the infoPanel to set
273
         */
274
        public void setInfoPanel(WFSInfoPanel infoPanel) {
275
                this.infoPanel = infoPanel;
276
        }
277

    
278
        /**
279
         * @return the wizardData
280
         */
281
        public WFSWizardData getWizardData() {
282
                return wizardData;
283
        }
284

    
285
        /**
286
         * @param wizardData the wizardData to set
287
         */
288
        public void setWizardData(WFSWizardData wizardData) {
289
                this.wizardData = wizardData;
290
        }
291

    
292
        /**
293
         * Verifies that the selected parameters are enough
294
         * to request the layer  to the server.
295
         */
296
        public boolean isCorretlyConfigured() {
297
                if (featurePanel.getWFSLayerNode() != null) {
298
                        return true;
299
                }else{
300
                        return false;
301
                }
302
        }
303

    
304
        /**
305
         * Sets a panel
306
         * @param panel
307
         */
308
        public void setPanel(IWFSDialogPanel panel) {
309
                if (panel instanceof WFSInfoPanel){
310
                        setInfoPanel((WFSInfoPanel)panel);
311
                }else if (panel instanceof WFSSelectFeaturePanel){
312
                        setFeaturePanel((WFSSelectFeaturePanel)panel);
313
                }else if (panel instanceof WFSSelectFieldsPanel){
314
                        setFieldsPanel((WFSSelectFieldsPanel)panel);
315
                }else if (panel instanceof WFSOptionsPanel){
316
                        setOptionsPanel((WFSOptionsPanel)panel);
317
                }else if (panel instanceof WFSFilterPanel){
318
                        setFilterPanel((WFSFilterPanel)panel);
319
                }else if (panel instanceof WFSAreaPanel){
320
                        setAreaPanel((WFSAreaPanel)panel);
321
                }                 
322
        }
323

    
324
        /**
325
         * @return the driver
326
         */
327
        public FMapWFSDriver getDriver() {
328
                return wizardData.getDriver();
329
        }        
330

    
331
        /**
332
         * Creates a FLyrWFS
333
         * @return
334
         * The layer
335
         */
336
        public FLyrWFS getLayer(){
337
                FLyrWFS layer = new FLyrWFS();
338
                layer.setName(getFeaturePanel().getLayerText());
339
                layer.setLayerName(getFeaturePanel().getLayerName());
340
                layer.setWfsLayerNode(getSelectedLayerNode());
341
                layer.setFields(getFieldsPanel().getSelectedFields());
342
                layer.setUserName(getOptionsPanel().getUserName());
343
                layer.setPassword(getOptionsPanel().getPassword());
344
                layer.setNumfeatures(getOptionsPanel().getBuffer());
345
                layer.setTimeout(getOptionsPanel().getTimeout());
346
                layer.setSrs(getOptionsPanel().getSRS());
347
                layer.setNameSapce(getFieldsPanel().getNamespace());
348

    
349
                // Sets the area (bounding box) filter
350
                Rectangle2D bbox = getAreaPanel().getExtent();
351

    
352
                if (getAreaPanel().hasUserDefinedAnArea()) {
353
                        // If user has written some invalid data in the coordinates text fields of the area tab
354
                        if ((bbox == null) && (getAreaPanel().areThereSomeCoordinatesWritten())) {
355
                                // Notify to user that no filter area will be applied
356
                                JOptionPane.showMessageDialog(null, PluginServices.getText(null, "no_filter_area_will_be_applied_in_the_load_of_the_layer"), PluginServices.getText(null, "warning"), JOptionPane.WARNING_MESSAGE);
357
                        }
358
                }
359

    
360
                layer.setBbox(bbox);
361
                String BboxPropertyName = getFieldsPanel().getGeometryFieldName();
362
                layer.setBboxPropertyName(BboxPropertyName);
363

    
364
                // Set the filter subconsultation that layer is
365
                layer.setFieldsQuery(getSelectedLayerNode().getFilter());
366
                layer.setVisualFilterQuery(getFilterPanel().getFilterExpressionFromInterface());
367
                layer.setWfsDriver(getDriver());
368
                return layer;
369
        }
370
        
371
        /**
372
         * @return the selected layer node 
373
         */
374
        private WFSLayerNode getSelectedLayerNode(){
375
                WFSLayerNode layerNode = getFeaturePanel().getWFSLayerNode();
376
                if (layerNode == null){
377
                        return null;
378
                }                
379
                layerNode.setSelectedFields(getFieldsPanel().getSelectedFields());
380
                
381
                // If the query is incorrect -> no query (no filter)
382
                String query = getFilterPanel().getQuery();
383
                if (query == null) {
384
                        layerNode.setFilter("");
385

    
386
                        // Removes filter expression from the JTextArea
387
                        getFilterPanel().removeFilterExpression();
388

    
389
                        // Notify to user that no filter will be applied
390
                        JOptionPane.showMessageDialog(null, PluginServices.getText(null, "no_filter_will_be_applied_in_the_load_of_the_layer"), PluginServices.getText(null, "warning"), JOptionPane.WARNING_MESSAGE);
391
                }
392
                else {
393
                        layerNode.setFilter(query);
394
                }
395

    
396
                return layerNode;
397
        }
398
}