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