root / branches / v2_0_0_prep / extensions / org.gvsig.daltransform.app.mainplugin / src / main / java / org / gvsig / daltransform / swing / impl / DataTransformSelectionAction.java @ 40354
History | View | Annotate | Download (4.19 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 | 40354 | jldominguez | import javax.swing.JOptionPane; |
31 | |||
32 | 28893 | jpiera | import jwizardcomponent.FinishAction; |
33 | |||
34 | 35605 | nfrancisco | import org.slf4j.Logger; |
35 | import org.slf4j.LoggerFactory; |
||
36 | |||
37 | 29627 | jpiera | import org.gvsig.andami.PluginServices; |
38 | 40354 | jldominguez | import org.gvsig.app.ApplicationLocator; |
39 | 35512 | nfrancisco | import org.gvsig.daltransform.swing.DataTransformGui; |
40 | 28893 | jpiera | import org.gvsig.fmap.dal.exception.DataException; |
41 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
42 | import org.gvsig.fmap.dal.feature.FeatureStoreTransform; |
||
43 | 40354 | jldominguez | import org.gvsig.fmap.mapcontext.MapContext; |
44 | 35605 | nfrancisco | import org.gvsig.fmap.mapcontext.MapContextLocator; |
45 | import org.gvsig.fmap.mapcontext.MapContextManager; |
||
46 | 28893 | jpiera | import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
47 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
48 | 40354 | jldominguez | import org.gvsig.i18n.Messages; |
49 | 28893 | jpiera | |
50 | |||
51 | /**
|
||
52 | * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
||
53 | */
|
||
54 | public class DataTransformSelectionAction extends FinishAction{ |
||
55 | private static final Logger logger = LoggerFactory.getLogger(DataTransformSelectionAction.class); |
||
56 | 29164 | jpiera | private DefaultDataTransformWizard dataTransformWizard = null; |
57 | 28893 | jpiera | |
58 | 29164 | jpiera | public DataTransformSelectionAction(DefaultDataTransformWizard dataTransformWizard) {
|
59 | super(dataTransformWizard.getWizardComponents());
|
||
60 | this.dataTransformWizard = dataTransformWizard;
|
||
61 | 28893 | jpiera | } |
62 | |||
63 | /* (non-Javadoc)
|
||
64 | * @see jwizardcomponent.Action#performAction()
|
||
65 | */
|
||
66 | 39493 | jldominguez | public void performAction() { |
67 | |||
68 | /*
|
||
69 | * For layer attributes table, this depends on the user
|
||
70 | * decision. For tables without layer, for example, this is
|
||
71 | * always false
|
||
72 | */
|
||
73 | boolean result_added_separately = dataTransformWizard.isLayerLoaded();
|
||
74 | 28893 | jpiera | //Gets the selected transformation
|
75 | 29164 | jpiera | DataTransformGui featureTransformGui = dataTransformWizard.getDataTransformGui(); |
76 | 28893 | jpiera | |
77 | //Gets the selected FeatureStore
|
||
78 | 39493 | jldominguez | FeatureStore fsto = dataTransformWizard.getFeatureStore(); |
79 | // FeatureStore cloned_store = null;
|
||
80 | |||
81 | if (result_added_separately) {
|
||
82 | try {
|
||
83 | /*
|
||
84 | * Clone if added separately
|
||
85 | */
|
||
86 | fsto = (FeatureStore) fsto.clone(); |
||
87 | } catch (CloneNotSupportedException e1) { |
||
88 | // FeatureStore always implements the clone method
|
||
89 | } |
||
90 | } |
||
91 | 39411 | jldominguez | |
92 | 29164 | jpiera | try {
|
93 | //Gets the transform
|
||
94 | 39493 | jldominguez | FeatureStoreTransform fst = null;
|
95 | 29164 | jpiera | |
96 | 38382 | jldominguez | // Apply the transformation
|
97 | 39493 | jldominguez | fst = featureTransformGui.createFeatureStoreTransform(fsto); |
98 | fsto.getTransforms().add(fst); |
||
99 | |||
100 | 28893 | jpiera | //Create and load a new layer...
|
101 | 39493 | jldominguez | if (result_added_separately){
|
102 | 35605 | nfrancisco | MapContextManager manager = MapContextLocator.getMapContextManager(); |
103 | 38382 | jldominguez | FLayer layer = manager.createLayer( |
104 | featureTransformGui.toString(), |
||
105 | 39493 | jldominguez | fsto); |
106 | 40354 | jldominguez | |
107 | MapContext mco = dataTransformWizard.getMapContext(); |
||
108 | if (mco != null) { |
||
109 | mco.getLayers().addLayer(layer); |
||
110 | } else {
|
||
111 | ApplicationLocator.getManager().messageDialog( |
||
112 | Messages.getText("_Layer_was_not_added_to_any_view"),
|
||
113 | Messages.getText("transform_apply"),
|
||
114 | JOptionPane.ERROR_MESSAGE);
|
||
115 | } |
||
116 | |||
117 | 34908 | fdiaz | layer.dispose(); |
118 | 28893 | jpiera | } |
119 | } catch (DataException e) {
|
||
120 | logger.error("Error creating the transformation", e);
|
||
121 | } catch (LoadLayerException e) {
|
||
122 | logger.error("Error loading the layer", e);
|
||
123 | } |
||
124 | //Closing the window
|
||
125 | 29164 | jpiera | PluginServices.getMDIManager().closeWindow(dataTransformWizard); |
126 | 28893 | jpiera | } |
127 | |||
128 | } |