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 / packagebuilder / BasePackageWizard.java @ 44420
History | View | Annotate | Download (9.08 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 |
package org.gvsig.installer.swing.impl.packagebuilder; |
24 |
|
25 |
import java.awt.BorderLayout; |
26 |
import java.awt.Dimension; |
27 |
import java.io.File; |
28 |
import java.net.URL; |
29 |
import java.util.Collection; |
30 |
import java.util.HashSet; |
31 |
import java.util.Set; |
32 |
import javax.swing.JComponent; |
33 |
|
34 |
import javax.swing.JPanel; |
35 |
import org.apache.commons.io.FilenameUtils; |
36 |
|
37 |
import org.gvsig.gui.beans.wizard.WizardPanel; |
38 |
import org.gvsig.gui.beans.wizard.WizardPanelActionListener; |
39 |
import org.gvsig.gui.beans.wizard.WizardPanelWithLogo; |
40 |
import org.gvsig.gui.beans.wizard.panel.OptionPanel; |
41 |
import org.gvsig.installer.lib.api.InstallerLocator; |
42 |
import org.gvsig.installer.lib.api.InstallerManager; |
43 |
import org.gvsig.installer.swing.api.packagebuilder.PackageBuildder; |
44 |
|
45 |
import org.gvsig.installer.swing.impl.packagebuilder.options.OutputOption; |
46 |
import org.gvsig.installer.swing.impl.packagebuilder.options.PackageInfoOption; |
47 |
import org.gvsig.installer.swing.impl.packagebuilder.options.ProgressOption; |
48 |
import org.gvsig.installer.swing.impl.packagebuilder.options.SelectFolderToPackagingOption; |
49 |
import org.gvsig.tools.ToolsLocator; |
50 |
import org.gvsig.tools.i18n.I18nManager; |
51 |
import org.gvsig.tools.locator.LocatorException; |
52 |
import org.gvsig.tools.packageutils.PackageInfo; |
53 |
|
54 |
public class BasePackageWizard extends JPanel implements WizardPanel, PackageBuildder { |
55 |
|
56 |
private static final long serialVersionUID = 9205891710214122265L; |
57 |
|
58 |
private WizardPanelWithLogo wizardPanelWithLogo = null; |
59 |
|
60 |
private PackageInfo packageInfo = null; |
61 |
private File folderToPackaging = null; |
62 |
private WizardPanelActionListener wizardListenerAdapter = null; |
63 |
|
64 |
private OutputOption outputOption = null; |
65 |
private OptionPanel packageInfoOption = null; |
66 |
private OptionPanel progressOption = null; |
67 |
private SelectFolderToPackagingOption selectFolderToPackagingOption = null; |
68 |
private final String packageType; |
69 |
private final File baseFolder; |
70 |
private final File outputFolder; |
71 |
|
72 |
private Set<BeforePackingListener> beforePackingListener = new HashSet<>(); |
73 |
|
74 |
public BasePackageWizard(String packageType, File selectionFolder, File outputFolder) throws LocatorException { |
75 |
this.packageType = packageType;
|
76 |
this.baseFolder = selectionFolder;
|
77 |
this.outputFolder = outputFolder;
|
78 |
initComponents(); |
79 |
} |
80 |
|
81 |
private void initComponents() { |
82 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
83 |
|
84 |
this.wizardPanelWithLogo = new WizardPanelWithLogo(); |
85 |
|
86 |
this.setCancelButtonEnabled(true); |
87 |
this.setFinishButtonEnabled(false); |
88 |
|
89 |
this.packageInfo = ToolsLocator.getPackageManager().createPackageInfo();
|
90 |
this.packageInfo.setType(this.packageType); |
91 |
|
92 |
this.addSelectFolderToPackagingOption(
|
93 |
i18nManager.getTranslation("_Seleccione_la_carpeta_que_desea_empaquetar")
|
94 |
); |
95 |
this.addPackageInfoOptionPanel();
|
96 |
this.addOutputOptionPanel();
|
97 |
this.addProgressOptionPanel();
|
98 |
this.setFolderToPackaging(this.baseFolder); |
99 |
|
100 |
wizardPanelWithLogo.setWizardListener(this);
|
101 |
|
102 |
this.setLayout(new BorderLayout()); |
103 |
this.add(wizardPanelWithLogo, BorderLayout.CENTER); |
104 |
this.setPreferredSize(new Dimension(700, 550)); |
105 |
} |
106 |
|
107 |
@Override
|
108 |
public String getPackageType() { |
109 |
return this.packageType; |
110 |
} |
111 |
|
112 |
protected void addPackageInfoOptionPanel() { |
113 |
if (this.packageInfoOption == null) { |
114 |
this.packageInfoOption = new PackageInfoOption(this); |
115 |
} |
116 |
this.wizardPanelWithLogo.addOptionPanel(this.packageInfoOption); |
117 |
} |
118 |
|
119 |
protected void addOutputOptionPanel() { |
120 |
if (this.outputOption == null) { |
121 |
this.outputOption = new OutputOption(this); |
122 |
} |
123 |
this.wizardPanelWithLogo.addOptionPanel(this.outputOption); |
124 |
} |
125 |
|
126 |
protected void addProgressOptionPanel() { |
127 |
if (this.progressOption == null) { |
128 |
|
129 |
this.progressOption = new ProgressOption(this); |
130 |
} |
131 |
this.wizardPanelWithLogo.addOptionPanel(this.progressOption); |
132 |
} |
133 |
|
134 |
protected void addSelectFolderToPackagingOption(String message) { |
135 |
if (this.selectFolderToPackagingOption == null) { |
136 |
this.selectFolderToPackagingOption = new SelectFolderToPackagingOption(this, message); |
137 |
} |
138 |
this.wizardPanelWithLogo.addOptionPanel(this.selectFolderToPackagingOption); |
139 |
} |
140 |
|
141 |
public void setNextButtonEnabled(boolean isEnabled) { |
142 |
wizardPanelWithLogo.setNextButtonEnabled(isEnabled); |
143 |
} |
144 |
|
145 |
public void setCancelButtonEnabled(boolean isEnabled) { |
146 |
wizardPanelWithLogo.setCancelButtonEnabled(isEnabled); |
147 |
} |
148 |
|
149 |
public void setFinishButtonEnabled(boolean isEnabled) { |
150 |
wizardPanelWithLogo.setFinishButtonEnabled(isEnabled); |
151 |
} |
152 |
|
153 |
public void setBackButtonEnabled(boolean isEnabled) { |
154 |
wizardPanelWithLogo.setBackButtonEnabled(isEnabled); |
155 |
} |
156 |
|
157 |
@Override
|
158 |
public WizardPanelActionListener getWizardPanelActionListener() {
|
159 |
if (this.wizardListenerAdapter == null) { |
160 |
this.wizardListenerAdapter = new WizardPanelActionListener() { |
161 |
@Override
|
162 |
public void finish(WizardPanel wizardPanel) { |
163 |
BasePackageWizard.this.setVisible(false);
|
164 |
} |
165 |
|
166 |
@Override
|
167 |
public void cancel(WizardPanel wizardPanel) { |
168 |
BasePackageWizard.this.setVisible(false);
|
169 |
} |
170 |
}; |
171 |
} |
172 |
return this.wizardListenerAdapter; |
173 |
} |
174 |
|
175 |
@Override
|
176 |
public void setWizardPanelActionListener( |
177 |
WizardPanelActionListener wizardActionListener) { |
178 |
// this.wizardListenerAdapter = wizardActionListener;
|
179 |
throw new RuntimeException("Esto falta por ver que hace"); |
180 |
} |
181 |
|
182 |
@Override
|
183 |
public void setFolderToPackaging(File file) { |
184 |
this.folderToPackaging = file;
|
185 |
if (this.selectFolderToPackagingOption != null) { |
186 |
this.selectFolderToPackagingOption.setCurrentFolder(file);
|
187 |
} |
188 |
packageInfo.setType(this.packageType);
|
189 |
packageInfo.setCode(FilenameUtils.getBaseName(file.getName())); |
190 |
packageInfo.setName(FilenameUtils.getBaseName(file.getName())); |
191 |
File pinfo = new File(file, "package.info"); |
192 |
if (pinfo.exists()) {
|
193 |
try {
|
194 |
ToolsLocator.getPackageManager().readPacakgeInfo( |
195 |
(org.gvsig.tools.packageutils.PackageInfo) packageInfo, pinfo); |
196 |
packageInfo.setType(this.packageType);
|
197 |
} catch (Exception e) { |
198 |
/*
|
199 |
* Do nothing, packageInfo remains empty
|
200 |
* form will be empty
|
201 |
*
|
202 |
*/
|
203 |
} |
204 |
} |
205 |
|
206 |
} |
207 |
|
208 |
@Override
|
209 |
public File getFolderToPackaging() { |
210 |
return this.folderToPackaging; |
211 |
} |
212 |
|
213 |
@Override
|
214 |
public PackageInfo getPackageInfo() {
|
215 |
return this.packageInfo; |
216 |
} |
217 |
|
218 |
public URL getDownloadURL() { |
219 |
return this.outputOption.getDownloadURL(); |
220 |
} |
221 |
|
222 |
public File getPackageIndexFile() { |
223 |
return this.outputOption.getPackageIndexFile(); |
224 |
} |
225 |
|
226 |
public boolean shouldCreateIndex() { |
227 |
return this.outputOption.shouldCreateIndex(); |
228 |
} |
229 |
|
230 |
public File getPackageFile() { |
231 |
return this.outputOption.getPackageFile(); |
232 |
} |
233 |
|
234 |
public void addOptionPanel(OptionPanel optionPanel) { |
235 |
this.wizardPanelWithLogo.addOptionPanel(optionPanel);
|
236 |
} |
237 |
|
238 |
public File getDefaultPackageBundleFile() { |
239 |
InstallerManager installerManager = InstallerLocator.getInstallerManager(); |
240 |
String fname = installerManager.getPackageFileName(this.getPackageInfo()); |
241 |
return new File(this.outputFolder, fname); |
242 |
} |
243 |
|
244 |
public File getDefaultPackageIndexBundleFile() { |
245 |
InstallerManager installerManager = InstallerLocator.getInstallerManager(); |
246 |
String fname = installerManager.getPackageIndexFileName(this.getPackageInfo()); |
247 |
return new File(this.outputFolder, fname); |
248 |
} |
249 |
|
250 |
@Override
|
251 |
public JComponent asJComponent() { |
252 |
return this; |
253 |
} |
254 |
|
255 |
@Override
|
256 |
public void addBeforePackingListener(BeforePackingListener listener) { |
257 |
this.beforePackingListener.add(listener);
|
258 |
} |
259 |
|
260 |
public Collection<BeforePackingListener> getBeforePackingListeners() { |
261 |
return this.beforePackingListener; |
262 |
} |
263 |
} |