Statistics
| Revision:

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
/* 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
import org.gvsig.installer.swing.impl.execution.panel.SelectPackagesPanel;
44
import org.gvsig.tools.swing.api.ToolsSwingLocator;
45
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
46
import org.slf4j.Logger;
47
import org.slf4j.LoggerFactory;
48

    
49
public class SelectPackagesWizard implements OptionPanel {
50

    
51
        private static final long serialVersionUID = -4678172923039393643L;
52

    
53
        private static Logger LOG = LoggerFactory
54
                        .getLogger(SelectPackagesWizard.class);
55

    
56
        protected DefaultInstallPackageWizard installerExecutionWizard;
57

    
58
        private SelectPackagesPanel selectPackagesPanel = null;
59
        private DefaultSwingInstallerManager swingInstallerManager = null;
60

    
61
        private int direccion = WizardPanelWithLogo.ACTION_NEXT;
62

    
63
        public SelectPackagesWizard(
64
                        DefaultInstallPackageWizard installerExecutionWizard) {
65
                super();
66
                this.installerExecutionWizard = installerExecutionWizard;
67
                selectPackagesPanel = new SelectPackagesPanel(this);
68

    
69
                swingInstallerManager = (DefaultSwingInstallerManager) SwingInstallerLocator
70
                                .getSwingInstallerManager();
71
        }
72

    
73
        public JPanel getJPanel() {
74
                return selectPackagesPanel;
75
        }
76

    
77
        public String getPanelTitle() {
78
                return swingInstallerManager.getText("_select_plugins");
79
        }
80

    
81
        public void lastPanel() {
82
                direccion = WizardPanelWithLogo.ACTION_NEXT;
83
                selectPackagesPanel.clearPanel();
84
        }
85

    
86
        public void nextPanel() throws NotContinueWizardException {
87
                checkDependencies();
88
                checkDevelAndUnoficialPackages();
89
                direccion = WizardPanelWithLogo.ACTION_PREVIOUS;
90
                installerExecutionWizard.setNextButtonEnabled(false);
91
        }
92

    
93
        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

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

    
107
                        // Le a?adimos los paquetes que ya hay instalados.
108

    
109
                        PackageInfo[] pkgs = swingInstallerManager.getInstallerManager()
110
                                        .getInstalledPackages();
111
                        calculator.addInstalledPackage(pkgs);
112

    
113
                        // Calculamos las dependencias
114
                        calculator.calculate();
115

    
116
                        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

    
146
                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

    
166
                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
                                                                        + " " +
173
                                                                        swingInstallerManager
174
                                    .getText("_do_you_want_to_continue_anyway")
175
                                                                        );
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
                                                                + " "
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
                selectPackagesPanel.setInitialFilter();
225

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

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

    
236
                checkIfPluginSelected();
237
        }
238

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

    
246
        public void saltaOno(InstallPackageService installerExecutionService) {
247

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

    
251
                boolean defaultPacketsExist = false;
252

    
253
                // 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

    
277
                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

    
292
                }
293

    
294
        }
295

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

    
300
        public DefaultInstallPackageWizard getDefaultInstallPackageWizard() {
301
                return this.installerExecutionWizard;
302
        }
303

    
304
        public Boolean isDefaultPackagesSelectionSet() {
305
                return installerExecutionWizard.getSelectDefaultPackages();
306
        }
307

    
308
}