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 / ProgressWizard.java @ 34974

History | View | Annotate | Download (5.78 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

    
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2010 {Prodevelop}   {Task}
26
 */
27

    
28
package org.gvsig.installer.swing.impl.execution.wizard;
29

    
30
import java.util.List;
31

    
32
import javax.swing.JOptionPane;
33
import javax.swing.JPanel;
34

    
35
import org.gvsig.gui.beans.wizard.panel.OptionPanel;
36
import org.gvsig.i18n.Messages;
37
import org.gvsig.installer.lib.api.PackageInfo;
38
import org.gvsig.installer.lib.api.execution.InstallPackageService;
39
import org.gvsig.installer.lib.api.execution.InstallPackageServiceException;
40
import org.gvsig.installer.swing.api.execution.AbstractInstallPackageWizard;
41
import org.gvsig.installer.swing.impl.execution.DefaultInstallPackageWizard;
42
import org.gvsig.installer.swing.impl.panel.ProgressPanel;
43
import org.gvsig.tools.task.AbstractMonitorableTask;
44
import org.gvsig.tools.task.SimpleTaskStatus;
45

    
46
/**
47
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
48
 */
49
public class ProgressWizard extends ProgressPanel implements OptionPanel {
50

    
51
    private static final long serialVersionUID = 8531884535246881448L;
52
    private AbstractInstallPackageWizard installerExecutionWizard;
53

    
54
    public ProgressWizard(DefaultInstallPackageWizard installerExecutionWizard) {
55
        super();
56
        this.installerExecutionWizard = installerExecutionWizard;
57
    }
58

    
59
    public JPanel getJPanel() {
60
        return this;
61
    }
62

    
63
    public String getPanelTitle() {
64
        return swingInstallerManager.getText("progress");
65
    }
66

    
67
    public void lastPanel() {
68
        installerExecutionWizard.setFinishButtonVisible(false);
69
        installerExecutionWizard.setCancelButtonEnabled(true);
70
    }
71

    
72
    public void nextPanel() {
73
        // Nothing to do, no next panel
74
    }
75

    
76
    public void updatePanel() {
77

    
78
        final ProgressWizard wizard = this;
79

    
80
        UpdatePanel task = new UpdatePanel(wizard);
81
        wizard.installerExecutionWizard.addCancellableTask(task);
82
        bind(task.getTaskStatus());
83
        task.start();
84
        installerExecutionWizard.setFinishButtonVisible(true);
85
        installerExecutionWizard.setCancelButtonEnabled(false);
86
    }
87

    
88
    private static class UpdatePanel extends AbstractMonitorableTask {
89

    
90
        private final ProgressWizard panel;
91

    
92
        public UpdatePanel(ProgressWizard panel) {
93
            super("Installing...");
94
            this.panel = panel;
95
        }
96

    
97
        public synchronized void run() {
98

    
99
            SimpleTaskStatus taskStatus =
100
                (SimpleTaskStatus) this.getTaskStatus();
101
            // bundle of packages
102
            InstallPackageService installerExecutionService =
103
                this.panel.installerExecutionWizard
104
                    .getInstallerExecutionService();
105
            // packages to install
106
            List<PackageInfo> installersToInstall =
107
                this.panel.installerExecutionWizard.getInstallersToInstall();
108
            taskStatus.setRangeOfValues(0, installersToInstall.size());
109
            try {
110
                for (int i = 0; i < installersToInstall.size(); i++) {
111
                    PackageInfo installerInfo = installersToInstall.get(i);
112
                    taskStatus.message(installerInfo.getName());
113
                    String msg = "";
114
                    if (!installerInfo.getState().equalsIgnoreCase("final")) {
115
                        msg += Messages.getText("_this_is_not_a_final_package");
116
                    }
117
                    if (!installerInfo.isOfficial()) {
118
                        if (!msg.equalsIgnoreCase("")) {
119
                            msg += "\n";
120
                        }
121
                        msg += Messages.getText("_this_is_not_an_official_package");
122
                    }
123
                    if (!msg.equalsIgnoreCase("")) {
124
                        msg =
125
                            installerInfo.getName() + ":\n" + msg + "\n"
126
                                + Messages.getText("_do_you_want_to_continue");
127
                        int resp =
128
                            JOptionPane.showConfirmDialog(null, msg, Messages
129
                                .getText("_select_an_option"),
130
                                JOptionPane.YES_NO_OPTION);
131
                        if (resp != JOptionPane.OK_OPTION) {
132
                            continue;
133
                        }
134
                    }
135

    
136
                    // taskStatus.SetIndeterminate(true);
137
                    installerExecutionService.installPackage(
138
                        panel.installerExecutionWizard.getApplicationFolder(),
139
                        installerInfo);
140
                    taskStatus.setCurValue(i + 1);
141
                }
142
                // Set the finished text
143
                taskStatus.message(panel.swingInstallerManager.getText("_Finished"));
144
            } catch (InstallPackageServiceException e) {
145
                panel.showErrorMessage(panel.swingInstallerManager
146
                    .getText("_Cant_install_packege"), e);
147
            }
148
            // panel.setProgress(100);
149
            taskStatus.terminate();
150
            taskStatus.remove();
151

    
152
        }
153

    
154
    }
155
}