Statistics
| Revision:

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

History | View | Annotate | Download (11.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.URL;
7
import java.util.HashMap;
8

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

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

    
15
import com.iver.andami.PluginServices;
16
import com.iver.andami.ui.mdiManager.IWindow;
17
import com.iver.andami.ui.mdiManager.WindowInfo;
18
import com.iver.cit.gvsig.fmap.DriverException;
19
import com.iver.cit.gvsig.fmap.MapControl;
20
import com.iver.cit.gvsig.fmap.layers.FLayer;
21
import com.iver.cit.gvsig.fmap.layers.FLayers;
22
import com.iver.cit.gvsig.fmap.layers.FLyrWFS;
23
import com.iver.cit.gvsig.fmap.layers.WFSLayerNode;
24
import com.iver.cit.gvsig.gui.panels.WFSParamsPanel;
25
import com.iver.cit.gvsig.gui.wizards.WFSWizardData;
26
import com.iver.cit.gvsig.gui.wizards.WizardListener;
27
import com.iver.cit.gvsig.gui.wizards.WizardListenerSupport;
28
import com.iver.cit.gvsig.project.documents.view.gui.View;
29

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

    
122
    public WFSPropsDialog(FLayer layer) {
123
                super();
124
                initialize(layer);
125
        }
126
    
127
    private void initialize(FLayer layer) {
128
                setLayout(null);                
129
        setFLayer(layer);
130
        wfsParamsTabbedPane = getParamsPanel(((FLyrWFS) layer).getProperties());
131
        wfsParamsTabbedPane.addWizardListener(new WizardListener(){
132
                        public void wizardStateChanged(boolean finishable) {
133
                                getBtnOk().setEnabled(finishable);
134
                                getBtnApply().setEnabled(finishable);
135
                        }
136

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

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

    
226
        /**
227
         * @return Returns the fLayer.
228
         */
229
        public FLayer getFLayer() {
230
                return fLayer;
231
        }
232

    
233
        /**
234
         * @param layer The fLayer to set.
235
         */
236
        public void setFLayer(FLayer layer) {
237
                fLayer = layer;
238
        }
239

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