Statistics
| Revision:

root / branches / v10 / extensions / extWFS2 / src / com / iver / cit / gvsig / gui / dialogs / WFSPropsDialog.java @ 9352

History | View | Annotate | Download (14.1 KB)

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

    
3
import java.awt.Component;
4
import java.awt.event.ActionEvent;
5
import java.awt.event.ActionListener;
6
import java.net.MalformedURLException;
7
import java.net.URL;
8
import java.util.HashMap;
9

    
10
import javax.swing.JButton;
11
import javax.swing.JOptionPane;
12
import javax.swing.JPanel;
13

    
14
import org.gvsig.remoteClient.wfs.WFSStatus;
15

    
16
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException;
17
import com.iver.andami.PluginServices;
18
import com.iver.andami.ui.mdiManager.IWindow;
19
import com.iver.andami.ui.mdiManager.WindowInfo;
20
import com.iver.cit.gvsig.fmap.DriverException;
21
import com.iver.cit.gvsig.fmap.MapControl;
22
import com.iver.cit.gvsig.fmap.drivers.wfs.FMapWFSDriver;
23
import com.iver.cit.gvsig.fmap.layers.FLayer;
24
import com.iver.cit.gvsig.fmap.layers.FLayers;
25
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
26
import com.iver.cit.gvsig.fmap.layers.FLyrWFS;
27
import com.iver.cit.gvsig.fmap.layers.FLyrWFSFactory;
28
import com.iver.cit.gvsig.fmap.layers.WFSLayerNode;
29
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
30
import com.iver.cit.gvsig.gui.layout.Layout;
31
import com.iver.cit.gvsig.gui.panels.WFSParamsPanel;
32
import com.iver.cit.gvsig.gui.wizards.WFSWizardData;
33
import com.iver.cit.gvsig.gui.wizards.WizardListener;
34
import com.iver.cit.gvsig.gui.wizards.WizardListenerSupport;
35
import com.iver.cit.gvsig.project.documents.view.gui.View;
36

    
37
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
38
 *
39
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
40
 *
41
 * This program is free software; you can redistribute it and/or
42
 * modify it under the terms of the GNU General Public License
43
 * as published by the Free Software Foundation; either version 2
44
 * of the License, or (at your option) any later version.
45
 *
46
 * This program is distributed in the hope that it will be useful,
47
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
48
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
49
 * GNU General Public License for more details.
50
 *
51
 * You should have received a copy of the GNU General Public License
52
 * along with this program; if not, write to the Free Software
53
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
54
 *
55
 * For more information, contact:
56
 *
57
 *  Generalitat Valenciana
58
 *   Conselleria d'Infraestructures i Transport
59
 *   Av. Blasco Ib??ez, 50
60
 *   46010 VALENCIA
61
 *   SPAIN
62
 *
63
 *      +34 963862235
64
 *   gvsig@gva.es
65
 *      www.gvsig.gva.es
66
 *
67
 *    or
68
 *
69
 *   IVER T.I. S.A
70
 *   Salamanca 50
71
 *   46005 Valencia
72
 *   Spain
73
 *
74
 *   +34 963163400
75
 *   dac@iver.es
76
 */
