Statistics
| Revision:

gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.swing / org.gvsig.tools.swing.spi / src / main / java / org / gvsig / tools / swing / spi / AbstractJDynFieldComponentFactory.java @ 306

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

    
36
import org.gvsig.tools.dynobject.DynClass;
37
import org.gvsig.tools.dynobject.DynField;
38
import org.gvsig.tools.dynobject.DynObject;
39
import org.gvsig.tools.service.Service;
40
import org.gvsig.tools.service.ServiceException;
41
import org.gvsig.tools.service.spi.ServiceManager;
42
import org.gvsig.tools.swing.api.dynobject.JDynObjectComponent;
43
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent;
44
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponentFactory;
45
import org.gvsig.tools.swing.api.dynobject.dynfield.ValueField;
46

    
47
/**
48
 * Extends {@link AbstractSwingServiceFactory} and provides with
49
 * 
50
 * @author 2010 - <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG Team
51
 * @author 2010 - <a href="mailto:reinhold@uji.es">Cristian Mart?n&nbsp;</a> -
52
 *         gvSIG Team
53
 * @version $Id$
54
 * 
55
 */
56
public abstract class AbstractJDynFieldComponentFactory extends
57
    AbstractSwingServiceFactory implements JDynFieldComponentFactory {
58

    
59
    @Override
60
    protected DynClass createParametersDynClass() {
61

    
62
                DynClass dynClassParams = this.getDynClassParams();
63

    
64
                dynClassParams.addDynFieldObject(JDynFieldComponent.PARAMETERS.PARENT)
65
                                .setClassOfValue(ValueField.class).setMandatory(true);
66
                dynClassParams
67
                                .addDynFieldObject(JDynFieldComponent.PARAMETERS.DYNFIELD)
68
                                .setClassOfValue(DynField.class).setMandatory(true);
69
                dynClassParams.addDynFieldBoolean(
70
                                JDynFieldComponent.PARAMETERS.WRITABLE).setMandatory(false);
71
                
72
                return dynClassParams;
73
    }
74

    
75
    /*
76
     * (non-Javadoc)
77
     * 
78
     * @see
79
     * org.gvsig.tools.service.spi.AbstractServiceFactory#doCreate(org.gvsig
80
     * .tools.dynobject.DynObject, org.gvsig.tools.service.spi.ServiceManager)
81
     */
82
    @Override
83
    protected Service doCreate(DynObject parameters,
84
        ServiceManager serviceManager) {
85

    
86
        DynField child =
87
            (DynField) parameters
88
                .getDynValue(JDynFieldComponent.PARAMETERS.DYNFIELD);
89
        ValueField valueField =
90
            (ValueField) parameters
91
                .getDynValue(JDynFieldComponent.PARAMETERS.PARENT);
92

    
93
                Boolean writable = (Boolean) parameters
94
                                .getDynValue(JDynObjectComponent.PARAMETERS.WRITABLE);
95
                writable = writable == null ? Boolean.FALSE : writable;
96

    
97
        //
98
        // JDynObjectComponent parent = (JDynObjectComponent) parameters
99
        // .getDynValue(JDynFieldComponent.PARAMETERS.PARENT);
100
        //
101
        // ValueField valueField = new
102
        // DynObjectValueField(parent.getDynObject(), child.getName());
103
        //        
104
        try {
105
                        JDynFieldComponent comp = this.createJDynFieldComponent(valueField,
106
                                        writable.booleanValue());
107

    
108
            return this.getSuitableComponent(comp, valueField);
109

    
110
        } catch (ServiceException e) {
111
            // TODO Auto-generated catch block
112
            e.printStackTrace();
113
            return null;
114
        }
115
    }
116

    
117
    /*
118
     * (non-Javadoc)
119
     * 
120
     * @see
121
     * org.gvsig.tools.swing.spi.AbstractSwingServiceFactory#getFactoryName()
122
     */
123
    @Override
124
    public String getFactoryName() {
125
        return this.getName();
126
    }
127

    
128
    /*
129
     * (non-Javadoc)
130
     * 
131
     * @see
132
     * org.gvsig.tools.swing.spi.AbstractSwingServiceFactory#getFactoryName()
133
     */
134
    @Override
135
    public String getName() {
136
        return this.getServiceManager().getServiceName(this.getFactoryType(),
137
            this.getFactorySubType());
138
    }
139

    
140
    /**
141
     * Checks if it's a container and has available values to render a JComboBox
142
     * object
143
     * instead of the otherwise created JComponent.
144
     * 
145
     * @param component
146
     *            the JDynFieldComponent created beforehand.
147
     * @param field
148
     *            the ValueField object.
149
     * @return
150
     *         the JDynFieldComponent.
151
     */
152

    
153
    private JDynFieldComponent getSuitableComponent(
154
        JDynFieldComponent component, ValueField field) {
155

    
156
        // if (field.isMultiple())
157
        // comp = new JNDynFieldComponent(component, field);
158

    
159
        // if ((field.isReadOnly()&&(field.getType()==DataTypes.STRING))){
160
        // return
161
        // this.getServiceManager().getJSingleReadOnlyDynFieldComponent(component,
162
        // field);
163
        // }
164
        if ((!field.getDynField().isContainer())
165
            && ((field.getDynField().getAvailableValues() != null))) {
166
            return this.getServiceManager()
167
                .getJSingleComboBoxDynFieldComponent(component, field);
168
        }
169
        return component;
170
    }
171

    
172
    /*
173
     * (non-Javadoc)
174
     * 
175
     * @see org.gvsig.tools.service.spi.ServiceFactory#initialize()
176
     */
177
    public void initialize() {
178
        // do nothing
179
    }
180
}