svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.exportto / org.gvsig.exportto.lib / org.gvsig.exportto.lib.impl / src / main / java / org / gvsig / export / impl / DefaultExportProcess.java @ 44406
History | View | Annotate | Download (8.09 KB)
1 |
package org.gvsig.export.impl; |
---|---|
2 |
|
3 |
import java.util.List; |
4 |
import java.util.Objects; |
5 |
import javax.swing.JOptionPane; |
6 |
import org.cresques.cts.ICoordTrans; |
7 |
import org.cresques.cts.IProjection; |
8 |
import org.gvsig.export.ExportException; |
9 |
import org.gvsig.export.ExportLocator; |
10 |
import org.gvsig.export.ExportParameters; |
11 |
import org.gvsig.export.ExportParametersGeometry; |
12 |
import org.gvsig.export.ExportProcess; |
13 |
import org.gvsig.export.spi.ExportService; |
14 |
import org.gvsig.export.spi.ExportServiceFactory; |
15 |
import org.gvsig.export.spi.ExportServiceManager; |
16 |
import org.gvsig.expressionevaluator.Expression; |
17 |
import org.gvsig.fmap.dal.OpenDataStoreParameters; |
18 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
19 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
20 |
import org.gvsig.tools.ToolsLocator; |
21 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
22 |
import org.gvsig.tools.task.TaskStatus; |
23 |
|
24 |
/**
|
25 |
*
|
26 |
* @author jjdelcerro
|
27 |
*/
|
28 |
public class DefaultExportProcess |
29 |
implements ExportProcess {
|
30 |
|
31 |
private ExportServiceFactory factory;
|
32 |
private ExportService service;
|
33 |
private ExportParameters parameters;
|
34 |
private FeatureStore sourceFeatureStore;
|
35 |
|
36 |
private IProjection contextProjection;
|
37 |
private ICoordTrans sourceTransformation;
|
38 |
private IProjection sourceProjection;
|
39 |
private Object context; |
40 |
private Expression filterExpression; |
41 |
private int featuresToUse; |
42 |
// private AttributeNamesTranslator attributeNamesTranslator;
|
43 |
|
44 |
public DefaultExportProcess() {
|
45 |
|
46 |
} |
47 |
|
48 |
@Override
|
49 |
public void setOutputFormat(String serviceName) throws ExportException { |
50 |
|
51 |
ExportServiceManager serviceManager = ExportLocator.getServiceManager(); |
52 |
this.factory = serviceManager.getServiceFactory(serviceName);
|
53 |
this.parameters = this.factory.createParameters(); |
54 |
this.service = this.factory.createService(this.parameters); |
55 |
this.parameters.setSourceFeatureStore(this.sourceFeatureStore); |
56 |
if (this.parameters instanceof ExportParametersGeometry) { |
57 |
ExportParametersGeometry params = (ExportParametersGeometry) this.parameters;
|
58 |
params.setContextProjection(this.contextProjection);
|
59 |
params.setSourceProjection(this.sourceProjection);
|
60 |
params.setSourceTransformation(this.sourceTransformation);
|
61 |
params.setContext(this.context);
|
62 |
} |
63 |
this.parameters.setFilterExpresion(this.filterExpression); |
64 |
this.parameters.setFeaturesToUse(this.featuresToUse); //valor que use la expression si no es nula |
65 |
|
66 |
} |
67 |
|
68 |
@Override
|
69 |
public void setParameters(ExportParameters params) { |
70 |
this.parameters = params;
|
71 |
this.factory = this.parameters.getFactory(); |
72 |
this.service = this.factory.createService(this.parameters); |
73 |
this.parameters.setSourceFeatureStore(this.sourceFeatureStore); |
74 |
this.parameters.setContext(this.context); |
75 |
|
76 |
this.featuresToUse = this.parameters.getFeaturesToUse(); |
77 |
if (Objects.equals(this.filterExpression, this.parameters.getFilterExpresion())) { |
78 |
int keepFilter = ToolsSwingLocator.getThreadSafeDialogsManager().confirmDialog(
|
79 |
ToolsLocator.getI18nManager().getTranslation("_Do_you_want_to_keep_the_applied_filter_and_not_use_the_one_in_the_parameters"),
|
80 |
ToolsLocator.getI18nManager().getTranslation("_Filter_to_apply"),
|
81 |
JOptionPane.YES_NO_OPTION,
|
82 |
JOptionPane.WARNING_MESSAGE,
|
83 |
"exporto-overwrite-expression-parameters");
|
84 |
if (keepFilter == JOptionPane.YES_OPTION) { |
85 |
this.parameters.setFilterExpresion(this.filterExpression); |
86 |
} else {
|
87 |
this.filterExpression = this.parameters.getFilterExpresion(); |
88 |
} |
89 |
} else {
|
90 |
this.filterExpression = this.parameters.getFilterExpresion(); |
91 |
} |
92 |
|
93 |
if (this.parameters instanceof ExportParametersGeometry) { |
94 |
ExportParametersGeometry pa = (ExportParametersGeometry) this.parameters;
|
95 |
this.contextProjection = pa.getContextProjection();
|
96 |
this.sourceProjection = pa.getSourceProjection();
|
97 |
this.sourceTransformation = pa.getSourceTransformation();
|
98 |
|
99 |
} |
100 |
} |
101 |
|
102 |
@Override
|
103 |
public void setSourceFeatureStore(FeatureStore store |
104 |
) { |
105 |
this.sourceFeatureStore = store;
|
106 |
if (this.parameters != null) { |
107 |
this.parameters.setSourceFeatureStore(sourceFeatureStore);
|
108 |
} |
109 |
} |
110 |
|
111 |
@Override
|
112 |
public void setContextProjection(IProjection projection |
113 |
) { |
114 |
this.contextProjection = projection;
|
115 |
if (this.parameters instanceof ExportParametersGeometry) { |
116 |
((ExportParametersGeometry) this.parameters).setContextProjection(projection);
|
117 |
} |
118 |
} |
119 |
|
120 |
@Override
|
121 |
public void setSourceTransformation(ICoordTrans transformation |
122 |
) { |
123 |
this.sourceTransformation = transformation;
|
124 |
if (this.parameters instanceof ExportParametersGeometry) { |
125 |
((ExportParametersGeometry) this.parameters).setSourceTransformation(transformation);
|
126 |
} |
127 |
} |
128 |
|
129 |
@Override
|
130 |
public void setSourceProjection(IProjection projection |
131 |
) { |
132 |
this.sourceProjection = projection;
|
133 |
if (this.parameters instanceof ExportParametersGeometry) { |
134 |
((ExportParametersGeometry) this.parameters).setSourceProjection(projection);
|
135 |
} |
136 |
} |
137 |
|
138 |
@Override
|
139 |
public Object getContext() { |
140 |
return context;
|
141 |
} |
142 |
|
143 |
@Override
|
144 |
public void setContext(Object context |
145 |
) { |
146 |
this.context = context;
|
147 |
if (this.parameters != null) { |
148 |
this.parameters.setContext(context);
|
149 |
} |
150 |
} |
151 |
|
152 |
@Override
|
153 |
public ExportParameters getParameters() {
|
154 |
return this.parameters; |
155 |
} |
156 |
|
157 |
@Override
|
158 |
public TaskStatus getTaskStatus() {
|
159 |
if (this.service == null) { |
160 |
throw new IllegalStateException("Can't access task status at this moment, need setting output format."); |
161 |
} |
162 |
return this.service.getTaskStatus(); |
163 |
} |
164 |
|
165 |
@Override
|
166 |
public void run() { |
167 |
if (this.factory == null) { |
168 |
throw new IllegalStateException("Can't start export process, need setting output format."); |
169 |
} |
170 |
if (this.parameters == null) { |
171 |
throw new IllegalStateException("Can't start export process, need setting parameters."); |
172 |
} |
173 |
try {
|
174 |
FeatureSet featureSet; |
175 |
switch (this.parameters.getFeaturesToUse()) { |
176 |
case ExportParameters.USE_ALL_FEATURES:
|
177 |
default:
|
178 |
featureSet = this.parameters.getSourceFeatureStore().getFeatureSet();
|
179 |
break;
|
180 |
case ExportParameters.USE_SELECTED_FEATURES:
|
181 |
featureSet = this.parameters.getSourceFeatureStore().getFeatureSelection();
|
182 |
break;
|
183 |
case ExportParameters.USE_FILTERED_FEATURES:
|
184 |
featureSet = this.parameters.getSourceFeatureStore().getFeatureSet(this.parameters.getFilterExpresion()); |
185 |
break;
|
186 |
} |
187 |
this.service.export(featureSet);
|
188 |
} catch (Exception ex) { |
189 |
throw new RuntimeException(ex); |
190 |
} |
191 |
} |
192 |
|
193 |
@Override
|
194 |
public List<OpenDataStoreParameters> getTargetOpenStoreParameters() { |
195 |
if (this.service == null) { |
196 |
return null; |
197 |
} |
198 |
try {
|
199 |
return this.service.getTargetOpenStoreParameters(); |
200 |
} catch (ExportException ex) { |
201 |
throw new RuntimeException("Can't create target open store parameters.", ex); |
202 |
} |
203 |
} |
204 |
|
205 |
@Override
|
206 |
public void setFilterExpression(Expression expression |
207 |
) { |
208 |
this.filterExpression = expression;
|
209 |
if (this.parameters != null) { |
210 |
this.parameters.setFilterExpresion(expression);
|
211 |
} |
212 |
if (expression == null) { |
213 |
this.setFeaturesToUse(ExportParameters.USE_ALL_FEATURES);
|
214 |
} else {
|
215 |
this.setFeaturesToUse(ExportParameters.USE_FILTERED_FEATURES);
|
216 |
} |
217 |
} |
218 |
|
219 |
@Override
|
220 |
public void setFeaturesToUse(int featuresToUse |
221 |
) { |
222 |
this.featuresToUse = featuresToUse;
|
223 |
if (this.parameters != null) { |
224 |
this.parameters.setFeaturesToUse(featuresToUse);
|
225 |
} |
226 |
} |
227 |
|
228 |
} |