Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extWFS2 / src / com / iver / cit / gvsig / gui / dialogs / WFSPropsDialog.java @ 8746

History | View | Annotate | Download (12.5 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.iver.andami.PluginServices;
17
import com.iver.andami.ui.mdiManager.IWindow;
18
import com.iver.andami.ui.mdiManager.WindowInfo;
19
import com.iver.cit.gvsig.fmap.DriverException;
20
import com.iver.cit.gvsig.fmap.MapControl;
21
import com.iver.cit.gvsig.fmap.drivers.wfs.FMapWFSDriver;
22
import com.iver.cit.gvsig.fmap.layers.FLayer;
23
import com.iver.cit.gvsig.fmap.layers.FLayers;
24
import com.iver.cit.gvsig.fmap.layers.FLyrWFS;
25
import com.iver.cit.gvsig.fmap.layers.FLyrWFSFactory;
26
import com.iver.cit.gvsig.fmap.layers.WFSLayerNode;
27
import com.iver.cit.gvsig.gui.panels.WFSParamsPanel;
28
import com.iver.cit.gvsig.gui.wizards.WFSWizardData;
29
import com.iver.cit.gvsig.gui.wizards.WizardListener;
30
import com.iver.cit.gvsig.gui.wizards.WizardListenerSupport;
31
import com.iver.cit.gvsig.project.documents.view.gui.View;
32

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

    
132
    public WFSPropsDialog(FLayer layer) {
133
                super();
134
                initialize(layer);
135
        }
136
    
137
    private void initialize(FLayer layer) {
138
                setLayout(null);                
139
        setFLayer(layer);
140
        wfsParamsTabbedPane = getParamsPanel(((FLyrWFS) layer).getProperties());
141
        wfsParamsTabbedPane.addWizardListener(new WizardListener(){
142
                        public void wizardStateChanged(boolean finishable) {
143
                                getBtnOk().setEnabled(finishable);
144
                                getBtnApply().setEnabled(finishable);
145
                        }
146

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

    
207
                            WFSParamsPanel toc = new WFSParamsPanel();
208
                            toc.setWizardData(dataSource);
209
                            toc.setListenerSupport(new WizardListenerSupport());
210
                            toc.setSelectedFeature((WFSLayerNode)info.get("wfsLayerNode"));
211
                            toc.setLayerName(fLayer.getName());
212
                            toc.refreshInfo((WFSLayerNode)info.get("wfsLayerNode"));
213
                            toc.setStatus((WFSStatus)info.get("status"));
214
                            toc.setVisible(true);
215
                            applied = false;
216
                            return toc;
217
                    } catch (DriverException e) {
218
                                // TODO Auto-generated catch block
219
                                e.printStackTrace();
220
                        }
221
            }
222
            return null;        
223
        }
224
        
225
        
226
        public WindowInfo getWindowInfo() {
227
                if (m_ViewInfo == null){
228
                        m_ViewInfo=new WindowInfo(WindowInfo.MODALDIALOG);
229
                        m_ViewInfo.setTitle(PluginServices.getText(this,"fit_WFS_layer"));
230
                        m_ViewInfo.setWidth(wfsParamsTabbedPane.getWidth()+ 10);
231
                        m_ViewInfo.setHeight(wfsParamsTabbedPane.getHeight() + 40);
232
                }
233
                return m_ViewInfo;
234
        }
235

    
236
        /**
237
         * @return Returns the fLayer.
238
         */
239
        public FLayer getFLayer() {
240
                return fLayer;
241
        }
242

    
243
        /**
244
         * @param layer The fLayer to set.
245
         */
246
        public void setFLayer(FLayer layer) {
247
                fLayer = layer;
248
        }
249

    
250
        public JButton getBtnOk() {
251
                if (btnOk == null) {
252
                btnOk = new JButton("ok");
253
                btnOk.setText(PluginServices.getText(this,"ok"));
254
                btnOk.setActionCommand("OK");
255
                btnOk.addActionListener(m_actionListener);
256
                btnOk.setBounds(367, 9, 90, 25);
257
                }
258
                return btnOk;
259
        }
260
        
261
        public JButton getBtnApply() {
262
                if (btnApply == null) {
263
                btnApply = new JButton("apply");
264
                btnApply.setText(PluginServices.getText(this,"apply"));
265
                btnApply.setEnabled(false);
266
                btnApply.setActionCommand("APPLY");
267
                btnApply.addActionListener(m_actionListener);
268
                btnApply.setBounds(267, 9, 90, 25);
269
                }
270
                return btnApply;
271
        }
272
        
273
        public JButton getBtnCancel() {
274
                if (btnCancel == null) {
275
                btnCancel = new JButton("cancel");
276
                btnCancel.setText(PluginServices.getText(this,"cancel"));
277
                btnCancel.setActionCommand("CANCEL");
278
                btnCancel.addActionListener(m_actionListener);
279
                btnCancel.setBounds(137, 9, 90, 25);
280
                }
281
                return btnCancel;
282
        }
283
        
284
        public void close() {
285
                PluginServices.getMDIManager().closeWindow(this);                
286
        }
287
        
288
    /**
289
     * Merge two FLayers in one
290
     * @param group1
291
     * @param group2
292
     * @return
293
     */
294
    private FLayers mergeFLayers(FLayers group1, FLayers group2)
295
    {            
296
            FLayer layer;
297
            for(int i = 0; i < group2.getLayersCount(); i++)
298
            {
299
                    layer = group2.getLayer( i );
300
                    if(group1.getLayer( layer.getName()) == null ){
301
                            group1.addLayer( layer );
302
                    }
303
            }
304
            
305
            return group1;
306
    }
307
        
308
         private class CommandListener implements ActionListener {
309
                 public CommandListener(WFSPropsDialog tp) {
310
                         //m_tp = tp;
311
                 }
312
                 
313
                 /* (non-Javadoc)
314
                  * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
315
                  */
316
                 public void actionPerformed(ActionEvent e) {
317
                         if (e.getActionCommand() == "CANCEL"){
318
                                 close();
319
                         }else{        
320
                                String layerName = fLayer.getName();
321
                                View activeView = 
322
                                        (View) PluginServices.getMDIManager().getActiveWindow();
323
                                
324
                                 try {
325
                                        fLayer = wfsParamsTabbedPane.getLayer();
326
                                        URL host = new URL(wfsParamsTabbedPane.getData().getHost());
327
                                        String onlineResource = wfsParamsTabbedPane.getData().getOnlineResource();
328
                                        FMapWFSDriver driver = wfsParamsTabbedPane.getData().getDriver();
329
                                        fLayer = new FLyrWFSFactory().getFLyrWFS(fLayer,host,onlineResource,driver,false);
330
                                } catch (MalformedURLException e1) {
331
                                        // TODO Auto-generated catch block
332
                                        e1.printStackTrace();
333
                                }                                  
334
                                if (e.getActionCommand() == "APPLY"){
335
                                         if (loadLayer(fLayer)){                 
336
                                                 View vista = (View) PluginServices.getMDIManager().getActiveWindow();
337
                                                 MapControl mapCtrl = vista.getMapControl();
338
                                
339
                                                 mapCtrl.getMapContext().getLayers().replaceLayer(layerName, fLayer);
340
                                                 wfsParamsTabbedPane.updateWFSFilterFieldValues();
341
                                                 mapCtrl.getMapContext().invalidate();
342
                                                 applied = true;
343
                                                 getBtnApply().setEnabled(!applied); 
344
                                         }
345
                                 }
346
                                 if (e.getActionCommand() == "OK") {
347
                                         if (!applied) {
348
                                                 if (getBtnApply().isEnabled()){
349
                                                         if (loadLayer(fLayer)){
350
                                                                 View vista = (View) PluginServices.getMDIManager().getActiveWindow();
351
                                                                 MapControl mapCtrl = vista.getMapControl();
352
                                                                 mapCtrl.getMapContext().getLayers().replaceLayer(layerName, fLayer);
353
                                                                 mapCtrl.getMapContext().invalidate();
354
                                                         }
355
                                                 }
356
                                         }        
357
                                         close();                                
358
                                 }
359
                         }
360
                 }
361
                 private boolean loadLayer(FLayer flayer){
362
                         try {
363
                                 ((FLyrWFS)fLayer).load();
364
                                
365
                                 if (((FLyrWFS)fLayer).getNumfeatures() == ((FLyrWFS)fLayer).getWfsDriver().getRowCount())  {
366
                                         JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
367
                                                         PluginServices.getText(this,"maxFeatures_aviso"));        
368
                                 }
369
                         } catch (Exception e1) {
370
                                 // TODO Auto-generated catch block
371
                                 e1.printStackTrace();
372
                                 JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
373
                                                 PluginServices.getText(this,"cantLoad"));
374
                                 return false;
375
                         }
376
                         return true;
377
                 }                         
378
                 
379
         }
380
         
381
        /**
382
         * @see WFSFilterPanel#setWFSFilterPanelIsAsTabForWFSLayersLoad(boolean)
383
         */
384
        public void setWFSFilterPanelIsAsTabForWFSLayersLoad(boolean b) {
385
                this.wfsParamsTabbedPane.setWFSFilterPanelIsAsTabForWFSLayersLoad(b);
386
        }        
387
}
388