Statistics
| Revision:

gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.swing / org.gvsig.tools.swing.impl / src / main / java / org / gvsig / tools / swing / impl / dynobject / DefaultDynObjectModel.java @ 632

History | View | Annotate | Download (3.9 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22
/*
23
 * AUTHORS (In addition to CIT):
24
 * 2010 Institute of New Imaging Technologies (INIT): 
25
 *   http://www.init.uji.es
26
 * Geographic Information research group: 
27
 *   http://www.geoinfo.uji.es
28
 * Universitat Jaume I, Spain
29
 */
30

    
31
/**
32
 * 
33
 */
34
package org.gvsig.tools.swing.impl.dynobject;
35

    
36
import org.gvsig.tools.dataTypes.DataTypes;
37
import org.gvsig.tools.dynobject.DynField;
38
import org.gvsig.tools.dynobject.DynStruct;
39
import org.gvsig.tools.swing.api.dynobject.DynFieldModel;
40
import org.gvsig.tools.swing.api.dynobject.DynObjectModel;
41

    
42
/**
43
 * 
44
 * {@link DynObjectModel} that basically consists of a {@link DynFieldModel}
45
 * elements' container.
46
 * 
47
 * @author 2010 - <a href="cordinyana@gvsig.org">C�sar Ordi�ana</a> - gvSIG
48
 *         Team
49
 * @author 2010 - <a href="mailto:reinhold@uji.es">Cristian Mart�n&nbsp;</a> -
50
 *         gvSIG Team
51
 * @version $Id$
52
 * 
53
 */
54
public class DefaultDynObjectModel extends AbstractDynObjectModel implements
55
                DynObjectModel {
56

    
57
        /**
58
         * Constructor.
59
         * 
60
         * @param theClass
61
         *            the current DynClass.
62
         * @param initAll
63
         * <br>
64
         *            &nbsp;&nbsp;&nbsp;&nbsp;<b>true</b>&nbsp;&nbsp;&nbsp;if we
65
         *            want to populate the Model with the default given values. <br>
66
         *            &nbsp;&nbsp;&nbsp;&nbsp;<b>false</b>&nbsp;&nbsp;if we want to
67
         *            get an empty DynObjectModel.
68
         */
69
        public DefaultDynObjectModel(DynStruct definition, boolean initAll) {
70
                super(definition, initAll);
71
        }
72

    
73
        /*
74
         * (non-Javadoc)
75
         * 
76
         * @seeorg.gvsig.tools.swing.spi.AbstractDynObjectModel#
77
         * createDynObjectComponentModelElement(org.gvsig.tools.dynobject.DynField,
78
         * org.gvsig.tools.dynobject.DynClass)
79
         */
80
        @Override
81
        protected DynFieldModel createDynObjectModelElement(String fieldName,
82
                        DynStruct definition, String group) {
83
                return new DefaultDynObjectModelElement(fieldName, definition, group);
84
        }
85

    
86
        /*
87
         * (non-Javadoc)
88
         * 
89
         * @seeorg.gvsig.tools.swing.spi.AbstractDynObjectModel#
90
         * initDynFieldModelList()
91
         */
92
        @Override
93
        protected void initDynFieldModelList() {
94
                if (this.dynStruct == null) {
95
                        return;
96
                }
97
                this.addGroup(getGenericLabel());
98

    
99
                DynField[] fields = this.dynStruct.getDynFields();
100
                if (fields == null) {
101
                        return;
102
                }
103
                DynField field = null;
104
                for (int i = 0; i < fields.length; i++) {
105
                        field = fields[i];
106
                        if (!field.isHidden()) {
107
                                String group = field.getGroup();
108
                                if (group != null && !group.equalsIgnoreCase("")) {
109
                                        this.add(group, field.getName());
110
                                } else {
111
                                        if ((field.getType() == DataTypes.DYNOBJECT)
112
                                                        || ((field.isContainer()) && (field
113
                                                                        .getElementsType().getType() == DataTypes.DYNOBJECT)))
114
                                                if (field.isMandatory()) {
115
                                                        this.add(field.getName(), field.getName());
116
                                                } else {
117
                                                        this.add(field.getName(), field.getName());
118
                                                }
119
                                        else{
120
                                                this.add(getGenericLabel(), field.getName());
121
                                        }
122
                                }
123
                        }
124
                }
125
        }
126

    
127
        public String getGenericLabel() {
128
                return "General";
129
        }
130
}