root / tags / v2_0_0_Build_2050 / 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 @ 38692
History | View | Annotate | Download (10.6 KB)
1 | 37538 | nfrancisco | /* 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 | 37539 | nfrancisco | import org.gvsig.installer.swing.impl.execution.panel.SelectPackagesPanel; |
44 | 37538 | nfrancisco | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
45 | import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
||
46 | 37822 | nfrancisco | import org.slf4j.Logger; |
47 | import org.slf4j.LoggerFactory; |
||
48 | 37538 | nfrancisco | |
49 | 37539 | nfrancisco | public class SelectPackagesWizard implements OptionPanel { |
50 | 37538 | nfrancisco | |
51 | 37598 | nfrancisco | private static final long serialVersionUID = -4678172923039393643L; |
52 | 37538 | nfrancisco | |
53 | 37598 | nfrancisco | private static Logger LOG = LoggerFactory |
54 | .getLogger(SelectPackagesWizard.class); |
||
55 | 37538 | nfrancisco | |
56 | 37598 | nfrancisco | protected DefaultInstallPackageWizard installerExecutionWizard;
|
57 | 37538 | nfrancisco | |
58 | 37598 | nfrancisco | private SelectPackagesPanel selectPackagesPanel = null; |
59 | private DefaultSwingInstallerManager swingInstallerManager = null; |
||
60 | 37538 | nfrancisco | |
61 | 37598 | nfrancisco | private int direccion = WizardPanelWithLogo.ACTION_NEXT; |
62 | 37538 | nfrancisco | |
63 | 37598 | nfrancisco | public SelectPackagesWizard(
|
64 | DefaultInstallPackageWizard installerExecutionWizard) { |
||
65 | super();
|
||
66 | this.installerExecutionWizard = installerExecutionWizard;
|
||
67 | selectPackagesPanel = new SelectPackagesPanel(this); |
||
68 | 37538 | nfrancisco | |
69 | 37598 | nfrancisco | swingInstallerManager = (DefaultSwingInstallerManager) SwingInstallerLocator |
70 | .getSwingInstallerManager(); |
||
71 | } |
||
72 | 37538 | nfrancisco | |
73 | 37598 | nfrancisco | public JPanel getJPanel() { |
74 | return selectPackagesPanel;
|
||
75 | } |
||
76 | 37538 | nfrancisco | |
77 | 37598 | nfrancisco | public String getPanelTitle() { |
78 | return swingInstallerManager.getText("_select_plugins"); |
||
79 | } |
||
80 | 37538 | nfrancisco | |
81 | 37598 | nfrancisco | public void lastPanel() { |
82 | direccion = WizardPanelWithLogo.ACTION_NEXT; |
||
83 | selectPackagesPanel.clearPanel(); |
||
84 | } |
||
85 | 37538 | nfrancisco | |
86 | 37598 | nfrancisco | public void nextPanel() throws NotContinueWizardException { |
87 | checkDependencies(); |
||
88 | checkDevelAndUnoficialPackages(); |
||
89 | direccion = WizardPanelWithLogo.ACTION_PREVIOUS; |
||
90 | installerExecutionWizard.setNextButtonEnabled(false);
|
||
91 | } |
||
92 | 37538 | nfrancisco | |
93 | 37598 | nfrancisco | 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 | 37538 | nfrancisco | |
103 | 37598 | nfrancisco | // Le indicamos los paquetes que queremos instalar
|
104 | calculator.addPackageToInstall(this.installerExecutionWizard
|
||
105 | .getInstallersToInstall()); |
||
106 | 37538 | nfrancisco | |
107 | 37598 | nfrancisco | // Le a?adimos los paquetes que ya hay instalados.
|
108 | 37538 | nfrancisco | |
109 | 37598 | nfrancisco | PackageInfo[] pkgs = swingInstallerManager.getInstallerManager()
|
110 | 37822 | nfrancisco | .getInstalledPackages(); |
111 | 37598 | nfrancisco | calculator.addInstalledPackage(pkgs); |
112 | 37538 | nfrancisco | |
113 | 37598 | nfrancisco | // Calculamos las dependencias
|
114 | calculator.calculate(); |
||
115 | 37538 | nfrancisco | |
116 | 37598 | nfrancisco | 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 | 37538 | nfrancisco | |
146 | 37598 | nfrancisco | 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 | 37538 | nfrancisco | |
166 | 37598 | nfrancisco | 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 | 38432 | jldominguez | + " " +
|
173 | swingInstallerManager |
||
174 | .getText("_do_you_want_to_continue_anyway")
|
||
175 | ); |
||
176 | 37598 | nfrancisco | if (dlg.needShow()) {
|
177 | WindowManager wm = ToolsSwingLocator.getWindowManager(); |
||
178 | wm.showWindow(dlg, swingInstallerManager |
||
179 | .getText("_do_you_want_to_continue"),
|
||
180 | WindowManager.MODE.DIALOG); |
||
181 | if (dlg.cancelled()) {
|
||
182 | throw new NotContinueWizardException("", null, false); |
||
183 | } |
||
184 | } |
||
185 | } |
||
186 | 37538 | nfrancisco | |
187 | 37598 | nfrancisco | Iterator<PackageInfo> it = requiredPackages.iterator();
|
188 | while (it.hasNext()) {
|
||
189 | selectPackagesPanel.getModel().selectPackage(it.next()); |
||
190 | // pluginsTableModel.selectPackage(it.next());
|
||
191 | } |
||
192 | } |
||
193 | 37538 | nfrancisco | |
194 | 37598 | nfrancisco | private void checkDevelAndUnoficialPackages() |
195 | throws NotContinueWizardException {
|
||
196 | List<PackageInfo> packagesToInstall = this.installerExecutionWizard |
||
197 | .getInstallersToInstall(); |
||
198 | 37538 | nfrancisco | |
199 | 37598 | nfrancisco | JShowPackageStatusAndAskContinuePanel dlg = this.swingInstallerManager
|
200 | .createJShowPackageStatusAndAskContinuePanel( |
||
201 | packagesToInstall, |
||
202 | swingInstallerManager |
||
203 | .getText("_you_have_selected_in_development_or_not_official_versions")
|
||
204 | 38432 | jldominguez | + " "
|
205 | 37598 | nfrancisco | + swingInstallerManager |
206 | .getText("_do_you_want_to_continue"));
|
||
207 | if (dlg.needShow()) {
|
||
208 | WindowManager wm = ToolsSwingLocator.getWindowManager(); |
||
209 | wm.showWindow(dlg, swingInstallerManager |
||
210 | .getText("_do_you_want_to_continue"),
|
||
211 | WindowManager.MODE.DIALOG); |
||
212 | if (dlg.cancelled()) {
|
||
213 | throw new NotContinueWizardException("", null, false); |
||
214 | } |
||
215 | } |
||
216 | } |
||
217 | 37538 | nfrancisco | |
218 | 37598 | nfrancisco | public void updatePanel() { |
219 | 37538 | nfrancisco | |
220 | 37598 | nfrancisco | InstallPackageService installerExecutionService = installerExecutionWizard |
221 | .getInstallerExecutionService(); |
||
222 | 37538 | nfrancisco | |
223 | 37598 | nfrancisco | selectPackagesPanel.updatePanel(); |
224 | 38423 | jldominguez | selectPackagesPanel.setInitialFilter(); |
225 | 37538 | nfrancisco | |
226 | 37598 | nfrancisco | // if default packages must be selected or not
|
227 | if (installerExecutionWizard.getSelectDefaultPackages()) {
|
||
228 | selectPackagesPanel.selectPackages(); |
||
229 | } |
||
230 | 37538 | nfrancisco | |
231 | 37598 | nfrancisco | // if this panel has not to be shown
|
232 | if (!installerExecutionWizard.showSelectPackagesPanel()) {
|
||
233 | saltaOno(installerExecutionService); |
||
234 | } |
||
235 | 37538 | nfrancisco | |
236 | 37598 | nfrancisco | checkIfPluginSelected(); |
237 | } |
||
238 | 37538 | nfrancisco | |
239 | 37598 | nfrancisco | public void checkIfPluginSelected() { |
240 | if (installerExecutionWizard.showSelectPackagesPanel()) {
|
||
241 | installerExecutionWizard.setNextButtonEnabled(selectPackagesPanel |
||
242 | .isPackageSelected()); |
||
243 | } |
||
244 | } |
||
245 | 37538 | nfrancisco | |
246 | 37598 | nfrancisco | public void saltaOno(InstallPackageService installerExecutionService) { |
247 | 37538 | nfrancisco | |
248 | 37598 | nfrancisco | List<String> defaultPackageIDs = installerExecutionService |
249 | .getDefaultSelectedPackagesIDs(); |
||
250 | 37538 | nfrancisco | |
251 | 37598 | nfrancisco | boolean defaultPacketsExist = false; |
252 | 37538 | nfrancisco | |
253 | 37598 | nfrancisco | // check if there is any default package
|
254 | if (defaultPackageIDs != null) { |
||
255 | for (int i = 0; i < installerExecutionService.getPackageCount(); i++) { |
||
256 | for (int j = 0; j < defaultPackageIDs.size(); j++) { |
||
257 | // if the package is in the default packages list
|
||
258 | if (installerExecutionService.getPackageInfo(i).matchID(
|
||
259 | defaultPackageIDs.get(j))) { |
||
260 | // if package is for all operating systems or the system
|
||
261 | // operating system equals the project's one
|
||
262 | if (installerExecutionService.getPackageInfo(i)
|
||
263 | .getOperatingSystem().equals("all")
|
||
264 | || installerExecutionService.getPackageInfo(i) |
||
265 | .getOperatingSystem().equals( |
||
266 | this.swingInstallerManager
|
||
267 | .getInstallerManager() |
||
268 | .getOperatingSystem())) { |
||
269 | defaultPacketsExist = true;
|
||
270 | break;
|
||
271 | } |
||
272 | } |
||
273 | } |
||
274 | } |
||
275 | } |
||
276 | 37538 | nfrancisco | |
277 | 37598 | nfrancisco | if (defaultPacketsExist) {
|
278 | (installerExecutionWizard).doAction(direccion); |
||
279 | // if there is not any package, show error and jump back.
|
||
280 | } else {
|
||
281 | (installerExecutionWizard) |
||
282 | .doAction(WizardPanelWithLogo.ACTION_PREVIOUS); |
||
283 | try {
|
||
284 | throw new Exception( |
||
285 | swingInstallerManager |
||
286 | .getText("_There_are_no_packages_in_typical_installation_to_select"));
|
||
287 | } catch (Exception e) { |
||
288 | // TODO Auto-generated catch block
|
||
289 | e.printStackTrace(); |
||
290 | } |
||
291 | 37538 | nfrancisco | |
292 | 37598 | nfrancisco | } |
293 | 37538 | nfrancisco | |
294 | 37598 | nfrancisco | } |
295 | 37538 | nfrancisco | |
296 | 37598 | nfrancisco | public List<PackageInfo> getPackagesToInstall() { |
297 | return selectPackagesPanel.getPackagesToInstall();
|
||
298 | } |
||
299 | 37538 | nfrancisco | |
300 | 37598 | nfrancisco | public DefaultInstallPackageWizard getDefaultInstallPackageWizard() {
|
301 | return this.installerExecutionWizard; |
||
302 | } |
||
303 | 37550 | nfrancisco | |
304 | 37598 | nfrancisco | public Boolean isDefaultPackagesSelectionSet() { |
305 | return installerExecutionWizard.getSelectDefaultPackages();
|
||
306 | } |
||
307 | |||
308 | 37538 | nfrancisco | } |