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 @ 32459

History | View | Annotate | Download (12.9 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
import java.util.List;
48

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

    
53
import org.cresques.cts.IProjection;
54
import org.gvsig.andami.PluginServices;
55
import org.gvsig.andami.ui.mdiManager.IWindow;
56
import org.gvsig.app.gui.WizardPanel;
57
import org.gvsig.app.gui.wizards.WizardListener;
58
import org.gvsig.app.gui.wizards.WizardListenerSupport;
59
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
60
import org.gvsig.arcims.feature.gui.panels.FeatureServicePanel;
61
import org.gvsig.arcims.feature.gui.panels.ServiceNamesPanel;
62
import org.gvsig.arcims.feature.gui.panels.utils.LayersListElement;
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.ArcImsVectStatus;
82
import org.gvsig.remoteclient.arcims.utils.ArcImsFeature;
83
import org.gvsig.remoteclient.arcims.utils.ServiceInfoTags;
84
import org.gvsig.remoteclient.arcims.utils.ServiceInformation;
85
import org.gvsig.remoteclient.arcims.utils.ServiceInformationLayerFeatures;
86
import org.slf4j.Logger;
87
import org.slf4j.LoggerFactory;
88

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

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

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

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

    
132
        }
133

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

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

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

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

    
166
                this.setSize(646, 359);
167
                this.setLayout(new BorderLayout(10, 10));
168

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

    
175
        /**
176
         * Execute final process. Create ArcIMS Layer
177
         */
178
        public void execute() {
179
                ArcImsStatus status = this.getServerExplorer().getStatus();
180
                // view envelope
181
                IWindow win = PluginServices.getMDIManager().getActiveWindow();
182
                ViewPort vport = ((DefaultViewPanel) win).getMapControl().getMapContext().getViewPort();
183
                Envelope2D enve = (Envelope2D) vport.getEnvelope();
184
                if(enve == null){
185
                        Rectangle2D r = status.getServiceInfo().getEnvelopeR2D();
186
                        
187
                        enve = new Envelope2D(r.getMinX(),r.getMinY(),r.getMinY(),r.getMaxY());
188
                }
189
                status.setEnvelope(enve);
190
                // status srs
191
                IProjection proj = ((DefaultViewPanel) win).getMapControl().getMapContext().getProjection();
192
                status.setSrs(proj.getAbrev());        
193
                ArcImsFeatureClient client = ((ArcImsFeatureClient)this.serverExplorer.getClient());
194
                try {
195
                        List<List<ArcImsFeature>> featuresLayers = client.getMap((ArcImsVectStatus)status);
196
                
197
//                        DataStoreProviderServices
198
//                        params.setDefaultFeatureType(this.createFeatureType(params, layerId, status));
199
                        FLayer layer = this.getLayer();
200
                        this.getMapCtrl().getMapContext().getLayers().addLayer(layer);
201
                } catch (Exception e) {
202
                        logger.error("Error creating ArcIms layer", e);
203
                }
204
        }
205

    
206
        /**
207
         * This method will be invoqued by gvSIG when the user clicks on the
208
         * <i>Accept</i> button to retrieve the layers selected by the user. They
209
         * will be seen from gvSIG as one layer.
210
         * 
211
         * @return the new ArcIMS layer to be added to the project
212
         * @throws ProviderNotRegisteredException
213
         * @throws InitializeException
214
         * @throws LoadLayerException
215
         */
216
        public FLayer getLayer() throws InitializeException,
217
                        ProviderNotRegisteredException, LoadLayerException {
218

    
219
                DataManager dataManager = DALLocator.getDataManager();
220
                ArcImsStoreParameters parameters = (ArcImsStoreParameters) dataManager
221
                                .createStoreParameters(ArcImsStoreProvider.NAME);
222

    
223
                parameters.setUrl((String) serverExplorer.getParameters().getDynValue(
224
                                "url"));
225
                parameters.setVersion((String) serverExplorer.getParameters()
226
                                .getDynValue("version"));
227
                parameters.setNameService(this.serverExplorer.getStatus()
228
                                .getServiceName());
229
                parameters.setTypeService(this.serverExplorer.getStatus()
230
                                .getServiceType());
231
                parameters.setLayersSelected(this.serverExplorer.getStatus()
232
                                .getLayerQueryString());
233

    
234
                // create layer
235

    
236
                this.theLayer = null;
237
                this.theLayer = LayerFactory.getInstance().createLayer(
238
                                this.serverExplorer.getStatus().getNewLayerName(), parameters);
239

    
240
                return theLayer;
241
        }
242

    
243
        /**
244
         * 
245
         * @return
246
         */
247
        public FLayer getLayerAsIs() {
248
                return theLayer;
249
        }
250

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

    
263
                return mainPanel;
264
        }
265

    
266
        public void addWizardListener(WizardListener listener) {
267
                listenerSupport.addWizardListener(listener);
268
        }
269

    
270
        public void removeWizardListener(WizardListener listener) {
271
                listenerSupport.removeWizardListener(listener);
272
        }
273

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

    
285
                svsNamesPanel.setVisible(false);
