svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.exportto / org.gvsig.exportto.swing / org.gvsig.exportto.swing.impl / src / main / java / org / gvsig / exportto / swing / impl / DefaultJExporttoServicePanel.java @ 42676
History | View | Annotate | Download (12.4 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 |
package org.gvsig.exportto.swing.impl; |
25 |
|
26 |
import java.awt.BorderLayout; |
27 |
import java.awt.Dimension; |
28 |
|
29 |
import javax.swing.ImageIcon; |
30 |
import javax.swing.JOptionPane; |
31 |
|
32 |
import jwizardcomponent.DefaultJWizardComponents; |
33 |
|
34 |
import org.cresques.cts.IProjection; |
35 |
import org.slf4j.Logger; |
36 |
import org.slf4j.LoggerFactory; |
37 |
|
38 |
import org.gvsig.exportto.ExporttoService; |
39 |
import org.gvsig.exportto.ExporttoServiceException; |
40 |
import org.gvsig.exportto.ExporttoServiceFinishAction; |
41 |
import org.gvsig.exportto.swing.JExporttoServicePanel; |
42 |
import org.gvsig.exportto.swing.JExporttoServicePanelListener; |
43 |
import org.gvsig.exportto.swing.impl.panel.MessagePanel; |
44 |
import org.gvsig.exportto.swing.impl.wizard.DefaultWizardContainer; |
45 |
import org.gvsig.exportto.swing.impl.wizard.ExportFilterWizard; |
46 |
import org.gvsig.exportto.swing.impl.wizard.ExportTargetProjectionWizard; |
47 |
import org.gvsig.exportto.swing.impl.wizard.ExporterSelectionWizard; |
48 |
import org.gvsig.exportto.swing.impl.wizard.ExporttoProgressWizard; |
49 |
import org.gvsig.exportto.swing.spi.ExporttoSwingProvider; |
50 |
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderFactory; |
51 |
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderLocator; |
52 |
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderManager; |
53 |
import org.gvsig.fmap.dal.DALLocator; |
54 |
import org.gvsig.fmap.dal.DataManager; |
55 |
import org.gvsig.fmap.dal.exception.DataException; |
56 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
57 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
58 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
59 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
60 |
import org.gvsig.gui.beans.wizard.WizardPanel; |
61 |
import org.gvsig.gui.beans.wizard.WizardPanelActionListener; |
62 |
import org.gvsig.gui.beans.wizard.WizardPanelWithLogo; |
63 |
import org.gvsig.tools.ToolsLocator; |
64 |
import org.gvsig.tools.evaluator.Evaluator; |
65 |
import org.gvsig.tools.i18n.I18nManager; |
66 |
import org.gvsig.tools.service.ServiceException; |
67 |
import org.gvsig.tools.task.SimpleTaskStatus; |
68 |
|
69 |
/**
|
70 |
* Default implementation for the {@link JExporttoServicePanel}.
|
71 |
*
|
72 |
* @author gvSIG Team
|
73 |
* @version $Id$
|
74 |
*/
|
75 |
public class DefaultJExporttoServicePanel extends JExporttoServicePanel |
76 |
implements WizardPanel {
|
77 |
|
78 |
private static final Logger LOG = LoggerFactory |
79 |
.getLogger(DefaultJExporttoServicePanel.class); |
80 |
|
81 |
private static final ExporttoSwingProviderManager EXPORTTO_SWING_PROVIDER_MANAGER = |
82 |
ExporttoSwingProviderLocator.getManager(); |
83 |
private static final DataManager DATA_MANAGER = DALLocator.getDataManager(); |
84 |
|
85 |
private static final long serialVersionUID = -7026467582252285238L; |
86 |
|
87 |
private FeatureStore featureStore;
|
88 |
private IProjection projection;
|
89 |
private FLyrVect vectorLayer = null; |
90 |
private DefaultExporttoSwingManager uimanager;
|
91 |
|
92 |
// Used to get the new feature store parameters
|
93 |
private ExporttoSwingProvider exporttoSwingProvider;
|
94 |
|
95 |
// Provider types that will be displayed
|
96 |
private int[] providerTypes; |
97 |
|
98 |
// Wizards used to create the main wizard
|
99 |
private ExporterSelectionWizard exporterSelectionWizard = null; |
100 |
private ExportFilterWizard exportFilterWizard = null; |
101 |
private ExportTargetProjectionWizard exportTargetProjectionWizard = null; |
102 |
private ExporttoProgressWizard exporttoProgressWizard = null; |
103 |
|
104 |
// Listener for the finish and cancell button
|
105 |
private WizardPanelActionListener exporttoServicePanelListener;
|
106 |
|
107 |
private WizardPanelWithLogo wizardPanelWithLogo = null; |
108 |
|
109 |
// Action to execute at the end of the export process
|
110 |
ExporttoServiceFinishAction exporttoServiceFinishAction; |
111 |
|
112 |
private int status; |
113 |
|
114 |
public DefaultJExporttoServicePanel(DefaultExporttoSwingManager uimanager,
|
115 |
FLyrVect vlayer, |
116 |
ExporttoServiceFinishAction exporttoServiceFinishAction, |
117 |
int[] providerTypes) { |
118 |
|
119 |
this(
|
120 |
uimanager, |
121 |
vlayer.getFeatureStore(), |
122 |
vlayer.getProjection(), |
123 |
exporttoServiceFinishAction, |
124 |
providerTypes); |
125 |
vectorLayer = vlayer; |
126 |
} |
127 |
|
128 |
public DefaultJExporttoServicePanel(DefaultExporttoSwingManager uimanager,
|
129 |
FeatureStore featureStore, IProjection projection, |
130 |
ExporttoServiceFinishAction exporttoServiceFinishAction, |
131 |
int[] providerTypes) { |
132 |
this.featureStore = featureStore;
|
133 |
this.projection = projection;
|
134 |
this.uimanager = uimanager;
|
135 |
this.exporttoServiceFinishAction = exporttoServiceFinishAction;
|
136 |
this.providerTypes = providerTypes;
|
137 |
this.status = JOptionPane.UNDEFINED_CONDITION; |
138 |
|
139 |
ImageIcon ii = IconThemeHelper.getImageIcon("wizard-export-to"); |
140 |
wizardPanelWithLogo = new WizardPanelWithLogo(ii);
|
141 |
|
142 |
// Initialize the wizards
|
143 |
exporterSelectionWizard = |
144 |
new ExporterSelectionWizard(this, providerTypes); |
145 |
exportTargetProjectionWizard = new ExportTargetProjectionWizard(this); |
146 |
exportFilterWizard = new ExportFilterWizard(this); |
147 |
exporttoProgressWizard = new ExporttoProgressWizard(this); |
148 |
|
149 |
// Adding the wizards to the main wizard
|
150 |
wizardPanelWithLogo.addOptionPanel(exporterSelectionWizard); |
151 |
|
152 |
// The finish button is called "export"
|
153 |
this.wizardPanelWithLogo.getWizardComponents().getFinishButton()
|
154 |
.setText(uimanager.getTranslation("export"));
|
155 |
|
156 |
this.setLayout(new BorderLayout()); |
157 |
this.add(wizardPanelWithLogo, BorderLayout.CENTER); |
158 |
|
159 |
// Disable the nextbutton
|
160 |
setNextButtonEnabled(false);
|
161 |
setExportButtonEnabled(false);
|
162 |
|
163 |
// Set the listener for the finish and cancell events
|
164 |
this.wizardPanelWithLogo.setWizardListener(this); |
165 |
this.setPreferredSize(new Dimension(700, 350)); |
166 |
} |
167 |
|
168 |
public FeatureStore getFeatureStore() {
|
169 |
return this.featureStore; |
170 |
} |
171 |
|
172 |
public void setNextButtonEnabled(boolean isEnabled) { |
173 |
wizardPanelWithLogo.setNextButtonEnabled(isEnabled); |
174 |
} |
175 |
|
176 |
public void setExportButtonEnabled(boolean isEnabled) { |
177 |
wizardPanelWithLogo.setFinishButtonEnabled(isEnabled); |
178 |
} |
179 |
|
180 |
public void setCancelButtonText(String text) { |
181 |
wizardPanelWithLogo.getWizardComponents().getCancelButton() |
182 |
.setText(text); |
183 |
} |
184 |
|
185 |
/**
|
186 |
* @return the uimanager
|
187 |
*/
|
188 |
public DefaultExporttoSwingManager getExporttoSwingManager() {
|
189 |
return uimanager;
|
190 |
} |
191 |
|
192 |
/**
|
193 |
* @param exporttoSwingProvider
|
194 |
* @throws ServiceException
|
195 |
*/
|
196 |
public void selectExporttoSwingProvider( |
197 |
ExporttoSwingProviderFactory provider) |
198 |
throws ServiceException {
|
199 |
|
200 |
if (vectorLayer == null) { |
201 |
exporttoSwingProvider = |
202 |
EXPORTTO_SWING_PROVIDER_MANAGER.createExporttoSwingProvider( |
203 |
provider.getName(), featureStore, projection); |
204 |
} else {
|
205 |
exporttoSwingProvider = |
206 |
EXPORTTO_SWING_PROVIDER_MANAGER.createExporttoSwingProvider( |
207 |
provider.getName(), vectorLayer); |
208 |
} |
209 |
|
210 |
DefaultJWizardComponents wizardComponents = |
211 |
wizardPanelWithLogo.getWizardComponents(); |
212 |
for (int i = wizardComponents.getWizardPanelList().size() - 1; i >= 1; i--) { |
213 |
wizardComponents.removeWizardPanel(i); |
214 |
} |
215 |
for (int i = 0; i < exporttoSwingProvider.getPanelCount(); i++) { |
216 |
wizardPanelWithLogo.addOptionPanel(new DefaultWizardContainer(
|
217 |
exporttoSwingProvider.getPanelAt(i))); |
218 |
} |
219 |
exportTargetProjectionWizard.setVectorLayer(vectorLayer); |
220 |
if (exporttoSwingProvider.needsPanelTargetProjection()){
|
221 |
wizardPanelWithLogo.addOptionPanel(exportTargetProjectionWizard); |
222 |
} |
223 |
wizardPanelWithLogo.addOptionPanel(exportFilterWizard); |
224 |
wizardPanelWithLogo.addOptionPanel(exporttoProgressWizard); |
225 |
} |
226 |
|
227 |
public Dimension getPreferredSize() { |
228 |
return new Dimension(800, 550); |
229 |
} |
230 |
|
231 |
public void export() throws DataException, ExporttoServiceException { |
232 |
this.lastWizard();
|
233 |
|
234 |
// Create the feature Set...
|
235 |
FeatureSet featureSet = null;
|
236 |
if ( exportFilterWizard.isFullLayerSelected() ) {
|
237 |
featureSet = featureStore.getFeatureSet(); |
238 |
|
239 |
} else if ( exportFilterWizard.isSelectedFeaturesSelected() ) { |
240 |
featureSet = (FeatureSet) featureStore.getSelection(); |
241 |
|
242 |
} else {
|
243 |
Evaluator filter = exportFilterWizard.getFilter(); |
244 |
if( filter!=null ) { |
245 |
FeatureQuery featureQuery = featureStore.createFeatureQuery(); |
246 |
featureQuery.setFilter(filter); |
247 |
featureSet = featureStore.getFeatureSet(featureQuery); |
248 |
} |
249 |
} |
250 |
if( exporttoSwingProvider.needsPanelTargetProjection()) {
|
251 |
exporttoSwingProvider.setTargetProjection(exportTargetProjectionWizard.getTargetProjection()); |
252 |
} |
253 |
|
254 |
Export export = new Export(featureSet); |
255 |
export.start();
|
256 |
} |
257 |
|
258 |
public void lastWizard() { |
259 |
this.wizardPanelWithLogo.getWizardComponents().getNextButton()
|
260 |
.getActionListeners()[0].actionPerformed(null); |
261 |
} |
262 |
|
263 |
private class Export extends Thread { |
264 |
|
265 |
private FeatureSet featureSet;
|
266 |
|
267 |
public Export(FeatureSet featureSet) {
|
268 |
super();
|
269 |
this.featureSet = featureSet;
|
270 |
} |
271 |
|
272 |
public synchronized void run() { |
273 |
ExporttoService exportService = |
274 |
exporttoSwingProvider.createExporttoService(); |
275 |
exporttoProgressWizard.bind(exportService.getTaskStatus()); |
276 |
exportService.setFinishAction(exporttoServiceFinishAction); |
277 |
String layerName = "(unknow)"; |
278 |
String layerFullName = "(unknow)"; |
279 |
try {
|
280 |
layerName = featureStore.getName(); |
281 |
layerFullName = featureStore.getFullName(); |
282 |
LOG.info("Exporting '"+layerName+"' using '"+exportService.getClass().getName()+"' ("+layerFullName+")."); |
283 |
((SimpleTaskStatus)(exportService.getTaskStatus())).setTitle("Exporting "+layerName+"..."); |
284 |
exportService.export(featureSet); |
285 |
} catch (ExporttoServiceException e) {
|
286 |
LOG.warn("Problems exporting the data (layer="+layerName+").", e); |
287 |
showError(e); |
288 |
} finally {
|
289 |
((SimpleTaskStatus)(exportService.getTaskStatus())).terminate(); |
290 |
} |
291 |
} |
292 |
} |
293 |
|
294 |
private void showError(ExporttoServiceException e) { |
295 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
296 |
MessagePanel.showMessage( |
297 |
i18nManager.getTranslation("_Warning"),
|
298 |
i18nManager.getTranslation("_There_have_been_problems_exporting_data"),
|
299 |
e, |
300 |
e.getFeature() |
301 |
); |
302 |
} |
303 |
|
304 |
public void setWizardPanelActionListener( |
305 |
WizardPanelActionListener wizardActionListener) { |
306 |
this.exporttoServicePanelListener = wizardActionListener;
|
307 |
} |
308 |
|
309 |
public WizardPanelActionListener getWizardPanelActionListener() {
|
310 |
if (exporttoServicePanelListener == null) { |
311 |
exporttoServicePanelListener = |
312 |
new DefaultJExporttoServicePanelListener(this); |
313 |
} |
314 |
return exporttoServicePanelListener;
|
315 |
} |
316 |
|
317 |
@Override
|
318 |
public void setExporttoServicePanelListener( |
319 |
JExporttoServicePanelListener exporttoServicePanelListener) { |
320 |
((DefaultJExporttoServicePanelListener) getWizardPanelActionListener()) |
321 |
.setExporttoServicePanelListener(exporttoServicePanelListener); |
322 |
} |
323 |
|
324 |
@Override
|
325 |
public int getStatus() { |
326 |
return this.status; |
327 |
} |
328 |
|
329 |
public void setStatus(int status) { |
330 |
this.status = status;
|
331 |
if( this.status == JOptionPane.CANCEL_OPTION ) { |
332 |
this.setVisible(false); |
333 |
} |
334 |
} |
335 |
} |