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