286
                feaServicePanel.setVisible(false);
287

    
288
                if (selectedPanel.compareToIgnoreCase("main") == 0) {
289
                        mainPanel.add(svsNamesPanel, BorderLayout.CENTER);
290
                        svsNamesPanel.setVisible(true);
291
                }
292

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

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

    
313
        /**
314
         * Decides which Panel must be loaded (ServiceNamesPanel or ...ServicePanel)
315
         * depending on the type of the service selected by the user.
316
         */
317
        public void fillAndMoveTabbedPaneToEnabled() {
318

    
319
                if (this.svsNamesPanel.getSelectedServiceType().compareToIgnoreCase(
320
                                ServiceInfoTags.vFEATURESERVICE) == 0) {
321
                        this.fillFeatureServiceTab();
322
                        this.setEnabledPanels("feature");
323
                }
324
        }
325

    
326
        /**
327
         * Loads the Feature Service Panel's controls.
328
         */
329
        private void fillFeatureServiceTab() {
330

    
331
                ArcImsClient cli = this.serverExplorer.getClient();
332

    
333
                ServiceInformation si = cli.getServiceInformation();
334
                String map_units = si.getMapunits();
335
                int _dpi = si.getScreen_dpi();
336

    
337
                feaServicePanel.setDetailsPanelServiceNameInBorder(this.serverExplorer
338
                                .getStatus().getServiceName());
339
                feaServicePanel.emptyTables();
340

    
341
                // ------------------- Test -------------------
342
                // this.imgServicePanel.addLayerToAvailableList(new
343
                // LayersListElement(sif, "meters", 96));
344
                // ------------------- Test -------------------
345
                this.feaServicePanel.loadServiceDetailsTable(si);
346

    
347
                // load available layers list
348
                for (int i = 0; i < si.getLayers().size(); i++) {
349
                        ServiceInformationLayerFeatures sif = (ServiceInformationLayerFeatures) si
350
                                        .getLayers().get(i);
351
                        this.feaServicePanel.addLayerToAvailableList(new LayersListElement(
352
                                        sif, map_units, _dpi));
353
                }
354

    
355
                JScrollPane sp = feaServicePanel.getAvailableLayersScrollPane();
356
                this.feaServicePanel.setAvailableLayersTree(null);
357

    
358
                JTree t = feaServicePanel.getAvailableLayersTree();
359
                sp.setViewportView(t);
360

    
361
                // feaServicePanel.setServiceInfoTabNumber(1);
362
                feaServicePanel.setServiceInfoTabNumber(0);
363
        }
364

    
365
        /**
366
         * 
367
         * @return
368
         */
369
        public FeatureServicePanel getFeaServicePanel() {
370
                return feaServicePanel;
371
        }
372

    
373
        /**
374
         * 
375
         * @param feaServicePanel
376
         */
377
        public void setFeaServicePanel(FeatureServicePanel feaServicePanel) {
378
                this.feaServicePanel = feaServicePanel;
379
        }
380

    
381
        /**
382
         * 
383
         * @param vers
384
         */
385
        public void setServerVersionInPanels(String vers) {
386

    
387
                if (feaServicePanel != null) {
388
                        feaServicePanel.setTextInVersionLabel(vers);
389
                }
390
        }
391

    
392
        /**
393
         * 
394
         */
395
        @Override
396
        public void close() {
397
                // TODO Auto-generated method stub
398

    
399
        }
400

    
401
        /**
402
         * 
403
         */
404
        @Override
405
        public DataStoreParameters[] getParameters() {
406
                // TODO Auto-generated method stub
407
                return null;
408
        }
409

    
410
        /**
411
         * 
412
         * @return
413
         */
414
        public ArcImsServerExplorer getServerExplorer() {
415
                return serverExplorer;
416
        }
417

    
418
        /**
419
         * 
420
         * @param serverExplorer
421
         */
422
        public void setServerExplorer(ArcImsServerExplorer serverExplorer) {
423
                this.serverExplorer = serverExplorer;
424
        }
425

    
426
        /**
427
         * 
428
         */
429
        @Override
430
        public void initWizard() {
431
                // nothing to do
432
        }
433
        
434
        /**
435
         * 
436
         * @param url
437
         * @param version
438
         * @throws ProviderNotRegisteredException 
439
         * @throws InitializeException 
440
         * @throws ValidateDataParametersException 
441
         */
442
        public void createServerExplorer(String url, String version) throws ValidateDataParametersException, InitializeException, ProviderNotRegisteredException{
443
                DataManager dataManager = DALLocator.getDataManager();
444
                // Create the server explorer parameters
445
                ArcImsServerExplorerParameters parameters = (ArcImsServerExplorerParameters) dataManager
446
                                .createServerExplorerParameters(ArcImsServerExplorer.NAME);
447
                parameters.setUrl(url);
448
                parameters.setVersion(version);
449

    
450
                // Create the server explorer
451
                serverExplorer = (ArcImsServerExplorer) dataManager
452
                                .createServerExplorer(parameters);
453
                
454
        }                
455
                
456

    
457
}