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