Statistics
| Revision:

root / trunk / extensions / extArcims / src / es / prodevelop / cit / gvsig / arcims / gui / wizards / ArcImsWizard.java @ 8110

History | View | Annotate | Download (14.3 KB)

1
package es.prodevelop.cit.gvsig.arcims.gui.wizards;
2

    
3
import javax.swing.JOptionPane;
4
import javax.swing.JPanel;
5
import javax.swing.JTree;
6
import javax.swing.JScrollPane;
7

    
8
import java.awt.BorderLayout;
9
import java.util.Date;
10
import java.util.HashMap;
11
import java.util.Map;
12

    
13
import com.iver.andami.PluginServices;
14
import com.iver.cit.gvsig.fmap.layers.FLayer;
15
import com.iver.cit.gvsig.gui.View;
16
import com.iver.cit.gvsig.gui.WizardPanel;
17
import com.iver.cit.gvsig.gui.wizards.WizardListener;
18
import com.iver.cit.gvsig.gui.wizards.WizardListenerSupport;
19
import com.iver.utiles.connections.ConnectionException;
20

    
21
import es.prodevelop.cit.gvsig.arcims.fmap.datasource.ArcImsWizardData;
22
import es.prodevelop.cit.gvsig.arcims.fmap.drivers.FMapRasterArcImsDriver;
23
import es.prodevelop.cit.gvsig.arcims.fmap.drivers.FMapFeatureArcImsDriver;
24
import es.prodevelop.cit.gvsig.arcims.fmap.layers.FFeatureLyrArcIMS;
25
import es.prodevelop.cit.gvsig.arcims.fmap.layers.FFeatureLyrArcIMSCollection;
26
import es.prodevelop.cit.gvsig.arcims.fmap.layers.FRasterLyrArcIMS;
27
import es.prodevelop.cit.gvsig.arcims.gui.panels.FeatureServicePanel;
28
import es.prodevelop.cit.gvsig.arcims.gui.panels.ImageServicePanel;
29
import es.prodevelop.cit.gvsig.arcims.gui.panels.ServiceNamesPanel;
30
import es.prodevelop.cit.gvsig.arcims.gui.panels.utils.LayersListElement;
31

    
32
import org.apache.log4j.Logger;
33
import org.gvsig.remoteClient.arcims.ArcImsClientP;
34
import org.gvsig.remoteClient.arcims.ArcImsImageClient;
35
import org.gvsig.remoteClient.arcims.ArcImsStatus;
36
import org.gvsig.remoteClient.arcims.utils.ServiceInfoTags;
37
import org.gvsig.remoteClient.arcims.utils.ServiceInformation;
38
import org.gvsig.remoteClient.arcims.utils.ServiceInformationLayerFeatures;
39
import org.gvsig.remoteClient.arcims.utils.ServiceInformationLayerImage;
40
import org.gvsig.remoteClient.utils.BoundaryBox;
41

    
42
/**
43
 * This class implements the wizard that enables the user to load an ArcIMS
44
 * layer. Passes most requests on to its <tt>ArcImsWizardData dataSource</tt>
45
 * object.
46
 * 
47
 * @see es.prodevelop.cit.gvsig.arcims.fmap.datasource.ArcImsWizardData
48
 * 
49
 * @author jldominguez
50
 */
