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 / ProgressWizardPage.java @ 43126
History | View | Annotate | Download (5.9 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 |
package org.gvsig.installer.swing.impl.execution.wizard; |
29 |
|
30 |
import java.util.Collections; |
31 |
import java.util.Comparator; |
32 |
import java.util.List; |
33 |
import javax.swing.JOptionPane; |
34 |
|
35 |
import javax.swing.JPanel; |
36 |
import javax.swing.SwingUtilities; |
37 |
|
38 |
import org.gvsig.gui.beans.wizard.panel.OptionPanel; |
39 |
import org.gvsig.installer.lib.api.PackageInfo; |
40 |
import org.gvsig.installer.lib.api.execution.InstallPackageService; |
41 |
import org.gvsig.installer.swing.impl.execution.InstallWizardPanel_ext; |
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 |
public class ProgressWizardPage extends DefaultProgressPanel implements OptionPanel { |
48 |
|
49 |
private static final long serialVersionUID = 8531884535246881448L; |
50 |
private final InstallWizardPanel_ext wizardPanel; |
51 |
|
52 |
public ProgressWizardPage(InstallWizardPanel_ext wizardPanel) {
|
53 |
super();
|
54 |
this.wizardPanel = wizardPanel;
|
55 |
} |
56 |
|
57 |
@Override
|
58 |
public JPanel getJPanel() { |
59 |
return this; |
60 |
} |
61 |
|
62 |
@Override
|
63 |
public String getPanelTitle() { |
64 |
return wizardPanel.getTranslation("_progress"); |
65 |
} |
66 |
|
67 |
@Override
|
68 |
public void lastPanel() { |
69 |
wizardPanel.setFinishButtonEnabled(false);
|
70 |
wizardPanel.setCancelButtonEnabled(true);
|
71 |
} |
72 |
|
73 |
@Override
|
74 |
public void nextPanel() { |
75 |
// Nothing to do, no next panel
|
76 |
} |
77 |
|
78 |
@Override
|
79 |
public void updatePanel() { |
80 |
wizardPanel.setFinishButtonEnabled(false);
|
81 |
wizardPanel.setCancelButtonEnabled(false);
|
82 |
|
83 |
final ProgressWizardPage wizard = this; |
84 |
|
85 |
UpdatePanel task = new UpdatePanel(wizard);
|
86 |
wizard.wizardPanel.addCancellableTask(task); |
87 |
bind(task.getTaskStatus()); |
88 |
task.setDaemon(true);
|
89 |
task.start(); |
90 |
} |
91 |
|
92 |
private static class UpdatePanel extends AbstractMonitorableTask { |
93 |
|
94 |
private final ProgressWizardPage panel; |
95 |
|
96 |
public UpdatePanel(ProgressWizardPage panel) {
|
97 |
super(panel.wizardPanel.getTranslation("_Install_package")); |
98 |
this.panel = panel;
|
99 |
} |
100 |
|
101 |
private void showWarning(final String msg) { |
102 |
if( !SwingUtilities.isEventDispatchThread() ) { |
103 |
try {
|
104 |
SwingUtilities.invokeAndWait(new Runnable() { |
105 |
public void run() { |
106 |
} |
107 |
}); |
108 |
} catch (Exception ex) { |
109 |
logger.warn("Cant show message to the user. "+msg);
|
110 |
} |
111 |
return;
|
112 |
} |
113 |
JOptionPane.showMessageDialog(panel, msg, "Warning", JOptionPane.WARNING_MESSAGE); |
114 |
} |
115 |
|
116 |
@Override
|
117 |
public synchronized void run() { |
118 |
|
119 |
int errcount = 0; |
120 |
try {
|
121 |
logger.info("Package installation iniitiated");
|
122 |
SimpleTaskStatus taskStatus = (SimpleTaskStatus) this.getTaskStatus();
|
123 |
// bundle of packages
|
124 |
InstallPackageService installerExecutionService = this.panel.wizardPanel
|
125 |
.getInstallerExecutionService(); |
126 |
// packages to install
|
127 |
List<PackageInfo> installersToInstall = this.panel.wizardPanel |
128 |
.getPackagesToInstall(); |
129 |
Collections.sort(installersToInstall, new Comparator<PackageInfo>() { |
130 |
public int compare(PackageInfo o1, PackageInfo o2) { |
131 |
return o1.getCode().compareTo(o2.getCode());
|
132 |
} |
133 |
}); |
134 |
taskStatus.setRangeOfValues(0, installersToInstall.size());
|
135 |
for ( int i = 0; i < installersToInstall.size(); i++ ) { |
136 |
PackageInfo installerInfo = installersToInstall.get(i); |
137 |
taskStatus.message(installerInfo.getName()); |
138 |
try {
|
139 |
installerExecutionService.installPackage( |
140 |
panel.wizardPanel.getApplicationFolder(), |
141 |
installerInfo |
142 |
); |
143 |
} catch (Throwable th) { |
144 |
logger.warn("Can't install package '" + installerInfo.getCode() + "'.", th); |
145 |
errcount++; |
146 |
} |
147 |
taskStatus.setCurValue(i + 1);
|
148 |
} |
149 |
this.panel.wizardPanel.setFinishButtonEnabled(true); |
150 |
if( errcount>0 ) { |
151 |
showWarning("Failed to install "+errcount+" packages."); |
152 |
} |
153 |
taskStatus.message(panel.wizardPanel.getTranslation("_Finished"));
|
154 |
|
155 |
taskStatus.terminate(); |
156 |
taskStatus.remove(); |
157 |
logger.info("Package installation finished");
|
158 |
} catch (Throwable th) { |
159 |
logger.warn("Problems install packages.",th);
|
160 |
showWarning(panel.wizardPanel.getTranslation("_Cant_install_packege"));
|
161 |
} |
162 |
|
163 |
} |
164 |
|
165 |
} |
166 |
} |