Statistics
| Revision:

svn-gvsig-desktop / tags / v1_11_0_Build_1306 / extensions / extArcims / src / es / prodevelop / cit / gvsig / arcims / gui / wizards / ArcImsWizard.java @ 35731

History | View | Annotate | Download (17.6 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 Prodevelop and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *   Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *   +34 963862235
28
 *   gvsig@gva.es
29
 *   www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   Prodevelop Integraci?n de Tecnolog?as SL
34
 *   Conde Salvatierra de ?lava , 34-10
35
 *   46004 Valencia
36
 *   Spain
37
 *
38
 *   +34 963 510 612
39
 *   +34 963 510 968
40
 *   gis@prodevelop.es
41
 *   http://www.prodevelop.es
42
 */
43
package es.prodevelop.cit.gvsig.arcims.gui.wizards;
44

    
45
import java.awt.BorderLayout;
46

    
47
import javax.swing.JOptionPane;
48
import javax.swing.JPanel;
49
import javax.swing.JScrollPane;
50
import javax.swing.JTree;
51

    
52
import org.apache.log4j.Logger;
53
import org.gvsig.remoteClient.arcims.ArcImsClientP;
54
import org.gvsig.remoteClient.arcims.ArcImsImageClient;
55
import org.gvsig.remoteClient.arcims.ArcImsStatus;
56
import org.gvsig.remoteClient.arcims.utils.ServiceInfoTags;
57
import org.gvsig.remoteClient.arcims.utils.ServiceInformation;
58
import org.gvsig.remoteClient.arcims.utils.ServiceInformationLayerFeatures;
59
import org.gvsig.remoteClient.arcims.utils.ServiceInformationLayerImage;
60

    
61
import com.iver.andami.PluginServices;
62
import com.iver.cit.gvsig.fmap.layers.FLayer;
63
import com.iver.cit.gvsig.gui.WizardPanel;
64
import com.iver.cit.gvsig.gui.wizards.WizardListener;
65
import com.iver.cit.gvsig.gui.wizards.WizardListenerSupport;
66
import com.iver.cit.gvsig.project.documents.view.gui.View;
67

    
68
import es.prodevelop.cit.gvsig.arcims.fmap.datasource.ArcImsWizardData;
69
import es.prodevelop.cit.gvsig.arcims.fmap.drivers.FMapFeatureArcImsDriver;
70
import es.prodevelop.cit.gvsig.arcims.fmap.drivers.FMapRasterArcImsDriver;
71
import es.prodevelop.cit.gvsig.arcims.fmap.layers.FFeatureLyrArcIMSCollection;
72
import es.prodevelop.cit.gvsig.arcims.fmap.layers.FRasterLyrArcIMS;
73
import es.prodevelop.cit.gvsig.arcims.gui.panels.FeatureServicePanel;
74
import es.prodevelop.cit.gvsig.arcims.gui.panels.ImageServicePanel;
75
import es.prodevelop.cit.gvsig.arcims.gui.panels.ServiceNamesPanel;
76
import es.prodevelop.cit.gvsig.arcims.gui.panels.utils.LayersListElement;
77

    
78

    
79
/**
80
 * This class implements the wizard that enables the user to load an ArcIMS
81
 * layer. Passes most requests on to its <tt>ArcImsWizardData dataSource</tt>
82
 * object.
83
 *
84
 * @see es.prodevelop.cit.gvsig.arcims.fmap.datasource.ArcImsWizardData
85
 *
86
 * @author jldominguez
87
 */
88
public class ArcImsWizard extends WizardPanel {
89
    private static Logger logger = Logger.getLogger(ArcImsWizard.class.getName());
90
    private static final long serialVersionUID = 0;
91
    private WizardListenerSupport listenerSupport = new WizardListenerSupport();
92
    private ArcImsWizardData dataSource;
93
    private ServiceNamesPanel svsNamesPanel;
94
    private FeatureServicePanel feaServicePanel;
95
    private ImageServicePanel imgServicePanel;
96
    private JPanel mainPanel = null;
97
    private String nombreTema = "ArcIMS layer";
98
    private String layerQuery = "Empty query";
99
    private String host = "";
100
    private String serviceName = "";
101
    private String serviceType = "";
102
    private String imageFormat;
103
    private FLayer theLayer;
104
    private View theView;
105

    
106
    public ArcImsWizard() {
107
        super();
108
        initialize(true, false);
109
    }
110

    
111
    public ArcImsWizard(boolean editionallowed, boolean props) {
112
        super();
113
        initialize(editionallowed, props);
114
    }
115

    
116
    public ServiceNamesPanel getSvsNamesPanel() {
117
        return svsNamesPanel;
118
    }
119

    
120
    public void setSvsNamesPanel(ServiceNamesPanel svsNamesPanel) {
121
        this.svsNamesPanel = svsNamesPanel;
122
    }
123

    
124
    public void setLayerQuery(String lq) {
125
        layerQuery = lq;
126
    }
127

    
128
    public String getLayerQuery() {
129
        return layerQuery;
130
    }
131

    
132
    public void setHostName(String h) {
133
        host = h;
134
    }
135

    
136
    public String getHostName() {
137
        return host;
138
    }
139

    
140
    public void setServiceName(String n) {
141
        serviceName = n;
142
    }
143

    
144
    public String getServiceName() {
145
        return serviceName;
146
    }
147

    
148
    public void setNewLayerName(String n) {
149
        nombreTema = n;
150
    }
151

    
152
    public String getNewLayerName() {
153
        return nombreTema;
154
    }
155

    
156
    /**
157
     * Sets tab name and creates gui panels.
158
     *
159
     */
160
    private void initialize(boolean editionallowed, boolean props) {
161
        setTabName("ArcIMS");
162
        svsNamesPanel = new ServiceNamesPanel(this);
163

    
164
        imgServicePanel = new ImageServicePanel(this, props);
165
        feaServicePanel = new FeatureServicePanel(this, editionallowed, props);
166

    
167
        setSize(646, 359);
168
        setLayout(new BorderLayout(10, 10));
169

    
170
        setPreferredSize(new java.awt.Dimension(750, 420));
171
        this.add(getMainPanel(), BorderLayout.CENTER);
172
        this.setEnabledPanels("main");
173
        this.validate();
174
    }
175

    
176
    public ArcImsWizardData getDataSource() {
177
        return dataSource;
178
    }
179

    
180
    public void setDataSource(ArcImsWizardData ds) {
181
        dataSource = ds;
182
    }
183

    
184
    public void initWizard() {
185
        dataSource = new ArcImsWizardData();
186
    }
187

    
188
    public void execute() {
189
    }
190

    
191
    /**
192
     * This method will be invoqued by gvSIG when the user clicks on the
193
     * <i>Accept</i> button to retrieve the layers selected by the user. They
194
     * will be seen from gvSIG as one layer.
195
     *
196
     * @return the new ArcIMS layer to be added to the project
197
     */
198
    public FLayer getLayer() {
199
        //                HashMap m = new HashMap();
200
        //                m.put("host", "http://noruega:9080");
201
        //                m.put("service_name", "CarreterasIS");
202
        //                m.put("srs", "EPSG:23030");
203
        //                // m.put("layer_name", "Prueba");
204
        //                
205
        //                try {
206
        //                        return new FRasterLyrArcIMS(m);
207
        //                } catch (ConnectionException e) {
208
        //                        // TODO Auto-generated catch block
209
        //                        return null;
210
        //                }
211

    
212
        // now we have the mapControl
213
        dataSource.setMapControl(getMapCtrl());
214

    
215
        theLayer = null;
216

    
217
        if (serviceType.compareToIgnoreCase(ServiceInfoTags.vIMAGESERVICE) == 0) {
218
            theLayer = createArcImsRasterLayer();
219
        }
220

    
221
        if (theLayer == null) {
222
            logger.error("Error while creating ArcIms layer.");
223
        }
224

    
225
        if (serviceType.compareToIgnoreCase(ServiceInfoTags.vFEATURESERVICE) == 0) {
226
            if (feaServicePanel.isGroupOptionSelected()) { // agrupar
227
                theLayer = createArcImsFeatureLayer(false);
228
            }
229
            else { // no agrupar
230
                theLayer = createArcImsFeatureLayer(true);
231
            }
232
        }
233

    
234
        if (theLayer == null) {
235
            logger.info("Returned a null layer (layers were added manually).");
236
        }
237

    
238
        return theLayer;
239
    }
240

    
241
    public FLayer getLayerAsIs() {
242
        return theLayer;
243
    }
244

    
245
    /**
246
     * Creates an ArcIMS feature layer. This method will use the
247
     * ArcImsWizardData method to create the layer.
248
     *
249
     * @return the ArcIMS raster layer
250
     */
251
    private FFeatureLyrArcIMSCollection createArcImsFeatureLayer(boolean sep) {
252
        FFeatureLyrArcIMSCollection layer = null;
253

    
254
        try {
255
            layer = dataSource.createArcImsFeatureLayer(host, serviceName,
256
                    layerQuery, nombreTema,
257
                    getMapCtrl().getMapContext().getProjection(), sep);
258
        }
259
        catch (Exception e1) {
260
            e1.printStackTrace();
261
        }
262

    
263
        return layer;
264
    }
265

    
266
    /**
267
     * Creates an ArcIMS raster layer. This method will use the
268
     * ArcImsWizardData method to create the layer.
269
     *
270
     * @return the ArcIMS raster layer
271
     */
272
    private FRasterLyrArcIMS createArcImsRasterLayer() {
273
        FRasterLyrArcIMS layer = null;
274

    
275
        try {
276
            // the value of these parameters was set by other gui objects (panels, etc)
277
            layer = dataSource.createArcImsRasterLayer(host, serviceName,
278
                    layerQuery, nombreTema,
279
                    getMapCtrl().getMapContext().getProjection(), imageFormat);
280
        }
281
        catch (Exception e1) {
282
            logger.error("While creating ArcImsRasterLayer ", e1);
283
        }
284

    
285
        // a warning is shown if the SRS was not provided by the server:
286
        //                if (dataSource.isMissingSrs()) {
287
        //                        showMissingSrsMessage();
288
        //                }
289

    
290
        //                if (layer != null) {
291
        //                        ArcImsStatus status = layer.getArcimsStatus();
292
        //                        String fmt = imageFormat.getFormatString();
293
        //                        boolean imagefmtok = ((FMapRasterArcImsDriver) layer.getDriver()).testFormat(status, fmt);
294
        //                        if (!imagefmtok) {
295
        //                                showImageFmtNotSupportedMessage(fmt);
296
        //                                return null;
297
        //                        }
298
        //                }
299
        return layer;
300
    }
301

    
302
    private void showImageFmtNotSupportedMessage(String fmt) {
303
        JOptionPane.showMessageDialog(this,
304
            PluginServices.getText(this,
305
                "server_doesnt_support_selected_image_format") + ": " +
306
            fmt.toUpperCase(), PluginServices.getText(this, "error"),
307
            JOptionPane.WARNING_MESSAGE);
308
    }
309

    
310
    /**
311
     * Utility method to display warning message.
312
     *
313
     */
314
    private void showMissingSrsMessage() {
315
        JOptionPane.showMessageDialog(this,
316
            PluginServices.getText(this,
317
                "server_provides_no_srs__scale_data_may_be_wrong"),
318
            PluginServices.getText(this, "warning"), JOptionPane.WARNING_MESSAGE);
319
    }
320

    
321
    /**
322
     * This method initializes mainPanel
323
     *
324
     * @return javax.swing.JPanel
325
     */
326
    private JPanel getMainPanel() {
327
        if (mainPanel == null) {
328
            mainPanel = new JPanel();
329
            mainPanel.setBounds(new java.awt.Rectangle(15, 90, 616, 256));
330
            mainPanel.setLayout(new BorderLayout());
331
        }
332

    
333
        return mainPanel;
334
    }
335

    
336
    public void addWizardListener(WizardListener listener) {
337
        listenerSupport.addWizardListener(listener);
338
    }
339

    
340
    public void removeWizardListener(WizardListener listener) {
341
        listenerSupport.removeWizardListener(listener);
342
    }
343

    
344
    /**
345
     * Enables or disables the main panel and the layer selection panel.
346
     *
347
     * @param selectedPanel a String that identifies which panel must be enabled:
348
     * "main" (for the service names panel) or "service" (for the layer
349
     * selection panel).
350
     */
351
    public void setEnabledPanels(String selectedPanel) {
352
        mainPanel.removeAll();
353

    
354
        svsNamesPanel.setVisible(false);
355
        imgServicePanel.setVisible(false);
356
        feaServicePanel.setVisible(false);
357

    
358
        if (selectedPanel.compareToIgnoreCase("main") == 0) {
359
            mainPanel.add(svsNamesPanel, BorderLayout.CENTER);
360
            svsNamesPanel.setVisible(true);
361
        }
362

    
363
        if (selectedPanel.compareToIgnoreCase("feature") == 0) {
364
            mainPanel.add(feaServicePanel, BorderLayout.CENTER);
365
            feaServicePanel.setVisible(true);
366
        }
367

    
368
        if (selectedPanel.compareToIgnoreCase("image") == 0) {
369
            mainPanel.add(imgServicePanel, BorderLayout.CENTER);
370
            imgServicePanel.setVisible(true);
371
            imgServicePanel.getImageFormatCombo().revalidate();
372
        }
373
    }
374

    
375
    /**
376
     * Fires a notification to this wizard listeners telling them if the
377
     * configuration is fair enough to send a GetMap request.
378
     *
379
     * @param b
380
     *            <b>true</b> if the data in the wizard is enough to send a
381
     *            <tt>getMap</tt> request and therefore create a new layer in
382
     *            the project; <b>false</b> otherwise.
383
     */
384
    public void fireWizardComplete(boolean b) {
385
        listenerSupport.callStateChanged(b);
386
        callStateChanged(b);
387
    }
388

    
389
    /**
390
     * Decides which Panel must be loaded (ServiceNamesPanel or
391
     * ...ServicePanel) depending on the type of the service selected by the
392
     * user.
393
     */
394
    public void fillAndMoveTabbedPaneToEnabled() {
395
        if (this.svsNamesPanel.getSelectedServiceType()
396
                                  .compareToIgnoreCase(ServiceInfoTags.vIMAGESERVICE) == 0) {
397
            this.fillImageServiceTab();
398
            this.setEnabledPanels("image");
399
        }
400

    
401
        if (this.svsNamesPanel.getSelectedServiceType()
402
                                  .compareToIgnoreCase(ServiceInfoTags.vFEATURESERVICE) == 0) {
403
            this.fillFeatureServiceTab();
404
            this.setEnabledPanels("feature");
405
        }
406
    }
407

    
408
    /**
409
     * Loads FeatureServicePanel's controls.
410
     */
411
    private void fillImageServiceTab() {
412
        FMapRasterArcImsDriver drv = (FMapRasterArcImsDriver) this.dataSource.getDriver();
413
        ArcImsClientP cli = (ArcImsClientP) drv.getClient();
414
        ServiceInformation si = cli.getServiceInformation();
415
        String map_units = si.getMapunits();
416
        int _dpi = si.getScreen_dpi();
417

    
418
        this.imgServicePanel.setDetailsPanelServiceNameInBorder(this.serviceName);
419
        this.imgServicePanel.emptyTables();
420
        this.imgServicePanel.emptyFormatsCombo();
421
        this.imgServicePanel.loadServiceDetailsTable(si);
422

    
423
        ArcImsStatus tmpStatus = new ArcImsStatus();
424
        tmpStatus.setServiceInformation(si);
425
        tmpStatus.setService(serviceName);
426
        this.imgServicePanel.loadImageFormatCombo((ArcImsImageClient) cli,
427
            tmpStatus);
428

    
429
        // load available layers list
430
        for (int i = 0; i < si.getLayers().size(); i++) {
431
            if (si.getLayers().get(i) instanceof ServiceInformationLayerImage) {
432
                ServiceInformationLayerImage sii = (ServiceInformationLayerImage) si.getLayers()
433
                                                                                    .get(i);
434
                this.imgServicePanel.addLayerToAvailableList(new LayersListElement(
435
                        sii, map_units, _dpi));
436
            }
437

    
438
            if (si.getLayers().get(i) instanceof ServiceInformationLayerFeatures) {
439
                ServiceInformationLayerFeatures sif = (ServiceInformationLayerFeatures) si.getLayers()
440
                                                                                          .get(i);
441
                this.imgServicePanel.addLayerToAvailableList(new LayersListElement(
442
                        sif, map_units, _dpi));
443
            }
444
        }
445

    
446
        JScrollPane sp = imgServicePanel.getAvailableLayersScrollPane();
447
        this.imgServicePanel.setAvailableLayersTree(null);
448

    
449
        JTree t = imgServicePanel.getAvailableLayersTree();
450
        sp.setViewportView(t);
451
        imgServicePanel.setServiceInfoTabNumber(1);
452
        imgServicePanel.setServiceInfoTabNumber(0);
453
    }
454

    
455
    /**
456
     * Loads the Feature Service Panel's controls.
457
     */
458
    private void fillFeatureServiceTab() {
459
        FMapFeatureArcImsDriver drv = (FMapFeatureArcImsDriver) this.dataSource.getDriver();
460
        ArcImsClientP cli = (ArcImsClientP) drv.getClient();
461

    
462
        ServiceInformation si = cli.getServiceInformation();
463
        String map_units = si.getMapunits();
464
        int _dpi = si.getScreen_dpi();
465

    
466
        feaServicePanel.setDetailsPanelServiceNameInBorder(serviceName);
467
        feaServicePanel.emptyTables();
468

    
469
        // ------------------- Test -------------------
470
        // this.imgServicePanel.addLayerToAvailableList(new LayersListElement(sif, "meters", 96));
471
        // ------------------- Test -------------------
472
        this.feaServicePanel.loadServiceDetailsTable(si);
473

    
474
        // load available layers list
475
        for (int i = 0; i < si.getLayers().size(); i++) {
476
            ServiceInformationLayerFeatures sif = (ServiceInformationLayerFeatures) si.getLayers()
477
                                                                                      .get(i);
478
            this.feaServicePanel.addLayerToAvailableList(new LayersListElement(
479
                    sif, map_units, _dpi));
480
        }
481

    
482
        JScrollPane sp = feaServicePanel.getAvailableLayersScrollPane();
483
        this.feaServicePanel.setAvailableLayersTree(null);
484

    
485
        JTree t = feaServicePanel.getAvailableLayersTree();
486
        sp.setViewportView(t);
487

    
488
        // feaServicePanel.setServiceInfoTabNumber(1);
489
        feaServicePanel.setServiceInfoTabNumber(0);
490
    }
491

    
492
    public String getServiceType() {
493
        return serviceType;
494
    }
495

    
496
    public void setServiceType(String serviceType) {
497
        this.serviceType = serviceType;
498
    }
499

    
500
    public FeatureServicePanel getFeaServicePanel() {
501
        return feaServicePanel;
502
    }
503

    
504
    public void setFeaServicePanel(FeatureServicePanel feaServicePanel) {
505
        this.feaServicePanel = feaServicePanel;
506
    }
507

    
508
    public ImageServicePanel getImgServicePanel() {
509
        return imgServicePanel;
510
    }
511

    
512
    public void setImgServicePanel(ImageServicePanel imgServicePanel) {
513
        this.imgServicePanel = imgServicePanel;
514
    }
515

    
516
    public void setImageFormat(String fmt) {
517
        this.imageFormat = fmt;
518
    }
519

    
520
    public String getImageFormat() {
521
        return imageFormat;
522
    }
523

    
524
    public void setServerVersionInPanels(String vers) {
525
        if (imgServicePanel != null) {
526
            imgServicePanel.setTextInVersionLabel(vers);
527
        }
528

    
529
        if (feaServicePanel != null) {
530
            feaServicePanel.setTextInVersionLabel(vers);
531
        }
532
    }
533
} // @jve:decl-index=0:visual-constraint="11,8"