51
public class ArcImsWizard extends WizardPanel {
52

    
53
        private static Logger logger = Logger.getLogger(ArcImsWizard.class.getName());
54
        private WizardListenerSupport listenerSupport = new WizardListenerSupport();
55
        private ArcImsWizardData dataSource;
56
        private ServiceNamesPanel svsNamesPanel;
57
        
58
        private FeatureServicePanel feaServicePanel;
59
        private ImageServicePanel imgServicePanel;
60
        
61
        private JPanel mainPanel = null;
62
        private String nombreTema = "ArcIMS layer";
63
        private String layerQuery = "Empty query";
64
        private String host = "";
65
        private String serviceName = "";
66
        private String serviceType = "";
67
        private String imageFormat; 
68
        private FLayer theLayer;
69
        private View theView;
70
        
71
        private static final long serialVersionUID = 0;
72

    
73
        public ArcImsWizard() {
74
                super();
75
                initialize(true, false);
76
        }
77

    
78
        public ArcImsWizard(boolean editionallowed, boolean props) {
79
                super();
80
                initialize(editionallowed, props);
81
        }
82

    
83
        public ServiceNamesPanel getSvsNamesPanel() {
84
                return svsNamesPanel;
85
        }
86

    
87
        public void setSvsNamesPanel(ServiceNamesPanel svsNamesPanel) {
88
                this.svsNamesPanel = svsNamesPanel;
89
        }
90

    
91
        public void setLayerQuery(String lq) {
92
                layerQuery = lq;
93
        }
94

    
95
        public String getLayerQuery() {
96
                return layerQuery;
97
        }
98

    
99
        public void setHostName(String h) {
100
                host = h;
101
        }
102

    
103
        public String getHostName() {
104
                return host;
105
        }
106

    
107
        public void setServiceName(String n) {
108
                serviceName = n;
109
        }
110

    
111
        public String getServiceName() {
112
                return serviceName;
113
        }
114

    
115
        public void setNewLayerName(String n) {
116
                nombreTema = n;
117
        }
118

    
119
        public String getNewLayerName() {
120
                return nombreTema;
121
        }
122

    
123
        /**
124
         * Sets tab name and creates gui panels.
125
         *
126
         */
127
        private void initialize(boolean editionallowed, boolean props) {
128
                setTabName("ArcIMS");
129
                svsNamesPanel = new ServiceNamesPanel(this);
130
                
131
                imgServicePanel = new ImageServicePanel(this, props);
132
                feaServicePanel = new FeatureServicePanel(this, editionallowed, props);
133

    
134
                setSize(646, 359);
135
                setLayout(new BorderLayout(10, 10));
136

    
137
                setPreferredSize(new java.awt.Dimension(750, 420));
138
                this.add(getMainPanel(), BorderLayout.CENTER);
139
                this.setEnabledPanels("main");
140
                this.validate();
141
        }
142

    
143
        public ArcImsWizardData getDataSource() {
144
                return dataSource;
145
        }
146

    
147
        public void setDataSource(ArcImsWizardData ds) {
148
                dataSource = ds;
149
        }
150

    
151
        public void initWizard() {
152
                dataSource = new ArcImsWizardData();
153
        }
154

    
155
        public void execute() {
156
        }
157

    
158
        /**
159
         * This method will be invoqued by gvSIG when the user clicks on the
160
         * <i>Accept</i> button to retrieve the layers selected by the user. They
161
         * will be seen from gvSIG as one layer.
162
         * 
163
         * @return the new ArcIMS layer to be added to the project
164
         */
165
        public FLayer getLayer() {
166
//                HashMap m = new HashMap();
167
//                m.put("host", "http://noruega:9080");
168
//                m.put("service_name", "CarreterasIS");
169
//                m.put("srs", "EPSG:23030");
170
//                // m.put("layer_name", "Prueba");
171
//                
172
//                try {
173
//                        return new FRasterLyrArcIMS(m);
174
//                } catch (ConnectionException e) {
175
//                        // TODO Auto-generated catch block
176
//                        return null;
177
//                }
178

    
179
                // now we have the mapControl
180
                dataSource.setMapControl(getMapCtrl());
181
                
182
                theLayer = null;
183
                
184
                if (serviceType.compareToIgnoreCase(ServiceInfoTags.vIMAGESERVICE) == 0) {
185
                        theLayer = createArcImsRasterLayer();
186
                }
187
                
188
                if (theLayer == null) {
189
                        logger.error("Error while creating ArcIms layer.");
190
                }
191
                
192
                if (serviceType.compareToIgnoreCase(ServiceInfoTags.vFEATURESERVICE) == 0) {
193
                        
194
                        if (feaServicePanel.isGroupOptionSelected()) { // agrupar
195
                                theLayer = createArcImsFeatureLayer(false);
196
                        } else { // no agrupar
197
                                theLayer = createArcImsFeatureLayer(true);
198
                        }
199
                }
200
                if (theLayer == null) {
201
                        logger.info("Returned a null layer (layers were added manually).");
202
                }
203
                return theLayer;
204
        }
205
        
206
        public FLayer getLayerAsIs() {
207
                return theLayer;
208
        }
209
        
210
        /**
211
         * Creates an ArcIMS feature layer. This method will use the
212
         * ArcImsWizardData method to create the layer.
213
         * 
214
         * @return the ArcIMS raster layer
215
         */
216
        private FFeatureLyrArcIMSCollection createArcImsFeatureLayer(boolean sep) {
217
                FFeatureLyrArcIMSCollection layer = null;
218
                try {
219
                        layer = dataSource.createArcImsFeatureLayer(host,
220
                                        serviceName, layerQuery, nombreTema, getMapCtrl()
221
                                                        .getMapContext().getProjection(), sep);
222
                } catch (Exception e1) {
223
                        e1.printStackTrace();
224
                }
225
                return layer;
226
        }
227

    
228
        /**
229
         * Creates an ArcIMS raster layer. This method will use the
230
         * ArcImsWizardData method to create the layer.
231
         * 
232
         * @return the ArcIMS raster layer
233
         */
234
        private FRasterLyrArcIMS createArcImsRasterLayer() {
235
                FRasterLyrArcIMS layer = null;
236
                try {
237
                        // the value of these parameters was set by other gui objects (panels, etc)
238
                        layer = dataSource.createArcImsRasterLayer(host,
239
                                        serviceName, layerQuery, nombreTema, getMapCtrl()
240
                                                        .getMapContext().getProjection(), imageFormat);
241
                } catch (Exception e1) {
242
                        logger.error("While creating ArcImsRasterLayer ", e1);
243
                }
244
                
245
                // a warning is shown if the SRS was not provided by the server:
246
//                if (dataSource.isMissingSrs()) {
247
//                        showMissingSrsMessage();
248
//                }
249

    
250
//                if (layer != null) {
251
//                        ArcImsStatus status = layer.getArcimsStatus();
252
//                        String fmt = imageFormat.getFormatString();
253
//                        boolean imagefmtok = ((FMapRasterArcImsDriver) layer.getDriver()).testFormat(status, fmt);
254
//                        if (!imagefmtok) {
255
//                                showImageFmtNotSupportedMessage(fmt);
256
//                                return null;
257
//                        }
258
//                }
259
                
260
                return layer;
261
        }
262
        
263
        private void showImageFmtNotSupportedMessage(String fmt) {
264
                JOptionPane.showMessageDialog(this,
265
                                PluginServices.getText(this, "server_doesnt_support_selected_image_format") + ": " +
266
                                fmt.toUpperCase(),
267
                                PluginServices.getText(this, "error"),
268
                                JOptionPane.WARNING_MESSAGE);
269
        }
270

    
271
        /**
272
         * Utility method to display warning message. 
273
         *
274
         */
275
        private void showMissingSrsMessage() {
276
                JOptionPane.showMessageDialog(this,
277
                                PluginServices.getText(this, "server_provides_no_srs__scale_data_may_be_wrong"),
278
                                PluginServices.getText(this, "warning"),
279
                                JOptionPane.WARNING_MESSAGE);
280
        }
281

    
282
        /**
283
         * This method initializes mainPanel
284
         * 
285
         * @return javax.swing.JPanel
286
         */
287
        private JPanel getMainPanel() {
288
                if (mainPanel == null) {
289
                        mainPanel = new JPanel();
290
                        mainPanel.setBounds(new java.awt.Rectangle(15, 90, 616, 256));
291
                        mainPanel.setLayout(new BorderLayout());
292
                }
293
                return mainPanel;
294
        }
295

    
296
        public void addWizardListener(WizardListener listener) {
297
                listenerSupport.addWizardListener(listener);
298
        }
299

    
300
        public void removeWizardListener(WizardListener listener) {
301
                listenerSupport.removeWizardListener(listener);
302
        }
303

    
304
        /**
305
         * Enables or disables the main panel and the layer selection panel.
306
         * 
307
         * @param selectedPanel a String that identifies which panel must be enabled:
308
         * "main" (for the service names panel) or "service" (for the layer
309
         * selection panel).
310
         */
311
        public void setEnabledPanels(String selectedPanel) {
312
                mainPanel.removeAll();
313
                
314
                svsNamesPanel.setVisible(false);
315
                imgServicePanel.setVisible(false);
316
                feaServicePanel.setVisible(false);
317
                
318
                if (selectedPanel.compareToIgnoreCase("main") == 0) {
319
                        mainPanel.add(svsNamesPanel, BorderLayout.CENTER);
320
                        svsNamesPanel.setVisible(true);
321
                }
322
                
323
                if (selectedPanel.compareToIgnoreCase("feature") == 0) {
324
                        mainPanel.add(feaServicePanel, BorderLayout.CENTER);
325
                        feaServicePanel.setVisible(true);
326
                }
327
                
328
                if (selectedPanel.compareToIgnoreCase("image") == 0) {
329
                        mainPanel.add(imgServicePanel, BorderLayout.CENTER);
330
                        imgServicePanel.setVisible(true);
331
                        imgServicePanel.getImageFormatCombo().revalidate();
332
                        
333
                }
334
                
335
        }
336

    
337
        /**
338
         * Fires a notification to this wizard listeners telling them if the
339
         * configuration is fair enough to send a GetMap request.
340
         * 
341
         * @param b
342
         *            <b>true</b> if the data in the wizard is enough to send a
343
         *            <tt>getMap</tt> request and therefore create a new layer in
344
         *            the project; <b>false</b> otherwise.
345
         */
346
        public void fireWizardComplete(boolean b) {
347
                listenerSupport.callStateChanged(b);
348
                callStateChanged(b);
349
        }
350

    
351
        /**
352
         * Decides which Panel must be loaded (ServiceNamesPanel or
353
         * ...ServicePanel) depending on the type of the service selected by the
354
         * user.
355
         */
356
        public void fillAndMoveTabbedPaneToEnabled() {
357
                if (this.svsNamesPanel.getSelectedServiceType().compareToIgnoreCase(
358
                                ServiceInfoTags.vIMAGESERVICE) == 0) {
359
                        this.fillImageServiceTab();
360
                        this.setEnabledPanels("image");
361
                }
362
                if (this.svsNamesPanel.getSelectedServiceType().compareToIgnoreCase(
363
                                ServiceInfoTags.vFEATURESERVICE) == 0) {
364
                        this.fillFeatureServiceTab();
365
                        this.setEnabledPanels("feature");
366
                }
367
        }
368

    
369
        /**
370
         * Loads FeatureServicePanel's controls.
371
         */
372
        private void fillImageServiceTab() {
373
                FMapRasterArcImsDriver drv = (FMapRasterArcImsDriver) this.dataSource.getDriver();
374
                ArcImsClientP cli = (ArcImsClientP) drv.getClient();
375
                ServiceInformation si = cli.getServiceInformation();
376
                String map_units = si.getMapunits();
377
                int _dpi = si.getScreen_dpi();
378

    
379
                this.imgServicePanel.setDetailsPanelServiceNameInBorder(this.serviceName);
380
                this.imgServicePanel.emptyTables();
381
                this.imgServicePanel.emptyFormatsCombo();
382
                this.imgServicePanel.loadServiceDetailsTable(si);
383
                
384
                ArcImsStatus tmpStatus = new ArcImsStatus();
385
                tmpStatus.setServiceInformation(si);
386
                tmpStatus.setService(serviceName);
387
                this.imgServicePanel.loadImageFormatCombo((ArcImsImageClient) cli, tmpStatus);
388

    
389
                // load available layers list
390
                for (int i = 0; i < si.getLayers().size(); i++) {
391
                        if (si.getLayers().get(i) instanceof ServiceInformationLayerImage) {
392
                                ServiceInformationLayerImage sii = (ServiceInformationLayerImage) si.getLayers().get(i);
393
                                this.imgServicePanel
394
                                                .addLayerToAvailableList(new LayersListElement(sii, map_units, _dpi));
395
                        }
396

    
397
                        if (si.getLayers().get(i) instanceof ServiceInformationLayerFeatures) {
398
                                ServiceInformationLayerFeatures sif = (ServiceInformationLayerFeatures) si.getLayers().get(i);
399
                                this.imgServicePanel
400
                                                .addLayerToAvailableList(new LayersListElement(sif, map_units, _dpi));
401
                        }
402
                }
403
                JScrollPane sp = imgServicePanel.getAvailableLayersScrollPane();
404
                this.imgServicePanel.setAvailableLayersTree(null);
405
                JTree t = imgServicePanel.getAvailableLayersTree();
406
                sp.setViewportView(t);
407
                imgServicePanel.setServiceInfoTabNumber(1);
408
                imgServicePanel.setServiceInfoTabNumber(0);
409
        }
410

    
411
        /**
412
         * Loads the Feature Service Panel's controls.
413
         */
414
        private void fillFeatureServiceTab() {
415
                FMapFeatureArcImsDriver drv = (FMapFeatureArcImsDriver) this.dataSource.getDriver();
416
                ArcImsClientP cli = (ArcImsClientP) drv.getClient();
417

    
418
                ServiceInformation si = cli.getServiceInformation();
419
                String map_units = si.getMapunits();
420
                int _dpi = si.getScreen_dpi();
421
                
422
                feaServicePanel.setDetailsPanelServiceNameInBorder(serviceName);
423
                feaServicePanel.emptyTables();
424
                // ------------------- Test -------------------
425
                // this.imgServicePanel.addLayerToAvailableList(new LayersListElement(sif, "meters", 96));
426
                // ------------------- Test -------------------
427

    
428
                this.feaServicePanel.loadServiceDetailsTable(si);
429

    
430
                // load available layers list
431
                for (int i = 0; i < si.getLayers().size(); i++) {
432
                                ServiceInformationLayerFeatures sif = (ServiceInformationLayerFeatures) si.getLayers().get(i);
433
                                this.feaServicePanel.addLayerToAvailableList(new LayersListElement(sif, map_units, _dpi));
434
                }
435

    
436
                
437
                
438
                JScrollPane sp = feaServicePanel.getAvailableLayersScrollPane();
439
                this.feaServicePanel.setAvailableLayersTree(null);
440
                JTree t = feaServicePanel.getAvailableLayersTree();
441
                sp.setViewportView(t);
442
                // feaServicePanel.setServiceInfoTabNumber(1);
443
                feaServicePanel.setServiceInfoTabNumber(0);
444
        }
445

    
446
        public String getServiceType() {
447
                return serviceType;
448
        }
449

    
450
        public void setServiceType(String serviceType) {
451
                this.serviceType = serviceType;
452
        }
453

    
454
        public FeatureServicePanel getFeaServicePanel() {
455
                return feaServicePanel;
456
        }
457

    
458
        public void setFeaServicePanel(FeatureServicePanel feaServicePanel) {
459
                this.feaServicePanel = feaServicePanel;
460
        }
461

    
462
        public ImageServicePanel getImgServicePanel() {
463
                return imgServicePanel;
464
        }
465

    
466
        public void setImgServicePanel(ImageServicePanel imgServicePanel) {
467
                this.imgServicePanel = imgServicePanel;
468
        }
469

    
470
        public void setImageFormat(String fmt) {
471
                this.imageFormat = fmt;
472
        }
473

    
474
        public String getImageFormat() {
475
                return imageFormat;
476
        }
477

    
478
        public void setServerVersionInPanels(String vers) {
479
                if (imgServicePanel != null) {
480
                        imgServicePanel.setTextInVersionLabel(vers);
481
                }
482
                
483
                if (feaServicePanel != null) {
484
                        feaServicePanel.setTextInVersionLabel(vers);
485
                }
486
        }
487
} // @jve:decl-index=0:visual-constraint="11,8"
488