Statistics
| Revision:

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

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 8220 2006-10-23 07:37:04Z jorpiell $
73
 * $Log$
74
 * Revision 1.7  2006-10-23 07:37:04  jorpiell
75
 * Ya funciona el filterEncoding
76
 *
77
 * Revision 1.6  2006/10/02 09:09:45  jorpiell
78
 * Cambios del 10 copiados al head
79
 *
80
 * Revision 1.4.2.3  2006/09/27 11:12:15  jorpiell
81
 * Hay que comprobar que se han devuelto un n?mero de features menor que el n?mero m?ximo permitido
82
 *
83
 * Revision 1.4.2.2  2006/09/27 09:15:01  jorpiell
84
 * Ya no se hace otra petici?n al pulsar sobre el bot?n aceptar.
85
 *
86
 * Revision 1.4.2.1  2006/09/19 12:28:11  jorpiell
87
 * Ya no se depende de geotools
88
 *
89
 *
90
 * Revision 1.4  2006/08/30 07:42:29  jorpiell
91
 * Se le asigna a la capa creada una proyecci?n concreta. Si esto no se hace, al exportar a postigis se produce un error.
92
 *
93
 * Revision 1.3  2006/08/29 07:56:12  cesar
94
 * Rename the *View* family of classes to *Window* (ie: SingletonView to SingletonWindow, ViewInfo to WindowInfo, etc)
95
 *
96
 * Revision 1.2  2006/08/29 07:13:40  cesar
97
 * Rename class com.iver.andami.ui.mdiManager.View to com.iver.andami.ui.mdiManager.IWindow
98
 *
99
 * Revision 1.1  2006/06/21 12:35:45  jorpiell
100
 * 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
101
 *
102
 *
103
 */
104
/**
105
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
106
 */
107
public class WFSPropsDialog extends JPanel implements IWindow{
108
        private WFSParamsPanel wfsParamsTabbedPane = null;
109
        private WindowInfo m_ViewInfo = null;
110
        private FLayer fLayer = null;
111
        private JButton btnApply = null;
112
        private JButton btnOk = null;
113
        private JButton btnCancel = null;
114
        private CommandListener m_actionListener = null;
115
        private JPanel buttonsPanel = null;
116
        boolean applied = false;
117
        
118

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

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

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

    
223
        /**
224
         * @return Returns the fLayer.
225
         */
226
        public FLayer getFLayer() {
227
                return fLayer;
228
        }
229

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

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