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