Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.daltransform.app / org.gvsig.daltransform.app.mainplugin / src / main / java / org / gvsig / daltransform / swing / impl / DataTransformSelectionAction.java @ 40558

History | View | Annotate | Download (5.13 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/* gvSIG. Geographic Information System of the Valencian Government
25
*
26
* Copyright (C) 2007-2008 Infrastructures and Transports Department
27
* of the Valencian Government (CIT)
28
* 
29
* This program is free software; you can redistribute it and/or
30
* modify it under the terms of the GNU General Public License
31
* as published by the Free Software Foundation; either version 2
32
* of the License, or (at your option) any later version.
33
* 
34
* This program is distributed in the hope that it will be useful,
35
* but WITHOUT ANY WARRANTY; without even the implied warranty of
36
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37
* GNU General Public License for more details.
38
* 
39
* You should have received a copy of the GNU General Public License
40
* along with this program; if not, write to the Free Software
41
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
42
* MA  02110-1301, USA.
43
* 
44
*/
45

    
46
/*
47
* AUTHORS (In addition to CIT):
48
* 2009 {Iver T.I.}   {Task}
49
*/
50
 
51
package org.gvsig.daltransform.swing.impl;
52

    
53
import javax.swing.JOptionPane;
54

    
55
import jwizardcomponent.FinishAction;
56

    
57
import org.slf4j.Logger;
58
import org.slf4j.LoggerFactory;
59

    
60
import org.gvsig.andami.PluginServices;
61
import org.gvsig.app.ApplicationLocator;
62
import org.gvsig.daltransform.swing.DataTransformGui;
63
import org.gvsig.fmap.dal.exception.DataException;
64
import org.gvsig.fmap.dal.feature.FeatureStore;
65
import org.gvsig.fmap.dal.feature.FeatureStoreTransform;
66
import org.gvsig.fmap.mapcontext.MapContext;
67
import org.gvsig.fmap.mapcontext.MapContextLocator;
68
import org.gvsig.fmap.mapcontext.MapContextManager;
69
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
70
import org.gvsig.fmap.mapcontext.layers.FLayer;
71
import org.gvsig.i18n.Messages;
72

    
73

    
74
/**
75
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
76
 */
77
public class DataTransformSelectionAction extends FinishAction{
78
        private static final Logger logger = LoggerFactory.getLogger(DataTransformSelectionAction.class);
79
        private DefaultDataTransformWizard dataTransformWizard = null;
80
        
81
        public DataTransformSelectionAction(DefaultDataTransformWizard dataTransformWizard) {
82
                super(dataTransformWizard.getWizardComponents());                
83
                this.dataTransformWizard = dataTransformWizard;
84
        }
85

    
86
        /* (non-Javadoc)
87
         * @see jwizardcomponent.Action#performAction()
88
         */
89
        public void performAction() {        
90
            
91
            /*
92
             * For layer attributes table, this depends on the user
93
             * decision. For tables without layer, for example, this is
94
             * always false
95
             */
96
            boolean result_added_separately = dataTransformWizard.isLayerLoaded();
97
                //Gets the selected transformation
98
                DataTransformGui featureTransformGui = dataTransformWizard.getDataTransformGui();
99
                        
100
                //Gets the selected FeatureStore
101
                FeatureStore fsto = dataTransformWizard.getFeatureStore();
102
                // FeatureStore cloned_store = null;
103
                
104
                if (result_added_separately) {
105
                try {
106
                    /*
107
                     * Clone if added separately
108
                     */
109
                    fsto = (FeatureStore) fsto.clone();
110
                } catch (CloneNotSupportedException e1) {
111
                    // FeatureStore always implements the clone method
112
                }
113
                }
114

    
115
                try {                        
116
                        //Gets the transform
117
                        FeatureStoreTransform fst = null;
118
                        
119
                        // Apply the transformation
120
                        fst = featureTransformGui.createFeatureStoreTransform(fsto);
121
                        fsto.getTransforms().add(fst);
122

    
123
                        //Create and load a new layer...
124
                        if (result_added_separately){
125
                            MapContextManager manager = MapContextLocator.getMapContextManager();
126
                            FLayer layer = manager.createLayer(
127
                                featureTransformGui.toString(),
128
                                fsto);
129
                            
130
                            MapContext mco = dataTransformWizard.getMapContext();
131
                            if (mco != null) {
132
                                mco.getLayers().addLayer(layer);
133
                            } else {
134
                                ApplicationLocator.getManager().messageDialog(
135
                        Messages.getText("_Layer_was_not_added_to_any_view"),
136
                        Messages.getText("transform_apply"),
137
                                    JOptionPane.ERROR_MESSAGE);
138
                            }
139
                                
140
                                layer.dispose();
141
                        }
142
                } catch (DataException e) {
143
                        logger.error("Error creating the transformation", e);
144
                } catch (LoadLayerException e) {
145
                        logger.error("Error loading the layer", e);
146
                }
147
                //Closing the window
148
                PluginServices.getMDIManager().closeWindow(dataTransformWizard);
149
        }
150

    
151
}
152