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 @ 270
History | View | Annotate | Download (5.79 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.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 |
*
|
50 |
*/
|
51 |
public class DefaultDynObjectSwingServiceManager extends AbstractServiceManager |
52 |
implements DynObjectSwingServiceManager {
|
53 |
|
54 |
private DynObject createJDynFieldParams(DynField field) {
|
55 |
int times = 0; |
56 |
Object res = null; |
57 |
|
58 |
while ((res == null) && (times < 4)) |
59 |
res = getServiceParams(field, times++); |
60 |
if (res == null) |
61 |
return null; |
62 |
|
63 |
return (DynObject) res;
|
64 |
|
65 |
} |
66 |
|
67 |
public JDynFieldComponent getJDynFieldComponent(ValueField parent,
|
68 |
DynField field, boolean getContainerType) throws ServiceException { |
69 |
|
70 |
DynObject serviceParams = createJDynFieldParams(field); |
71 |
|
72 |
serviceParams |
73 |
.setDynValue(JDynFieldComponent.PARAMETERS.DYNFIELD, field); |
74 |
serviceParams.setDynValue(JDynFieldComponent.PARAMETERS.PARENT, parent); |
75 |
|
76 |
return (JDynFieldComponent) this.createService(serviceParams); |
77 |
|
78 |
} |
79 |
|
80 |
/*
|
81 |
* (non-Javadoc)
|
82 |
*
|
83 |
* @seeorg.gvsig.tools.swing.spi.DynObjectSwingServiceManager#
|
84 |
* getJSingleComboBoxDynFieldComponent(org.gvsig.tools.dynobject.DynField,
|
85 |
* org.gvsig.tools.swing.api.dynobject.dynfield.ValueField)
|
86 |
*/
|
87 |
public JDynFieldComponent getJSingleComboBoxDynFieldComponent(
|
88 |
JDynFieldComponent component, DynField field) { |
89 |
return new JComboBoxDynFieldComponent(component, field); |
90 |
|
91 |
} |
92 |
|
93 |
/*
|
94 |
* (non-Javadoc)
|
95 |
*
|
96 |
* @see
|
97 |
* org.gvsig.tools.service.spi.AbstractServiceManager#getRegistryDescription
|
98 |
* ()
|
99 |
*/
|
100 |
@Override
|
101 |
protected String getRegistryDescription() { |
102 |
// TODO Auto-generated method stub
|
103 |
return null; |
104 |
} |
105 |
|
106 |
/*
|
107 |
* (non-Javadoc)
|
108 |
*
|
109 |
* @see org.gvsig.tools.service.spi.AbstractServiceManager#getRegistryKey()
|
110 |
*/
|
111 |
@Override
|
112 |
protected String getRegistryKey() { |
113 |
return "DefaultDynObjectSwingServiceManager"; |
114 |
} |
115 |
|
116 |
/**
|
117 |
* @param field
|
118 |
* @return
|
119 |
*/
|
120 |
private String getServiceName(DynField field, int times) { |
121 |
// if (field.getType()==DataTypes.DYNOBJECT)
|
122 |
// getServiceName(field.getType(),field.get.getFullName(),true);
|
123 |
|
124 |
if (times == 0) { |
125 |
// Search in type and subtype
|
126 |
// if (field.getElementsType()!=null) // if container
|
127 |
// getServiceName(field.getType(),field.getSubType(),true);
|
128 |
//
|
129 |
return getServiceName(field.getType(), field.getSubtype(), true); |
130 |
} |
131 |
if (times == 1) |
132 |
return getServiceName(field.getType(), field.getSubtype(), false); |
133 |
return getServiceName(DataTypes.STRING, null, true); |
134 |
} |
135 |
|
136 |
public String getServiceName(int type, String subType) { |
137 |
return getServiceName(type, subType, true); |
138 |
} |
139 |
|
140 |
public String getServiceName(int type, String subType, boolean useSubType) { |
141 |
if ((subType == null) || (subType.equals(""))) { |
142 |
// No subtype
|
143 |
return "field." |
144 |
+ ToolsLocator.getDataTypesManager().getTypeName(type); |
145 |
} |
146 |
if (useSubType)
|
147 |
return "field." |
148 |
+ ToolsLocator.getDataTypesManager().getTypeName(type) + "."
|
149 |
+ subType; |
150 |
return "field." + ToolsLocator.getDataTypesManager().getTypeName(type); |
151 |
} |
152 |
|
153 |
private DynObject getServiceParams(DynField field, int times) { |
154 |
try {
|
155 |
return this.createServiceParameters(getServiceName(field, times)); |
156 |
} catch (ServiceException e) {
|
157 |
return null; |
158 |
} |
159 |
|
160 |
} |
161 |
|
162 |
// /* (non-Javadoc)
|
163 |
// * @see
|
164 |
// org.gvsig.tools.swing.spi.DynObjectSwingServiceManager#getJSingleReadOnlyDynFieldComponent(org.gvsig.tools.dynobject.DynField,
|
165 |
// org.gvsig.tools.swing.api.dynobject.dynfield.ValueField)
|
166 |
// */
|
167 |
// public JDynFieldComponent
|
168 |
// getJSingleReadOnlyDynFieldComponent(JDynFieldComponent component,
|
169 |
// DynField field) {
|
170 |
// return new JReadOnlyDynFieldComponent(component, field);
|
171 |
// }
|
172 |
|
173 |
} |