svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.installer / org.gvsig.installer.swing / org.gvsig.installer.swing.impl / src / main / java / org / gvsig / installer / swing / impl / execution / wizard / DownloadProgressWizardPage.java @ 43126
History | View | Annotate | Download (7.83 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or modify it under
|
7 |
* the terms of the GNU General Public License as published by the Free Software
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later
|
9 |
* version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
14 |
* details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License along with
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
21 |
* gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.installer.swing.impl.execution.wizard; |
24 |
|
25 |
import java.util.ArrayList; |
26 |
import java.util.List; |
27 |
|
28 |
import javax.swing.JOptionPane; |
29 |
import javax.swing.JPanel; |
30 |
import javax.swing.SwingUtilities; |
31 |
|
32 |
import org.slf4j.Logger; |
33 |
import org.slf4j.LoggerFactory; |
34 |
|
35 |
import org.gvsig.gui.beans.wizard.WizardPanelWithLogo; |
36 |
import org.gvsig.gui.beans.wizard.panel.NotContinueWizardException; |
37 |
import org.gvsig.gui.beans.wizard.panel.OptionPanel; |
38 |
import org.gvsig.i18n.Messages; |
39 |
import org.gvsig.installer.lib.api.PackageInfo; |
40 |
import org.gvsig.installer.lib.api.execution.InstallPackageService; |
41 |
import org.gvsig.installer.swing.api.SwingInstallerLocator; |
42 |
import org.gvsig.installer.swing.api.SwingInstallerManager; |
43 |
import org.gvsig.installer.swing.impl.DefaultSwingInstallerManager; |
44 |
import org.gvsig.installer.swing.impl.execution.DefaultInstallWizardPanel; |
45 |
import org.gvsig.installer.swing.impl.execution.InstallWizardPanel_ext; |
46 |
import org.gvsig.installer.swing.impl.panel.DefaultProgressPanel; |
47 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
48 |
import org.gvsig.tools.task.AbstractMonitorableTask; |
49 |
import org.gvsig.tools.task.SimpleTaskStatus; |
50 |
|
51 |
/**
|
52 |
* @author gvSIG Team
|
53 |
* @version $Id$
|
54 |
*
|
55 |
*/
|
56 |
public class DownloadProgressWizardPage extends DefaultProgressPanel implements |
57 |
OptionPanel { |
58 |
|
59 |
private static final long serialVersionUID = -7064334977678611609L; |
60 |
private static final Logger logger = LoggerFactory.getLogger(DownloadProgressWizardPage.class); |
61 |
|
62 |
private final InstallWizardPanel_ext wizardPanel; |
63 |
|
64 |
public DownloadProgressWizardPage(InstallWizardPanel_ext wizardPanel) {
|
65 |
super();
|
66 |
this.wizardPanel = wizardPanel;
|
67 |
} |
68 |
|
69 |
@Override
|
70 |
public JPanel getJPanel() { |
71 |
return this; |
72 |
} |
73 |
|
74 |
@Override
|
75 |
public String getPanelTitle() { |
76 |
return wizardPanel.getTranslation("_download_progress"); |
77 |
} |
78 |
|
79 |
@Override
|
80 |
public void lastPanel() { |
81 |
wizardPanel.setFinishButtonEnabled(false);
|
82 |
wizardPanel.setCancelButtonEnabled(true);
|
83 |
} |
84 |
|
85 |
@Override
|
86 |
public void nextPanel() throws NotContinueWizardException { |
87 |
} |
88 |
|
89 |
@Override
|
90 |
public void updatePanel() { |
91 |
if( wizardPanel.getDirection() == WizardPanelWithLogo.ACTION_PREVIOUS ) {
|
92 |
wizardPanel.skip(); |
93 |
return;
|
94 |
} |
95 |
boolean AreTherePackagesToDownload = false; |
96 |
|
97 |
this.wizardPanel.setNextButtonEnabled(false); |
98 |
this.wizardPanel.setBackButtonEnabled(false); |
99 |
this.wizardPanel.setFinishButtonEnabled(false); |
100 |
|
101 |
InstallPackageService service = wizardPanel.getInstallerExecutionService(); |
102 |
service.getPackageCount(); |
103 |
|
104 |
List<PackageInfo> packagesToInstall = wizardPanel.getPackagesToInstall();
|
105 |
for (PackageInfo packageToInstall : packagesToInstall) {
|
106 |
if( packageToInstall.getDownloadURL() != null ) { |
107 |
AreTherePackagesToDownload = true;
|
108 |
break;
|
109 |
} |
110 |
} |
111 |
|
112 |
if (!AreTherePackagesToDownload) {
|
113 |
wizardPanel.skip(); |
114 |
} |
115 |
|
116 |
UpdatePanel task = new UpdatePanel(this); |
117 |
wizardPanel.addCancellableTask(task); |
118 |
bind(task.getTaskStatus()); |
119 |
task.setDaemon(true);
|
120 |
task.start(); |
121 |
|
122 |
} |
123 |
|
124 |
private String getText(String key) { |
125 |
return this.wizardPanel.getTranslation(key); |
126 |
} |
127 |
|
128 |
private static class UpdatePanel extends AbstractMonitorableTask { |
129 |
|
130 |
private final DownloadProgressWizardPage panel; |
131 |
|
132 |
public UpdatePanel(DownloadProgressWizardPage panel) {
|
133 |
super(panel.getText("_downloading_files")); |
134 |
this.panel = panel;
|
135 |
} |
136 |
|
137 |
@Override
|
138 |
public synchronized void run() { |
139 |
SimpleTaskStatus taskStatus = (SimpleTaskStatus) this.getTaskStatus();
|
140 |
final List<String> not_downloaded = new ArrayList<>(); |
141 |
try {
|
142 |
|
143 |
List<PackageInfo> packagesToInstall = this.panel.wizardPanel.getPackagesToInstall(); |
144 |
InstallPackageService installerService = this.panel.wizardPanel.getInstallerExecutionService();
|
145 |
|
146 |
taskStatus.setRangeOfValues(0, packagesToInstall.size());
|
147 |
for (int i = 0; i < packagesToInstall.size(); i++) { |
148 |
taskStatus.setCurValue(i); |
149 |
PackageInfo packageInfo = packagesToInstall.get(i); |
150 |
taskStatus.message(packageInfo.getName()); |
151 |
if (packageInfo.getDownloadURL() != null) { |
152 |
try {
|
153 |
installerService.downloadPackage( |
154 |
packageInfo, |
155 |
taskStatus |
156 |
); |
157 |
} catch (Exception e) { |
158 |
not_downloaded.add(packageInfo.getName()); |
159 |
logger.info("Can't download package '"+packageInfo.getName()+"'.", e); |
160 |
} |
161 |
} |
162 |
|
163 |
if (not_downloaded.size() > 0) { |
164 |
break;
|
165 |
} |
166 |
} |
167 |
SwingUtilities.invokeAndWait(new Runnable() { |
168 |
|
169 |
@Override
|
170 |
public void run() { |
171 |
if (not_downloaded.isEmpty()) {
|
172 |
panel.wizardPanel.setNextButtonEnabled(true);
|
173 |
panel.wizardPanel.doAction(WizardPanelWithLogo.ACTION_NEXT); |
174 |
} else {
|
175 |
panel.wizardPanel.setNextButtonEnabled(false);
|
176 |
} |
177 |
panel.wizardPanel.setBackButtonEnabled(true);
|
178 |
} |
179 |
}); |
180 |
|
181 |
} catch(Exception ex) { |
182 |
logger.warn("Problems downloading packages.", ex);
|
183 |
ToolsSwingLocator.getThreadSafeDialogsManager().messageDialog( |
184 |
panel.getText("_Cant_download_packages"),
|
185 |
panel.getText("_Warning"),
|
186 |
JOptionPane.WARNING_MESSAGE
|
187 |
); |
188 |
} finally {
|
189 |
if (not_downloaded.isEmpty()) {
|
190 |
taskStatus.message(panel.getText("_finished"));
|
191 |
} else {
|
192 |
taskStatus.message(panel.getText("_finished_Some_files_not_downloaded"));
|
193 |
showNotDownloaded(not_downloaded); |
194 |
} |
195 |
taskStatus.terminate(); |
196 |
taskStatus.remove(); |
197 |
} |
198 |
} |
199 |
|
200 |
} |
201 |
|
202 |
private static synchronized void showNotDownloaded(final List<String> names) { |
203 |
|
204 |
int sz = names.size();
|
205 |
String list_str = ""; |
206 |
for (int i = 0; i < sz; i++) { |
207 |
list_str = list_str + "\n - " + names.get(i);
|
208 |
} |
209 |
|
210 |
list_str = Messages.getText("_These_packages_not_downloaded")
|
211 |
+ ":\n" + list_str + "\n"; |
212 |
ToolsSwingLocator.getThreadSafeDialogsManager().messageDialog( |
213 |
list_str, |
214 |
Messages.getText("_Warning"),
|
215 |
JOptionPane.WARNING_MESSAGE
|
216 |
); |
217 |
} |
218 |
|
219 |
|
220 |
} |