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 / InstallersWizardPage.java @ 43126

History | View | Annotate | Download (5.51 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
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2010 {Prodevelop}   {Task}
26
 */
27
package org.gvsig.installer.swing.impl.execution.wizard;
28

    
29
import javax.swing.JOptionPane;
30

    
31
import javax.swing.JPanel;
32
import javax.swing.SwingUtilities;
33
import org.gvsig.gui.beans.wizard.WizardPanelWithLogo;
34

    
35
import org.gvsig.gui.beans.wizard.panel.OptionPanel;
36
import org.gvsig.installer.lib.api.execution.InstallPackageService;
37
import org.gvsig.installer.swing.api.SwingInstallerLocator;
38
import org.gvsig.installer.swing.api.SwingInstallerManager;
39
import org.gvsig.installer.swing.impl.DefaultSwingInstallerManager;
40
import org.gvsig.installer.swing.impl.execution.InstallWizardPanel_ext;
41
import org.gvsig.installer.swing.impl.panel.DefaultProgressPanel;
42
import org.gvsig.tools.task.AbstractMonitorableTask;
43
import org.gvsig.tools.task.SimpleTaskStatus;
44

    
45
public class InstallersWizardPage extends DefaultProgressPanel implements OptionPanel {
46

    
47
    private static final long serialVersionUID = 8531884535246881448L;
48
    private final InstallWizardPanel_ext wizardPanel;
49

    
50
    public InstallersWizardPage(InstallWizardPanel_ext installerExecutionWizard) {
51
        super();
52
        this.wizardPanel = installerExecutionWizard;
53
    }
54

    
55
    @Override
56
    public JPanel getJPanel() {
57
        return this;
58
    }
59

    
60
    @Override
61
    public String getPanelTitle() {
62
        return wizardPanel.getTranslation("_Install_required_addons");
63
    }
64

    
65
    @Override
66
    public void lastPanel() {
67
        wizardPanel.setFinishButtonEnabled(false);
68
        wizardPanel.setCancelButtonEnabled(true);
69
    }
70

    
71
    @Override
72
    public void nextPanel() {
73
    }
74

    
75
    @Override
76
    public void updatePanel() {
77
        if( wizardPanel.getDirection() == WizardPanelWithLogo.ACTION_PREVIOUS ) {
78
            wizardPanel.skip();
79
            return;
80
        }
81
        InstallPackageService bundle = wizardPanel.getInstallerExecutionService();
82
        if (! bundle.needInstallPackageProviders()) {
83
            wizardPanel.skip();
84
            return;
85
        }
86

    
87
        wizardPanel.setFinishButtonEnabled(false);
88
        wizardPanel.setBackButtonEnabled(false);
89
        wizardPanel.setNextButtonEnabled(false);
90
        wizardPanel.setCancelButtonEnabled(true);
91

    
92
        UpdatePanel task = new UpdatePanel(this);
93
        this.wizardPanel.addCancellableTask(task);
94
        bind(task.getTaskStatus());
95
        task.setDaemon(true);
96
        task.start();
97
    }
98

    
99
    private class UpdatePanel extends AbstractMonitorableTask {
100

    
101
        private final InstallersWizardPage panel;
102

    
103
        public UpdatePanel(InstallersWizardPage panel) {
104
            super(panel.wizardPanel.getTranslation("_Installing prerequisites..."));
105
            this.panel = panel;
106
        }
107

    
108
        private void showWarning(final String msg) {
109
            if (!SwingUtilities.isEventDispatchThread()) {
110
                try {
111
                    SwingUtilities.invokeAndWait(new Runnable() {
112
                        @Override
113
                        public void run() {
114
                        }
115
                    });
116
                } catch (Exception ex) {
117
                    logger.warn("Cant show message to the user. " + msg);
118
                }
119
                return;
120
            }
121
            JOptionPane.showMessageDialog(panel, msg, "Warning", JOptionPane.WARNING_MESSAGE);
122
        }
123

    
124
        @Override
125
        public synchronized void run() {
126

    
127
            try {
128

    
129
                logger.info("Package installation initiated");
130
                SimpleTaskStatus taskStatus = (SimpleTaskStatus) this.getTaskStatus();
131

    
132
                InstallPackageService bundle = wizardPanel.getInstallerExecutionService();
133
                if (bundle.needInstallPackageProviders()) {
134
                    bundle.installPackageProviders(taskStatus);
135
                }
136

    
137
                taskStatus.message(panel.wizardPanel.getTranslation("_Finished"));
138

    
139
                taskStatus.terminate();
140
                SwingUtilities.invokeAndWait(new Runnable() {
141

    
142
                    @Override
143
                    public void run() {
144
                        wizardPanel.setFinishButtonEnabled(false);
145
                        wizardPanel.setBackButtonEnabled(true);
146
                        wizardPanel.setNextButtonEnabled(true);
147
                        wizardPanel.setCancelButtonEnabled(true);
148
                        wizardPanel.doAction(WizardPanelWithLogo.ACTION_NEXT);
149
                    }
150
                });
151
                logger.info("Package installation finished");
152
            } catch (Throwable th) {
153
                logger.warn("Problems install packages.", th);
154
                showWarning(panel.wizardPanel.getTranslation("_Cant_install_package"));
155
            }
156
        }
157

    
158
    }
159
}