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