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