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 / DefaultDynObjectSwingServiceManager.java @ 298

History | View | Annotate | Download (5.28 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 java.util.Locale;
37

    
38
import org.gvsig.tools.ToolsLocator;
39
import org.gvsig.tools.dataTypes.DataTypes;
40
import org.gvsig.tools.dynobject.DynField;
41
import org.gvsig.tools.dynobject.DynObject;
42
import org.gvsig.tools.service.ServiceException;
43
import org.gvsig.tools.service.spi.AbstractServiceManager;
44
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent;
45
import org.gvsig.tools.swing.api.dynobject.dynfield.ValueField;
46
import org.gvsig.tools.swing.impl.dynobject.dynfield.JComboBoxDynFieldComponent;
47
import org.gvsig.tools.swing.spi.DynObjectSwingServiceManager;
48

    
49
/**
50
 * @author <a href="mailto:reinhold@uji.es">cmartin</a>
51
 * 
52
 */
53
public class DefaultDynObjectSwingServiceManager extends AbstractServiceManager
54
    implements DynObjectSwingServiceManager {
55

    
56
    private DynObject createJDynFieldParams(DynField field) {
57
        int times = 0;
58
        Object res = null;
59

    
60
        while ((res == null) && (times < 4)) {
61
            res = getServiceParams(field, times++);
62
        }
63
        if (res == null) {
64
            return null;
65
        }
66

    
67
        return (DynObject) res;
68

    
69
    }
70

    
71
    public JDynFieldComponent getJDynFieldComponent(ValueField parent,
72
        boolean getContainerType) throws ServiceException {
73
        DynField field = parent.getDynField();
74
        DynObject serviceParams = createJDynFieldParams(field);
75

    
76
        serviceParams
77
            .setDynValue(JDynFieldComponent.PARAMETERS.DYNFIELD, field);
78
        serviceParams.setDynValue(JDynFieldComponent.PARAMETERS.PARENT, parent);
79

    
80
        return (JDynFieldComponent) this.createService(serviceParams);
81

    
82
    }
83

    
84
    public JDynFieldComponent getJSingleComboBoxDynFieldComponent(
85
        JDynFieldComponent component, ValueField field) {
86
        return new JComboBoxDynFieldComponent(component, field, getLocale());
87

    
88
    }
89

    
90
    private Locale getLocale() {
91
        return new Locale("es-ES");
92
    }
93

    
94
    /*
95
     * (non-Javadoc)
96
     * 
97
     * @see
98
     * org.gvsig.tools.service.spi.AbstractServiceManager#getRegistryDescription
99
     * ()
100
     */
101
    @Override
102
    protected String getRegistryDescription() {
103
        // TODO Auto-generated method stub
104
        return null;
105
    }
106

    
107
    /*
108
     * (non-Javadoc)
109
     * 
110
     * @see org.gvsig.tools.service.spi.AbstractServiceManager#getRegistryKey()
111
     */
112
    @Override
113
    protected String getRegistryKey() {
114
        return "DefaultDynObjectSwingServiceManager";
115
    }
116

    
117
    /**
118
     * @param field
119
     * @return
120
     */
121
    private String getServiceName(DynField field, int times) {
122
        // if (field.getType()==DataTypes.DYNOBJECT)
123
        // getServiceName(field.getType(),field.get.getFullName(),true);
124

    
125
        if (times == 0) {
126
            // Search in type and subtype
127
            // if (field.getElementsType()!=null) // if container
128
            // getServiceName(field.getType(),field.getSubType(),true);
129
            //                        
130
            return getServiceName(field.getType(), field.getSubtype(), true);
131
        }
132
        if (times == 1) {
133
            return getServiceName(field.getType(), field.getSubtype(), false);
134
        }
135
        return getServiceName(DataTypes.STRING, null, true);
136
    }
137

    
138
    public String getServiceName(int type, String subType) {
139
        return getServiceName(type, subType, true);
140
    }
141

    
142
    public String getServiceName(int type, String subType, boolean useSubType) {
143
        if ((subType == null) || (subType.equals(""))) {
144
            // No subtype
145
            return "field."
146
                + ToolsLocator.getDataTypesManager().getTypeName(type);
147
        }
148
        if (useSubType) {
149
            return "field."
150
                + ToolsLocator.getDataTypesManager().getTypeName(type) + "."
151
                + subType;
152
        }
153
        return "field." + ToolsLocator.getDataTypesManager().getTypeName(type);
154
    }
155

    
156
    private DynObject getServiceParams(DynField field, int times) {
157
        try {
158
            return this.createServiceParameters(getServiceName(field, times));
159
        } catch (ServiceException e) {
160
            return null;
161
        }
162

    
163
    }
164
}