77
/* CVS MESSAGES:
78
 *
79
 * $Id: WFSPropsDialog.java 9352 2006-12-18 08:43:55Z jorpiell $
80
 * $Log$
81
 * Revision 1.4.2.9  2006-12-18 08:43:55  jorpiell
82
 * Add a new method to set the layerDriver
83
 *
84
 * Revision 1.4.2.8  2006/12/04 09:38:51  ppiqueras
85
 * Bug corregido
86
 *
87
 * Revision 1.15  2006/12/04 08:59:47  ppiqueras
88
 * Algunos bugs corregidos. A cambio hay 2 bugs relacionados que todav?a no han sido corregidos (ver PHPCollab) (los tiene asignados Jorge).
89
 *
90
 * Revision 1.14  2006/11/28 08:05:31  jorpiell
91
 * Se refrescan los mapas despu?s de aplicar un filtro
92
 *
93
 * Revision 1.13  2006/11/16 16:57:49  jorpiell
94
 * Se copia la laeyenda de la capa anterior antes de eliminarla
95
 *
96
 * Revision 1.12  2006/11/14 13:45:49  ppiqueras
97
 * A?adida peque?a funcionalidad:
98
 * 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.
99
 *
100
 * Revision 1.11  2006/10/31 09:40:49  jorpiell
101
 * Se ha creado una factoria para crear la capa. De ese modo no se repite c?digo desde le panel de propiedades y desde el panel de la capa
102
 *
103
 * Revision 1.9  2006/10/23 08:47:12  jorpiell
104
 * Refactorizado un m?todo
105
 *
106
 * Revision 1.8  2006/10/23 08:29:06  ppiqueras
107
 * Algunos cambios
108
 *
109
 * Revision 1.6  2006/10/02 09:09:45  jorpiell
110
 * Cambios del 10 copiados al head
111
 *
112
 * Revision 1.4.2.3  2006/09/27 11:12:15  jorpiell
113
 * Hay que comprobar que se han devuelto un n?mero de features menor que el n?mero m?ximo permitido
114
 *
115
 * Revision 1.4.2.2  2006/09/27 09:15:01  jorpiell
116
 * Ya no se hace otra petici?n al pulsar sobre el bot?n aceptar.
117
 *
118
 * Revision 1.4.2.1  2006/09/19 12:28:11  jorpiell
119
 * Ya no se depende de geotools
120
 *
121
 *
122
 * Revision 1.4  2006/08/30 07:42:29  jorpiell
123
 * Se le asigna a la capa creada una proyecci?n concreta. Si esto no se hace, al exportar a postigis se produce un error.
124
 *
125
 * Revision 1.3  2006/08/29 07:56:12  cesar
126
 * Rename the *View* family of classes to *Window* (ie: SingletonView to SingletonWindow, ViewInfo to WindowInfo, etc)
127
 *
128
 * Revision 1.2  2006/08/29 07:13:40  cesar
129
 * Rename class com.iver.andami.ui.mdiManager.View to com.iver.andami.ui.mdiManager.IWindow
130
 *
131
 * Revision 1.1  2006/06/21 12:35:45  jorpiell
132
 * 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
133
 *
134
 *
135
 */
136
/**
137
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
138
 */
