Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.daltransform.app.mainplugin / src / main / java / org / gvsig / daltransform / swing / impl / DataTransformSelectionAction.java @ 39493

History | View | Annotate | Download (3.71 KB)

1
/* 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
package org.gvsig.daltransform.swing.impl;
29

    
30
import jwizardcomponent.FinishAction;
31

    
32
import org.slf4j.Logger;
33
import org.slf4j.LoggerFactory;
34

    
35
import org.gvsig.andami.PluginServices;
36
import org.gvsig.daltransform.swing.DataTransformGui;
37
import org.gvsig.fmap.dal.exception.DataException;
38
import org.gvsig.fmap.dal.feature.FeatureStore;
39
import org.gvsig.fmap.dal.feature.FeatureStoreTransform;
40
import org.gvsig.fmap.mapcontext.MapContextLocator;
41
import org.gvsig.fmap.mapcontext.MapContextManager;
42
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
43
import org.gvsig.fmap.mapcontext.layers.FLayer;
44

    
45

    
46
/**
47
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
48
 */
49
public class DataTransformSelectionAction extends FinishAction{
50
        private static final Logger logger = LoggerFactory.getLogger(DataTransformSelectionAction.class);
51
        private DefaultDataTransformWizard dataTransformWizard = null;
52
        
53
        public DataTransformSelectionAction(DefaultDataTransformWizard dataTransformWizard) {
54
                super(dataTransformWizard.getWizardComponents());                
55
                this.dataTransformWizard = dataTransformWizard;
56
        }
57

    
58
        /* (non-Javadoc)
59
         * @see jwizardcomponent.Action#performAction()
60
         */
61
        public void performAction() {        
62
            
63
            /*
64
             * For layer attributes table, this depends on the user
65
             * decision. For tables without layer, for example, this is
66
             * always false
67
             */
68
            boolean result_added_separately = dataTransformWizard.isLayerLoaded();
69
                //Gets the selected transformation
70
                DataTransformGui featureTransformGui = dataTransformWizard.getDataTransformGui();
71
                        
72
                //Gets the selected FeatureStore
73
                FeatureStore fsto = dataTransformWizard.getFeatureStore();
74
                // FeatureStore cloned_store = null;
75
                
76
                if (result_added_separately) {
77
                try {
78
                    /*
79
                     * Clone if added separately
80
                     */
81
                    fsto = (FeatureStore) fsto.clone();
82
                } catch (CloneNotSupportedException e1) {
83
                    // FeatureStore always implements the clone method
84
                }
85
                }
86

    
87
                try {                        
88
                        //Gets the transform
89
                        FeatureStoreTransform fst = null;
90
                        
91
                        // Apply the transformation
92
                        fst = featureTransformGui.createFeatureStoreTransform(fsto);
93
                        fsto.getTransforms().add(fst);
94

    
95
                        //Create and load a new layer...
96
                        if (result_added_separately){
97
                            MapContextManager manager = MapContextLocator.getMapContextManager();
98
                            FLayer layer = manager.createLayer(
99
                                featureTransformGui.toString(),
100
                                fsto);
101
                                dataTransformWizard.getMapContext().getLayers().addLayer(layer);
102
                                layer.dispose();
103
                        }
104
                } catch (DataException e) {
105
                        logger.error("Error creating the transformation", e);
106
                } catch (LoadLayerException e) {
107
                        logger.error("Error loading the layer", e);
108
                }
109
                //Closing the window
110
                PluginServices.getMDIManager().closeWindow(dataTransformWizard);
111
        }
112

    
113
}
114