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 @ 1405
History | View | Annotate | Download (7.58 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.DynFormFieldDefinition; |
35 |
import org.gvsig.tools.dynform.DynFormLocator; |
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.AbstractJDynForm; |
41 |
import org.gvsig.tools.dynform.spi.AbstractJDynFormSet; |
42 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
43 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormField; |
44 |
import org.gvsig.tools.dynobject.DynField; |
45 |
import org.gvsig.tools.dynobject.DynField_v2; |
46 |
import org.gvsig.tools.dynobject.DynObject; |
47 |
import org.gvsig.tools.dynobject.DynStruct; |
48 |
import org.gvsig.tools.service.ServiceException; |
49 |
import org.gvsig.tools.service.spi.ServiceManager; |
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 AbstractJDynFormSet jdynFormSet = null; |
56 |
protected boolean readonly = false; |
57 |
|
58 |
public JDynFormFieldDynObjectList(DynObject parameters,
|
59 |
ServiceManager serviceManager) { |
60 |
super(parameters, serviceManager);
|
61 |
this.assignedValue = (List) this.getParameterValue(); |
62 |
} |
63 |
|
64 |
public void setReadOnly(boolean readonly) { |
65 |
super.setReadOnly(readonly);
|
66 |
if (this.contents != null) { |
67 |
this.jdynFormSet.setReadOnly(readonly);
|
68 |
} |
69 |
} |
70 |
|
71 |
public Object getAssignedValue() { |
72 |
return this.assignedValue; |
73 |
} |
74 |
|
75 |
public void initComponent() { |
76 |
this.contents = new JPanel(); |
77 |
this.contents.setLayout(new BorderLayout()); |
78 |
try {
|
79 |
DynFormFieldDefinition def = this.getDefinition();
|
80 |
DynField_v2 fielddef = (DynField_v2) def; |
81 |
DynStruct struct = fielddef.getDynClassOfItems(); |
82 |
String viewMode = getTagValueAsString("ViewMode", DynFormSPIManager.TAG_DYNFORM_VIEWMODE, "Subform"); |
83 |
try {
|
84 |
this.jdynFormSet = (AbstractJDynFormSet) DynFormLocator.getDynFormManager().createJDynFormSet(viewMode, struct);
|
85 |
} catch (Exception e) { |
86 |
logger.warn("Error en la creaci?n del DynFormSet '" + viewMode + "'", e); |
87 |
this.jdynFormSet = (AbstractJDynFormSet) DynFormLocator.getDynFormManager().createJDynFormSet(struct);
|
88 |
} |
89 |
this.jdynFormSet.loadDefaultValueFromTags(this.getDefinition().getTags()); |
90 |
|
91 |
// int height = getTagValueAsInt(DynFormSPIManager.TAG_DYNFORM_HEIGHT, -1);
|
92 |
// if (height > 0) {
|
93 |
// this.jdynFormSet.setFormSize(50, height);
|
94 |
// }
|
95 |
|
96 |
this.jdynFormSet.addListener(this); |
97 |
this.contents.add(jdynFormSet.asJComponent(), BorderLayout.CENTER); |
98 |
this.contents.setVisible(true); |
99 |
this.setValue(this.assignedValue); |
100 |
} catch (Exception e) { |
101 |
logger.warn("", e);
|
102 |
} |
103 |
// this.jdynForm.addFocusListener(this);
|
104 |
|
105 |
} |
106 |
|
107 |
public void setValue(Object value) { |
108 |
if (value == null) { |
109 |
// TODO
|
110 |
// this.jdynForm.clear();
|
111 |
} else {
|
112 |
if (!(value instanceof List)) { |
113 |
logger.info("setValue invoked with non List value (" + value.toString() + ")."); |
114 |
return;
|
115 |
} |
116 |
try {
|
117 |
this.jdynFormSet.setValues((List) value); |
118 |
} catch (ServiceException e) {
|
119 |
logger.warn("Error settings values to DynformSet", e);
|
120 |
} |
121 |
} |
122 |
this.assignedValue = (List) value; |
123 |
this.currentValue = this.assignedValue; |
124 |
} |
125 |
|
126 |
public Object getValue() { |
127 |
return this.jdynFormSet.getValues(); |
128 |
} |
129 |
|
130 |
public boolean hasValidValue() { |
131 |
return this.jdynFormSet.hasValidValues(); |
132 |
} |
133 |
|
134 |
public void focusGained(FocusEvent arg0) { |
135 |
fireFieldEnterEvent(); |
136 |
this.problemIndicator().restore();
|
137 |
} |
138 |
|
139 |
public void focusLost(FocusEvent arg0) { |
140 |
fireFieldExitEvent(); |
141 |
} |
142 |
|
143 |
public void message(String message) { |
144 |
fireMessageEvent(message); |
145 |
} |
146 |
|
147 |
public void fieldChanged(JDynFormField field) { |
148 |
// TODO Auto-generated method stub
|
149 |
|
150 |
} |
151 |
|
152 |
public void formMessage(String message) { |
153 |
// TODO Auto-generated method stub
|
154 |
|
155 |
} |
156 |
|
157 |
public void formClose() { |
158 |
// TODO Auto-generated method stub
|
159 |
|
160 |
} |
161 |
|
162 |
public void formMovedTo(int currentPosition) { |
163 |
// TODO Auto-generated method stub
|
164 |
|
165 |
} |
166 |
|
167 |
public void formBeforeSave(JDynFormSet dynformSet) throws AbortActionException { |
168 |
// TODO Auto-generated method stub
|
169 |
|
170 |
} |
171 |
|
172 |
public void formBeforeNew(JDynFormSet dynformSet) throws AbortActionException { |
173 |
DynFormFieldDefinition def = this.getDefinition();
|
174 |
DynField_v2 fielddef = (DynField_v2) def; |
175 |
DynStruct struct = fielddef.getDynClassOfItems(); |
176 |
DynObject value = createDynObject(struct); |
177 |
this.currentValue.add(value);
|
178 |
} |
179 |
|
180 |
public void formBeforeCancelNew(JDynFormSet dynformSet) throws AbortActionException { |
181 |
// TODO Auto-generated method stub
|
182 |
|
183 |
} |
184 |
|
185 |
private DynObject createDynObject(DynStruct dynStruct) {
|
186 |
DynObject value = ToolsLocator.getDynObjectManager().createDynObject(dynStruct); |
187 |
DynField[] fields = dynStruct.getDynFields();
|
188 |
for (int i = 0; i < fields.length; i++) { |
189 |
DynField_v2 field = (DynField_v2) fields[i]; |
190 |
if (field.getDataType().isDynObject()) {
|
191 |
value.setDynValue(field.getName(), createDynObject(field.getDynClassOfValue())); |
192 |
} |
193 |
} |
194 |
return value;
|
195 |
} |
196 |
|
197 |
public void formBeforeDelete(JDynFormSet dynformSet) throws AbortActionException { |
198 |
this.currentValue.remove(dynformSet.getCurrentIndex());
|
199 |
} |
200 |
|
201 |
public void formBeforeSearch(JDynFormSet dynformSet) throws AbortActionException { |
202 |
// TODO Auto-generated method stub
|
203 |
|
204 |
} |
205 |
|
206 |
public void formAfterSave(JDynFormSet dynformSet) { |
207 |
// TODO Auto-generated method stub
|
208 |
|
209 |
} |
210 |
|
211 |
public void formAfterNew(JDynFormSet dynformSet) { |
212 |
// TODO Auto-generated method stub
|
213 |
|
214 |
} |
215 |
|
216 |
public void formAfterCancelNew(JDynFormSet dynformSet) { |
217 |
// TODO Auto-generated method stub
|
218 |
|
219 |
} |
220 |
|
221 |
public void formAfterDelete(JDynFormSet dynformSet) { |
222 |
// TODO Auto-generated method stub
|
223 |
|
224 |
} |
225 |
|
226 |
public void formAfterSearch(JDynFormSet dynformSet) { |
227 |
// TODO Auto-generated method stub
|
228 |
|
229 |
} |
230 |
|
231 |
} |