root / branches / v2_0_0_prep / extensions / org.gvsig.installer / org.gvsig.installer.swing / org.gvsig.installer.swing.impl / src / main / java / org / gvsig / installer / swing / impl / execution / wizard / SelectPackagesWizard.java @ 38423
History | View | Annotate | Download (10.5 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 |
package org.gvsig.installer.swing.impl.execution.wizard; |
23 |
|
24 |
import java.util.Iterator; |
25 |
import java.util.List; |
26 |
|
27 |
import javax.swing.JOptionPane; |
28 |
import javax.swing.JPanel; |
29 |
|
30 |
import org.gvsig.gui.beans.wizard.WizardPanelWithLogo; |
31 |
import org.gvsig.gui.beans.wizard.panel.NotContinueWizardException; |
32 |
import org.gvsig.gui.beans.wizard.panel.OptionPanel; |
33 |
import org.gvsig.installer.lib.api.Dependencies; |
34 |
import org.gvsig.installer.lib.api.DependenciesCalculator; |
35 |
import org.gvsig.installer.lib.api.PackageInfo; |
36 |
import org.gvsig.installer.lib.api.execution.InstallPackageService; |
37 |
import org.gvsig.installer.swing.api.SwingInstallerLocator; |
38 |
import org.gvsig.installer.swing.api.execution.JShowPackageStatusAndAskContinuePanel; |
39 |
import org.gvsig.installer.swing.api.execution.JShowRequiredPackagesAndAskContinuePanel; |
40 |
import org.gvsig.installer.swing.api.execution.JShowUnresolvedDependenciesAndAskContinuePanel; |
41 |
import org.gvsig.installer.swing.impl.DefaultSwingInstallerManager; |
42 |
import org.gvsig.installer.swing.impl.execution.DefaultInstallPackageWizard; |
43 |
import org.gvsig.installer.swing.impl.execution.panel.SelectPackagesPanel; |
44 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
45 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
46 |
import org.slf4j.Logger; |
47 |
import org.slf4j.LoggerFactory; |
48 |
|
49 |
public class SelectPackagesWizard implements OptionPanel { |
50 |
|
51 |
private static final long serialVersionUID = -4678172923039393643L; |
52 |
|
53 |
private static Logger LOG = LoggerFactory |
54 |
.getLogger(SelectPackagesWizard.class); |
55 |
|
56 |
protected DefaultInstallPackageWizard installerExecutionWizard;
|
57 |
|
58 |
private SelectPackagesPanel selectPackagesPanel = null; |
59 |
private DefaultSwingInstallerManager swingInstallerManager = null; |
60 |
|
61 |
private int direccion = WizardPanelWithLogo.ACTION_NEXT; |
62 |
|
63 |
public SelectPackagesWizard(
|
64 |
DefaultInstallPackageWizard installerExecutionWizard) { |
65 |
super();
|
66 |
this.installerExecutionWizard = installerExecutionWizard;
|
67 |
selectPackagesPanel = new SelectPackagesPanel(this); |
68 |
|
69 |
swingInstallerManager = (DefaultSwingInstallerManager) SwingInstallerLocator |
70 |
.getSwingInstallerManager(); |
71 |
} |
72 |
|
73 |
public JPanel getJPanel() { |
74 |
return selectPackagesPanel;
|
75 |
} |
76 |
|
77 |
public String getPanelTitle() { |
78 |
return swingInstallerManager.getText("_select_plugins"); |
79 |
} |
80 |
|
81 |
public void lastPanel() { |
82 |
direccion = WizardPanelWithLogo.ACTION_NEXT; |
83 |
selectPackagesPanel.clearPanel(); |
84 |
} |
85 |
|
86 |
public void nextPanel() throws NotContinueWizardException { |
87 |
checkDependencies(); |
88 |
checkDevelAndUnoficialPackages(); |
89 |
direccion = WizardPanelWithLogo.ACTION_PREVIOUS; |
90 |
installerExecutionWizard.setNextButtonEnabled(false);
|
91 |
} |
92 |
|
93 |
private void checkDependencies() throws NotContinueWizardException { |
94 |
List<PackageInfo> requiredPackages = null; |
95 |
Dependencies unresolvedDependencies = null;
|
96 |
try {
|
97 |
// Creamos el calculador de dependencias
|
98 |
DependenciesCalculator calculator = this.swingInstallerManager
|
99 |
.getInstallerManager().createDependenciesCalculator( |
100 |
installerExecutionWizard |
101 |
.getInstallerExecutionService()); |
102 |
|
103 |
// Le indicamos los paquetes que queremos instalar
|
104 |
calculator.addPackageToInstall(this.installerExecutionWizard
|
105 |
.getInstallersToInstall()); |
106 |
|
107 |
// Le a?adimos los paquetes que ya hay instalados.
|
108 |
|
109 |
PackageInfo[] pkgs = swingInstallerManager.getInstallerManager()
|
110 |
.getInstalledPackages(); |
111 |
calculator.addInstalledPackage(pkgs); |
112 |
|
113 |
// Calculamos las dependencias
|
114 |
calculator.calculate(); |
115 |
|
116 |
requiredPackages = calculator.getRequiredPackages(); |
117 |
unresolvedDependencies = calculator.getUnresolvedDependencies(); |
118 |
} catch (Throwable e) { |
119 |
LOG |
120 |
.error( |
121 |
swingInstallerManager |
122 |
.getText("_an_error_has_occurred_when_calculating_the_dependecies_of_the_packages_to_install"),
|
123 |
e); |
124 |
int resp = JOptionPane |
125 |
.showConfirmDialog( |
126 |
null,
|
127 |
swingInstallerManager |
128 |
.getText("_an_error_has_occurred_when_calculating_the_dependecies_of_the_selected_packages")
|
129 |
+ "\n"
|
130 |
+ swingInstallerManager |
131 |
.getText("_it_is_not_possible_to_verify_if_any_additional_package_is_needed_to_install_the_selected_packages")
|
132 |
+ "\n"
|
133 |
+ swingInstallerManager |
134 |
.getText("_if_you_want_you_can_select_again_manually_the_packets_that_might_be_necessary")
|
135 |
+ swingInstallerManager |
136 |
.getText("_do_you_want_to_continue_and_install_the_packages_you_already_have_selected"),
|
137 |
swingInstallerManager |
138 |
.getText("_a_problem_has_occurred_when_calculating_the_dependencies"),
|
139 |
JOptionPane.YES_NO_OPTION,
|
140 |
JOptionPane.WARNING_MESSAGE);
|
141 |
if (resp == JOptionPane.NO_OPTION) { |
142 |
throw new NotContinueWizardException("", null, false); |
143 |
} |
144 |
} |
145 |
|
146 |
if (requiredPackages != null && requiredPackages.size() > 0) { |
147 |
JShowRequiredPackagesAndAskContinuePanel dlg = this.swingInstallerManager
|
148 |
.createJShowRequiredPackagesAndAskContinuePanel( |
149 |
requiredPackages, |
150 |
swingInstallerManager |
151 |
.getText("_the_selected_packages_require_to_install_or_update_the_following_packages")
|
152 |
+ "\n"
|
153 |
+ swingInstallerManager |
154 |
.getText("_do_you_want_to_continue"));
|
155 |
if (dlg.needShow()) {
|
156 |
WindowManager wm = ToolsSwingLocator.getWindowManager(); |
157 |
wm.showWindow(dlg, swingInstallerManager |
158 |
.getText("_do_you_want_to_continue"),
|
159 |
WindowManager.MODE.DIALOG); |
160 |
if (dlg.cancelled()) {
|
161 |
throw new NotContinueWizardException("", null, false); |
162 |
} |
163 |
} |
164 |
} |
165 |
|
166 |
if (unresolvedDependencies != null && unresolvedDependencies.size() > 0) { |
167 |
JShowUnresolvedDependenciesAndAskContinuePanel dlg = this.swingInstallerManager
|
168 |
.createJShowUnresolvedDependenciesAndAskContinuePanel( |
169 |
unresolvedDependencies, |
170 |
swingInstallerManager |
171 |
.getText("_the_following_dependencies_have_not_been_possible_to_resolve")
|
172 |
+ "\n" + "_do_you_want_to_continue_anyway"); |
173 |
if (dlg.needShow()) {
|
174 |
WindowManager wm = ToolsSwingLocator.getWindowManager(); |
175 |
wm.showWindow(dlg, swingInstallerManager |
176 |
.getText("_do_you_want_to_continue"),
|
177 |
WindowManager.MODE.DIALOG); |
178 |
if (dlg.cancelled()) {
|
179 |
throw new NotContinueWizardException("", null, false); |
180 |
} |
181 |
} |
182 |
} |
183 |
|
184 |
Iterator<PackageInfo> it = requiredPackages.iterator();
|
185 |
while (it.hasNext()) {
|
186 |
selectPackagesPanel.getModel().selectPackage(it.next()); |
187 |
// pluginsTableModel.selectPackage(it.next());
|
188 |
} |
189 |
} |
190 |
|
191 |
private void checkDevelAndUnoficialPackages() |
192 |
throws NotContinueWizardException {
|
193 |
List<PackageInfo> packagesToInstall = this.installerExecutionWizard |
194 |
.getInstallersToInstall(); |
195 |
|
196 |
JShowPackageStatusAndAskContinuePanel dlg = this.swingInstallerManager
|
197 |
.createJShowPackageStatusAndAskContinuePanel( |
198 |
packagesToInstall, |
199 |
swingInstallerManager |
200 |
.getText("_you_have_selected_in_development_or_not_official_versions")
|
201 |
+ "\n"
|
202 |
+ swingInstallerManager |
203 |
.getText("_do_you_want_to_continue"));
|
204 |
if (dlg.needShow()) {
|
205 |
WindowManager wm = ToolsSwingLocator.getWindowManager(); |
206 |
wm.showWindow(dlg, swingInstallerManager |
207 |
.getText("_do_you_want_to_continue"),
|
208 |
WindowManager.MODE.DIALOG); |
209 |
if (dlg.cancelled()) {
|
210 |
throw new NotContinueWizardException("", null, false); |
211 |
} |
212 |
} |
213 |
} |
214 |
|
215 |
public void updatePanel() { |
216 |
|
217 |
InstallPackageService installerExecutionService = installerExecutionWizard |
218 |
.getInstallerExecutionService(); |
219 |
|
220 |
selectPackagesPanel.updatePanel(); |
221 |
selectPackagesPanel.setInitialFilter(); |
222 |
|
223 |
// if default packages must be selected or not
|
224 |
if (installerExecutionWizard.getSelectDefaultPackages()) {
|
225 |
selectPackagesPanel.selectPackages(); |
226 |
} |
227 |
|
228 |
// if this panel has not to be shown
|
229 |
if (!installerExecutionWizard.showSelectPackagesPanel()) {
|
230 |
saltaOno(installerExecutionService); |
231 |
} |
232 |
|
233 |
checkIfPluginSelected(); |
234 |
} |
235 |
|
236 |
public void checkIfPluginSelected() { |
237 |
if (installerExecutionWizard.showSelectPackagesPanel()) {
|
238 |
installerExecutionWizard.setNextButtonEnabled(selectPackagesPanel |
239 |
.isPackageSelected()); |
240 |
} |
241 |
} |
242 |
|
243 |
public void saltaOno(InstallPackageService installerExecutionService) { |
244 |
|
245 |
List<String> defaultPackageIDs = installerExecutionService |
246 |
.getDefaultSelectedPackagesIDs(); |
247 |
|
248 |
boolean defaultPacketsExist = false; |
249 |
|
250 |
// check if there is any default package
|
251 |
if (defaultPackageIDs != null) { |
252 |
for (int i = 0; i < installerExecutionService.getPackageCount(); i++) { |
253 |
for (int j = 0; j < defaultPackageIDs.size(); j++) { |
254 |
// if the package is in the default packages list
|
255 |
if (installerExecutionService.getPackageInfo(i).matchID(
|
256 |
defaultPackageIDs.get(j))) { |
257 |
// if package is for all operating systems or the system
|
258 |
// operating system equals the project's one
|
259 |
if (installerExecutionService.getPackageInfo(i)
|
260 |
.getOperatingSystem().equals("all")
|
261 |
|| installerExecutionService.getPackageInfo(i) |
262 |
.getOperatingSystem().equals( |
263 |
this.swingInstallerManager
|
264 |
.getInstallerManager() |
265 |
.getOperatingSystem())) { |
266 |
defaultPacketsExist = true;
|
267 |
break;
|
268 |
} |
269 |
} |
270 |
} |
271 |
} |
272 |
} |
273 |
|
274 |
if (defaultPacketsExist) {
|
275 |
(installerExecutionWizard).doAction(direccion); |
276 |
// if there is not any package, show error and jump back.
|
277 |
} else {
|
278 |
(installerExecutionWizard) |
279 |
.doAction(WizardPanelWithLogo.ACTION_PREVIOUS); |
280 |
try {
|
281 |
throw new Exception( |
282 |
swingInstallerManager |
283 |
.getText("_There_are_no_packages_in_typical_installation_to_select"));
|
284 |
} catch (Exception e) { |
285 |
// TODO Auto-generated catch block
|
286 |
e.printStackTrace(); |
287 |
} |
288 |
|
289 |
} |
290 |
|
291 |
} |
292 |
|
293 |
public List<PackageInfo> getPackagesToInstall() { |
294 |
return selectPackagesPanel.getPackagesToInstall();
|
295 |
} |
296 |
|
297 |
public DefaultInstallPackageWizard getDefaultInstallPackageWizard() {
|
298 |
return this.installerExecutionWizard; |
299 |
} |
300 |
|
301 |
public Boolean isDefaultPackagesSelectionSet() { |
302 |
return installerExecutionWizard.getSelectDefaultPackages();
|
303 |
} |
304 |
|
305 |
} |