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 @ 37171
History | View | Annotate | Download (5.27 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.WizardPanel; |
38 |
import org.gvsig.gui.beans.wizard.panel.OptionPanel; |
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á</a>
|
52 |
*/
|
53 |
public class ProgressWizard implements OptionPanel { |
54 |
|
55 |
private static final long serialVersionUID = -2940454513497249659L; |
56 |
private DefaultMakeSymbolPackageWizard wizard;
|
57 |
private PackageInfo packageInfo;
|
58 |
private JOutputPanel outputPanel;
|
59 |
private JProgressPanel progressPanel;
|
60 |
|
61 |
public ProgressWizard(WizardPanel wizard, PackageInfo packageInfo,
|
62 |
JOutputPanel outputPanel) { |
63 |
super();
|
64 |
this.wizard = (DefaultMakeSymbolPackageWizard) wizard;
|
65 |
this.packageInfo = packageInfo;
|
66 |
this.outputPanel = outputPanel;
|
67 |
progressPanel = |
68 |
SwingInstallerLocator.getSwingInstallerManager() |
69 |
.createProgressPanel(); |
70 |
} |
71 |
|
72 |
private String getText(String msg) { |
73 |
return msg; // FIXME |
74 |
} |
75 |
|
76 |
public JPanel getJPanel() { |
77 |
return this.progressPanel; |
78 |
} |
79 |
|
80 |
public String getPanelTitle() { |
81 |
return getText("_Installer_progress"); |
82 |
} |
83 |
|
84 |
public void lastPanel() { |
85 |
wizard.setFinishButtonEnabled(false);
|
86 |
wizard.setCancelButtonEnabled(true);
|
87 |
} |
88 |
|
89 |
public void nextPanel() { |
90 |
// Do nothing
|
91 |
} |
92 |
|
93 |
public void updatePanel() { |
94 |
|
95 |
OutputStream outputStream =
|
96 |
openFileOutputStream(outputPanel.getPackageFile()); |
97 |
if (outputStream == null) { |
98 |
return;
|
99 |
} |
100 |
OutputStream indexOutputStream = null; |
101 |
if (outputPanel.isCreatePackageIndex()) {
|
102 |
indexOutputStream = |
103 |
openFileOutputStream(outputPanel.getPackageIndexFile()); |
104 |
if (indexOutputStream == null) { |
105 |
return;
|
106 |
} |
107 |
} |
108 |
|
109 |
SimpleTaskStatus taskStatus = |
110 |
ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus( |
111 |
packageInfo.getName()); |
112 |
|
113 |
this.progressPanel.bind(taskStatus);
|
114 |
|
115 |
try {
|
116 |
|
117 |
MakePackageService makePackageService = |
118 |
InstallerLocator.getInstallerManager().createMakePackage( |
119 |
wizard.getSymbolFolderToInsertInPackage(), packageInfo); |
120 |
|
121 |
taskStatus.message(getText("_Compressing"));
|
122 |
|
123 |
makePackageService.preparePackage(); |
124 |
makePackageService.createPackage(outputStream); |
125 |
if (indexOutputStream != null) { |
126 |
taskStatus.message(getText("_Creating_index"));
|
127 |
makePackageService.createPackageIndex(outputPanel |
128 |
.getDownloadURL(), indexOutputStream); |
129 |
} |
130 |
taskStatus.terminate(); |
131 |
|
132 |
// Set the finished text
|
133 |
taskStatus.message(getText("_Finished"));
|
134 |
} catch (MakePackageServiceException e) {
|
135 |
JOptionPane.showMessageDialog(null, getText("_cant_create_package") |
136 |
+ "\n\n" + e.getLocalizedMessageStack(),
|
137 |
getText("_create_package"), JOptionPane.ERROR_MESSAGE); |
138 |
} |
139 |
wizard.setFinishButtonEnabled(true);
|
140 |
wizard.setCancelButtonEnabled(false);
|
141 |
} |
142 |
|
143 |
private OutputStream openFileOutputStream(File file) { |
144 |
OutputStream os;
|
145 |
|
146 |
try {
|
147 |
os = new FileOutputStream(file); |
148 |
} catch (FileNotFoundException e1) { |
149 |
JOptionPane.showMessageDialog(null, |
150 |
getText("_cant_create_package_file") + " (" + file + ").", |
151 |
getText("_create_package"), JOptionPane.WARNING_MESSAGE); |
152 |
return null; |
153 |
} |
154 |
return os;
|
155 |
} |
156 |
} |