Statistics
| Revision:

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 @ 42534

History | View | Annotate | Download (7.7 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.Map;
35

    
36
import org.gvsig.installer.lib.api.PackageInfo;
37
import org.gvsig.installer.lib.api.Version;
38
import org.gvsig.installer.swing.api.SwingInstallerLocator;
39
import org.gvsig.installer.swing.api.creation.JPackageInfoPanel;
40
import org.gvsig.installer.swing.impl.DefaultSwingInstallerManager;
41
import org.gvsig.tools.ToolsLocator;
42
import org.gvsig.tools.dynform.DynFormLocator;
43
import org.gvsig.tools.dynform.DynFormManager;
44
import org.gvsig.tools.dynform.JDynForm;
45
import org.gvsig.tools.dynobject.DynField;
46
import org.gvsig.tools.dynobject.DynObject;
47
import org.gvsig.tools.dynobject.DynObjectManager;
48
import org.gvsig.tools.dynobject.DynStruct;
49
import org.gvsig.tools.packageutils.impl.PackageInfoTags;
50
import org.slf4j.Logger;
51
import org.slf4j.LoggerFactory;
52

    
53
public class DefaultPackageInfoPanel extends JPackageInfoPanel {
54

    
55
        private static final Logger logger = LoggerFactory.getLogger(DefaultPackageInfoPanel.class);
56
        
57
        private static final long serialVersionUID = 3220127550495628087L;
58

    
59
        protected DefaultSwingInstallerManager swingInstallerManager = null;
60

    
61
        private JDynForm form = null;
62
        private DynObject data = null;
63
        private final String packageType;
64

    
65
        
66
        public DefaultPackageInfoPanel() {
67
            this(null);
68
        }
69
        
70
        public DefaultPackageInfoPanel(String packageType) {
71
                super();
72
                this.packageType = packageType;
73
                swingInstallerManager = (DefaultSwingInstallerManager) SwingInstallerLocator
74
                                .getSwingInstallerManager();
75
                initComponents();
76
        }
77

    
78
        private void initComponents() {
79
                DynObjectManager dynObjectManager = ToolsLocator.getDynObjectManager();
80
                InputStream resource = this.getClass().getClassLoader().getResourceAsStream("org/gvsig/installer/swing/impl/creation/panel/formPackageinfo.xml");
81
                try {
82
                        Map definitions = dynObjectManager.importDynClassDefinitions(resource, this.getClass().getClassLoader());
83
                        DynStruct definition = (DynStruct) definitions.get("FormPackageinfo");
84
                        if( this.packageType!=null ) {
85
                            DynField dynField = definition.getDynField("type");
86
                            dynField.setReadOnly(true);
87
                        }
88
                        this.data = dynObjectManager.createDynObject(definition);
89
                        if( this.packageType!=null ) {
90
                            this.data.setDynValue("type", this.packageType);
91
                        }
92
                        DynFormManager dynFormManager = DynFormLocator.getDynFormManager();
93
                        this.form = dynFormManager.createJDynForm(data);
94
                } catch (Exception e) {
95
                        // Uf....
96
                        logger.warn("No se puede crear el formulario.", e);
97
                        throw new RuntimeException("No se puede crear el formulario.", e);
98
                }
99
                
100
                this.setLayout(new BorderLayout(4, 4));
101
                this.add(form.asJComponent(),BorderLayout.CENTER);
102
        }
103
        
104
        
105
        protected String findCurrentGvSIGVersion() {
106
                return SwingInstallerLocator.getSwingInstallerManager()
107
                                .getApplicationVersion();
108
        }
109

    
110

    
111
        public String getName() {
112
                return (String) this.form.getValue(PackageInfoTags.NAME);
113
        }
114

    
115
        public void setName(String name) {
116
                this.form.setValue(PackageInfoTags.NAME, name);
117
        }
118

    
119

    
120
        @Override
121
        public boolean validatePanel() {
122
                return this.form.hasValidValues();
123
        }
124

    
125
        @Override
126
        public void panelToPackageInfo(PackageInfo packageInfo) {
127
                
128
                this.form.getValues(data);
129
                packageInfo.setType( (String) data.getDynValue(PackageInfoTags.TYPE));
130
                packageInfo.setCode( (String) data.getDynValue(PackageInfoTags.CODE));
131
                packageInfo.setName((String) data.getDynValue(PackageInfoTags.NAME));
132
                packageInfo.setDescription((String) data.getDynValue(PackageInfoTags.DESCRIPTION));
133
                packageInfo.setVersion((Version) data.getDynValue(PackageInfoTags.VERSION));
134
                packageInfo.setBuild(((Integer) data.getDynValue(PackageInfoTags.BUILD)).intValue());
135
                packageInfo.setState((String) data.getDynValue(PackageInfoTags.STATE));
136
                packageInfo.setOfficial(((Boolean) data.getDynValue(PackageInfoTags.OFFICIAL)).booleanValue());
137
                packageInfo.setOperatingSystem((String) data.getDynValue(PackageInfoTags.OS));
138
                packageInfo.setArchitecture((String) data.getDynValue(PackageInfoTags.ARCHITECTURE));
139
                packageInfo.setJavaVM((String) data.getDynValue(PackageInfoTags.JVM));
140
                packageInfo.setGvSIGVersion((String) data.getDynValue(PackageInfoTags.GVSIG_VERSION));
141
                packageInfo.setSourcesURL((URL) data.getDynValue(PackageInfoTags.SOURCES_URL));
142
                packageInfo.setOwnerURL((URL) data.getDynValue(PackageInfoTags.OWNER_URL));
143
                packageInfo.setOwner((String) data.getDynValue(PackageInfoTags.OWNER));
144
                packageInfo.setDependencies((String) data.getDynValue(PackageInfoTags.DEPENDENCIES));
145
                packageInfo.addCategoriesAsString((String) data.getDynValue(PackageInfoTags.CATEGORIES));
146
        }
147

    
148
        private boolean isEmptyString(String s) {
149
                if( s==null) {
150
                        return true;
151
                }
152
                return s.length() == 0; 
153
        }
154
        
155
        @Override
156
        public void packageInfoToPanel(PackageInfo packageInfo) {
157
                if( this.packageType!=null ) {
158
                    this.data.setDynValue(PackageInfoTags.TYPE, this.packageType);
159
                } else {
160
                    this.data.setDynValue(PackageInfoTags.TYPE, packageInfo.getType());
161
                }
162
                this.data.setDynValue(PackageInfoTags.CODE, packageInfo.getCode());
163
                this.data.setDynValue(PackageInfoTags.NAME, packageInfo.getName());
164
                this.data.setDynValue(PackageInfoTags.VERSION, packageInfo.getVersion());
165
                this.data.setDynValue(PackageInfoTags.GVSIG_VERSION, findCurrentGvSIGVersion());
166
                this.data.setDynValue(PackageInfoTags.BUILD, packageInfo.getBuild());
167
                this.data.setDynValue(PackageInfoTags.OFFICIAL, packageInfo.isOfficial());
168
                this.data.setDynValue(PackageInfoTags.STATE, packageInfo.getState());
169
                this.data.setDynValue(PackageInfoTags.DESCRIPTION, packageInfo.getDescription());
170
                this.data.setDynValue(PackageInfoTags.OS, packageInfo.getOperatingSystem());
171
                this.data.setDynValue(PackageInfoTags.ARCHITECTURE, packageInfo.getArchitecture());
172
                this.data.setDynValue(PackageInfoTags.JVM, packageInfo.getJavaVM());
173
                this.data.setDynValue(PackageInfoTags.SOURCES_URL, packageInfo.getSourcesURL());
174
                this.data.setDynValue(PackageInfoTags.OWNER, packageInfo.getOwner());
175
                this.data.setDynValue(PackageInfoTags.OWNER_URL, packageInfo.getOwnerURL());
176
                this.data.setDynValue(PackageInfoTags.DEPENDENCIES, packageInfo.getDependencies());
177
                this.data.setDynValue(PackageInfoTags.CATEGORIES, packageInfo.getCategoriesAsString());
178
                //this.data.setDynValue(PackageInfoTags.CODEALIAS, packageInfo.getAllCodes().toString());
179
                this.form.getField(PackageInfoTags.CODEALIAS).setReadOnly(true);
180
                
181
//                if (  !isEmptyString(packageInfo.getCode()) ){
182
//                        this.form.getField(PackageInfoTags.CODE).setReadOnly(true);
183
//                }
184
                this.form.setValues(data);
185

    
186
        }
187
        
188

    
189
}