Statistics
| Revision:

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 @ 37598

History | View | Annotate | Download (10.6 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.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.SelectPackagesPanel;
48
import org.gvsig.tools.swing.api.ToolsSwingLocator;
49
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
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
                checkDependencies();
90
                checkDevelAndUnoficialPackages();
91
                direccion = WizardPanelWithLogo.ACTION_PREVIOUS;
92
                installerExecutionWizard.setNextButtonEnabled(false);
93
        }
94

    
95
        private void checkDependencies() throws NotContinueWizardException {
96
                List<PackageInfo> requiredPackages = null;
97
                Dependencies unresolvedDependencies = null;
98
                try {
99
                        // Creamos el calculador de dependencias
100
                        DependenciesCalculator calculator = this.swingInstallerManager
101
                                        .getInstallerManager().createDependenciesCalculator(
102
                                                        installerExecutionWizard
103
                                                                        .getInstallerExecutionService());
104

    
105
                        // Le indicamos los paquetes que queremos instalar
106
                        calculator.addPackageToInstall(this.installerExecutionWizard
107
                                        .getInstallersToInstall());
108

    
109
                        // Le a?adimos los paquetes que ya hay instalados.
110

    
111
                        PackageInfo[] pkgs = swingInstallerManager.getInstallerManager()
112
                                        .getInstalledPackages(
113
                                                        installerExecutionWizard.getPluginsFolder());
114
                        calculator.addInstalledPackage(pkgs);
115

    
116
                        // Calculamos las dependencias
117
                        calculator.calculate();
118

    
119
                        requiredPackages = calculator.getRequiredPackages();
120
                        unresolvedDependencies = calculator.getUnresolvedDependencies();
121
                } catch (Throwable e) {
122
                        LOG
123
                                        .error(
124
                                                        swingInstallerManager
125
                                                                        .getText("_an_error_has_occurred_when_calculating_the_dependecies_of_the_packages_to_install"),
126
                                                        e);
127
                        int resp = JOptionPane
128
                                        .showConfirmDialog(
129
                                                        null,
130
                                                        swingInstallerManager
131
                                                                        .getText("_an_error_has_occurred_when_calculating_the_dependecies_of_the_selected_packages")
132
                                                                        + "\n"
133
                                                                        + swingInstallerManager
134
                                                                                        .getText("_it_is_not_possible_to_verify_if_any_additional_package_is_needed_to_install_the_selected_packages")
135
                                                                        + "\n"
136
                                                                        + swingInstallerManager
137
                                                                                        .getText("_if_you_want_you_can_select_again_manually_the_packets_that_might_be_necessary")
138
                                                                        + swingInstallerManager
139
                                                                                        .getText("_do_you_want_to_continue_and_install_the_packages_you_already_have_selected"),
140
                                                        swingInstallerManager
141
                                                                        .getText("_a_problem_has_occurred_when_calculating_the_dependencies"),
142
                                                        JOptionPane.YES_NO_OPTION,
143
                                                        JOptionPane.WARNING_MESSAGE);
144
                        if (resp == JOptionPane.NO_OPTION) {
145
                                throw new NotContinueWizardException("", null, false);
146
                        }
147
                }
148

    
149
                if (requiredPackages != null && requiredPackages.size() > 0) {
150
                        JShowRequiredPackagesAndAskContinuePanel dlg = this.swingInstallerManager
151
                                        .createJShowRequiredPackagesAndAskContinuePanel(
152
                                                        requiredPackages,
153
                                                        swingInstallerManager
154
                                                                        .getText("_the_selected_packages_require_to_install_or_update_the_following_packages")
155
                                                                        + "\n"
156
                                                                        + swingInstallerManager
157
                                                                                        .getText("_do_you_want_to_continue"));
158
                        if (dlg.needShow()) {
159
                                WindowManager wm = ToolsSwingLocator.getWindowManager();
160
                                wm.showWindow(dlg, swingInstallerManager
161
                                                .getText("_do_you_want_to_continue"),
162
                                                WindowManager.MODE.DIALOG);
163
                                if (dlg.cancelled()) {
164
                                        throw new NotContinueWizardException("", null, false);
165
                                }
166
                        }
167
                }
168

    
169
                if (unresolvedDependencies != null && unresolvedDependencies.size() > 0) {
170
                        JShowUnresolvedDependenciesAndAskContinuePanel dlg = this.swingInstallerManager
171
                                        .createJShowUnresolvedDependenciesAndAskContinuePanel(
172
                                                        unresolvedDependencies,
173
                                                        swingInstallerManager
174
                                                                        .getText("_the_following_dependencies_have_not_been_possible_to_resolve")
175
                                                                        + "\n" + "_do_you_want_to_continue_anyway");
176
                        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

    
187
                Iterator<PackageInfo> it = requiredPackages.iterator();
188
                while (it.hasNext()) {
189
                        selectPackagesPanel.getModel().selectPackage(it.next());
190
                        // pluginsTableModel.selectPackage(it.next());
191
                }
192
        }
193

    
194
        private void checkDevelAndUnoficialPackages()
195
                        throws NotContinueWizardException {
196
                List<PackageInfo> packagesToInstall = this.installerExecutionWizard
197
                                .getInstallersToInstall();
198

    
199
                JShowPackageStatusAndAskContinuePanel dlg = this.swingInstallerManager
200
                                .createJShowPackageStatusAndAskContinuePanel(
201
                                                packagesToInstall,
202
                                                swingInstallerManager
203
                                                                .getText("_you_have_selected_in_development_or_not_official_versions")
204
                                                                + "\n"
205
                                                                + 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

    
218
        public void updatePanel() {
219

    
220
                InstallPackageService installerExecutionService = installerExecutionWizard
221
                                .getInstallerExecutionService();
222

    
223
                selectPackagesPanel.updatePanel();
224

    
225
                // if default packages must be selected or not
226
                if (installerExecutionWizard.getSelectDefaultPackages()) {
227
                        selectPackagesPanel.selectPackages();
228
                }
229

    
230
                // if this panel has not to be shown
231
                if (!installerExecutionWizard.showSelectPackagesPanel()) {
232
                        saltaOno(installerExecutionService);
233
                }
234

    
235
                checkIfPluginSelected();
236
        }
237

    
238
        public void checkIfPluginSelected() {
239
                if (installerExecutionWizard.showSelectPackagesPanel()) {
240
                        installerExecutionWizard.setNextButtonEnabled(selectPackagesPanel
241
                                        .isPackageSelected());
242
                }
243
        }
244

    
245
        public void saltaOno(InstallPackageService installerExecutionService) {
246

    
247
                List<String> defaultPackageIDs = installerExecutionService
248
                                .getDefaultSelectedPackagesIDs();
249

    
250
                boolean defaultPacketsExist = false;
251

    
252
                // check if there is any default package
253
                if (defaultPackageIDs != null) {
254
                        for (int i = 0; i < installerExecutionService.getPackageCount(); i++) {
255
                                for (int j = 0; j < defaultPackageIDs.size(); j++) {
256
                                        // if the package is in the default packages list
257
                                        if (installerExecutionService.getPackageInfo(i).matchID(
258
                                                        defaultPackageIDs.get(j))) {
259
                                                // if package is for all operating systems or the system
260
                                                // operating system equals the project's one
261
                                                if (installerExecutionService.getPackageInfo(i)
262
                                                                .getOperatingSystem().equals("all")
263
                                                                || installerExecutionService.getPackageInfo(i)
264
                                                                                .getOperatingSystem().equals(
265
                                                                                                this.swingInstallerManager
266
                                                                                                                .getInstallerManager()
267
                                                                                                                .getOperatingSystem())) {
268
                                                        defaultPacketsExist = true;
269
                                                        break;
270
                                                }
271
                                        }
272
                                }
273
                        }
274
                }
275

    
276
                if (defaultPacketsExist) {
277
                        (installerExecutionWizard).doAction(direccion);
278
                        // if there is not any package, show error and jump back.
279
                } else {
280
                        (installerExecutionWizard)
281
                                        .doAction(WizardPanelWithLogo.ACTION_PREVIOUS);
282
                        try {
283
                                throw new Exception(
284
                                                swingInstallerManager
285
                                                                .getText("_There_are_no_packages_in_typical_installation_to_select"));
286
                        } catch (Exception e) {
287
                                // TODO Auto-generated catch block
288
                                e.printStackTrace();
289
                        }
290

    
291
                }
292

    
293
        }
294

    
295
        public List<PackageInfo> getPackagesToInstall() {
296
                return selectPackagesPanel.getPackagesToInstall();
297
        }
298

    
299
        public File getPluginsFolder() {
300
                return installerExecutionWizard.getPluginsFolder();
301
        }
302

    
303
        public DefaultInstallPackageWizard getDefaultInstallPackageWizard() {
304
                return this.installerExecutionWizard;
305
        }
306

    
307
        public Boolean isDefaultPackagesSelectionSet() {
308
                return installerExecutionWizard.getSelectDefaultPackages();
309
        }
310

    
311
}