Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.arcims.feature.extension / src / main / java / org / gvsig / arcims / feature / gui / wizards / ArcImsFeatureWizard.java @ 32545

History | View | Annotate | Download (13 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 org.gvsig.arcims.feature.gui.wizards;
44

    
45
import java.awt.BorderLayout;
46
import java.awt.geom.Rectangle2D;
47

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

    
52
import org.cresques.cts.IProjection;
53
import org.gvsig.andami.PluginServices;
54
import org.gvsig.andami.ui.mdiManager.IWindow;
55
import org.gvsig.app.gui.WizardPanel;
56
import org.gvsig.app.gui.wizards.WizardListener;
57
import org.gvsig.app.gui.wizards.WizardListenerSupport;
58
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
59
import org.gvsig.arcims.feature.gui.panels.FeatureServicePanel;
60
import org.gvsig.arcims.feature.gui.panels.ServiceNamesPanel;
61
import org.gvsig.arcims.feature.gui.panels.utils.LayersListElement;
62
import org.gvsig.fmap.crs.CRSFactory;
63
import org.gvsig.fmap.dal.DALLocator;
64
import org.gvsig.fmap.dal.DataManager;
65
import org.gvsig.fmap.dal.DataStoreParameters;
66
import org.gvsig.fmap.dal.exception.InitializeException;
67
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
68
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
69
import org.gvsig.fmap.dal.serverexplorer.arcims.ArcImsServerExplorer;
70
import org.gvsig.fmap.dal.serverexplorer.arcims.ArcImsServerExplorerParameters;
71
import org.gvsig.fmap.dal.store.arcims.ArcImsStoreParameters;
72
import org.gvsig.fmap.dal.store.arcims.ArcImsStoreProvider;
73
import org.gvsig.fmap.geom.primitive.impl.Envelope2D;
74
import org.gvsig.fmap.mapcontext.ViewPort;
75
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
76
import org.gvsig.fmap.mapcontext.layers.FLayer;
77
import org.gvsig.fmap.mapcontext.layers.LayerFactory;
78
import org.gvsig.remoteclient.arcims.ArcImsClient;
79
import org.gvsig.remoteclient.arcims.ArcImsFeatureClient;
80
import org.gvsig.remoteclient.arcims.ArcImsStatus;
81
import org.gvsig.remoteclient.arcims.utils.ServiceInfoTags;
82
import org.gvsig.remoteclient.arcims.utils.ServiceInformation;
83
import org.gvsig.remoteclient.arcims.utils.ServiceInformationLayerFeatures;
84
import org.slf4j.Logger;
85
import org.slf4j.LoggerFactory;
86

    
87
/**
88
 * This class implements the wizard that enables the user to load an ArcIMS
89
 * layer. Passes most requests on to its <tt>ArcImsWizardData dataSource</tt>
90
 * object.
91
 * 
92
 * @see org.gvsig.arcims.feature.fmap.datasource.ArcImsFeatureWizardData
93
 * 
94
 * @author jldominguez
95
 * @author vsanjaime version 2.0
96
 */
97
public class ArcImsFeatureWizard extends WizardPanel {
98

    
99
        private static Logger logger = LoggerFactory
100
                        .getLogger(ArcImsFeatureWizard.class.getName());
101
        private static final long serialVersionUID = 0;
102
        private WizardListenerSupport listenerSupport = new WizardListenerSupport();
103
        // PANELS
104
        private ServiceNamesPanel svsNamesPanel;
105
        private FeatureServicePanel feaServicePanel;
106
        private JPanel mainPanel = null;
107
        // DAL
108
        private ArcImsServerExplorer serverExplorer = null;
109
        // LAYER
110
        private FLayer theLayer;
111

    
112
        /**
113
         * Constructor
114
         */
115
        public ArcImsFeatureWizard() {
116
                super();
117
                initialize(true, false);
118
        }
119

    
120
        /**
121
         * Constructor
122
         * 
123
         * @param editionallowed
124
         * @param props
125
         */
126
        public ArcImsFeatureWizard(boolean editionallowed, boolean props) {
127
                super();
128
                initialize(editionallowed, props);
129

    
130
        }
131

    
132
        /**
133
         * Get services names PANEL
134
         * 
135
         * @return
136
         */
137
        public ServiceNamesPanel getSvsNamesPanel() {
138
                return svsNamesPanel;
139
        }
140

    
141
        /**
142
         * Set service name PANEL
143
         * 
144
         * @param svsNamesPanel
145
         */
146
        public void setSvsNamesPanel(ServiceNamesPanel svsNamesPanel) {
147
                this.svsNamesPanel = svsNamesPanel;
148
        }
149

    
150
        /**
151
         * Sets tab name and creates gui panels.
152
         * 
153
         * @param editionallowed
154
         * @param props
155
         */
156
        private void initialize(boolean editionallowed, boolean props) {
157

    
158
                this.setTabName("ArcIMS Feature");
159
                // Auxiliar panels
160
                this.svsNamesPanel = new ServiceNamesPanel(this);
161
                this.feaServicePanel = new FeatureServicePanel(this, editionallowed,
162
                                props);
163

    
164
                this.setSize(646, 359);
165
                this.setLayout(new BorderLayout(10, 10));
166

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

    
173
        /**
174
         * Execute final process. Create ArcIMS Layer
175
         */
176
        public void execute() {
177
                ArcImsStatus status = this.getServerExplorer().getStatus();
178
                // view envelope
179
                IWindow win = PluginServices.getMDIManager().getActiveWindow();
180
                ViewPort vport = ((DefaultViewPanel) win).getMapControl()
181
                                .getMapContext().getViewPort();
182
                Envelope2D enve = (Envelope2D) vport.getEnvelope();
183
                if (enve == null) {
184
                        Rectangle2D r = status.getServiceInfo().getEnvelopeR2D();
185

    
186
                        enve = new Envelope2D(r.getMinX(), r.getMinY(), r.getMinY(), r
187
                                        .getMaxY());
188
                }
189
                status.setEnvelope(enve);
190

    
191
                // status srs
192
                IProjection proj = ((DefaultViewPanel) win).getMapControl()
193
                                .getMapContext().getProjection();
194
                status.setSrs(proj.getAbrev());
195
                ArcImsFeatureClient client = ((ArcImsFeatureClient) this.serverExplorer
196
                                .getClient());
197
                try {
198

    
199
                        ArcImsStoreParameters parameters = this.getStoreParameters();
200

    
201
                        FLayer layer = LayerFactory.getInstance().createLayer(
202
                                        status.getNewLayerName(), parameters);
203

    
204
                        this.getMapCtrl().getMapContext().getLayers().addLayer(layer);
205
                } catch (Exception e) {
206
                        logger.error("Error creating ArcIms layer", e);
207
                }
208
        }
209

    
210
        /**
211
         * This method will be invoqued by gvSIG when the user clicks on the
212
         * <i>Accept</i> button to retrieve the layers selected by the user. They
213
         * will be seen from gvSIG as one layer.
214
         * 
215
         * @return the new ArcIMS layer to be added to the project
216
         * @throws ProviderNotRegisteredException
217
         * @throws InitializeException
218
         * @throws ProviderNotRegisteredException
219
         * @throws InitializeException
220
         * @throws LoadLayerException
221
         */
222
        private ArcImsStoreParameters getStoreParameters()
223
                        throws InitializeException, ProviderNotRegisteredException {
224

    
225
                DataManager dataManager = DALLocator.getDataManager();
226
                ArcImsStoreParameters parameters = (ArcImsStoreParameters) dataManager
227
                                .createStoreParameters(ArcImsStoreProvider.NAME);
228

    
229
                parameters.setServerUrl((String) serverExplorer.getParameters()
230
                                .getDynValue("url"));
231
                parameters.setServerVersion((String) serverExplorer.getParameters()
232
                                .getDynValue("version"));
233
                parameters.setServiceName(this.serverExplorer.getStatus()
234
                                .getServiceName());
235
                parameters.setServiceType(this.serverExplorer.getStatus()
236
                                .getServiceType());
237
                parameters.setSelectedLayers(this.serverExplorer.getStatus()
238
                                .getLayersIdsSelected());
239
                parameters.setServiceInfo(this.serverExplorer.getStatus()
240
                                .getServiceInfo());
241
                parameters.setGroupLayers(feaServicePanel.isGroupOptionSelected());
242
                parameters.setSRS(CRSFactory.getCRS(this.serverExplorer.getStatus()
243
                                .getSrs()));
244
                parameters.setEnvelope(this.serverExplorer.getStatus().getEnvelope());
245
                return parameters;
246
        }
247

    
248
        /**
249
         * 
250
         * @return
251
         */
252
        public FLayer getLayerAsIs() {
253
                return theLayer;
254
        }
255

    
256
        /**
257
         * This method initializes mainPanel
258
         * 
259
         * @return javax.swing.JPanel
260
         */
261
        private JPanel getMainPanel() {
262
                if (mainPanel == null) {
263
                        mainPanel = new JPanel();
264
                        mainPanel.setBounds(new java.awt.Rectangle(15, 90, 616, 256));
265
                        mainPanel.setLayout(new BorderLayout());
266
                }
267

    
268
                return mainPanel;
269
        }
270

    
271
        public void addWizardListener(WizardListener listener) {
272
                listenerSupport.addWizardListener(listener);
273
        }
274

    
275
        public void removeWizardListener(WizardListener listener) {
276
                listenerSupport.removeWizardListener(listener);
277
        }
278

    
279
        /**
280
         * Enables or disables the main panel and the layer selection panel.
281
         * 
282
         * @param selectedPanel
283
         *            a String that identifies which panel must be enabled: "main"
284
         *            (for the service names panel) or "service" (for the layer
285
         *            selection panel).
286
         */
287
        public void setEnabledPanels(String selectedPanel) {
288
                mainPanel.removeAll();
289

    
290
                svsNamesPanel.setVisible(false);
291
                feaServicePanel.setVisible(false);
292

    
293
                if (selectedPanel.compareToIgnoreCase("main") == 0) {
294
                        mainPanel.add(svsNamesPanel, BorderLayout.CENTER);
295
                        svsNamesPanel.setVisible(true);
296
                }
297

    
298
                if (selectedPanel.compareToIgnoreCase("feature") == 0) {
299
                        mainPanel.add(feaServicePanel, BorderLayout.CENTER);
300
                        feaServicePanel.setVisible(true);
301
                }
302
        }
303

    
304
        /**
305
         * Fires a notification to this wizard listeners telling them if the
306
         * configuration is fair enough to send a GetMap request.
307
         * 
308
         * @param b
309
         *            <b>true</b> if the data in the wizard is enough to send a
310
         *            <tt>getMap</tt> request and therefore create a new layer in
311
         *            the project; <b>false</b> otherwise.
312
         */
313
        public void fireWizardComplete(boolean b) {
314
                listenerSupport.callStateChanged(b);
315
                callStateChanged(b);
316
        }
317

    
318
        /**
319
         * Decides which Panel must be loaded (ServiceNamesPanel or ...ServicePanel)
320
         * depending on the type of the service selected by the user.
321
         */
322
        public void fillAndMoveTabbedPaneToEnabled() {
323

    
324
                if (this.svsNamesPanel.getSelectedServiceType().compareToIgnoreCase(
325
                                ServiceInfoTags.vFEATURESERVICE) == 0) {
326
                        this.fillFeatureServiceTab();
327
                        this.setEnabledPanels("feature");
328
                }
329
        }
330

    
331
        /**
332
         * Loads the Feature Service Panel's controls.
333
         */
334
        private void fillFeatureServiceTab() {
335

    
336
                ArcImsClient cli = this.serverExplorer.getClient();
337

    
338
                ServiceInformation si = cli.getServiceInformation();
339
                String map_units = si.getMapunits();
340
                int _dpi = si.getScreen_dpi();
341

    
342
                feaServicePanel.setDetailsPanelServiceNameInBorder(this.serverExplorer
343
                                .getStatus().getServiceName());
344
                feaServicePanel.emptyTables();
345

    
346
                // ------------------- Test -------------------
347
                // this.imgServicePanel.addLayerToAvailableList(new
348
                // LayersListElement(sif, "meters", 96));
349
                // ------------------- Test -------------------
350
                this.feaServicePanel.loadServiceDetailsTable(si);
351

    
352
                // load available layers list
353
                for (int i = 0; i < si.getLayers().size(); i++) {
354
                        ServiceInformationLayerFeatures sif = (ServiceInformationLayerFeatures) si
355
                                        .getLayers().get(i);
356
                        this.feaServicePanel.addLayerToAvailableList(new LayersListElement(
357
                                        sif, map_units, _dpi));
358
                }
359

    
360
                JScrollPane sp = feaServicePanel.getAvailableLayersScrollPane();
361
                this.feaServicePanel.setAvailableLayersTree(null);
362

    
363
                JTree t = feaServicePanel.getAvailableLayersTree();
364
                sp.setViewportView(t);
365

    
366
                // feaServicePanel.setServiceInfoTabNumber(1);
367
                feaServicePanel.setServiceInfoTabNumber(0);
368
        }
369

    
370
        /**
371
         * 
372
         * @return
373
         */
374
        public FeatureServicePanel getFeaServicePanel() {
375
                return feaServicePanel;
376
        }
377

    
378
        /**
379
         * 
380
         * @param feaServicePanel
381
         */
382
        public void setFeaServicePanel(FeatureServicePanel feaServicePanel) {
383
                this.feaServicePanel = feaServicePanel;
384
        }
385

    
386
        /**
387
         * 
388
         * @param vers
389
         */
390
        public void setServerVersionInPanels(String vers) {
391

    
392
                if (feaServicePanel != null) {
393
                        feaServicePanel.setTextInVersionLabel(vers);
394
                }
395
        }
396

    
397
        /**
398
         * 
399
         */
400
        @Override
401
        public void close() {
402
                // TODO Auto-generated method stub
403

    
404
        }
405

    
406
        /**
407
         * 
408
         */
409
        @Override
410
        public DataStoreParameters[] getParameters() {
411
                // TODO Auto-generated method stub
412
                return null;
413
        }
414

    
415
        /**
416
         * 
417
         * @return
418
         */
419
        public ArcImsServerExplorer getServerExplorer() {
420
                return serverExplorer;
421
        }
422

    
423
        /**
424
         * 
425
         * @param serverExplorer
426
         */
427
        public void setServerExplorer(ArcImsServerExplorer serverExplorer) {
428
                this.serverExplorer = serverExplorer;
429
        }
430

    
431
        /**
432
         * 
433
         */
434
        @Override
435
        public void initWizard() {
436
                // nothing to do
437
        }
438

    
439
        /**
440
         * 
441
         * @param url
442
         * @param version
443
         * @throws ProviderNotRegisteredException
444
         * @throws InitializeException
445
         * @throws ValidateDataParametersException
446
         */
447
        public void createServerExplorer(String url, String version)
448
                        throws ValidateDataParametersException, InitializeException,
449
                        ProviderNotRegisteredException {
450
                DataManager dataManager = DALLocator.getDataManager();
451
                // Create the server explorer parameters
452
                ArcImsServerExplorerParameters parameters = (ArcImsServerExplorerParameters) dataManager
453
                                .createServerExplorerParameters(ArcImsServerExplorer.NAME);
454
                parameters.setUrl(url);
455
                parameters.setVersion(version);
456

    
457
                // Create the server explorer
458
                serverExplorer = (ArcImsServerExplorer) dataManager
459
                                .createServerExplorer(parameters);
460

    
461
        }
462

    
463
}