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