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 40560 jjdelcerro
/**
2
 * gvSIG. Desktop Geographic Information System.
3 40435 jjdelcerro
 *
4 40560 jjdelcerro
 * Copyright (C) 2007-2013 gvSIG Association.
5 40435 jjdelcerro
 *
6 43126 jjdelcerro
 * 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 40435 jjdelcerro
 *
11 43126 jjdelcerro
 * 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 40435 jjdelcerro
 *
16 43126 jjdelcerro
 * 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 40435 jjdelcerro
 *
20 43126 jjdelcerro
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
22 40435 jjdelcerro
 */
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 43126 jjdelcerro
import org.gvsig.installer.lib.api.InstallerLocator;
36
import org.gvsig.installer.lib.api.InstallerManager;
37 40435 jjdelcerro
import org.gvsig.installer.lib.api.PackageInfo;
38
import org.gvsig.installer.swing.api.SwingInstallerLocator;
39 43126 jjdelcerro
import org.gvsig.installer.swing.api.SwingInstallerManager;
40 40435 jjdelcerro
import org.gvsig.installer.swing.api.execution.JShowPackageStatusAndAskContinuePanel;
41 40634 jjdelcerro
import org.gvsig.installer.swing.api.execution.JShowPackagesAndAskContinuePanel;
42 40435 jjdelcerro
import org.gvsig.installer.swing.api.execution.JShowRequiredPackagesAndAskContinuePanel;
43
import org.gvsig.installer.swing.api.execution.JShowUnresolvedDependenciesAndAskContinuePanel;
44 43126 jjdelcerro
import org.gvsig.installer.swing.api.execution.PackageFilter;
45
import org.gvsig.installer.swing.impl.execution.InstallWizardPanel_ext;
46 40435 jjdelcerro
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 43126 jjdelcerro
public class SelectPackagesWizardPage implements OptionPanel {
53 40435 jjdelcerro
54 43126 jjdelcerro
    private static final long serialVersionUID = -4678172923039393643L;
55 40435 jjdelcerro
56 43126 jjdelcerro
    private static final Logger LOG = LoggerFactory.getLogger(SelectPackagesWizardPage.class);
57 40435 jjdelcerro
58 43126 jjdelcerro
    private final InstallWizardPanel_ext wizardPanel;
59 40435 jjdelcerro
60 43126 jjdelcerro
    private SelectPackagesPanel selectPackagesPanel = null;
61 40435 jjdelcerro
62 43126 jjdelcerro
    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 40435 jjdelcerro
74 43126 jjdelcerro
    @Override
75
    public String getPanelTitle() {
76
        return wizardPanel.getTranslation("_select_plugins");
77
    }
78 40435 jjdelcerro
79 43126 jjdelcerro
    @Override
80
    public void lastPanel() {
81
        selectPackagesPanel.clearPanel();
82
    }
83 40435 jjdelcerro
84 43126 jjdelcerro
    @Override
85
    public void nextPanel() throws NotContinueWizardException {
86
        SwingInstallerManager swingManager = SwingInstallerLocator.getSwingInstallerManager();
87 40435 jjdelcerro
        /*
88 43126 jjdelcerro
         * First warn about packages in development or unofficial
89
         */
90
        checkDevelAndUnoficialPackages(swingManager);
91
        /*
92 40435 jjdelcerro
         * Then check dependencies
93
         */
94 43126 jjdelcerro
        checkDependencies(swingManager);
95
        wizardPanel.setNextButtonEnabled(false);
96
    }
97 40435 jjdelcerro
98 43126 jjdelcerro
    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 40435 jjdelcerro
109 43126 jjdelcerro
            // Le indicamos los paquetes que queremos instalar
110
            calculator.addPackageToInstall(
111
                    this.wizardPanel.getPackagesToInstall()
112
            );
113 40435 jjdelcerro
114 43126 jjdelcerro
            // Le a?adimos los paquetes que ya hay instalados.
115
            PackageInfo[] pkgs = manager.getInstalledPackages();
116
            calculator.addInstalledPackage(pkgs);
117 40435 jjdelcerro
118 43126 jjdelcerro
            // Calculamos las dependencias
119
            calculator.calculate();
120 40435 jjdelcerro
121 43126 jjdelcerro
            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 40435 jjdelcerro
146 43126 jjdelcerro
        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 40435 jjdelcerro
                            + ". "
152 43126 jjdelcerro
                            + 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 40435 jjdelcerro
169 43126 jjdelcerro
        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 40435 jjdelcerro
189 43126 jjdelcerro
        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 40435 jjdelcerro
212 43126 jjdelcerro
        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 40435 jjdelcerro
220 43126 jjdelcerro
    private void checkDevelAndUnoficialPackages(SwingInstallerManager swingManager)
221
            throws NotContinueWizardException {
222
        List<PackageInfo> packagesToInstall = this.wizardPanel.getPackagesToInstall();
223 40435 jjdelcerro
224 43126 jjdelcerro
        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 40435 jjdelcerro
245 43126 jjdelcerro
    @Override
246
    public void updatePanel() {
247
        selectPackagesPanel.updatePanel();
248
        selectPackagesPanel.setInitialFilter();
249 40435 jjdelcerro
250 43126 jjdelcerro
        // 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 40435 jjdelcerro
259 43126 jjdelcerro
        this.selectPackagesPanel.setBaseFilter(this.wizardPanel.getPackageFilter());
260 40435 jjdelcerro
261 43126 jjdelcerro
        if (wizardPanel.getSkipSelectPackagesWizardPage() && !this.getPackagesToInstall().isEmpty()) {
262
            wizardPanel.skip();
263
            return;
264
        }
265 40435 jjdelcerro
266 43126 jjdelcerro
        checkIfPluginSelected();
267
    }
268 40435 jjdelcerro
269 43126 jjdelcerro
    public void checkIfPluginSelected() {
270
        wizardPanel.setNextButtonEnabled(selectPackagesPanel.isPackageSelected());
271
    }
272 40435 jjdelcerro
273 43126 jjdelcerro
    public List<PackageInfo> getPackagesToInstall() {
274
        return selectPackagesPanel.getPackagesToInstall();
275
    }
276 40435 jjdelcerro
277 43126 jjdelcerro
    public Boolean isDefaultPackagesSelectionSet() {
278
        return wizardPanel.getSelectDefaultPackages();
279
    }
280 40435 jjdelcerro
281 43126 jjdelcerro
    public InstallWizardPanel_ext getWizardPanel() {
282
        return this.wizardPanel;
283
    }
284 40435 jjdelcerro
285
}