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