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