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 / creation / panel / DefaultPackageInfoPanel.java @ 42580
History | View | Annotate | Download (8.57 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 |
/*
|
25 |
* AUTHORS (In addition to CIT):
|
26 |
* 2010 {Prodevelop} {Task}
|
27 |
*/
|
28 |
|
29 |
package org.gvsig.installer.swing.impl.creation.panel; |
30 |
|
31 |
import java.awt.BorderLayout; |
32 |
import java.io.InputStream; |
33 |
import java.net.URL; |
34 |
import java.util.List; |
35 |
import java.util.Map; |
36 |
|
37 |
import org.gvsig.installer.lib.api.PackageInfo; |
38 |
import org.gvsig.installer.lib.api.Version; |
39 |
import org.gvsig.installer.swing.api.SwingInstallerLocator; |
40 |
import org.gvsig.installer.swing.api.creation.JPackageInfoPanel; |
41 |
import org.gvsig.installer.swing.impl.DefaultSwingInstallerManager; |
42 |
import org.gvsig.tools.ToolsLocator; |
43 |
import org.gvsig.tools.dynform.DynFormLocator; |
44 |
import org.gvsig.tools.dynform.DynFormManager; |
45 |
import org.gvsig.tools.dynform.JDynForm; |
46 |
import org.gvsig.tools.dynobject.DynField; |
47 |
import org.gvsig.tools.dynobject.DynObject; |
48 |
import org.gvsig.tools.dynobject.DynObjectManager; |
49 |
import org.gvsig.tools.dynobject.DynObjectValueItem; |
50 |
import org.gvsig.tools.dynobject.DynStruct; |
51 |
import org.gvsig.tools.packageutils.impl.PackageInfoTags; |
52 |
import org.gvsig.tools.service.spi.ProviderFactory; |
53 |
import org.gvsig.tools.service.spi.ProviderManager_WithGetFactories; |
54 |
import org.slf4j.Logger; |
55 |
import org.slf4j.LoggerFactory; |
56 |
import org.gvsig.installer.lib.spi.InstallerProviderLocator; |
57 |
|
58 |
public class DefaultPackageInfoPanel extends JPackageInfoPanel { |
59 |
|
60 |
private static final Logger logger = LoggerFactory.getLogger(DefaultPackageInfoPanel.class); |
61 |
|
62 |
private static final long serialVersionUID = 3220127550495628087L; |
63 |
|
64 |
protected DefaultSwingInstallerManager swingInstallerManager = null; |
65 |
|
66 |
private JDynForm form = null; |
67 |
private DynObject data = null; |
68 |
private final String packageType; |
69 |
|
70 |
|
71 |
public DefaultPackageInfoPanel() {
|
72 |
this(null); |
73 |
} |
74 |
|
75 |
public DefaultPackageInfoPanel(String packageType) { |
76 |
super();
|
77 |
this.packageType = packageType;
|
78 |
swingInstallerManager = (DefaultSwingInstallerManager) SwingInstallerLocator |
79 |
.getSwingInstallerManager(); |
80 |
initComponents(); |
81 |
} |
82 |
|
83 |
private void initComponents() { |
84 |
DynObjectManager dynObjectManager = ToolsLocator.getDynObjectManager(); |
85 |
InputStream resource = this.getClass().getClassLoader().getResourceAsStream("org/gvsig/installer/swing/impl/creation/panel/formPackageinfo.xml"); |
86 |
try {
|
87 |
Map definitions = dynObjectManager.importDynClassDefinitions(resource, this.getClass().getClassLoader()); |
88 |
DynStruct definition = (DynStruct) definitions.get("FormPackageinfo");
|
89 |
DynField dynField = definition.getDynField("type");
|
90 |
setAvailableValuesOfFieldType(dynField); |
91 |
if( this.packageType!=null ) { |
92 |
dynField.setReadOnly(true);
|
93 |
} |
94 |
this.data = dynObjectManager.createDynObject(definition);
|
95 |
if( this.packageType!=null ) { |
96 |
this.data.setDynValue("type", this.packageType); |
97 |
} |
98 |
DynFormManager dynFormManager = DynFormLocator.getDynFormManager(); |
99 |
this.form = dynFormManager.createJDynForm(data);
|
100 |
} catch (Exception e) { |
101 |
// Uf....
|
102 |
logger.warn("No se puede crear el formulario.", e);
|
103 |
throw new RuntimeException("No se puede crear el formulario.", e); |
104 |
} |
105 |
|
106 |
this.setLayout(new BorderLayout(4, 4)); |
107 |
this.add(form.asJComponent(),BorderLayout.CENTER); |
108 |
} |
109 |
|
110 |
|
111 |
protected String findCurrentGvSIGVersion() { |
112 |
return SwingInstallerLocator.getSwingInstallerManager()
|
113 |
.getApplicationVersion(); |
114 |
} |
115 |
|
116 |
|
117 |
public String getName() { |
118 |
return (String) this.form.getValue(PackageInfoTags.NAME); |
119 |
} |
120 |
|
121 |
public void setName(String name) { |
122 |
this.form.setValue(PackageInfoTags.NAME, name);
|
123 |
} |
124 |
|
125 |
|
126 |
@Override
|
127 |
public boolean validatePanel() { |
128 |
return this.form.hasValidValues(); |
129 |
} |
130 |
|
131 |
@Override
|
132 |
public void panelToPackageInfo(PackageInfo packageInfo) { |
133 |
|
134 |
this.form.getValues(data);
|
135 |
packageInfo.setType( (String) data.getDynValue(PackageInfoTags.TYPE));
|
136 |
packageInfo.setCode( (String) data.getDynValue(PackageInfoTags.CODE));
|
137 |
packageInfo.setName((String) data.getDynValue(PackageInfoTags.NAME));
|
138 |
packageInfo.setDescription((String) data.getDynValue(PackageInfoTags.DESCRIPTION));
|
139 |
packageInfo.setVersion((Version) data.getDynValue(PackageInfoTags.VERSION)); |
140 |
packageInfo.setBuild(((Integer) data.getDynValue(PackageInfoTags.BUILD)).intValue());
|
141 |
packageInfo.setState((String) data.getDynValue(PackageInfoTags.STATE));
|
142 |
packageInfo.setOfficial(((Boolean) data.getDynValue(PackageInfoTags.OFFICIAL)).booleanValue());
|
143 |
packageInfo.setOperatingSystem((String) data.getDynValue(PackageInfoTags.OS));
|
144 |
packageInfo.setArchitecture((String) data.getDynValue(PackageInfoTags.ARCHITECTURE));
|
145 |
packageInfo.setJavaVM((String) data.getDynValue(PackageInfoTags.JVM));
|
146 |
packageInfo.setGvSIGVersion((String) data.getDynValue(PackageInfoTags.GVSIG_VERSION));
|
147 |
packageInfo.setSourcesURL((URL) data.getDynValue(PackageInfoTags.SOURCES_URL));
|
148 |
packageInfo.setOwnerURL((URL) data.getDynValue(PackageInfoTags.OWNER_URL));
|
149 |
packageInfo.setOwner((String) data.getDynValue(PackageInfoTags.OWNER));
|
150 |
packageInfo.setDependencies((String) data.getDynValue(PackageInfoTags.DEPENDENCIES));
|
151 |
packageInfo.addCategoriesAsString((String) data.getDynValue(PackageInfoTags.CATEGORIES));
|
152 |
} |
153 |
|
154 |
private boolean isEmptyString(String s) { |
155 |
if( s==null) { |
156 |
return true; |
157 |
} |
158 |
return s.length() == 0; |
159 |
} |
160 |
|
161 |
@Override
|
162 |
public void packageInfoToPanel(PackageInfo packageInfo) { |
163 |
if( this.packageType!=null ) { |
164 |
this.data.setDynValue(PackageInfoTags.TYPE, this.packageType); |
165 |
} else {
|
166 |
this.data.setDynValue(PackageInfoTags.TYPE, packageInfo.getType());
|
167 |
} |
168 |
this.data.setDynValue(PackageInfoTags.CODE, packageInfo.getCode());
|
169 |
this.data.setDynValue(PackageInfoTags.NAME, packageInfo.getName());
|
170 |
this.data.setDynValue(PackageInfoTags.VERSION, packageInfo.getVersion());
|
171 |
this.data.setDynValue(PackageInfoTags.GVSIG_VERSION, findCurrentGvSIGVersion());
|
172 |
this.data.setDynValue(PackageInfoTags.BUILD, packageInfo.getBuild());
|
173 |
this.data.setDynValue(PackageInfoTags.OFFICIAL, packageInfo.isOfficial());
|
174 |
this.data.setDynValue(PackageInfoTags.STATE, packageInfo.getState());
|
175 |
this.data.setDynValue(PackageInfoTags.DESCRIPTION, packageInfo.getDescription());
|
176 |
this.data.setDynValue(PackageInfoTags.OS, packageInfo.getOperatingSystem());
|
177 |
this.data.setDynValue(PackageInfoTags.ARCHITECTURE, packageInfo.getArchitecture());
|
178 |
this.data.setDynValue(PackageInfoTags.JVM, packageInfo.getJavaVM());
|
179 |
this.data.setDynValue(PackageInfoTags.SOURCES_URL, packageInfo.getSourcesURL());
|
180 |
this.data.setDynValue(PackageInfoTags.OWNER, packageInfo.getOwner());
|
181 |
this.data.setDynValue(PackageInfoTags.OWNER_URL, packageInfo.getOwnerURL());
|
182 |
this.data.setDynValue(PackageInfoTags.DEPENDENCIES, packageInfo.getDependencies());
|
183 |
this.data.setDynValue(PackageInfoTags.CATEGORIES, packageInfo.getCategoriesAsString());
|
184 |
//this.data.setDynValue(PackageInfoTags.CODEALIAS, packageInfo.getAllCodes().toString());
|
185 |
this.form.getField(PackageInfoTags.CODEALIAS).setReadOnly(true); |
186 |
|
187 |
// if ( !isEmptyString(packageInfo.getCode()) ){
|
188 |
// this.form.getField(PackageInfoTags.CODE).setReadOnly(true);
|
189 |
// }
|
190 |
this.form.setValues(data);
|
191 |
|
192 |
} |
193 |
|
194 |
private void setAvailableValuesOfFieldType(DynField dynField) { |
195 |
ProviderManager_WithGetFactories providerManager = InstallerProviderLocator.getProviderManager(); |
196 |
List<ProviderFactory> factories = providerManager.getProviderFactories();
|
197 |
DynObjectValueItem[] values = new DynObjectValueItem[factories.size()]; |
198 |
int i=0; |
199 |
for( ProviderFactory factory : factories ) {
|
200 |
String name = factory.getName();
|
201 |
values[i++] = new DynObjectValueItem(name,name);
|
202 |
} |
203 |
dynField.setAvailableValues(values); |
204 |
} |
205 |
|
206 |
|
207 |
} |