svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.installer / org.gvsig.installer.swing / org.gvsig.installer.swing.impl / src / main / java / org / gvsig / installer / swing / impl / execution / wizard / DownloadProgressWizard.java @ 37598
History | View | Annotate | Download (6.95 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 |
|
23 |
package org.gvsig.installer.swing.impl.execution.wizard; |
24 |
|
25 |
import java.awt.GridBagConstraints; |
26 |
import java.awt.Insets; |
27 |
import java.awt.event.ActionEvent; |
28 |
import java.awt.event.ActionListener; |
29 |
import java.util.List; |
30 |
|
31 |
import javax.swing.JButton; |
32 |
import javax.swing.JOptionPane; |
33 |
import javax.swing.JPanel; |
34 |
|
35 |
import org.slf4j.Logger; |
36 |
import org.slf4j.LoggerFactory; |
37 |
|
38 |
import org.gvsig.gui.beans.wizard.WizardPanelWithLogo; |
39 |
import org.gvsig.gui.beans.wizard.panel.NotContinueWizardException; |
40 |
import org.gvsig.gui.beans.wizard.panel.OptionPanel; |
41 |
import org.gvsig.installer.lib.api.PackageInfo; |
42 |
import org.gvsig.installer.lib.api.execution.InstallPackageService; |
43 |
import org.gvsig.installer.swing.api.SwingInstallerLocator; |
44 |
import org.gvsig.installer.swing.api.execution.AbstractInstallPackageWizard; |
45 |
import org.gvsig.installer.swing.impl.DefaultSwingInstallerManager; |
46 |
import org.gvsig.installer.swing.impl.execution.DefaultInstallPackageWizard; |
47 |
import org.gvsig.installer.swing.impl.panel.DefaultProgressPanel; |
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 |
|
57 |
public class DownloadProgressWizard extends DefaultProgressPanel implements |
58 |
OptionPanel { |
59 |
|
60 |
private static final long serialVersionUID = -7064334977678611609L; |
61 |
private static Logger logger = LoggerFactory |
62 |
.getLogger(DownloadProgressWizard.class); |
63 |
private AbstractInstallPackageWizard abstractInstallPackageWizard;
|
64 |
// private abstractInstallPackageWizard abstractInstallPackageWizard;
|
65 |
public JButton startDownload; |
66 |
private int direccion = WizardPanelWithLogo.ACTION_NEXT; |
67 |
private DefaultSwingInstallerManager swingInstallerManager;
|
68 |
|
69 |
public DownloadProgressWizard(
|
70 |
AbstractInstallPackageWizard abstractInstallPackageWizard) { |
71 |
super();
|
72 |
this.abstractInstallPackageWizard = abstractInstallPackageWizard;
|
73 |
} |
74 |
|
75 |
@Override
|
76 |
protected void initComponents() { |
77 |
super.initComponents();
|
78 |
|
79 |
final DownloadProgressWizard wizard = this; |
80 |
|
81 |
swingInstallerManager = (DefaultSwingInstallerManager) SwingInstallerLocator |
82 |
.getSwingInstallerManager(); |
83 |
|
84 |
startDownload = new JButton(swingInstallerManager |
85 |
.getText("_start_download"));
|
86 |
|
87 |
java.awt.GridBagConstraints gridBagConstraints; |
88 |
gridBagConstraints = new GridBagConstraints(); |
89 |
gridBagConstraints.gridx = 0;
|
90 |
gridBagConstraints.gridy = 3;
|
91 |
gridBagConstraints.anchor = GridBagConstraints.EAST;
|
92 |
gridBagConstraints.insets = new Insets(5, 2, 2, 2); |
93 |
add(startDownload, gridBagConstraints); |
94 |
|
95 |
startDownload.addActionListener(new ActionListener() { |
96 |
|
97 |
public void actionPerformed(ActionEvent e) { |
98 |
UpdatePanel task = new UpdatePanel(wizard);
|
99 |
wizard.abstractInstallPackageWizard.addCancellableTask(task); |
100 |
bind(task.getTaskStatus()); |
101 |
task.start(); |
102 |
} |
103 |
}); |
104 |
} |
105 |
|
106 |
public JPanel getJPanel() { |
107 |
return this; |
108 |
} |
109 |
|
110 |
public String getPanelTitle() { |
111 |
return swingInstallerManager.getText("_download_progress"); |
112 |
} |
113 |
|
114 |
public void lastPanel() { |
115 |
abstractInstallPackageWizard.setFinishButtonVisible(false);
|
116 |
abstractInstallPackageWizard.setCancelButtonEnabled(true);
|
117 |
direccion = WizardPanelWithLogo.ACTION_NEXT; |
118 |
} |
119 |
|
120 |
public void nextPanel() throws NotContinueWizardException { |
121 |
direccion = WizardPanelWithLogo.ACTION_PREVIOUS; |
122 |
} |
123 |
|
124 |
public void updatePanel() { |
125 |
boolean thereIsDownloablePackage = false; |
126 |
|
127 |
InstallPackageService service = abstractInstallPackageWizard |
128 |
.getInstallerExecutionService(); |
129 |
service.getPackageCount(); |
130 |
|
131 |
for (int i = 0; i < abstractInstallPackageWizard |
132 |
.getInstallersToInstall().size(); i++) { |
133 |
|
134 |
if (abstractInstallPackageWizard.getInstallersToInstall().get(i)
|
135 |
.getDownloadURL() != null) {
|
136 |
thereIsDownloablePackage = true;
|
137 |
break;
|
138 |
} |
139 |
} |
140 |
|
141 |
if (thereIsDownloablePackage) {
|
142 |
this.abstractInstallPackageWizard.setNextButtonEnabled(false); |
143 |
this.startDownload.setEnabled(true); |
144 |
} else {
|
145 |
((DefaultInstallPackageWizard) abstractInstallPackageWizard) |
146 |
.doAction(direccion); |
147 |
} |
148 |
} |
149 |
|
150 |
private String getText(String key) { |
151 |
return this.swingInstallerManager.getText(key); |
152 |
} |
153 |
|
154 |
private static class UpdatePanel extends AbstractMonitorableTask { |
155 |
|
156 |
private final DownloadProgressWizard panel; |
157 |
|
158 |
public UpdatePanel(DownloadProgressWizard panel) {
|
159 |
super(panel.getText("_downloading")); |
160 |
this.panel = panel;
|
161 |
} |
162 |
|
163 |
@Override
|
164 |
public synchronized void run() { |
165 |
List<PackageInfo> installersToInstall = this.panel.abstractInstallPackageWizard |
166 |
.getInstallersToInstall(); |
167 |
this.panel.startDownload.setEnabled(false); |
168 |
this.panel.abstractInstallPackageWizard.setBackButtonEnabled(false); |
169 |
InstallPackageService installerService = this.panel.abstractInstallPackageWizard
|
170 |
.getInstallerExecutionService(); |
171 |
SimpleTaskStatus taskStatus = (SimpleTaskStatus) this
|
172 |
.getTaskStatus(); |
173 |
for (int i = 0; i < installersToInstall.size(); i++) { |
174 |
taskStatus.setCurValue(0);
|
175 |
PackageInfo installerInfo = installersToInstall.get(i); |
176 |
taskStatus.message(installerInfo.getName() + " " + (i + 1) |
177 |
+ " / " + installersToInstall.size());
|
178 |
if (installerInfo.getDownloadURL() != null) { |
179 |
try {
|
180 |
installerService.downloadPackage(installerInfo, |
181 |
taskStatus); |
182 |
} catch (Exception e) { |
183 |
String msg = panel.swingInstallerManager
|
184 |
.getText("_Cant_download_package_files")
|
185 |
+ " " + installerInfo.getName();
|
186 |
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 |
} |
199 |
} |
200 |
if (taskStatus.isCancellationRequested()) {
|
201 |
break;
|
202 |
} |
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);
|
211 |
} |
212 |
this.panel.abstractInstallPackageWizard.setBackButtonEnabled(true); |
213 |
} |
214 |
|
215 |
} |
216 |
|
217 |
} |