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 @ 631
History | View | Annotate | Download (5.63 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.dataTypes.DataTypes; |
37 |
import org.gvsig.tools.dynobject.DynClass; |
38 |
import org.gvsig.tools.dynobject.DynField; |
39 |
import org.gvsig.tools.dynobject.DynObject; |
40 |
import org.gvsig.tools.dynobject.DynObjectValueItem; |
41 |
import org.gvsig.tools.service.Service; |
42 |
import org.gvsig.tools.service.ServiceException; |
43 |
import org.gvsig.tools.service.spi.ServiceManager; |
44 |
import org.gvsig.tools.swing.api.dynobject.JDynObjectComponent; |
45 |
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent; |
46 |
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponentFactory; |
47 |
import org.gvsig.tools.swing.api.dynobject.dynfield.ValueField; |
48 |
|
49 |
/**
|
50 |
* Extends {@link AbstractSwingServiceFactory} and provides with
|
51 |
*
|
52 |
* @author 2010 - <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG Team
|
53 |
* @author 2010 - <a href="mailto:reinhold@uji.es">Cristian Mart?n </a> -
|
54 |
* gvSIG Team
|
55 |
* @version $Id$
|
56 |
*
|
57 |
*/
|
58 |
public abstract class AbstractJDynFieldComponentFactory extends |
59 |
AbstractSwingServiceFactory implements JDynFieldComponentFactory {
|
60 |
|
61 |
@Override
|
62 |
protected DynClass createParametersDynClass() {
|
63 |
|
64 |
DynClass dynClassParams = this.getDynClassParams();
|
65 |
|
66 |
dynClassParams.addDynFieldObject(JDynFieldComponent.PARAMETERS.PARENT) |
67 |
.setClassOfValue(ValueField.class).setMandatory(true);
|
68 |
dynClassParams |
69 |
.addDynFieldObject(JDynFieldComponent.PARAMETERS.DYNFIELD) |
70 |
.setClassOfValue(DynField.class).setMandatory(true);
|
71 |
dynClassParams.addDynFieldBoolean( |
72 |
JDynFieldComponent.PARAMETERS.WRITABLE).setMandatory(false);
|
73 |
|
74 |
return dynClassParams;
|
75 |
} |
76 |
|
77 |
/*
|
78 |
* (non-Javadoc)
|
79 |
*
|
80 |
* @see
|
81 |
* org.gvsig.tools.service.spi.AbstractServiceFactory#doCreate(org.gvsig
|
82 |
* .tools.dynobject.DynObject, org.gvsig.tools.service.spi.ServiceManager)
|
83 |
*/
|
84 |
@Override
|
85 |
protected Service doCreate(DynObject parameters,
|
86 |
ServiceManager serviceManager) { |
87 |
|
88 |
DynField child = |
89 |
(DynField) parameters |
90 |
.getDynValue(JDynFieldComponent.PARAMETERS.DYNFIELD); |
91 |
ValueField valueField = |
92 |
(ValueField) parameters |
93 |
.getDynValue(JDynFieldComponent.PARAMETERS.PARENT); |
94 |
|
95 |
Boolean writable = (Boolean) parameters |
96 |
.getDynValue(JDynObjectComponent.PARAMETERS.WRITABLE); |
97 |
writable = ( writable == null ? Boolean.TRUE : writable ); |
98 |
|
99 |
try {
|
100 |
JDynFieldComponent comp = this.createJDynFieldComponent(child, valueField,
|
101 |
writable.booleanValue()); |
102 |
|
103 |
return this.getSuitableComponent(comp, valueField); |
104 |
|
105 |
} catch (ServiceException e) {
|
106 |
// TODO Auto-generated catch block
|
107 |
e.printStackTrace(); |
108 |
return null; |
109 |
} |
110 |
} |
111 |
|
112 |
/*
|
113 |
* (non-Javadoc)
|
114 |
*
|
115 |
* @see
|
116 |
* org.gvsig.tools.swing.spi.AbstractSwingServiceFactory#getFactoryName()
|
117 |
*/
|
118 |
@Override
|
119 |
public String getFactoryName() { |
120 |
return this.getName(); |
121 |
} |
122 |
|
123 |
/*
|
124 |
* (non-Javadoc)
|
125 |
*
|
126 |
* @see
|
127 |
* org.gvsig.tools.swing.spi.AbstractSwingServiceFactory#getFactoryName()
|
128 |
*/
|
129 |
@Override
|
130 |
public String getName() { |
131 |
return this.getServiceManager().getServiceName(this.getFactoryType(), |
132 |
this.getFactorySubType());
|
133 |
} |
134 |
|
135 |
/**
|
136 |
* Checks if it's a container and has available values to render a JComboBox
|
137 |
* object
|
138 |
* instead of the otherwise created JComponent.
|
139 |
*
|
140 |
* @param component
|
141 |
* the JDynFieldComponent created beforehand.
|
142 |
* @param field
|
143 |
* the ValueField object.
|
144 |
* @return
|
145 |
* the JDynFieldComponent.
|
146 |
*/
|
147 |
|
148 |
private JDynFieldComponent getSuitableComponent(
|
149 |
JDynFieldComponent component, ValueField field) { |
150 |
|
151 |
// Checking containers
|
152 |
DynField dynField = field.getDynField(); |
153 |
if ((dynField.getType() == DataTypes.DYNOBJECT)
|
154 |
|| (dynField.getType() == DataTypes.LIST)) { |
155 |
return component;
|
156 |
} |
157 |
|
158 |
// If a simple component has available values it is a combobox
|
159 |
DynObjectValueItem[] values = dynField.getAvailableValues();
|
160 |
if ((values != null) && (values.length > 0)) { |
161 |
return this.getServiceManager() |
162 |
.getJSingleComboBoxDynFieldComponent(component, field); |
163 |
} |
164 |
return component;
|
165 |
} |
166 |
|
167 |
/*
|
168 |
* (non-Javadoc)
|
169 |
*
|
170 |
* @see org.gvsig.tools.service.spi.ServiceFactory#initialize()
|
171 |
*/
|
172 |
public void initialize() { |
173 |
// do nothing
|
174 |
} |
175 |
} |