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

History | View | Annotate | Download (5.24 KB)

1 168 cmartin
/* gvSIG. Geographic Information System of the Valencian Government
2 270 cmartin
 *
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 168 cmartin
/*
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.ToolsLocator;
37
import org.gvsig.tools.dataTypes.DataTypes;
38
import org.gvsig.tools.dynobject.DynField;
39
import org.gvsig.tools.dynobject.DynObject;
40
import org.gvsig.tools.service.ServiceException;
41
import org.gvsig.tools.service.spi.AbstractServiceManager;
42
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent;
43
import org.gvsig.tools.swing.api.dynobject.dynfield.ValueField;
44
import org.gvsig.tools.swing.impl.dynobject.dynfield.JComboBoxDynFieldComponent;
45
import org.gvsig.tools.swing.spi.DynObjectSwingServiceManager;
46
47
/**
48
 * @author <a href="mailto:reinhold@uji.es">cmartin</a>
49 270 cmartin
 *
50 168 cmartin
 */
51 270 cmartin
public class DefaultDynObjectSwingServiceManager extends AbstractServiceManager
52
    implements DynObjectSwingServiceManager {
53 168 cmartin
54 270 cmartin
    private DynObject createJDynFieldParams(DynField field) {
55
        int times = 0;
56
        Object res = null;
57
58 298 cmartin
        while ((res == null) && (times < 4)) {
59 270 cmartin
            res = getServiceParams(field, times++);
60 298 cmartin
        }
61 270 cmartin
62
        return (DynObject) res;
63
64 168 cmartin
    }
65
66 306 cordinyana
        public JDynFieldComponent getJDynFieldComponent(ValueField parent,
67
                        boolean getContainerType, boolean writable) throws ServiceException {
68 281 cmartin
        DynField field = parent.getDynField();
69 270 cmartin
        DynObject serviceParams = createJDynFieldParams(field);
70 168 cmartin
71 270 cmartin
        serviceParams
72
            .setDynValue(JDynFieldComponent.PARAMETERS.DYNFIELD, field);
73
        serviceParams.setDynValue(JDynFieldComponent.PARAMETERS.PARENT, parent);
74 306 cordinyana
                serviceParams.setDynValue(JDynFieldComponent.PARAMETERS.WRITABLE,
75
                                Boolean.valueOf(writable));
76 168 cmartin
77 270 cmartin
        return (JDynFieldComponent) this.createService(serviceParams);
78
79
    }
80
81
    public JDynFieldComponent getJSingleComboBoxDynFieldComponent(
82 306 cordinyana
        // TODO: remove this method???
83 281 cmartin
        JDynFieldComponent component, ValueField field) {
84 306 cordinyana
                return new JComboBoxDynFieldComponent(component, field);
85 168 cmartin
86
    }
87
88 270 cmartin
    /*
89
     * (non-Javadoc)
90
     *
91
     * @see
92
     * org.gvsig.tools.service.spi.AbstractServiceManager#getRegistryDescription
93
     * ()
94 168 cmartin
     */
95
    @Override
96
    protected String getRegistryDescription() {
97 270 cmartin
        // TODO Auto-generated method stub
98
        return null;
99 168 cmartin
    }
100 270 cmartin
101
    /*
102
     * (non-Javadoc)
103
     *
104 168 cmartin
     * @see org.gvsig.tools.service.spi.AbstractServiceManager#getRegistryKey()
105
     */
106
    @Override
107
    protected String getRegistryKey() {
108 270 cmartin
        return "DefaultDynObjectSwingServiceManager";
109 168 cmartin
    }
110 270 cmartin
111 168 cmartin
    /**
112
     * @param field
113
     * @return
114
     */
115
    private String getServiceName(DynField field, int times) {
116 270 cmartin
        // if (field.getType()==DataTypes.DYNOBJECT)
117
        // getServiceName(field.getType(),field.get.getFullName(),true);
118
119
        if (times == 0) {
120
            // Search in type and subtype
121
            // if (field.getElementsType()!=null) // if container
122
            // getServiceName(field.getType(),field.getSubType(),true);
123
            //
124
            return getServiceName(field.getType(), field.getSubtype(), true);
125
        }
126 298 cmartin
        if (times == 1) {
127 270 cmartin
            return getServiceName(field.getType(), field.getSubtype(), false);
128 298 cmartin
        }
129 270 cmartin
        return getServiceName(DataTypes.STRING, null, true);
130 168 cmartin
    }
131 270 cmartin
132
    public String getServiceName(int type, String subType) {
133
        return getServiceName(type, subType, true);
134 168 cmartin
    }
135 270 cmartin
136
    public String getServiceName(int type, String subType, boolean useSubType) {
137
        if ((subType == null) || (subType.equals(""))) {
138
            // No subtype
139
            return "field."
140
                + ToolsLocator.getDataTypesManager().getTypeName(type);
141
        }
142 298 cmartin
        if (useSubType) {
143 270 cmartin
            return "field."
144
                + ToolsLocator.getDataTypesManager().getTypeName(type) + "."
145
                + subType;
146 298 cmartin
        }
147 270 cmartin
        return "field." + ToolsLocator.getDataTypesManager().getTypeName(type);
148 168 cmartin
    }
149
150 270 cmartin
    private DynObject getServiceParams(DynField field, int times) {
151
        try {
152
            return this.createServiceParameters(getServiceName(field, times));
153
        } catch (ServiceException e) {
154
            return null;
155
        }
156 168 cmartin
157
    }
158
}