22 |
22 |
|
23 |
23 |
package org.gvsig.installer.swing.impl.execution.wizard;
|
24 |
24 |
|
|
25 |
import java.awt.Component;
|
25 |
26 |
import java.awt.GridBagConstraints;
|
26 |
27 |
import java.awt.Insets;
|
27 |
28 |
import java.awt.event.ActionEvent;
|
28 |
29 |
import java.awt.event.ActionListener;
|
|
30 |
import java.util.ArrayList;
|
29 |
31 |
import java.util.List;
|
30 |
32 |
|
31 |
33 |
import javax.swing.JButton;
|
32 |
34 |
import javax.swing.JOptionPane;
|
33 |
35 |
import javax.swing.JPanel;
|
|
36 |
import javax.swing.SwingUtilities;
|
34 |
37 |
|
35 |
38 |
import org.slf4j.Logger;
|
36 |
39 |
import org.slf4j.LoggerFactory;
|
... | ... | |
38 |
41 |
import org.gvsig.gui.beans.wizard.WizardPanelWithLogo;
|
39 |
42 |
import org.gvsig.gui.beans.wizard.panel.NotContinueWizardException;
|
40 |
43 |
import org.gvsig.gui.beans.wizard.panel.OptionPanel;
|
|
44 |
import org.gvsig.i18n.Messages;
|
41 |
45 |
import org.gvsig.installer.lib.api.PackageInfo;
|
42 |
46 |
import org.gvsig.installer.lib.api.execution.InstallPackageService;
|
43 |
47 |
import org.gvsig.installer.swing.api.SwingInstallerLocator;
|
... | ... | |
156 |
160 |
private final DownloadProgressWizard panel;
|
157 |
161 |
|
158 |
162 |
public UpdatePanel(DownloadProgressWizard panel) {
|
159 |
|
super(panel.getText("_downloading"));
|
|
163 |
super(panel.getText("_downloading"));
|
|
164 |
// super(panel.getText("_downloading"));
|
160 |
165 |
this.panel = panel;
|
161 |
166 |
}
|
162 |
167 |
|
... | ... | |
170 |
175 |
.getInstallerExecutionService();
|
171 |
176 |
SimpleTaskStatus taskStatus = (SimpleTaskStatus) this
|
172 |
177 |
.getTaskStatus();
|
|
178 |
|
|
179 |
List<String> not_downloaded = new ArrayList<String>();
|
|
180 |
|
173 |
181 |
for (int i = 0; i < installersToInstall.size(); i++) {
|
174 |
182 |
taskStatus.setCurValue(0);
|
175 |
183 |
PackageInfo installerInfo = installersToInstall.get(i);
|
... | ... | |
180 |
188 |
installerService.downloadPackage(installerInfo,
|
181 |
189 |
taskStatus);
|
182 |
190 |
} catch (Exception e) {
|
|
191 |
|
|
192 |
not_downloaded.add(installerInfo.getName());
|
183 |
193 |
String msg = panel.swingInstallerManager
|
184 |
194 |
.getText("_Cant_download_package_files")
|
185 |
195 |
+ " " + installerInfo.getName();
|
186 |
196 |
logger.info(msg, e);
|
187 |
|
int resp = JOptionPane.showOptionDialog(null, msg
|
188 |
|
+ "\n"
|
189 |
|
+ panel.swingInstallerManager
|
190 |
|
.getText("_do_you_want_to_continue"),
|
191 |
|
panel.swingInstallerManager
|
192 |
|
.getText("_Download_error"),
|
193 |
|
JOptionPane.YES_NO_OPTION,
|
194 |
|
JOptionPane.ERROR_MESSAGE, null, null, null);
|
195 |
|
if (resp == JOptionPane.NO_OPTION) {
|
196 |
|
taskStatus.cancelRequest();
|
197 |
|
}
|
198 |
197 |
}
|
199 |
198 |
}
|
200 |
|
if (taskStatus.isCancellationRequested()) {
|
201 |
|
break;
|
|
199 |
|
|
200 |
if (not_downloaded.size() > 0) {
|
|
201 |
break;
|
202 |
202 |
}
|
203 |
203 |
}
|
204 |
|
// Set the finished text
|
205 |
|
taskStatus.message(panel.getText("_finished"));
|
206 |
|
taskStatus.terminate();
|
207 |
|
taskStatus.remove();
|
208 |
|
if (!taskStatus.isCancellationRequested()) {
|
209 |
|
this.panel.abstractInstallPackageWizard
|
210 |
|
.setNextButtonEnabled(true);
|
|
204 |
|
|
205 |
this.panel.abstractInstallPackageWizard.setBackButtonEnabled(true);
|
|
206 |
|
|
207 |
if (not_downloaded.size() == 0) {
|
|
208 |
// Set the finished text
|
|
209 |
taskStatus.message(panel.getText("_finished"));
|
|
210 |
taskStatus.terminate();
|
|
211 |
taskStatus.remove();
|
|
212 |
this.panel.abstractInstallPackageWizard.setNextButtonEnabled(true);
|
|
213 |
} else {
|
|
214 |
taskStatus.cancelRequest();
|
|
215 |
taskStatus.cancel();
|
|
216 |
// taskStatus.setCurValue(0);
|
|
217 |
taskStatus.remove();
|
|
218 |
this.panel.abstractInstallPackageWizard.setNextButtonEnabled(false);
|
|
219 |
showNotDownloaded(this.panel, not_downloaded);
|
211 |
220 |
}
|
212 |
|
this.panel.abstractInstallPackageWizard.setBackButtonEnabled(true);
|
|
221 |
|
213 |
222 |
}
|
214 |
223 |
|
215 |
224 |
}
|
|
225 |
|
|
226 |
|
|
227 |
private static synchronized void showNotDownloaded(
|
|
228 |
final Component parentPanel, final List<String> names) {
|
|
229 |
|
|
230 |
int sz = names.size();
|
|
231 |
String list_str = "";
|
|
232 |
for (int i=0; i<sz; i++) {
|
|
233 |
list_str = list_str + "\n - " + names.get(i);
|
|
234 |
}
|
|
235 |
|
|
236 |
list_str = Messages.getText("_These_packages_not_downloaded")
|
|
237 |
+ ":\n" + list_str + "\n";
|
|
238 |
final String list_str_copy = list_str;
|
|
239 |
if (!SwingUtilities.isEventDispatchThread()) {
|
|
240 |
try {
|
|
241 |
SwingUtilities.invokeLater(new Runnable() {
|
|
242 |
public void run() {
|
|
243 |
|
|
244 |
JOptionPane.showMessageDialog(
|
|
245 |
parentPanel, list_str_copy,
|
|
246 |
Messages.getText("_Download_error"),
|
|
247 |
JOptionPane.ERROR_MESSAGE);
|
|
248 |
|
|
249 |
}
|
|
250 |
});
|
|
251 |
} catch (Throwable e) {
|
|
252 |
logger.info("Error while showing message dialog. ", e);
|
|
253 |
}
|
|
254 |
|
|
255 |
} else {
|
|
256 |
JOptionPane.showMessageDialog(
|
|
257 |
parentPanel, list_str, Messages.getText("_Download_error"),
|
|
258 |
JOptionPane.ERROR_MESSAGE);
|
|
259 |
}
|
|
260 |
|
|
261 |
}
|
|
262 |
|
|
263 |
|
|
264 |
|
|
265 |
private static synchronized int showOptionDialog(
|
|
266 |
final Component parentComponent,
|
|
267 |
final String message,
|
|
268 |
final String title,
|
|
269 |
final int optionType,
|
|
270 |
final int messageType) {
|
216 |
271 |
|
|
272 |
if (!SwingUtilities.isEventDispatchThread()) {
|
|
273 |
try {
|
|
274 |
final int[] resp = new int[1];
|
|
275 |
SwingUtilities.invokeAndWait(new Runnable() {
|
|
276 |
|
|
277 |
public void run() {
|
|
278 |
resp[0] = showOptionDialog(
|
|
279 |
parentComponent, message, title, optionType, messageType);
|
|
280 |
|
|
281 |
}
|
|
282 |
});
|
|
283 |
|
|
284 |
return resp[0];
|
|
285 |
} catch (Throwable e) {
|
|
286 |
logger.info("Error while showing message dialog. ", e);
|
|
287 |
}
|
|
288 |
}
|
|
289 |
|
|
290 |
return JOptionPane.showOptionDialog(
|
|
291 |
parentComponent, message, title,
|
|
292 |
optionType, messageType, null, null, null);
|
|
293 |
|
|
294 |
}
|
|
295 |
|
|
296 |
|
|
297 |
|
217 |
298 |
}
|