Revision 47557 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
DataTransformSelectionAction.java | ||
---|---|---|
51 | 51 |
package org.gvsig.daltransform.swing.impl; |
52 | 52 |
|
53 | 53 |
import javax.swing.JOptionPane; |
54 |
|
|
55 | 54 |
import jwizardcomponent.FinishAction; |
56 |
|
|
57 |
import org.slf4j.Logger; |
|
58 |
import org.slf4j.LoggerFactory; |
|
59 |
|
|
60 | 55 |
import org.gvsig.andami.PluginServices; |
61 | 56 |
import org.gvsig.app.ApplicationLocator; |
57 |
import org.gvsig.app.project.ProjectManager; |
|
58 |
import org.gvsig.app.project.documents.table.TableDocument; |
|
59 |
import org.gvsig.app.project.documents.table.TableManager; |
|
62 | 60 |
import org.gvsig.daltransform.swing.DataTransformGui; |
63 |
import org.gvsig.fmap.dal.exception.DataException; |
|
64 | 61 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
65 | 62 |
import org.gvsig.fmap.dal.feature.FeatureStoreTransform; |
66 | 63 |
import org.gvsig.fmap.mapcontext.MapContext; |
67 | 64 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
68 | 65 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
69 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
|
|
66 |
import org.gvsig.fmap.mapcontext.layers.CancelationException;
|
|
70 | 67 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
68 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
|
69 |
import org.gvsig.fmap.mapcontext.layers.LayerCollectionAdapter; |
|
70 |
import org.gvsig.fmap.mapcontext.layers.LayerCollectionEvent; |
|
71 |
import org.gvsig.fmap.mapcontext.layers.LayerCollectionListener; |
|
72 |
import org.gvsig.fmap.mapcontext.layers.LayerPositionEvent; |
|
73 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
74 |
import org.gvsig.fmap.mapcontext.layers.vectorial.VectorLayer; |
|
71 | 75 |
import org.gvsig.i18n.Messages; |
76 |
import org.slf4j.Logger; |
|
77 |
import org.slf4j.LoggerFactory; |
|
72 | 78 |
|
73 | 79 |
|
74 | 80 |
/** |
... | ... | |
83 | 89 |
this.dataTransformWizard = dataTransformWizard; |
84 | 90 |
} |
85 | 91 |
|
86 |
/* (non-Javadoc)
|
|
92 |
/* (non-Javadoc)
|
|
87 | 93 |
* @see jwizardcomponent.Action#performAction() |
88 |
*/ |
|
89 |
public void performAction() { |
|
90 |
|
|
91 |
/* |
|
94 |
*/ |
|
95 |
@Override |
|
96 |
public void performAction() { |
|
97 |
|
|
98 |
/* |
|
92 | 99 |
* For layer attributes table, this depends on the user |
93 | 100 |
* decision. For tables without layer, for example, this is |
94 | 101 |
* 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 |
} |
|
102 |
*/ |
|
103 |
boolean result_added_separately = dataTransformWizard.isLayerLoaded(); |
|
104 |
//Gets the selected transformation |
|
105 |
DataTransformGui featureTransformGui = dataTransformWizard.getDataTransformGui(); |
|
114 | 106 |
|
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); |
|
107 |
//Gets the selected FeatureStore |
|
108 |
FeatureStore fsto = dataTransformWizard.getFeatureStore(); |
|
109 |
// FeatureStore cloned_store = null; |
|
122 | 110 |
|
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 |
} |
|
111 |
// if (result_added_separately) { |
|
112 |
// try { |
|
113 |
// /* |
|
114 |
// * Clone if added separately |
|
115 |
// */ |
|
116 |
// fsto = (FeatureStore) fsto.clone(); |
|
117 |
// } catch (CloneNotSupportedException e1) { |
|
118 |
// // FeatureStore always implements the clone method |
|
119 |
// } |
|
120 |
// } |
|
121 |
try { |
|
122 |
//Gets the transform |
|
123 |
FeatureStoreTransform fst = null; |
|
150 | 124 |
|
125 |
// Apply the transformation |
|
126 |
fst = featureTransformGui.createFeatureStoreTransform(fsto); |
|
127 |
fsto.getTransforms().add(fst); |
|
128 |
|
|
129 |
//Create and load a new layer... |
|
130 |
if (result_added_separately) { |
|
131 |
MapContextManager manager = MapContextLocator.getMapContextManager(); |
|
132 |
VectorLayer layer = (VectorLayer) manager.createLayer( |
|
133 |
featureTransformGui.toString(), |
|
134 |
fsto); |
|
135 |
|
|
136 |
MapContext mco = dataTransformWizard.getMapContext(); |
|
137 |
if (mco != null) { |
|
138 |
mco.getLayers().addLayer(layer); |
|
139 |
} else { |
|
140 |
ApplicationLocator.getManager().messageDialog( |
|
141 |
Messages.getText("_Layer_was_not_added_to_any_view"), |
|
142 |
Messages.getText("transform_apply"), |
|
143 |
JOptionPane.ERROR_MESSAGE); |
|
144 |
} |
|
145 |
ProjectManager projectManager = ApplicationLocator.getProjectManager(); |
|
146 |
final TableManager tableManager = (TableManager) projectManager.getDocumentManager(TableManager.TYPENAME); |
|
147 |
TableDocument tableDoc = tableManager.getTableDocument(layer); |
|
148 |
if (tableDoc == null) { |
|
149 |
tableDoc = tableManager.getTableDocument(layer.getFeatureStore()); |
|
150 |
if (tableDoc == null) { |
|
151 |
tableDoc = (TableDocument) tableManager.createDocument(); |
|
152 |
tableDoc.setName(layer.getName()); |
|
153 |
tableDoc.setStore(layer.getFeatureStore()); |
|
154 |
layer.getParentLayer().addLayerCollectionListener(new LayerCollectionAdapter() { |
|
155 |
@Override |
|
156 |
public void layerRemoved(LayerCollectionEvent e) { |
|
157 |
FLayer affectedLayer = e.getAffectedLayer(); |
|
158 |
if (layer == affectedLayer) { |
|
159 |
// Just in case we where listening to a group of layers being removed |
|
160 |
// remove us from there |
|
161 |
// if (layer instanceof FLayers) { |
|
162 |
// ((FLayers) layer).removeLayerCollectionListener(this); |
|
163 |
// } |
|
164 |
// Remove the related table document, if any |
|
165 |
if (layer instanceof FLyrVect) { |
|
166 |
TableDocument tableDoc = tableManager.getTableDocument(layer); |
|
167 |
tableDoc.setAssociatedLayer(null); |
|
168 |
// If the parent layers has not other child layers, for sure there |
|
169 |
// are not related tables opened, don't need to listen |
|
170 |
// LayerCollectionEvents anymore. |
|
171 |
// TODO: remove us also when there are not any child layers with |
|
172 |
// related table documents |
|
173 |
FLayers layers = layer.getParentLayer(); |
|
174 |
if (layers != null && layers.getLayersCount() == 0) { |
|
175 |
layers.removeLayerCollectionListener(this); |
|
176 |
} |
|
177 |
} |
|
178 |
} |
|
179 |
} |
|
180 |
}); |
|
181 |
projectManager.getCurrentProject().addDocument(tableDoc); |
|
182 |
} |
|
183 |
} |
|
184 |
tableDoc.setAssociatedLayer(layer); |
|
185 |
|
|
186 |
layer.dispose(); |
|
187 |
} |
|
188 |
} catch (Exception e) { |
|
189 |
logger.error("Error loading the layer", e); |
|
190 |
} |
|
191 |
//Closing the window |
|
192 |
PluginServices.getMDIManager().closeWindow(dataTransformWizard); |
|
193 |
} |
|
194 |
|
|
151 | 195 |
} |
152 | 196 |
|
Also available in: Unified diff