gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.dynform / org.gvsig.tools.dynform.services / src / main / java / org / gvsig / tools / dynform / services / dynformfield / DynObjectList / JDynFormFieldDynObjectList.java @ 1881
History | View | Annotate | Download (8.08 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or modify it under
|
7 |
* the terms of the GNU General Public License as published by the Free Software
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later
|
9 |
* version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
14 |
* details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License along with
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
21 |
* gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.tools.dynform.services.dynformfield.DynObjectList; |
24 |
|
25 |
import java.awt.BorderLayout; |
26 |
import java.awt.event.FocusEvent; |
27 |
import java.awt.event.FocusListener; |
28 |
import java.util.List; |
29 |
|
30 |
import javax.swing.JPanel; |
31 |
|
32 |
import org.gvsig.tools.ToolsLocator; |
33 |
import org.gvsig.tools.dynform.AbortActionException; |
34 |
import org.gvsig.tools.dynform.DynFormDefinition; |
35 |
import org.gvsig.tools.dynform.DynFormFieldDefinition; |
36 |
import org.gvsig.tools.dynform.JDynForm.JDynFormListener; |
37 |
import org.gvsig.tools.dynform.JDynFormField; |
38 |
import org.gvsig.tools.dynform.JDynFormSet; |
39 |
import org.gvsig.tools.dynform.JDynFormSet.JDynFormSetListener; |
40 |
import org.gvsig.tools.dynform.spi.dynformset.AbstractJDynFormSet; |
41 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
42 |
import org.gvsig.tools.dynform.spi.dynformfield.JDynFormFieldFactory; |
43 |
import org.gvsig.tools.dynform.spi.dynformset.JDynFormSetFactory; |
44 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormField; |
45 |
import org.gvsig.tools.dynobject.DynField; |
46 |
import org.gvsig.tools.dynobject.DynField_v2; |
47 |
import org.gvsig.tools.dynobject.DynObject; |
48 |
import org.gvsig.tools.dynobject.DynStruct; |
49 |
import org.gvsig.tools.service.ServiceException; |
50 |
|
51 |
public class JDynFormFieldDynObjectList extends AbstractJDynFormField implements JDynFormField, JDynFormListener, JDynFormSetListener, FocusListener { |
52 |
|
53 |
protected List assignedValue = null; |
54 |
protected List currentValue = null; |
55 |
protected JDynFormSet jdynFormSet = null; |
56 |
protected boolean readonly = false; |
57 |
|
58 |
public JDynFormFieldDynObjectList(
|
59 |
DynFormSPIManager serviceManager, |
60 |
DynFormSPIManager.ComponentsFactory componentsFactory, |
61 |
JDynFormFieldFactory factory, |
62 |
DynFormFieldDefinition definition, |
63 |
Object value
|
64 |
) { |
65 |
super(serviceManager, componentsFactory, factory, definition, value);
|
66 |
this.assignedValue = (List) value; |
67 |
} |
68 |
|
69 |
public void setReadOnly(boolean readonly) { |
70 |
super.setReadOnly(readonly);
|
71 |
if (this.contents != null) { |
72 |
this.jdynFormSet.setReadOnly(readonly);
|
73 |
} |
74 |
} |
75 |
|
76 |
public Object getAssignedValue() { |
77 |
return this.assignedValue; |
78 |
} |
79 |
|
80 |
public void initComponent() { |
81 |
this.contents = new JPanel(); |
82 |
this.contents.setLayout(new BorderLayout()); |
83 |
try {
|
84 |
DynFormFieldDefinition def = this.getDefinition();
|
85 |
DynField_v2 fielddef = (DynField_v2) def; |
86 |
DynStruct struct = fielddef.getDynClassOfItems(); |
87 |
String viewMode = getTagValueAsString("ViewMode", DynFormSPIManager.TAG_DYNFORM_VIEWMODE, "Subform"); |
88 |
DynFormDefinition theDefinition = getServiceManager().getDynFormManager().getDefinition(struct); |
89 |
try {
|
90 |
JDynFormSetFactory factory = getServiceManager().getJDynFormSetFactory( |
91 |
this.getForm().getContext(),
|
92 |
theDefinition, |
93 |
this.getDefinition().getTags()
|
94 |
); |
95 |
this.jdynFormSet = factory.create(
|
96 |
getServiceManager(), |
97 |
this.getForm().getContext(),
|
98 |
theDefinition, |
99 |
this.getDefinition().getTags()
|
100 |
); |
101 |
((AbstractJDynFormSet) this.jdynFormSet).loadDefaultValueFromTags(this.getDefinition().getTags()); |
102 |
this.jdynFormSet.addListener(this); |
103 |
this.contents.add(jdynFormSet.asJComponent(), BorderLayout.CENTER); |
104 |
this.contents.setVisible(true); |
105 |
this.setValue(this.assignedValue); |
106 |
} catch (Exception e) { |
107 |
LOGGER.warn("Error en la creaci?n del DynFormSet '" + viewMode + "'", e); |
108 |
} |
109 |
|
110 |
// int height = getTagValueAsInt(DynFormSPIManager.TAG_DYNFORM_HEIGHT, -1);
|
111 |
// if (height > 0) {
|
112 |
// this.jdynFormSet.setFormSize(50, height);
|
113 |
// }
|
114 |
|
115 |
} catch (Exception e) { |
116 |
LOGGER.warn("", e);
|
117 |
} |
118 |
// this.jdynForm.addFocusListener(this);
|
119 |
|
120 |
} |
121 |
|
122 |
public void setValue(Object value) { |
123 |
if (value == null) { |
124 |
// TODO
|
125 |
// this.jdynForm.clear();
|
126 |
} else {
|
127 |
if (!(value instanceof List)) { |
128 |
LOGGER.info("setValue invoked with non List value (" + value.toString() + ")."); |
129 |
return;
|
130 |
} |
131 |
this.jdynFormSet.setValues((List) value); |
132 |
} |
133 |
this.assignedValue = (List) value; |
134 |
this.currentValue = this.assignedValue; |
135 |
} |
136 |
|
137 |
public Object getValue() { |
138 |
return this.jdynFormSet.getValues(); |
139 |
} |
140 |
|
141 |
public boolean hasValidValue() { |
142 |
return this.jdynFormSet.hasValidValues(); |
143 |
} |
144 |
|
145 |
public void focusGained(FocusEvent arg0) { |
146 |
fireFieldEnterEvent(); |
147 |
this.problemIndicator().restore();
|
148 |
} |
149 |
|
150 |
public void focusLost(FocusEvent arg0) { |
151 |
fireFieldExitEvent(); |
152 |
} |
153 |
|
154 |
public void message(String message) { |
155 |
fireMessageEvent(message); |
156 |
} |
157 |
|
158 |
public void fieldChanged(JDynFormField field) { |
159 |
// TODO Auto-generated method stub
|
160 |
|
161 |
} |
162 |
|
163 |
public void formMessage(String message) { |
164 |
// TODO Auto-generated method stub
|
165 |
|
166 |
} |
167 |
|
168 |
public void formClose() { |
169 |
// TODO Auto-generated method stub
|
170 |
|
171 |
} |
172 |
|
173 |
public void formMovedTo(int currentPosition) { |
174 |
// TODO Auto-generated method stub
|
175 |
|
176 |
} |
177 |
|
178 |
public void formBeforeSave(JDynFormSet dynformSet) throws AbortActionException { |
179 |
// TODO Auto-generated method stub
|
180 |
|
181 |
} |
182 |
|
183 |
public void formBeforeNew(JDynFormSet dynformSet) throws AbortActionException { |
184 |
DynFormFieldDefinition def = this.getDefinition();
|
185 |
DynField_v2 fielddef = (DynField_v2) def; |
186 |
DynStruct struct = fielddef.getDynClassOfItems(); |
187 |
DynObject value = createDynObject(struct); |
188 |
this.currentValue.add(value);
|
189 |
} |
190 |
|
191 |
public void formBeforeCancelNew(JDynFormSet dynformSet) throws AbortActionException { |
192 |
// TODO Auto-generated method stub
|
193 |
|
194 |
} |
195 |
|
196 |
private DynObject createDynObject(DynStruct dynStruct) {
|
197 |
DynObject value = ToolsLocator.getDynObjectManager().createDynObject(dynStruct); |
198 |
DynField[] fields = dynStruct.getDynFields();
|
199 |
for (int i = 0; i < fields.length; i++) { |
200 |
DynField_v2 field = (DynField_v2) fields[i]; |
201 |
if (field.getDataType().isDynObject()) {
|
202 |
value.setDynValue(field.getName(), createDynObject(field.getDynClassOfValue())); |
203 |
} |
204 |
} |
205 |
return value;
|
206 |
} |
207 |
|
208 |
public void formBeforeDelete(JDynFormSet dynformSet) throws AbortActionException { |
209 |
this.currentValue.remove(dynformSet.getCurrentIndex());
|
210 |
} |
211 |
|
212 |
public void formBeforeSearch(JDynFormSet dynformSet) throws AbortActionException { |
213 |
// TODO Auto-generated method stub
|
214 |
|
215 |
} |
216 |
|
217 |
public void formAfterSave(JDynFormSet dynformSet) { |
218 |
// TODO Auto-generated method stub
|
219 |
|
220 |
} |
221 |
|
222 |
public void formAfterNew(JDynFormSet dynformSet) { |
223 |
// TODO Auto-generated method stub
|
224 |
|
225 |
} |
226 |
|
227 |
public void formAfterCancelNew(JDynFormSet dynformSet) { |
228 |
// TODO Auto-generated method stub
|
229 |
|
230 |
} |
231 |
|
232 |
public void formAfterDelete(JDynFormSet dynformSet) { |
233 |
// TODO Auto-generated method stub
|
234 |
|
235 |
} |
236 |
|
237 |
public void formAfterSearch(JDynFormSet dynformSet) { |
238 |
// TODO Auto-generated method stub
|
239 |
|
240 |
} |
241 |
|
242 |
} |