Statistics
| Revision:

gvsig-raster / org.gvsig.raster.wcs / trunk / org.gvsig.raster.wcs / org.gvsig.raster.wcs.app / org.gvsig.raster.wcs.app.wcsclient / src / main / java / org / gvsig / raster / wcs / app / wcsclient / gui / dialog / WCSPropsDialog.java @ 1356

History | View | Annotate | Download (13.7 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
 
23
package org.gvsig.raster.wcs.app.wcsclient.gui.dialog;
24

    
25
import java.awt.event.ActionEvent;
26
import java.awt.event.ActionListener;
27
import java.util.HashMap;
28

    
29
import javax.swing.JButton;
30
import javax.swing.JDialog;
31
import javax.swing.JOptionPane;
32
import javax.swing.JPanel;
33

    
34
import org.gvsig.andami.PluginServices;
35
import org.gvsig.andami.ui.mdiManager.IWindow;
36
import org.gvsig.andami.ui.mdiManager.WindowInfo;
37
import org.gvsig.app.gui.wizards.WizardListener;
38
import org.gvsig.app.gui.wizards.WizardListenerSupport;
39
import org.gvsig.fmap.dal.coverage.exception.RemoteServiceException;
40
import org.gvsig.fmap.dal.exception.InitializeException;
41
import org.gvsig.fmap.mapcontext.MapContext;
42
import org.gvsig.fmap.mapcontext.exceptions.ConnectionErrorLayerException;
43
import org.gvsig.fmap.mapcontext.exceptions.DriverLayerException;
44
import org.gvsig.fmap.mapcontext.exceptions.LegendLayerException;
45
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
46
import org.gvsig.fmap.mapcontext.exceptions.NameLayerException;
47
import org.gvsig.fmap.mapcontext.exceptions.ProjectionLayerException;
48
import org.gvsig.fmap.mapcontext.exceptions.TypeLayerException;
49
import org.gvsig.fmap.mapcontext.exceptions.URLLayerException;
50
import org.gvsig.fmap.mapcontext.exceptions.UnsupportedVersionLayerException;
51
import org.gvsig.fmap.mapcontext.layers.FLayer;
52
import org.gvsig.fmap.mapcontext.layers.FLayers;
53
import org.gvsig.fmap.mapcontrol.MapControl;
54
import org.gvsig.raster.fmap.layers.FLyrRaster;
55
import org.gvsig.raster.tools.app.basic.RasterToolsUtil;
56
import org.gvsig.raster.util.CancelTaskImpl;
57
import org.gvsig.raster.wcs.app.wcsclient.gui.panel.WCSParamsPanel;
58
import org.gvsig.raster.wcs.app.wcsclient.layer.FLyrWCS;
59
import org.gvsig.raster.wcs.io.WCSServerExplorer;
60
import org.slf4j.Logger;
61
import org.slf4j.LoggerFactory;
62

    
63

    
64
/**
65
 * The TOC WCS properties panel container.
66
 *
67
 * @author jaume - jaume.dominguez@iver.es
68
 *
69
 */
70
public class WCSPropsDialog extends JPanel implements IWindow {
71

    
72
        private static final long         serialVersionUID    = 1L;
73
        JDialog                           dlg                 = null;  
74
        private JPanel                    buttonsPanel        = null;
75
        private FLyrRaster                fLayer              = null;
76
        boolean                           applied             = false;;
77
        private WindowInfo                m_ViewInfo          = null;
78

    
79
        private JButton                   btnApply            = null;
80
        private JButton                   btnOk               = null;
81
        private JButton                   btnCancel           = null;
82
        private WCSParamsPanel            wcsParamsTabbedPane;
83
    private CommandListener           m_actionListener;
84
    private WCSServerExplorer         explorer            = null;
85
    private Logger                    logger              = LoggerFactory.getLogger(WCSPropsDialog.class);
86

    
87
    public WCSPropsDialog(FLayer layer) {
88
                super();
89
                if(layer instanceof FLyrRaster)
90
                        initialize((FLyrRaster)layer);
91
        }
92

    
93

    
94
        private void initialize(FLyrRaster layer) {
95
                setLayout(null);
96

    
97
        setFLayer(layer);
98
        wcsParamsTabbedPane = getParamsPanel(((FLyrWCS) layer).getProperties());
99
        wcsParamsTabbedPane.addWizardListener(new WizardListener() {
100
                        public void wizardStateChanged(boolean finishable) {
101
                                getBtnOk().setEnabled(finishable);
102
                                getBtnApply().setEnabled(finishable);
103
                        }
104

    
105
                        public void error(Exception e) {
106
                        }
107

    
108
        })  ;
109
        this.add(wcsParamsTabbedPane);
110
        this.add(getButtonsPanel(), null);
111

    
112
        }
113

    
114

    
115
        public void setFLayer(FLyrRaster f) {
116
                fLayer = f;
117
        }
118

    
119
        /**
120
         * With getParamsPanel we have access to the map config TabbedPane.
121
         * If this panel doesn't exist yet (which can occur when an existing project is
122
         * recovered) it is been automatically constructed by connecting to the server,
123
         * reloading the necessary data, filling up the content and setting the selected
124
         * values that were selected when the projet was saved.
125
         *
126
         *
127
         * Since a connection to the server is needed when rebuiliding the panel, this
128
         * causes a delay for the panel's showing up or a nullPointer error if there is
129
         * no path to the server.
130
         *
131
         *
132
         * Con getParamsPanel tenemos acceso a juego de pesta?as de configuraci?n
133
         * del mapa. Si este panel todav?a no existe (como puede ser cuando
134
         * recuperamos un proyecto guardado) ?ste se crea autom?ticamente conectando
135
         * al servidor, recuperando los datos necesarios, rellenando el contenido y
136
         * dejando seleccionados los valores que estaban seleccionados cuando se
137
         * guarda el proyecto.
138
         *
139
         *
140
         * Como para reconstruirse requiere una conexi?n con el servidor esto causa
141
         * un retardo en la aparici?n en el toc o un error de nullPointer si no
142
         * hay conexi?n hasta el servidor.
143
         *
144
         *
145
         * @return WCSParamsPanel
146
         */
147
        public WCSParamsPanel getParamsPanel(HashMap info) {
148
            if (info != null) {
149
                    try {
150
                            if(explorer == null) {
151
                                        explorer = ((FLyrWCS)fLayer).getExplorer();
152
                                        
153
                                        try {
154
                                            explorer.connect(new CancelTaskImpl());
155
                                        } catch (RemoteServiceException e) {
156
                                                RasterToolsUtil.messageBoxError("The connection cannot be established", this, e);
157
                                                return null;
158
                                        } 
159
                            }
160
                    } catch (Exception e) {
161
                            explorer = null;
162
                            JOptionPane.showMessageDialog(null, "error_comunicacion_servidor", "Error", JOptionPane.ERROR_MESSAGE);
163
                    }
164
                    try {
165

    
166
                                WCSParamsPanel toc = new WCSParamsPanel();
167
                                toc.setVisible(true);
168
                                toc.setListenerSupport(new WizardListenerSupport());
169
                                toc.setWizardData(explorer);
170

    
171
                                toc.getLayerPanel().getLstCoverages().setListData(explorer.getCoverageList());
172

    
173
                                String coverageName = (String) info.get("name");
174
                                int index = toc.getLayerPanel().getCoverageIndex( coverageName );
175
                                if (index != -1) {
176
                                        toc.getLayerPanel().getLstCoverages().setSelectedIndex(index);
177
                                }
178

    
179
                                toc.refreshData(((FLyrWCS)fLayer).getParameters());
180

    
181
                                index = toc.getFormatsPanel().getSRSIndex((String) info.get("crs") );
182
                                if (index != -1) {
183
                                        toc.getFormatsPanel().getLstCRSs().setSelectedIndex(index);
184
                                }
185
                                index = toc.getFormatsPanel().getFormatIndex((String) info.get("format"));
186
                                if (index != -1) {
187
                                        toc.getFormatsPanel().getLstFormats().setSelectedIndex(index);
188
                                }
189
                                String time = (String) info.get("time");
190
                                if (time != null && !time.equals("")) {
191
                                        toc.getTimePanel().getLstSelectedTimes().setListData(time.split(","));
192
                                }
193
                                String parameter = (String) info.get("parameter");
194
                                if (parameter != null && !parameter.equals("")){
195
                                        String[] s = parameter.split("=");
196
                                        String pName = s[0];
197

    
198
                                        String regexDouble = "-?[0-9]+(\\.[0-9]+)?";
199
                                        String regexInterval = regexDouble+"/"+regexDouble;
200
                                        String regexIntervalList = regexInterval+"(,"+regexInterval+")*";
201
                                        if (s[1].matches(regexInterval)){
202
                                                // Single Interval
203
                                                toc.getParameterPanel().getJScrollPane5().setVisible(false);
204
                                                toc.getParameterPanel().getSingleParamValuesList().setEnabled(false);
205

    
206

    
207
                                        } else if (s[1].matches(regexIntervalList)){
208
                                                // Multiple Interval
209

    
210
                                        } else {
211
                                                // Single values
212
                                                toc.getParameterPanel().getJScrollPane5().setVisible(true);
213
                                                toc.getParameterPanel().getSingleParamValuesList().setEnabled(true);
214

    
215
                                                String[] pVals = s[1].split(",");
216
                                                index = toc.getParameterPanel().getParamIndex(pName);
217
                                                toc.getParameterPanel().getCmbParam().setSelectedIndex(index);
218
                                                //toc.refreshParamValues( coverageName );
219
                                                int[] indexes = new int[pVals.length];
220
                                                for (int i = 0; i < pVals.length; i++) {
221
                                                        indexes[i] = toc.getParameterPanel().getValueIndex(pVals[i]);
222
                                                }
223

    
224
                                                toc.getParameterPanel().getSingleParamValuesList().setSelectedIndices(indexes);
225
                                        }
226
                                }
227
                                toc.refreshInfo();
228
                                return toc;
229
                        } catch (Exception e) {
230
                                JOptionPane.showMessageDialog(null, "servidor_wcs_no_responde", "Error", JOptionPane.ERROR_MESSAGE);
231
                                e.printStackTrace();
232
                        }
233
            }
234
            return null;
235
        }
236

    
237
        public JPanel getButtonsPanel() {
238
                if (buttonsPanel == null) {
239
                        m_actionListener = new CommandListener(this);
240
                        buttonsPanel = new JPanel();
241
                buttonsPanel.setBounds(5, wcsParamsTabbedPane.getHeight(), 471, 40);
242
                        buttonsPanel.setLayout(null);
243
                        buttonsPanel.setName("buttonPanel");
244

    
245
                buttonsPanel.add(getBtnOk(), null);
246
                buttonsPanel.add(getBtnApply(), null);
247
                buttonsPanel.add(getBtnCancel(), null);
248
                }
249
                return buttonsPanel;
250
        }
251

    
252
        public JButton getBtnOk() {
253
                if (btnOk == null) {
254
                btnOk = new JButton("ok");
255
                btnOk.setText(PluginServices.getText(this,"ok"));
256
                btnOk.setActionCommand("OK");
257
                btnOk.addActionListener(m_actionListener);
258
                btnOk.setBounds(367, 9, 90, 25);
259
                }
260
                return btnOk;
261
        }
262

    
263
        public JButton getBtnApply() {
264
                if (btnApply == null) {
265
                btnApply = new JButton("apply");
266
                btnApply.setText(PluginServices.getText(this,"apply"));
267
                btnApply.setEnabled(false);
268
                btnApply.setActionCommand("APPLY");
269
                btnApply.addActionListener(m_actionListener);
270
                btnApply.setBounds(267, 9, 90, 25);
271
                }
272
                return btnApply;
273
        }
274

    
275
        public JButton getBtnCancel() {
276
                if (btnCancel == null) {
277
                btnCancel = new JButton("cancel");
278
                btnCancel.setText(PluginServices.getText(this,"cancel"));
279
                btnCancel.setActionCommand("CANCEL");
280
                btnCancel.addActionListener(m_actionListener);
281
                btnCancel.setBounds(137, 9, 90, 25);
282
                }
283
                return btnCancel;
284
        }
285

    
286
        private class CommandListener implements ActionListener {
287

    
288
                /**
289
                 * Creates a new ComandosListener object.
290
                 *
291
                 * @param lg DOCUMENT ME!
292
                 */
293
                public CommandListener(WCSPropsDialog tp) {
294
                        //m_tp = tp;
295
                }
296

    
297
                /* (non-Javadoc)
298
                 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
299
                 */
300
                public void actionPerformed(ActionEvent e) {
301
                        if (e.getActionCommand() == "CANCEL") {
302
                                close();
303
                        } else {
304
                                ((FLyrWCS) fLayer).getParameters().setFormat(wcsParamsTabbedPane.getFormat());
305
                                try {
306
                                        ((FLyrWCS) fLayer).getParameters().setSRS(wcsParamsTabbedPane.getSRS());
307
                                        ((FLyrWCS) fLayer).getParameters().setCoverageName(wcsParamsTabbedPane.getLayerPanel().getSelectedCoverageName());
308

    
309
                                        //fLayer = wcsParamsTabbedPane.getLayer();
310
                                        FLayers parent = ((FLayer)fLayer).getParentLayer();
311

    
312
                                        MapControl mapCtrl = null;
313

    
314
                                        IWindow[] w = PluginServices.getMDIManager().getAllWindows();
315
                                        for (int i = 0; i < w.length; i++) {
316
                                                if (w[i] instanceof org.gvsig.app.project.documents.view.gui.AbstractViewPanel) {
317
                                                        MapContext mapContext = ((org.gvsig.app.project.documents.view.gui.AbstractViewPanel)w[i]).getMapControl().getMapContext();
318
                                                        if(mapContext == fLayer.getMapContext())
319
                                                                mapCtrl = ((org.gvsig.app.project.documents.view.gui.AbstractViewPanel)w[i]).getMapControl();
320
                                                }
321
                                        } 
322

    
323
                                        if (parent != null) {
324
                                                FLayer layer = wcsParamsTabbedPane.getLayer();
325
                                                if(layer == null)
326
                                                        return;
327
                                                mapCtrl.getMapContext().getLayers().
328
                                                replaceLayer(fLayer.getName(), layer);
329
                                        } else {
330
                                                mapCtrl.getMapContext().getLayers().replaceLayer(fLayer.getName(), wcsParamsTabbedPane.getLayer());
331
                                        }
332
                                        //mapCtrl.getMapContext().getLayers().addLayer( fLayer );
333
                                        mapCtrl.getMapContext().invalidate();
334
                                        applied = true;
335
                                        getBtnApply().setEnabled(!applied);
336
                                        
337
                                        if (e.getActionCommand() == "OK") {
338
                                                close();
339
                                        }
340
                                } catch (ConnectionErrorLayerException e1) {
341
                                        logger.info("", e1);
342
                                } catch (DriverLayerException e1) {
343
                                        logger.info("", e1);
344
                                } catch (LegendLayerException e1) {
345
                                        logger.info("", e1);
346
                                } catch (NameLayerException e1) {
347
                                        logger.info("", e1);
348
                                } catch (ProjectionLayerException e1) {
349
                                        logger.info("", e1);
350
                                } catch (TypeLayerException e1) {
351
                                        logger.info("", e1);
352
                                } catch (UnsupportedVersionLayerException e1) {
353
                                        logger.info("", e1);
354
                                } catch (URLLayerException e1) {
355
                                        logger.info("", e1);
356
                                } catch (LoadLayerException e1) {
357
                                        logger.info("", e1);
358
                                } catch (InitializeException e1) {
359
                                        logger.info("", e1);
360
                                }
361
                        }
362
                }
363
        }
364
    /**
365
     * Merge two FLayers in one
366
     * @param group1
367
     * @param group2
368
     * @return
369
     */
370
    @SuppressWarnings("unused")
371
        private FLayers mergeFLayers(FLayers group1, FLayers group2) {
372
            //FLayers agrupation = new FLayers(group1.getFMap(), group1.getParentLayer());
373
            FLayer layer;
374
            for(int i = 0; i < group2.getLayersCount(); i++) {
375
                    layer = group2.getLayer( i );
376
                    if(group1.getLayer( layer.getName()) == null ) {
377
                            group1.addLayer( layer );
378
                    }
379
            }
380

    
381
            return group1;
382
    }
383

    
384

    
385

    
386
        public WindowInfo getWindowInfo() {
387
                if (m_ViewInfo==null){
388
                        m_ViewInfo=new WindowInfo(WindowInfo.MODALDIALOG);
389
                        m_ViewInfo.setTitle(PluginServices.getText(this,"fit_WCS_layer"));
390
                m_ViewInfo.setWidth(wcsParamsTabbedPane.getWidth()+10);
391
                m_ViewInfo.setHeight(wcsParamsTabbedPane.getHeight()+40);
392

    
393
                }
394
                return m_ViewInfo;
395
        }
396

    
397
        public void close() {
398
                PluginServices.getMDIManager().closeWindow(this);
399
        }
400

    
401

    
402
        public Object getWindowProfile() {
403
                return WindowInfo.DIALOG_PROFILE;
404
        }
405

    
406
}  //  @jve:decl-index=0:visual-constraint="10,10"