10 |
10 |
*
|
11 |
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
14 |
* GNU General Public License for more details.
|
15 |
15 |
*
|
16 |
16 |
* You should have received a copy of the GNU General Public License
|
17 |
17 |
* along with this program; if not, write to the Free Software
|
18 |
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
|
* MA 02110-1301, USA.
|
|
19 |
* MA 02110-1301, USA.
|
20 |
20 |
*
|
21 |
21 |
* For any additional information, do not hesitate to contact us
|
22 |
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
... | ... | |
25 |
25 |
* AUTHORS (In addition to CIT):
|
26 |
26 |
* 2010 {Prodevelop} {Task}
|
27 |
27 |
*/
|
28 |
|
|
29 |
28 |
package org.gvsig.installer.swing.impl.execution.wizard;
|
30 |
29 |
|
|
30 |
import java.lang.reflect.InvocationTargetException;
|
31 |
31 |
import java.util.Collections;
|
32 |
32 |
import java.util.Comparator;
|
33 |
33 |
import java.util.List;
|
|
34 |
import java.util.logging.Level;
|
|
35 |
import java.util.logging.Logger;
|
|
36 |
import javax.swing.JOptionPane;
|
34 |
37 |
|
35 |
38 |
import javax.swing.JPanel;
|
|
39 |
import javax.swing.SwingUtilities;
|
36 |
40 |
|
37 |
41 |
import org.gvsig.gui.beans.wizard.panel.OptionPanel;
|
38 |
42 |
import org.gvsig.installer.lib.api.PackageInfo;
|
... | ... | |
51 |
55 |
*/
|
52 |
56 |
public class ProgressWizard extends DefaultProgressPanel implements OptionPanel {
|
53 |
57 |
|
54 |
|
private static final long serialVersionUID = 8531884535246881448L;
|
55 |
|
private AbstractInstallPackageWizard installerExecutionWizard;
|
56 |
|
private DefaultSwingInstallerManager swingInstallerManager;
|
|
58 |
private static final long serialVersionUID = 8531884535246881448L;
|
|
59 |
private AbstractInstallPackageWizard installerExecutionWizard;
|
|
60 |
private DefaultSwingInstallerManager swingInstallerManager;
|
57 |
61 |
|
58 |
|
public ProgressWizard(DefaultInstallPackageWizard installerExecutionWizard) {
|
59 |
|
super();
|
60 |
|
this.installerExecutionWizard = installerExecutionWizard;
|
61 |
|
swingInstallerManager = (DefaultSwingInstallerManager) SwingInstallerLocator
|
62 |
|
.getSwingInstallerManager();
|
63 |
|
}
|
|
62 |
public ProgressWizard(DefaultInstallPackageWizard installerExecutionWizard) {
|
|
63 |
super();
|
|
64 |
this.installerExecutionWizard = installerExecutionWizard;
|
|
65 |
swingInstallerManager = (DefaultSwingInstallerManager) SwingInstallerLocator
|
|
66 |
.getSwingInstallerManager();
|
|
67 |
}
|
64 |
68 |
|
65 |
|
public JPanel getJPanel() {
|
66 |
|
return this;
|
67 |
|
}
|
|
69 |
public JPanel getJPanel() {
|
|
70 |
return this;
|
|
71 |
}
|
68 |
72 |
|
69 |
|
public String getPanelTitle() {
|
70 |
|
return swingInstallerManager.getText("_progress");
|
71 |
|
}
|
|
73 |
public String getPanelTitle() {
|
|
74 |
return swingInstallerManager.getText("_progress");
|
|
75 |
}
|
72 |
76 |
|
73 |
|
public void lastPanel() {
|
74 |
|
installerExecutionWizard.setFinishButtonVisible(false);
|
75 |
|
installerExecutionWizard.setCancelButtonEnabled(true);
|
76 |
|
}
|
|
77 |
public void lastPanel() {
|
|
78 |
installerExecutionWizard.setFinishButtonVisible(false);
|
|
79 |
installerExecutionWizard.setCancelButtonEnabled(true);
|
|
80 |
}
|
77 |
81 |
|
78 |
|
public void nextPanel() {
|
79 |
|
// Nothing to do, no next panel
|
80 |
|
}
|
|
82 |
public void nextPanel() {
|
|
83 |
// Nothing to do, no next panel
|
|
84 |
}
|
81 |
85 |
|
82 |
|
public void updatePanel() {
|
83 |
|
installerExecutionWizard.setFinishButtonVisible(false);
|
84 |
|
installerExecutionWizard.setCancelButtonEnabled(false);
|
|
86 |
public void updatePanel() {
|
|
87 |
installerExecutionWizard.setFinishButtonVisible(false);
|
|
88 |
installerExecutionWizard.setCancelButtonEnabled(false);
|
85 |
89 |
|
86 |
|
final ProgressWizard wizard = this;
|
|
90 |
final ProgressWizard wizard = this;
|
87 |
91 |
|
88 |
|
UpdatePanel task = new UpdatePanel(wizard);
|
89 |
|
wizard.installerExecutionWizard.addCancellableTask(task);
|
90 |
|
bind(task.getTaskStatus());
|
91 |
|
task.start();
|
92 |
|
}
|
|
92 |
UpdatePanel task = new UpdatePanel(wizard);
|
|
93 |
wizard.installerExecutionWizard.addCancellableTask(task);
|
|
94 |
bind(task.getTaskStatus());
|
|
95 |
task.setDaemon(true);
|
|
96 |
task.start();
|
|
97 |
}
|
93 |
98 |
|
94 |
|
private static class UpdatePanel extends AbstractMonitorableTask {
|
|
99 |
private static class UpdatePanel extends AbstractMonitorableTask {
|
95 |
100 |
|
96 |
|
private final ProgressWizard panel;
|
|
101 |
private final ProgressWizard panel;
|
97 |
102 |
|
98 |
|
public UpdatePanel(ProgressWizard panel) {
|
99 |
|
super(panel.swingInstallerManager
|
100 |
|
.getText("_Install_package"));
|
101 |
|
this.panel = panel;
|
102 |
|
}
|
|
103 |
public UpdatePanel(ProgressWizard panel) {
|
|
104 |
super(panel.swingInstallerManager
|
|
105 |
.getText("_Install_package"));
|
|
106 |
this.panel = panel;
|
|
107 |
}
|
103 |
108 |
|
104 |
|
@Override
|
105 |
|
public synchronized void run() {
|
|
109 |
private void showWarning(final String msg) {
|
|
110 |
if( !SwingUtilities.isEventDispatchThread() ) {
|
|
111 |
try {
|
|
112 |
SwingUtilities.invokeAndWait(new Runnable() {
|
|
113 |
public void run() {
|
|
114 |
}
|
|
115 |
});
|
|
116 |
} catch (Exception ex) {
|
|
117 |
logger.warn("Cant show message to the user. "+msg);
|
|
118 |
}
|
|
119 |
return;
|
|
120 |
}
|
|
121 |
JOptionPane.showMessageDialog(panel, msg, "Warning", JOptionPane.WARNING_MESSAGE);
|
|
122 |
}
|
|
123 |
|
|
124 |
@Override
|
|
125 |
public synchronized void run() {
|
106 |
126 |
|
107 |
|
SimpleTaskStatus taskStatus = (SimpleTaskStatus) this
|
108 |
|
.getTaskStatus();
|
109 |
|
// bundle of packages
|
110 |
|
InstallPackageService installerExecutionService = this.panel.installerExecutionWizard
|
111 |
|
.getInstallerExecutionService();
|
112 |
|
// packages to install
|
113 |
|
List<PackageInfo> installersToInstall = this.panel.installerExecutionWizard
|
114 |
|
.getInstallersToInstall();
|
115 |
|
Collections.sort(installersToInstall, new Comparator<PackageInfo>() {
|
116 |
|
public int compare(PackageInfo o1, PackageInfo o2) {
|
117 |
|
return o1.getCode().compareTo(o2.getCode());
|
118 |
|
}
|
119 |
|
});
|
120 |
|
taskStatus.setRangeOfValues(0, installersToInstall.size());
|
121 |
|
try {
|
122 |
|
for (int i = 0; i < installersToInstall.size(); i++) {
|
123 |
|
PackageInfo installerInfo = installersToInstall.get(i);
|
124 |
|
taskStatus.message(installerInfo.getName());
|
125 |
|
installerExecutionService.installPackage(
|
126 |
|
panel.installerExecutionWizard
|
127 |
|
.getApplicationFolder(), installerInfo);
|
128 |
|
taskStatus.setCurValue(i + 1);
|
129 |
|
}
|
130 |
|
this.panel.installerExecutionWizard
|
131 |
|
.setFinishButtonVisible(true);
|
132 |
|
} catch (InstallPackageServiceException e) {
|
133 |
|
panel.showErrorMessage(panel.swingInstallerManager
|
134 |
|
.getText("_Cant_install_packege"), e);
|
135 |
|
}
|
136 |
|
// Set the finished text
|
137 |
|
taskStatus.message(panel.swingInstallerManager
|
138 |
|
.getText("_Finished"));
|
139 |
|
|
140 |
|
taskStatus.terminate();
|
141 |
|
taskStatus.remove();
|
|
127 |
int errcount = 0;
|
|
128 |
try {
|
|
129 |
logger.info("Package installation iniitiated");
|
|
130 |
SimpleTaskStatus taskStatus = (SimpleTaskStatus) this
|
|
131 |
.getTaskStatus();
|
|
132 |
// bundle of packages
|
|
133 |
InstallPackageService installerExecutionService = this.panel.installerExecutionWizard
|
|
134 |
.getInstallerExecutionService();
|
|
135 |
// packages to install
|
|
136 |
List<PackageInfo> installersToInstall = this.panel.installerExecutionWizard
|
|
137 |
.getInstallersToInstall();
|
|
138 |
Collections.sort(installersToInstall, new Comparator<PackageInfo>() {
|
|
139 |
public int compare(PackageInfo o1, PackageInfo o2) {
|
|
140 |
return o1.getCode().compareTo(o2.getCode());
|
|
141 |
}
|
|
142 |
});
|
|
143 |
taskStatus.setRangeOfValues(0, installersToInstall.size());
|
|
144 |
for ( int i = 0; i < installersToInstall.size(); i++ ) {
|
|
145 |
PackageInfo installerInfo = installersToInstall.get(i);
|
|
146 |
taskStatus.message(installerInfo.getName());
|
|
147 |
try {
|
|
148 |
installerExecutionService.installPackage(
|
|
149 |
panel.installerExecutionWizard.getApplicationFolder(),
|
|
150 |
installerInfo
|
|
151 |
);
|
|
152 |
} catch (Throwable th) {
|
|
153 |
logger.warn("Can't install package '" + installerInfo.getCode() + "'.", th);
|
|
154 |
errcount++;
|
|
155 |
}
|
|
156 |
taskStatus.setCurValue(i + 1);
|
|
157 |
}
|
|
158 |
this.panel.installerExecutionWizard.setFinishButtonVisible(true);
|
|
159 |
if( errcount>0 ) {
|
|
160 |
showWarning("Failed to install "+errcount+" packages.");
|
|
161 |
}
|
|
162 |
taskStatus.message(panel.swingInstallerManager.getText("_Finished"));
|
142 |
163 |
|
143 |
|
}
|
|
164 |
taskStatus.terminate();
|
|
165 |
taskStatus.remove();
|
|
166 |
logger.info("Package installation finished");
|
|
167 |
} catch (Throwable th) {
|
|
168 |
logger.warn("Problems install packages.",th);
|
|
169 |
showWarning(panel.swingInstallerManager.getText("_Cant_install_packege"));
|
|
170 |
}
|
144 |
171 |
|
145 |
|
}
|
|
172 |
}
|
|
173 |
|
|
174 |
}
|
146 |
175 |
}
|