Statistics
| Revision:

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

History | View | Annotate | Download (14.4 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 9152 2006-12-04 09:38:51Z ppiqueras $
80
 * $Log$
81
 * Revision 1.4.2.8  2006-12-04 09:38:51  ppiqueras
82
 * Bug corregido
83
 *
84
 * Revision 1.15  2006/12/04 08:59:47  ppiqueras
85
 * Algunos bugs corregidos. A cambio hay 2 bugs relacionados que todav?a no han sido corregidos (ver PHPCollab) (los tiene asignados Jorge).
86
 *
87
 * Revision 1.14  2006/11/28 08:05:31  jorpiell
88
 * Se refrescan los mapas despu?s de aplicar un filtro
89
 *
90
 * Revision 1.13  2006/11/16 16:57:49  jorpiell
91
 * Se copia la laeyenda de la capa anterior antes de eliminarla
92
 *
93
 * Revision 1.12  2006/11/14 13:45:49  ppiqueras
94
 * A?adida peque?a funcionalidad:
95
 * 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.
96
 *
97
 * Revision 1.11  2006/10/31 09:40:49  jorpiell
98
 * 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
99
 *
100
 * Revision 1.9  2006/10/23 08:47:12  jorpiell
101
 * Refactorizado un m?todo
102
 *
103
 * Revision 1.8  2006/10/23 08:29:06  ppiqueras
104
 * Algunos cambios
105
 *
106
 * Revision 1.6  2006/10/02 09:09:45  jorpiell
107
 * Cambios del 10 copiados al head
108
 *
109
 * Revision 1.4.2.3  2006/09/27 11:12:15  jorpiell
110
 * Hay que comprobar que se han devuelto un n?mero de features menor que el n?mero m?ximo permitido
111
 *
112
 * Revision 1.4.2.2  2006/09/27 09:15:01  jorpiell
113
 * Ya no se hace otra petici?n al pulsar sobre el bot?n aceptar.
114
 *
115
 * Revision 1.4.2.1  2006/09/19 12:28:11  jorpiell
116
 * Ya no se depende de geotools
117
 *
118
 *
119
 * Revision 1.4  2006/08/30 07:42:29  jorpiell
120
 * Se le asigna a la capa creada una proyecci?n concreta. Si esto no se hace, al exportar a postigis se produce un error.
121
 *
122
 * Revision 1.3  2006/08/29 07:56:12  cesar
123
 * Rename the *View* family of classes to *Window* (ie: SingletonView to SingletonWindow, ViewInfo to WindowInfo, etc)
124
 *
125
 * Revision 1.2  2006/08/29 07:13:40  cesar
126
 * Rename class com.iver.andami.ui.mdiManager.View to com.iver.andami.ui.mdiManager.IWindow
127
 *
128
 * Revision 1.1  2006/06/21 12:35:45  jorpiell
129
 * 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
130
 *
131
 *
132
 */
133
/**
134
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
135
 */
136
public class WFSPropsDialog extends JPanel implements IWindow{
137
        private WFSParamsPanel wfsParamsTabbedPane = null;
138
        private WindowInfo m_ViewInfo = null;
139
        private FLayer fLayer = null;
140
        private JButton btnApply = null;
141
        private JButton btnOk = null;
142
        private JButton btnCancel = null;
143
        private CommandListener m_actionListener = null;
144
        private JPanel buttonsPanel = null;
145
        boolean applied = false;
146
        
147

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

    
163
                        public void error(Exception e) {
164
                        }
165
                
166
        })  ;
167
        //wfsParamsTabbedPane.disableDisagregatedLayers();
168
        this.add(wfsParamsTabbedPane);
169
        this.add(getButtonsPanel(), null);
170
    }
171
    
172
    public JPanel getButtonsPanel() {
173
                if (buttonsPanel == null) {
174
                        m_actionListener = new CommandListener(this);
175
                        buttonsPanel = new JPanel();
176
                buttonsPanel.setBounds(5, wfsParamsTabbedPane.getHeight(), 471, 40);
177
                        buttonsPanel.setLayout(null);     
178
                        buttonsPanel.setName("buttonPanel");
179
                        
180
                buttonsPanel.add(getBtnOk(), null);
181
                buttonsPanel.add(getBtnApply(), null);
182
                buttonsPanel.add(getBtnCancel(), null);
183
                }
184
                return buttonsPanel;
185
        }
186
        
187
    
188
    /**
189
         * With getParamsPanel we have access to the map config TabbedPane.
190
         * If this panel doesn't exist yet (which can occur when an existing project is
191
         * recovered) it is been automatically constructed by connecting to the server,
192
         * reloading the necessary data, filling up the content and setting the selected
193
         * values that were selected when the projet was saved.
194
         * 
195
         * 
196
         * Since a connection to the server is needed when rebuiliding the panel, this
197
         * causes a delay for the panel's showing up or a nullPointer error if there is
198
         * no path to the server.
199
         * 
200
         * 
201
         * Con getParamsPanel tenemos acceso a juego de pesta?as de configuraci?n
202
         * del mapa. Si este panel todav?a no existe (como puede ser cuando
203
         * recuperamos un proyecto guardado) ?ste se crea autom?ticamente conectando
204
         * al servidor, recuperando los datos necesarios, rellenando el contenido y
205
         * dejando seleccionados los valores que estaban seleccionados cuando se
206
         * guard? el proyecto.
207
         * 
208
         * 
209
         * Como para reconstruirse requiere una conexi?n con el servidor esto causa
210
         * un retardo en la aparici?n en el toc o un error de nullPointer si no
211
         * hay conexi?n hasta el servidor.
212
         * 
213
         * 
214
         * @return WMSParamsPanel
215
         */
216
        public WFSParamsPanel getParamsPanel(HashMap info) {
217
            if (info!=null){
218
                    try {                            
219
                            URL host = (URL) info.get("host");
220
                            WFSWizardData dataSource = new WFSWizardData();
221
                            dataSource.setHost(host, false);
222

    
223
                            WFSParamsPanel toc = new WFSParamsPanel();
224
                            toc.setWizardData(dataSource);
225
                            toc.setListenerSupport(new WizardListenerSupport());
226
                            toc.setSelectedFeature((WFSLayerNode)info.get("wfsLayerNode"));
227
                            toc.setLayerName(fLayer.getName());
228
                            toc.refreshInfo((WFSLayerNode)info.get("wfsLayerNode"));
229
                            toc.setStatus((WFSStatus)info.get("status"));
230
                            toc.setVisible(true);
231
                            applied = false;
232
                            return toc;
233
                    } catch (DriverException e) {
234
                                // TODO Auto-generated catch block
235
                                e.printStackTrace();
236
                        }
237
            }
238
            return null;        
239
        }
240
        
241
        
242
        public WindowInfo getWindowInfo() {
243
                if (m_ViewInfo == null){
244
                        m_ViewInfo=new WindowInfo(WindowInfo.MODALDIALOG);
245
                        m_ViewInfo.setTitle(PluginServices.getText(this,"fit_WFS_layer"));
246
                        m_ViewInfo.setWidth(wfsParamsTabbedPane.getWidth()+ 10);
247
                        m_ViewInfo.setHeight(wfsParamsTabbedPane.getHeight() + 40);
248
                }
249
                return m_ViewInfo;
250
        }
251

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

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

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

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