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 | 40560 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40560 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | *
|
||
6 | 40435 | jjdelcerro | * This program is free software; you can redistribute it and/or
|
7 | * modify it under the terms of the GNU General Public License
|
||
8 | 40560 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * of the License, or (at your option) any later version.
|
10 | 40560 | jjdelcerro | *
|
11 | 40435 | jjdelcerro | * This program is distributed in the hope that it will be useful,
|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | 41718 | jjdelcerro | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 40435 | jjdelcerro | * GNU General Public License for more details.
|
15 | 40560 | jjdelcerro | *
|
16 | 40435 | jjdelcerro | * 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 | 40560 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | 41718 | jjdelcerro | * MA 02110-1301, USA.
|
20 | 40560 | jjdelcerro | *
|
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 | 40435 | jjdelcerro | */
|
24 | /*
|
||
25 | * AUTHORS (In addition to CIT):
|
||
26 | * 2010 {Prodevelop} {Task}
|
||
27 | */
|
||
28 | package org.gvsig.installer.swing.impl.execution.wizard; |
||
29 | |||
30 | 40991 | jjdelcerro | import java.util.Collections; |
31 | import java.util.Comparator; |
||
32 | 40435 | jjdelcerro | import java.util.List; |
33 | 41718 | jjdelcerro | import javax.swing.JOptionPane; |
34 | 40435 | jjdelcerro | |
35 | import javax.swing.JPanel; |
||
36 | 41718 | jjdelcerro | import javax.swing.SwingUtilities; |
37 | 40435 | jjdelcerro | |
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 | 43126 | jjdelcerro | import org.gvsig.installer.swing.impl.execution.InstallWizardPanel_ext; |
42 | 40435 | jjdelcerro | 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 | 43126 | jjdelcerro | public class ProgressWizardPage extends DefaultProgressPanel implements OptionPanel { |
48 | |||
49 | 41718 | jjdelcerro | private static final long serialVersionUID = 8531884535246881448L; |
50 | 43126 | jjdelcerro | private final InstallWizardPanel_ext wizardPanel; |
51 | 40435 | jjdelcerro | |
52 | 43126 | jjdelcerro | public ProgressWizardPage(InstallWizardPanel_ext wizardPanel) {
|
53 | 41718 | jjdelcerro | super();
|
54 | 43126 | jjdelcerro | this.wizardPanel = wizardPanel;
|
55 | 41718 | jjdelcerro | } |
56 | 40435 | jjdelcerro | |
57 | 43126 | jjdelcerro | @Override
|
58 | 41718 | jjdelcerro | public JPanel getJPanel() { |
59 | return this; |
||
60 | } |
||
61 | 40435 | jjdelcerro | |
62 | 43126 | jjdelcerro | @Override
|
63 | 41718 | jjdelcerro | public String getPanelTitle() { |
64 | 43126 | jjdelcerro | return wizardPanel.getTranslation("_progress"); |
65 | 41718 | jjdelcerro | } |
66 | 40435 | jjdelcerro | |
67 | 43126 | jjdelcerro | @Override
|
68 | 41718 | jjdelcerro | public void lastPanel() { |
69 | 43126 | jjdelcerro | wizardPanel.setFinishButtonEnabled(false);
|
70 | wizardPanel.setCancelButtonEnabled(true);
|
||
71 | 41718 | jjdelcerro | } |
72 | 40435 | jjdelcerro | |
73 | 43126 | jjdelcerro | @Override
|
74 | 41718 | jjdelcerro | public void nextPanel() { |
75 | // Nothing to do, no next panel
|
||
76 | } |
||
77 | 40435 | jjdelcerro | |
78 | 43126 | jjdelcerro | @Override
|
79 | 41718 | jjdelcerro | public void updatePanel() { |
80 | 43126 | jjdelcerro | wizardPanel.setFinishButtonEnabled(false);
|
81 | wizardPanel.setCancelButtonEnabled(false);
|
||
82 | 40435 | jjdelcerro | |
83 | 43126 | jjdelcerro | final ProgressWizardPage wizard = this; |
84 | 40435 | jjdelcerro | |
85 | 41718 | jjdelcerro | UpdatePanel task = new UpdatePanel(wizard);
|
86 | 43126 | jjdelcerro | wizard.wizardPanel.addCancellableTask(task); |
87 | 41718 | jjdelcerro | bind(task.getTaskStatus()); |
88 | task.setDaemon(true);
|
||
89 | task.start(); |
||
90 | } |
||
91 | 40435 | jjdelcerro | |
92 | 41718 | jjdelcerro | private static class UpdatePanel extends AbstractMonitorableTask { |
93 | 40435 | jjdelcerro | |
94 | 43126 | jjdelcerro | private final ProgressWizardPage panel; |
95 | 40435 | jjdelcerro | |
96 | 43126 | jjdelcerro | public UpdatePanel(ProgressWizardPage panel) {
|
97 | super(panel.wizardPanel.getTranslation("_Install_package")); |
||
98 | 41718 | jjdelcerro | this.panel = panel;
|
99 | } |
||
100 | 40435 | jjdelcerro | |
101 | 41718 | jjdelcerro | 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 | 40435 | jjdelcerro | |
119 | 41718 | jjdelcerro | int errcount = 0; |
120 | try {
|
||
121 | logger.info("Package installation iniitiated");
|
||
122 | 43126 | jjdelcerro | SimpleTaskStatus taskStatus = (SimpleTaskStatus) this.getTaskStatus();
|
123 | 41718 | jjdelcerro | // bundle of packages
|
124 | 43126 | jjdelcerro | InstallPackageService installerExecutionService = this.panel.wizardPanel
|
125 | 41718 | jjdelcerro | .getInstallerExecutionService(); |
126 | // packages to install
|
||
127 | 43126 | jjdelcerro | List<PackageInfo> installersToInstall = this.panel.wizardPanel |
128 | .getPackagesToInstall(); |
||
129 | 41718 | jjdelcerro | 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 | 43126 | jjdelcerro | panel.wizardPanel.getApplicationFolder(), |
141 | 41718 | jjdelcerro | 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 | 43126 | jjdelcerro | this.panel.wizardPanel.setFinishButtonEnabled(true); |
150 | 41718 | jjdelcerro | if( errcount>0 ) { |
151 | showWarning("Failed to install "+errcount+" packages."); |
||
152 | } |
||
153 | 43126 | jjdelcerro | taskStatus.message(panel.wizardPanel.getTranslation("_Finished"));
|
154 | 40435 | jjdelcerro | |
155 | 41718 | jjdelcerro | taskStatus.terminate(); |
156 | taskStatus.remove(); |
||
157 | logger.info("Package installation finished");
|
||
158 | } catch (Throwable th) { |
||
159 | logger.warn("Problems install packages.",th);
|
||
160 | 43126 | jjdelcerro | showWarning(panel.wizardPanel.getTranslation("_Cant_install_packege"));
|
161 | 41718 | jjdelcerro | } |
162 | 40435 | jjdelcerro | |
163 | 41718 | jjdelcerro | } |
164 | |||
165 | } |
||
166 | 40435 | jjdelcerro | } |