root / branches / v2_0_0_prep / libraries / org.gvsig.exportto / org.gvsig.exportto.swing / org.gvsig.exportto.swing.impl / src / main / java / org / gvsig / exportto / swing / impl / DefaultJExporttoServicePanel.java @ 38609
History | View | Annotate | Download (9.96 KB)
1 |
/* 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 |
package org.gvsig.exportto.swing.impl; |
23 |
|
24 |
import java.awt.BorderLayout; |
25 |
import java.net.URL; |
26 |
|
27 |
import javax.swing.ImageIcon; |
28 |
import javax.swing.JOptionPane; |
29 |
|
30 |
import jwizardcomponent.DefaultJWizardComponents; |
31 |
|
32 |
import org.cresques.cts.IProjection; |
33 |
import org.slf4j.Logger; |
34 |
import org.slf4j.LoggerFactory; |
35 |
|
36 |
import org.gvsig.exportto.ExporttoService; |
37 |
import org.gvsig.exportto.ExporttoServiceException; |
38 |
import org.gvsig.exportto.ExporttoServiceFinishAction; |
39 |
import org.gvsig.exportto.swing.JExporttoServicePanel; |
40 |
import org.gvsig.exportto.swing.JExporttoServicePanelListener; |
41 |
import org.gvsig.exportto.swing.impl.wizard.DefaultWizardContainer; |
42 |
import org.gvsig.exportto.swing.impl.wizard.ExportFilterWizard; |
43 |
import org.gvsig.exportto.swing.impl.wizard.ExporterSelectionWizard; |
44 |
import org.gvsig.exportto.swing.impl.wizard.ExporttoProgressWizard; |
45 |
import org.gvsig.exportto.swing.spi.ExporttoSwingProvider; |
46 |
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderFactory; |
47 |
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderLocator; |
48 |
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderManager; |
49 |
import org.gvsig.fmap.dal.DALLocator; |
50 |
import org.gvsig.fmap.dal.DataManager; |
51 |
import org.gvsig.fmap.dal.exception.DataException; |
52 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
53 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
54 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
55 |
import org.gvsig.gui.beans.wizard.WizardPanel; |
56 |
import org.gvsig.gui.beans.wizard.WizardPanelActionListener; |
57 |
import org.gvsig.gui.beans.wizard.WizardPanelWithLogo; |
58 |
import org.gvsig.tools.evaluator.Evaluator; |
59 |
import org.gvsig.tools.service.ServiceException; |
60 |
import org.gvsig.tools.task.TaskStatus; |
61 |
|
62 |
/**
|
63 |
* Default implementation for the {@link JExporttoServicePanel}.
|
64 |
*
|
65 |
* @author gvSIG Team
|
66 |
* @version $Id$
|
67 |
*/
|
68 |
public class DefaultJExporttoServicePanel extends JExporttoServicePanel |
69 |
implements WizardPanel {
|
70 |
|
71 |
private static final Logger LOG = LoggerFactory |
72 |
.getLogger(DefaultJExporttoServicePanel.class); |
73 |
|
74 |
private static final ExporttoSwingProviderManager EXPORTTO_SWING_PROVIDER_MANAGER = |
75 |
ExporttoSwingProviderLocator.getManager(); |
76 |
private static final DataManager DATA_MANAGER = DALLocator.getDataManager(); |
77 |
|
78 |
private static final long serialVersionUID = -7026467582252285238L; |
79 |
|
80 |
private FeatureStore featureStore;
|
81 |
private IProjection projection;
|
82 |
private DefaultExporttoSwingManager uimanager;
|
83 |
|
84 |
// Used to get the new feature store parameters
|
85 |
private ExporttoSwingProvider exporttoSwingProvider;
|
86 |
|
87 |
// Provider types that will be displayed
|
88 |
private int[] providerTypes; |
89 |
|
90 |
// Wizards used to create the main wizard
|
91 |
private ExporterSelectionWizard exporterSelectionWizard = null; |
92 |
private ExportFilterWizard exportFilterWizard = null; |
93 |
private ExporttoProgressWizard exporttoProgressWizard = null; |
94 |
|
95 |
// Listener for the finish and cancell button
|
96 |
private WizardPanelActionListener exporttoServicePanelListener;
|
97 |
|
98 |
private WizardPanelWithLogo wizardPanelWithLogo = null; |
99 |
|
100 |
// Action to execute at the end of the export process
|
101 |
ExporttoServiceFinishAction exporttoServiceFinishAction; |
102 |
|
103 |
private int status; |
104 |
|
105 |
public DefaultJExporttoServicePanel(DefaultExporttoSwingManager uimanager,
|
106 |
FeatureStore featureStore, IProjection projection, |
107 |
ExporttoServiceFinishAction exporttoServiceFinishAction, |
108 |
int[] providerTypes) { |
109 |
this.featureStore = featureStore;
|
110 |
this.projection = projection;
|
111 |
this.uimanager = uimanager;
|
112 |
this.exporttoServiceFinishAction = exporttoServiceFinishAction;
|
113 |
this.providerTypes = providerTypes;
|
114 |
this.status = JOptionPane.UNDEFINED_CONDITION; |
115 |
|
116 |
wizardPanelWithLogo = new WizardPanelWithLogo(IconThemeHelper.getImageIcon("wizard-export-to")); |
117 |
|
118 |
// Initialize the wizards
|
119 |
exporterSelectionWizard = |
120 |
new ExporterSelectionWizard(this, providerTypes); |
121 |
exportFilterWizard = new ExportFilterWizard(this); |
122 |
exporttoProgressWizard = new ExporttoProgressWizard(this); |
123 |
|
124 |
// Adding the wizards to the main wizard
|
125 |
wizardPanelWithLogo.addOptionPanel(exporterSelectionWizard); |
126 |
|
127 |
// The finish button is called "export"
|
128 |
this.wizardPanelWithLogo.getWizardComponents().getFinishButton()
|
129 |
.setText(uimanager.getTranslation("export"));
|
130 |
|
131 |
this.setLayout(new BorderLayout()); |
132 |
this.add(wizardPanelWithLogo, BorderLayout.CENTER); |
133 |
|
134 |
// Disable the nextbutton
|
135 |
setNextButtonEnabled(false);
|
136 |
setExportButtonEnabled(false);
|
137 |
|
138 |
// Set the listener for the finish and cancell events
|
139 |
this.wizardPanelWithLogo.setWizardListener(this); |
140 |
} |
141 |
|
142 |
public void setNextButtonEnabled(boolean isEnabled) { |
143 |
wizardPanelWithLogo.setNextButtonEnabled(isEnabled); |
144 |
} |
145 |
|
146 |
public void setExportButtonEnabled(boolean isEnabled) { |
147 |
wizardPanelWithLogo.setFinishButtonEnabled(isEnabled); |
148 |
} |
149 |
|
150 |
public void setCancelButtonText(String text) { |
151 |
wizardPanelWithLogo.getWizardComponents().getCancelButton() |
152 |
.setText(text); |
153 |
} |
154 |
|
155 |
/**
|
156 |
* @return the uimanager
|
157 |
*/
|
158 |
public DefaultExporttoSwingManager getExporttoSwingManager() {
|
159 |
return uimanager;
|
160 |
} |
161 |
|
162 |
/**
|
163 |
* @param exporttoSwingProvider
|
164 |
* @throws ServiceException
|
165 |
*/
|
166 |
public void selectExporttoSwingProvider( |
167 |
ExporttoSwingProviderFactory provider) |
168 |
throws ServiceException {
|
169 |
exporttoSwingProvider = |
170 |
EXPORTTO_SWING_PROVIDER_MANAGER.createExporttoSwingProvider( |
171 |
provider.getName(), featureStore, projection); |
172 |
|
173 |
DefaultJWizardComponents wizardComponents = |
174 |
wizardPanelWithLogo.getWizardComponents(); |
175 |
for (int i = wizardComponents.getWizardPanelList().size() - 1; i >= 1; i--) { |
176 |
wizardComponents.removeWizardPanel(i); |
177 |
} |
178 |
for (int i = 0; i < exporttoSwingProvider.getPanelCount(); i++) { |
179 |
wizardPanelWithLogo.addOptionPanel(new DefaultWizardContainer(
|
180 |
exporttoSwingProvider.getPanelAt(i))); |
181 |
} |
182 |
wizardPanelWithLogo.addOptionPanel(exportFilterWizard); |
183 |
wizardPanelWithLogo.addOptionPanel(exporttoProgressWizard); |
184 |
} |
185 |
|
186 |
public void export() throws DataException, ExporttoServiceException { |
187 |
this.lastWizard();
|
188 |
|
189 |
// Create the feature Set...
|
190 |
FeatureSet featureSet = null;
|
191 |
if (exportFilterWizard.isFullLayerSelected()) {
|
192 |
featureSet = featureStore.getFeatureSet(); |
193 |
} else
|
194 |
if (exportFilterWizard.isSelectedFeaturesSelected()) {
|
195 |
featureSet = (FeatureSet) featureStore.getSelection(); |
196 |
} else {
|
197 |
FeatureQuery featureQuery = featureStore.createFeatureQuery(); |
198 |
Evaluator evaluator = |
199 |
DATA_MANAGER.createExpresion(exportFilterWizard |
200 |
.getFreeFilter()); |
201 |
featureQuery.setFilter(evaluator); |
202 |
featureSet = featureStore.getFeatureSet(featureQuery); |
203 |
} |
204 |
|
205 |
Export export = new Export(featureSet); |
206 |
export.start();
|
207 |
} |
208 |
|
209 |
public void lastWizard() { |
210 |
this.wizardPanelWithLogo.getWizardComponents().getNextButton()
|
211 |
.getActionListeners()[0].actionPerformed(null); |
212 |
} |
213 |
|
214 |
private class Export extends Thread { |
215 |
|
216 |
private FeatureSet featureSet;
|
217 |
|
218 |
public Export(FeatureSet featureSet) {
|
219 |
super();
|
220 |
this.featureSet = featureSet;
|
221 |
} |
222 |
|
223 |
public synchronized void run() { |
224 |
ExporttoService exportService = |
225 |
exporttoSwingProvider.createExporttoService(); |
226 |
exporttoProgressWizard.bind(exportService.getTaskStatus()); |
227 |
exportService.setFinishAction(exporttoServiceFinishAction); |
228 |
try {
|
229 |
exportService.export(featureSet); |
230 |
} catch (ExporttoServiceException e) {
|
231 |
LOG.error("Error exporting the store", e);
|
232 |
showError(e, exportService.getTaskStatus()); |
233 |
} |
234 |
} |
235 |
} |
236 |
|
237 |
private void showError(ExporttoServiceException e, TaskStatus taskStatus) { |
238 |
String message = e.getMessage();
|
239 |
if (e.getCause() != null) { |
240 |
message = e.getCause().getMessage(); |
241 |
} |
242 |
JOptionPane.showMessageDialog(exporttoProgressWizard, message);
|
243 |
} |
244 |
|
245 |
public void setWizardPanelActionListener( |
246 |
WizardPanelActionListener wizardActionListener) { |
247 |
this.exporttoServicePanelListener = wizardActionListener;
|
248 |
} |
249 |
|
250 |
public WizardPanelActionListener getWizardPanelActionListener() {
|
251 |
if (exporttoServicePanelListener == null) { |
252 |
exporttoServicePanelListener = |
253 |
new DefaultJExporttoServicePanelListener(this); |
254 |
} |
255 |
return exporttoServicePanelListener;
|
256 |
} |
257 |
|
258 |
@Override
|
259 |
public void setExporttoServicePanelListener( |
260 |
JExporttoServicePanelListener exporttoServicePanelListener) { |
261 |
((DefaultJExporttoServicePanelListener) getWizardPanelActionListener()) |
262 |
.setExporttoServicePanelListener(exporttoServicePanelListener); |
263 |
} |
264 |
|
265 |
@Override
|
266 |
public int getStatus() { |
267 |
return this.status; |
268 |
} |
269 |
|
270 |
public void setStatus(int status) { |
271 |
this.status = status;
|
272 |
} |
273 |
} |