Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / org.gvsig.symbology.app / org.gvsig.symbology.app.symbolinstaller / src / main / java / org / gvsig / symbology / app / symbolinstaller / creation / wizard / ProgressWizard.java @ 37296

History | View | Annotate | Download (5.28 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
package org.gvsig.symbology.app.symbolinstaller.creation.wizard;
28

    
29
import java.io.File;
30
import java.io.FileNotFoundException;
31
import java.io.FileOutputStream;
32
import java.io.OutputStream;
33

    
34
import javax.swing.JOptionPane;
35
import javax.swing.JPanel;
36

    
37
import org.gvsig.gui.beans.wizard.panel.OptionPanel;
38
import org.gvsig.i18n.Messages;
39
import org.gvsig.installer.lib.api.InstallerLocator;
40
import org.gvsig.installer.lib.api.PackageInfo;
41
import org.gvsig.installer.lib.api.creation.MakePackageService;
42
import org.gvsig.installer.lib.api.creation.MakePackageServiceException;
43
import org.gvsig.installer.swing.api.JProgressPanel;
44
import org.gvsig.installer.swing.api.SwingInstallerLocator;
45
import org.gvsig.installer.swing.api.creation.JOutputPanel;
46
import org.gvsig.symbology.app.symbolinstaller.creation.DefaultMakeSymbolPackageWizard;
47
import org.gvsig.tools.ToolsLocator;
48
import org.gvsig.tools.task.SimpleTaskStatus;
49

    
50
/**
51
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
52
 */
53
public class ProgressWizard implements OptionPanel {
54

    
55
    private DefaultMakeSymbolPackageWizard wizard;
56
    private PackageInfo packageInfo;
57
    private JOutputPanel outputPanel;
58
    private JProgressPanel progressPanel;
59

    
60
    public ProgressWizard(DefaultMakeSymbolPackageWizard wizard,
61
        PackageInfo packageInfo, JOutputPanel outputPanel) {
62
        super();
63
        this.wizard = wizard;
64
        this.packageInfo = packageInfo;
65
        this.outputPanel = outputPanel;
66
        progressPanel =
67
            SwingInstallerLocator.getSwingInstallerManager()
68
                .createProgressPanel();
69
    }
70

    
71
    private String getText(String msg) {
72
        return Messages.getText(msg);
73
    }
74

    
75
    public JPanel getJPanel() {
76
        return this.progressPanel;
77
    }
78

    
79
    public String getPanelTitle() {
80
        return Messages.getText("_Installer_progress");
81
    }
82

    
83
    public void lastPanel() {
84
        wizard.setFinishButtonEnabled(false);
85
        wizard.setCancelButtonEnabled(true);
86
    }
87

    
88
    public void nextPanel() {
89
        // Do nothing
90
    }
91

    
92
    public void updatePanel() {
93

    
94
        OutputStream outputStream =
95
            openFileOutputStream(outputPanel.getPackageFile());
96
        if (outputStream == null) {
97
            return;
98
        }
99
        OutputStream indexOutputStream = null;
100
        if (outputPanel.isCreatePackageIndex()) {
101
            indexOutputStream =
102
                openFileOutputStream(outputPanel.getPackageIndexFile());
103
            if (indexOutputStream == null) {
104
                return;
105
            }
106
        }
107

    
108
        wizard.setFinishButtonEnabled(false);
109
        wizard.setCancelButtonEnabled(false);
110

    
111
        SimpleTaskStatus taskStatus =
112
            ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus(
113
                packageInfo.getName());
114

    
115
        this.progressPanel.bind(taskStatus);
116

    
117
        try {
118

    
119
            MakePackageService makePackageService =
120
                InstallerLocator.getInstallerManager().createMakePackage(
121
                    wizard.getSymbolFolderToInsertInPackage(), packageInfo);
122

    
123
            taskStatus.message(getText("_Compressing"));
124

    
125
            makePackageService.preparePackage();
126
            makePackageService.createPackage(outputStream);
127
            if (indexOutputStream != null) {
128
                taskStatus.message(getText("_Creating_index"));
129
                makePackageService.createPackageIndex(outputPanel
130
                    .getDownloadURL(), indexOutputStream);
131
            }
132
            taskStatus.terminate();
133

    
134
            // Set the finished text
135
            taskStatus.message(getText("_Finished"));
136
        } catch (MakePackageServiceException e) {
137
            JOptionPane.showMessageDialog(null, getText("_cant_create_the_package")
138
                + "\n\n" + e.getLocalizedMessageStack(),
139
                getText("_create_package"), JOptionPane.ERROR_MESSAGE);
140
        }
141
        wizard.setFinishButtonEnabled(true);
142
        wizard.setCancelButtonEnabled(false);
143
    }
144

    
145
    private OutputStream openFileOutputStream(File file) {
146
        OutputStream os;
147

    
148
        try {
149
            os = new FileOutputStream(file);
150
        } catch (FileNotFoundException e1) {
151
            JOptionPane.showMessageDialog(null,
152
                getText("_cant_create_the_package") + " (" + file + ").",
153
                getText("_create_package"), JOptionPane.WARNING_MESSAGE);
154
            return null;
155
        }
156
        return os;
157
    }
158
}