Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / org.gvsig.daltransform.app.mainplugin / src / main / java / org / gvsig / daltransform / swing / impl / DataTransformSelectionAction.java @ 38382

History | View | Annotate | Download (3.48 KB)

1 28893 jpiera
/* 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
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {Iver T.I.}   {Task}
26
*/
27
28 35512 nfrancisco
package org.gvsig.daltransform.swing.impl;
29 28893 jpiera
30
import jwizardcomponent.FinishAction;
31
32 35605 nfrancisco
import org.slf4j.Logger;
33
import org.slf4j.LoggerFactory;
34
35 29627 jpiera
import org.gvsig.andami.PluginServices;
36 35512 nfrancisco
import org.gvsig.daltransform.swing.DataTransformGui;
37 29790 jpiera
import org.gvsig.fmap.crs.CRSFactory;
38 28893 jpiera
import org.gvsig.fmap.dal.exception.DataException;
39
import org.gvsig.fmap.dal.feature.FeatureStore;
40
import org.gvsig.fmap.dal.feature.FeatureStoreTransform;
41 35605 nfrancisco
import org.gvsig.fmap.mapcontext.MapContextLocator;
42
import org.gvsig.fmap.mapcontext.MapContextManager;
43 28893 jpiera
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
44
import org.gvsig.fmap.mapcontext.layers.FLayer;
45
46
47
/**
48
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
49
 */
50
public class DataTransformSelectionAction extends FinishAction{
51
        private static final Logger logger = LoggerFactory.getLogger(DataTransformSelectionAction.class);
52 29164 jpiera
        private DefaultDataTransformWizard dataTransformWizard = null;
53 28893 jpiera
54 29164 jpiera
        public DataTransformSelectionAction(DefaultDataTransformWizard dataTransformWizard) {
55
                super(dataTransformWizard.getWizardComponents());
56
                this.dataTransformWizard = dataTransformWizard;
57 28893 jpiera
        }
58
59
        /* (non-Javadoc)
60
         * @see jwizardcomponent.Action#performAction()
61
         */
62
        public void performAction() {
63
                //Gets the selected transformation
64 29164 jpiera
                DataTransformGui featureTransformGui = dataTransformWizard.getDataTransformGui();
65 28893 jpiera
66
                //Gets the selected FeatureStore
67 29164 jpiera
                FeatureStore featureStore = dataTransformWizard.getFeatureStore();
68
69
                try {
70
                        //Gets the transform
71
                        FeatureStoreTransform featureStoreTransform = featureTransformGui.createFeatureStoreTransform(featureStore);
72
73 38382 jldominguez
                        // before applying
74
                        featureTransformGui.beforeApplyingTransform(featureStore, featureStoreTransform);
75
76
                        // Apply the transformation
77 28893 jpiera
                        featureStore.getTransforms().add(featureStoreTransform);
78 29164 jpiera
79 38382 jldominguez
                 // after applying
80
            featureTransformGui.afterApplyingTransform(featureStore, featureStoreTransform);
81
82 28893 jpiera
                        //Create and load a new layer...
83 29164 jpiera
                        if (dataTransformWizard.isLayerLoaded()){
84 35605 nfrancisco
                            MapContextManager manager = MapContextLocator.getMapContextManager();
85 38382 jldominguez
                            FLayer layer = manager.createLayer(
86
                                featureTransformGui.toString(),
87
                                featureStore);
88 29164 jpiera
                                dataTransformWizard.getMapContext().getLayers().addLayer(layer);
89 34908 fdiaz
                                layer.dispose();
90 28893 jpiera
                        }
91
                } catch (DataException e) {
92
                        logger.error("Error creating the transformation", e);
93
                } catch (LoadLayerException e) {
94
                        logger.error("Error loading the layer", e);
95
                }
96
                //Closing the window
97 29164 jpiera
                PluginServices.getMDIManager().closeWindow(dataTransformWizard);
98 28893 jpiera
        }
99
100
}