Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.installer / org.gvsig.installer.swing / org.gvsig.installer.swing.impl / src / main / java / org / gvsig / installer / swing / impl / execution / wizard / SelectPackagesWizardPage.java @ 43126

History | View | Annotate | Download (11.8 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License as published by the Free Software
8
 * Foundation; either version 3 of the License, or (at your option) any later
9
 * version.
10
 *
11
 * This program is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
 * details.
15
 *
16
 * You should have received a copy of the GNU General Public License along with
17
 * this program; if not, write to the Free Software Foundation, Inc., 51
18
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.installer.swing.impl.execution.wizard;
24

    
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.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.InstallerLocator;
36
import org.gvsig.installer.lib.api.InstallerManager;
37
import org.gvsig.installer.lib.api.PackageInfo;
38
import org.gvsig.installer.swing.api.SwingInstallerLocator;
39
import org.gvsig.installer.swing.api.SwingInstallerManager;
40
import org.gvsig.installer.swing.api.execution.JShowPackageStatusAndAskContinuePanel;
41
import org.gvsig.installer.swing.api.execution.JShowPackagesAndAskContinuePanel;
42
import org.gvsig.installer.swing.api.execution.JShowRequiredPackagesAndAskContinuePanel;
43
import org.gvsig.installer.swing.api.execution.JShowUnresolvedDependenciesAndAskContinuePanel;
44
import org.gvsig.installer.swing.api.execution.PackageFilter;
45
import org.gvsig.installer.swing.impl.execution.InstallWizardPanel_ext;
46
import org.gvsig.installer.swing.impl.execution.panel.SelectPackagesPanel;
47
import org.gvsig.tools.swing.api.ToolsSwingLocator;
48
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
49
import org.slf4j.Logger;
50
import org.slf4j.LoggerFactory;
51

    
52
public class SelectPackagesWizardPage implements OptionPanel {
53

    
54
    private static final long serialVersionUID = -4678172923039393643L;
55

    
56
    private static final Logger LOG = LoggerFactory.getLogger(SelectPackagesWizardPage.class);
57

    
58
    private final InstallWizardPanel_ext wizardPanel;
59

    
60
    private SelectPackagesPanel selectPackagesPanel = null;
61

    
62
    public SelectPackagesWizardPage(
63
            InstallWizardPanel_ext wizardPanel) {
64
        super();
65
        this.wizardPanel = wizardPanel;
66
        this.selectPackagesPanel = new SelectPackagesPanel(this);
67
    }
68
    
69
    @Override
70
    public JPanel getJPanel() {
71
        return selectPackagesPanel;
72
    }
73

    
74
    @Override
75
    public String getPanelTitle() {
76
        return wizardPanel.getTranslation("_select_plugins");
77
    }
78

    
79
    @Override
80
    public void lastPanel() {
81
        selectPackagesPanel.clearPanel();
82
    }
83

    
84
    @Override
85
    public void nextPanel() throws NotContinueWizardException {
86
        SwingInstallerManager swingManager = SwingInstallerLocator.getSwingInstallerManager();
87
        /*
88
         * First warn about packages in development or unofficial
89
         */
90
        checkDevelAndUnoficialPackages(swingManager);
91
        /*
92
         * Then check dependencies
93
         */
94
        checkDependencies(swingManager);
95
        wizardPanel.setNextButtonEnabled(false);
96
    }
97

    
98
    private void checkDependencies(SwingInstallerManager swingManager) throws NotContinueWizardException {
99
        List<PackageInfo> requiredPackages = null;
100
        List<PackageInfo> troubledPackages = null;
101
        Dependencies unresolvedDependencies = null;
102
        try {
103
            InstallerManager manager = InstallerLocator.getInstallerManager();
104
            // Creamos el calculador de dependencias
105
            DependenciesCalculator calculator = manager.createDependenciesCalculator(
106
                wizardPanel.getInstallerExecutionService()
107
            );
108

    
109
            // Le indicamos los paquetes que queremos instalar
110
            calculator.addPackageToInstall(
111
                    this.wizardPanel.getPackagesToInstall()
112
            );
113

    
114
            // Le a?adimos los paquetes que ya hay instalados.
115
            PackageInfo[] pkgs = manager.getInstalledPackages();
116
            calculator.addInstalledPackage(pkgs);
117

    
118
            // Calculamos las dependencias
119
            calculator.calculate();
120

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

    
146
        if (troubledPackages != null && troubledPackages.size() > 0) {
147
            JShowPackagesAndAskContinuePanel dlg = swingManager
148
                    .createJShowTroubledPackagesAndAskContinuePanel(
149
                            troubledPackages,
150
                            wizardPanel.getTranslation("_Some_of_the_selected_addons_should_not_be_installed_simultaneously")
151
                            + ". "
152
                            + wizardPanel.getTranslation("_Installing_these_addons_may_cause_errors")
153
                            + "\n"
154
                            + wizardPanel.getTranslation("_do_you_want_to_continue")
155
                    );
156
            if (dlg.needShow()) {
157
                WindowManager wm = ToolsSwingLocator.getWindowManager();
158
                wm.showWindow(
159
                    dlg, 
160
                    wizardPanel.getTranslation("_do_you_want_to_continue"),
161
                    WindowManager.MODE.DIALOG
162
                );
163
                if (dlg.cancelled()) {
164
                    throw new NotContinueWizardException("", null, false);
165
                }
166
            }
167
        }
168

    
169
        if (requiredPackages != null && requiredPackages.size() > 0) {
170
            JShowRequiredPackagesAndAskContinuePanel dlg = swingManager
171
                    .createJShowRequiredPackagesAndAskContinuePanel(
172
                            requiredPackages,
173
                            wizardPanel.getTranslation("_the_selected_packages_require_to_install_or_update_the_following_packages")
174
                            + ":\n"
175
                            + wizardPanel.getTranslation("_do_you_want_to_continue"));
176
            if (dlg.needShow()) {
177
                WindowManager wm = ToolsSwingLocator.getWindowManager();
178
                wm.showWindow(
179
                    dlg, 
180
                    wizardPanel.getTranslation("_do_you_want_to_continue"),
181
                    WindowManager.MODE.DIALOG
182
                );
183
                if (dlg.cancelled()) {
184
                    throw new NotContinueWizardException("", null, false);
185
                }
186
            }
187
        }
188

    
189
        if (unresolvedDependencies != null && unresolvedDependencies.size() > 0) {
190
            JShowUnresolvedDependenciesAndAskContinuePanel dlg = swingManager
191
                .createJShowUnresolvedDependenciesAndAskContinuePanel(
192
                    unresolvedDependencies,
193
                    wizardPanel.getTranslation("_the_following_dependencies_have_not_been_possible_to_resolve")
194
                    + ". "
195
                    + wizardPanel.getTranslation("_This_may_cause_issues_in_gvSIG")
196
                    + "\n"
197
                    + wizardPanel.getTranslation("_do_you_want_to_continue_anyway")
198
                );
199
            if (dlg.needShow()) {
200
                WindowManager wm = ToolsSwingLocator.getWindowManager();
201
                wm.showWindow(
202
                    dlg, 
203
                    wizardPanel.getTranslation("_do_you_want_to_continue"),
204
                    WindowManager.MODE.DIALOG
205
                );
206
                if (dlg.cancelled()) {
207
                    throw new NotContinueWizardException("", null, false);
208
                }
209
            }
210
        }
211

    
212
        Iterator<PackageInfo> it = requiredPackages.iterator();
213
        while (it.hasNext()) {
214
            PackageInfo pkg = it.next();
215
            selectPackagesPanel.getModel().selectPackage(pkg);
216
            LOG.info("Automatic selection of required package " + pkg.getCode());
217
        }
218
    }
219

    
220
    private void checkDevelAndUnoficialPackages(SwingInstallerManager swingManager)
221
            throws NotContinueWizardException {
222
        List<PackageInfo> packagesToInstall = this.wizardPanel.getPackagesToInstall();
223

    
224
        JShowPackageStatusAndAskContinuePanel dlg = swingManager
225
                .createJShowPackageStatusAndAskContinuePanel(
226
                        packagesToInstall,
227
                        wizardPanel.getTranslation("_you_have_selected_in_development_or_not_official_versions")
228
                        + ". "
229
                        + wizardPanel.getTranslation("_Installing_devel_addons_may_cause_errors")
230
                        + "\n"
231
                        + wizardPanel.getTranslation("_do_you_want_to_continue_anyway"));
232
        if (dlg.needShow()) {
233
            WindowManager wm = ToolsSwingLocator.getWindowManager();
234
            wm.showWindow(
235
                    dlg, 
236
                    wizardPanel.getTranslation("_do_you_want_to_continue"),
237
                    WindowManager.MODE.DIALOG
238
            );
239
            if (dlg.cancelled()) {
240
                throw new NotContinueWizardException("", null, false);
241
            }
242
        }
243
    }
244

    
245
    @Override
246
    public void updatePanel() {
247
        selectPackagesPanel.updatePanel();
248
        selectPackagesPanel.setInitialFilter();
249

    
250
        // if default packages must be selected or not
251
        if (wizardPanel.getSelectDefaultPackages()) {
252
            selectPackagesPanel.selectPackages();
253
        }
254
        wizardPanel.setFinishButtonEnabled(true);
255
        wizardPanel.setBackButtonEnabled(true);
256
        wizardPanel.setNextButtonEnabled(false);
257
        wizardPanel.setCancelButtonEnabled(true);
258

    
259
        this.selectPackagesPanel.setBaseFilter(this.wizardPanel.getPackageFilter());
260

    
261
        if (wizardPanel.getSkipSelectPackagesWizardPage() && !this.getPackagesToInstall().isEmpty()) {
262
            wizardPanel.skip();
263
            return;
264
        }
265

    
266
        checkIfPluginSelected();
267
    }
268

    
269
    public void checkIfPluginSelected() {
270
        wizardPanel.setNextButtonEnabled(selectPackagesPanel.isPackageSelected());
271
    }
272

    
273
    public List<PackageInfo> getPackagesToInstall() {
274
        return selectPackagesPanel.getPackagesToInstall();
275
    }
276

    
277
    public Boolean isDefaultPackagesSelectionSet() {
278
        return wizardPanel.getSelectDefaultPackages();
279
    }
280

    
281
    public InstallWizardPanel_ext getWizardPanel() {
282
        return this.wizardPanel;
283
    }
284

    
285
}