139
public class WFSPropsDialog extends JPanel implements IWindow{
140
        private WFSParamsPanel wfsParamsTabbedPane = null;
141
        private WindowInfo m_ViewInfo = null;
142
        private FLayer fLayer = null;
143
        private JButton btnApply = null;
144
        private JButton btnOk = null;
145
        private JButton btnCancel = null;
146
        private CommandListener m_actionListener = null;
147
        private JPanel buttonsPanel = null;
148
        boolean applied = false;
149
        
150

    
151
    public WFSPropsDialog(FLayer layer) {
152
                super();
153
                initialize(layer);
154
        }
155
    
156
    private void initialize(FLayer layer) {
157
                setLayout(null);                
158
        setFLayer(layer);
159
        wfsParamsTabbedPane = getParamsPanel(((FLyrWFS) layer).getProperties());
160
        wfsParamsTabbedPane.addWizardListener(new WizardListener(){
161
                        public void wizardStateChanged(boolean finishable) {
162
                                getBtnOk().setEnabled(finishable);
163
                                getBtnApply().setEnabled(finishable);
164
                        }
165

    
166
                        public void error(Exception e) {
167
                        }
168
                
169
        })  ;
170
        //wfsParamsTabbedPane.disableDisagregatedLayers();
171
        this.add(wfsParamsTabbedPane);
172
        this.add(getButtonsPanel(), null);
173
    }
174
    
175
    public JPanel getButtonsPanel() {
176
                if (buttonsPanel == null) {
177
                        m_actionListener = new CommandListener(this);
178
                        buttonsPanel = new JPanel();
179
                buttonsPanel.setBounds(5, wfsParamsTabbedPane.getHeight(), 471, 40);
180
                        buttonsPanel.setLayout(null);     
181
                        buttonsPanel.setName("buttonPanel");
182
                        
183
                buttonsPanel.add(getBtnOk(), null);
184
                buttonsPanel.add(getBtnApply(), null);
185
                buttonsPanel.add(getBtnCancel(), null);
186
                }
187
                return buttonsPanel;
188
        }
189
        
190
    
191
    /**
192
         * With getParamsPanel we have access to the map config TabbedPane.
193
         * If this panel doesn't exist yet (which can occur when an existing project is
194
         * recovered) it is been automatically constructed by connecting to the server,
195
         * reloading the necessary data, filling up the content and setting the selected
196
         * values that were selected when the projet was saved.
197
         * 
198
         * 
199
         * Since a connection to the server is needed when rebuiliding the panel, this
200
         * causes a delay for the panel's showing up or a nullPointer error if there is
201
         * no path to the server.
202
         * 
203
         * 
204
         * Con getParamsPanel tenemos acceso a juego de pesta?as de configuraci?n
205
         * del mapa. Si este panel todav?a no existe (como puede ser cuando
206
         * recuperamos un proyecto guardado) ?ste se crea autom?ticamente conectando
207
         * al servidor, recuperando los datos necesarios, rellenando el contenido y
208
         * dejando seleccionados los valores que estaban seleccionados cuando se
209
         * guard? el proyecto.
210
         * 
211
         * 
212
         * Como para reconstruirse requiere una conexi?n con el servidor esto causa
213
         * un retardo en la aparici?n en el toc o un error de nullPointer si no
214
         * hay conexi?n hasta el servidor.
215
         * 
216
         * 
217
         * @return WMSParamsPanel
218
         */
219
        public WFSParamsPanel getParamsPanel(HashMap info) {
220
            if (info != null){
221
                    URL host = (URL) info.get("host");
222
                    WFSWizardData dataSource = new WFSWizardData();
223
                    //dataSource.setHost(host, false);
224
                    dataSource.setDriver(((FLyrWFS)fLayer).getWfsDriver());
225
                    WFSParamsPanel toc = new WFSParamsPanel();
226
                    toc.setWizardData(dataSource);
227
                    toc.setListenerSupport(new WizardListenerSupport());
228
                    toc.setSelectedFeature((WFSLayerNode)info.get("wfsLayerNode"));
229
                    toc.setLayerName(fLayer.getName());
230
                    toc.refreshInfo((WFSLayerNode)info.get("wfsLayerNode"));
231
                    toc.setStatus((WFSStatus)info.get("status"));
232
                    toc.setVisible(true);
233
                    applied = false;
234
                    return toc;                    
235
            }
236
            return null;        
237
        }
238
        
239
        
240
        public WindowInfo getWindowInfo() {
241
                if (m_ViewInfo == null){
242
                        m_ViewInfo=new WindowInfo(WindowInfo.MODALDIALOG);
243
                        m_ViewInfo.setTitle(PluginServices.getText(this,"fit_WFS_layer"));
244
                        m_ViewInfo.setWidth(wfsParamsTabbedPane.getWidth()+ 10);
245
                        m_ViewInfo.setHeight(wfsParamsTabbedPane.getHeight() + 40);
246
                }
247
                return m_ViewInfo;
248
        }
249

    
250
        /**
251
         * @return Returns the fLayer.
252
         */
253
        public FLayer getFLayer() {
254
                return fLayer;
255
        }
256

    
257
        /**
258
         * @param layer The fLayer to set.
259
         */
260
        public void setFLayer(FLayer layer) {
261
                fLayer = layer;
262
        }
263

    
264
        public JButton getBtnOk() {
265
                if (btnOk == null) {
266
                btnOk = new JButton("ok");
267
                btnOk.setText(PluginServices.getText(this,"ok"));
268
                btnOk.setActionCommand("OK");
269
                btnOk.addActionListener(m_actionListener);
270
                btnOk.setBounds(367, 9, 90, 25);
271
                }
272
                return btnOk;
273
        }
274
        
275
        public JButton getBtnApply() {
276
                if (btnApply == null) {
277
                btnApply = new JButton("apply");
278
                btnApply.setText(PluginServices.getText(this,"apply"));
279
                btnApply.setEnabled(false);
280
                btnApply.setActionCommand("APPLY");
281
                btnApply.addActionListener(m_actionListener);
282
                btnApply.setBounds(267, 9, 90, 25);
283
                }
284
                return btnApply;
285
        }
286
        
287
        public JButton getBtnCancel() {
288
                if (btnCancel == null) {
289
                btnCancel = new JButton("cancel");
290
                btnCancel.setText(PluginServices.getText(this,"cancel"));
291
                btnCancel.setActionCommand("CANCEL");
292
                btnCancel.addActionListener(m_actionListener);
293
                btnCancel.setBounds(137, 9, 90, 25);
294
                }
295
                return btnCancel;
296
        }
297
        
298
        public void close() {
299
                PluginServices.getMDIManager().closeWindow(this);                
300
        }  
301
        
302
         private class CommandListener implements ActionListener {
303
                 public CommandListener(WFSPropsDialog tp) {
304
                         //m_tp = tp;
305
                 }
306
                 
307
                 /* (non-Javadoc)
308
                  * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
309
                  */
310
                 public void actionPerformed(ActionEvent e) {
311
                         if (e.getActionCommand() == "CANCEL"){
312
                                 close();
313
                         }else{        
314
                                 String layerName = fLayer.getName();
315
                                        View activeView = (View) PluginServices.getMDIManager().getActiveWindow();
316
                                        VectorialLegend legend = (VectorialLegend)((FLyrVect)fLayer).getLegend();
317
                                        FMapWFSDriver driver = wfsParamsTabbedPane.getDriver();                                                
318
                                        try {
319
                                                fLayer = wfsParamsTabbedPane.getLayer();
320
                                                URL host = new URL(wfsParamsTabbedPane.getData().getHost());
321
                                                String onlineResource = wfsParamsTabbedPane.getData().getOnlineResource();
322
                                                fLayer = new FLyrWFSFactory().getFLyrWFS(fLayer,host,onlineResource,driver,true);
323
                                                if (fLayer != null){
324
                                                        ((FLyrWFS)fLayer).setLegend(legend);
325
                                                }
326
                                } catch (MalformedURLException e1) {
327
                                        // TODO Auto-generated catch block
328
                                        e1.printStackTrace();
329
                                } catch (FieldNotFoundException e1) {
330
                                        // TODO Auto-generated catch block
331
                                        e1.printStackTrace();
332
                                } catch (DriverException e1) {
333
                                        // TODO Auto-generated catch block
334
                                        e1.printStackTrace();
335
                                }                  
336
                                if (e.getActionCommand() == "APPLY"){
337
                                         if (loadLayer(fLayer)){                 
338
                                                 View vista = (View) PluginServices.getMDIManager().getActiveWindow();
339
                                                 MapControl mapCtrl = vista.getMapControl();
340
                                
341
                                                 mapCtrl.getMapContext().getLayers().replaceLayer(layerName, fLayer);
342
                                                 
343
                                                 mapCtrl.getMapContext().invalidate();
344
                                                 applied = true;
345
                                                 getBtnApply().setEnabled(!applied);
346
                                                 refreshLayouts();                                                 
347

    
348
                                                 // If we load another layer, or the same but we've selected others attributes -> notify it to he WFSFilter panel
349
                                                 if (getWFSFilterPanelIsAsTabForWFSLayersLoad() || (wfsParamsTabbedPane.getAttributesSelectedOfSameLayerHasChanged())) {
350
                                                         setWFSFilterPanelIsAsTabForWFSLayersLoad(false);
351
                                                         wfsParamsTabbedPane.resetAttributesSelectedOfSameLayerHasChanged(); // reset that attribute
352
                                                 }
353
                                                 
354
                                                 wfsParamsTabbedPane.updateWFSFilterFieldValues();
355
                                         }
356
                                 }
357
                                 if (e.getActionCommand() == "OK") {
358
                                         if (!applied) {
359
                                                 if (getBtnApply().isEnabled()){
360
                                                         if (loadLayer(fLayer)){
361
                                                                 View vista = (View) PluginServices.getMDIManager().getActiveWindow();
362
                                                                 MapControl mapCtrl = vista.getMapControl();
363
                                                                 mapCtrl.getMapContext().getLayers().replaceLayer(layerName, fLayer);
364
                                                                 mapCtrl.getMapContext().invalidate();
365
                                                                 refreshLayouts();
366
                                                         }
367
                                                 }
368
                                         }        
369
                                         close();                                
370
                                 }
371
                         }
372
                 }
373
                 private boolean loadLayer(FLayer flayer){
374
                         try {
375
                                 ((FLyrWFS)fLayer).load();
376
                                
377
                                 if (((FLyrWFS)fLayer).getNumfeatures() == ((FLyrWFS)fLayer).getWfsDriver().getRowCount())  {
378
                                         JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
379
                                                         PluginServices.getText(this,"maxFeatures_aviso"));        
380
                                 }
381
                         } catch (Exception e1) {
382
                                 // TODO Auto-generated catch block
383
                                 e1.printStackTrace();
384
                                 JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
385
                                                 PluginServices.getText(this,"cantLoad"));
386
                                 return false;
387
                         }
388
                         return true;
389
                 }                         
390
                 
391
         }
392
         
393
        /**
394
         * @see WFSFilterPanel#setWFSFilterPanelIsAsTabForWFSLayersLoad(boolean)
395
         */
396
        public void setWFSFilterPanelIsAsTabForWFSLayersLoad(boolean b) {
397
                this.wfsParamsTabbedPane.setWFSFilterPanelIsAsTabForWFSLayersLoad(b);
398
        }
399
        
400
        /**
401
         * @see WFSFilterPanel#getWFSFilterPanelIsAsTabForWFSLayersLoad()
402
         */
403
        public boolean getWFSFilterPanelIsAsTabForWFSLayersLoad() {
404
                return this.wfsParamsTabbedPane.getWFSFilterPanelIsAsTabForWFSLayersLoad();
405
        }
406
        
407
        /**
408
         * Refresh the layouts
409
         *
410
         */
411
        private void refreshLayouts(){        
412
                IWindow[] windows = PluginServices.getMDIManager().getAllWindows();
413
                for (int i=0 ; i<windows.length ; i++){
414
                        if (windows[i] instanceof Layout){
415
                                ((Layout)windows[i]).fullRefresh();
416
                        }
417
                }
418
        }
419
}
420