svn-gvsig-desktop / tags / v2_0_0_Build_2060 / extensions / org.gvsig.installer / org.gvsig.installer.swing / org.gvsig.installer.swing.impl / src / main / java / org / gvsig / installer / swing / impl / execution / wizard / ProgressWizard.java @ 39380
History | View | Annotate | Download (4.54 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 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2010 {Prodevelop} {Task}
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.installer.swing.impl.execution.wizard; |
29 |
|
30 |
import java.util.List; |
31 |
|
32 |
import javax.swing.JPanel; |
33 |
|
34 |
import org.gvsig.gui.beans.wizard.panel.OptionPanel; |
35 |
import org.gvsig.installer.lib.api.PackageInfo; |
36 |
import org.gvsig.installer.lib.api.execution.InstallPackageService; |
37 |
import org.gvsig.installer.lib.api.execution.InstallPackageServiceException; |
38 |
import org.gvsig.installer.swing.api.SwingInstallerLocator; |
39 |
import org.gvsig.installer.swing.api.execution.AbstractInstallPackageWizard; |
40 |
import org.gvsig.installer.swing.impl.DefaultSwingInstallerManager; |
41 |
import org.gvsig.installer.swing.impl.execution.DefaultInstallPackageWizard; |
42 |
import org.gvsig.installer.swing.impl.panel.DefaultProgressPanel; |
43 |
import org.gvsig.tools.task.AbstractMonitorableTask; |
44 |
import org.gvsig.tools.task.SimpleTaskStatus; |
45 |
|
46 |
/**
|
47 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a>
|
48 |
*/
|
49 |
public class ProgressWizard extends DefaultProgressPanel implements OptionPanel { |
50 |
|
51 |
private static final long serialVersionUID = 8531884535246881448L; |
52 |
private AbstractInstallPackageWizard installerExecutionWizard;
|
53 |
private DefaultSwingInstallerManager swingInstallerManager;
|
54 |
|
55 |
public ProgressWizard(DefaultInstallPackageWizard installerExecutionWizard) {
|
56 |
super();
|
57 |
this.installerExecutionWizard = installerExecutionWizard;
|
58 |
swingInstallerManager = (DefaultSwingInstallerManager) SwingInstallerLocator |
59 |
.getSwingInstallerManager(); |
60 |
} |
61 |
|
62 |
public JPanel getJPanel() { |
63 |
return this; |
64 |
} |
65 |
|
66 |
public String getPanelTitle() { |
67 |
return swingInstallerManager.getText("_progress"); |
68 |
} |
69 |
|
70 |
public void lastPanel() { |
71 |
installerExecutionWizard.setFinishButtonVisible(false);
|
72 |
installerExecutionWizard.setCancelButtonEnabled(true);
|
73 |
} |
74 |
|
75 |
public void nextPanel() { |
76 |
// Nothing to do, no next panel
|
77 |
} |
78 |
|
79 |
public void updatePanel() { |
80 |
installerExecutionWizard.setFinishButtonVisible(false);
|
81 |
installerExecutionWizard.setCancelButtonEnabled(false);
|
82 |
|
83 |
final ProgressWizard wizard = this; |
84 |
|
85 |
UpdatePanel task = new UpdatePanel(wizard);
|
86 |
wizard.installerExecutionWizard.addCancellableTask(task); |
87 |
bind(task.getTaskStatus()); |
88 |
task.start(); |
89 |
} |
90 |
|
91 |
private static class UpdatePanel extends AbstractMonitorableTask { |
92 |
|
93 |
private final ProgressWizard panel; |
94 |
|
95 |
public UpdatePanel(ProgressWizard panel) {
|
96 |
super(panel.swingInstallerManager
|
97 |
.getText("_Install_package"));
|
98 |
this.panel = panel;
|
99 |
} |
100 |
|
101 |
@Override
|
102 |
public synchronized void run() { |
103 |
|
104 |
SimpleTaskStatus taskStatus = (SimpleTaskStatus) this
|
105 |
.getTaskStatus(); |
106 |
// bundle of packages
|
107 |
InstallPackageService installerExecutionService = this.panel.installerExecutionWizard
|
108 |
.getInstallerExecutionService(); |
109 |
// packages to install
|
110 |
List<PackageInfo> installersToInstall = this.panel.installerExecutionWizard |
111 |
.getInstallersToInstall(); |
112 |
taskStatus.setRangeOfValues(0, installersToInstall.size());
|
113 |
try {
|
114 |
for (int i = 0; i < installersToInstall.size(); i++) { |
115 |
PackageInfo installerInfo = installersToInstall.get(i); |
116 |
taskStatus.message(installerInfo.getName()); |
117 |
installerExecutionService.installPackage( |
118 |
panel.installerExecutionWizard |
119 |
.getApplicationFolder(), installerInfo); |
120 |
taskStatus.setCurValue(i + 1);
|
121 |
} |
122 |
this.panel.installerExecutionWizard
|
123 |
.setFinishButtonVisible(true);
|
124 |
} catch (InstallPackageServiceException e) {
|
125 |
panel.showErrorMessage(panel.swingInstallerManager |
126 |
.getText("_Cant_install_packege"), e);
|
127 |
} |
128 |
// Set the finished text
|
129 |
taskStatus.message(panel.swingInstallerManager |
130 |
.getText("_Finished"));
|
131 |
|
132 |
taskStatus.terminate(); |
133 |
taskStatus.remove(); |
134 |
|
135 |
} |
136 |
|
137 |
} |
138 |
} |