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