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 | 1031 | jbadia | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
5 | *
|
||
6 | 1405 | jjdelcerro | * 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 | 1031 | jbadia | *
|
11 | 1405 | jjdelcerro | * 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 | 1031 | jbadia | *
|
16 | 1405 | jjdelcerro | * 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 | 1031 | jbadia | *
|
20 | 1405 | jjdelcerro | * For any additional information, do not hesitate to contact us at info AT
|
21 | * gvsig.com, or visit our website www.gvsig.com.
|
||
22 | 1031 | jbadia | */
|
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 | 1098 | jbadia | import org.gvsig.tools.ToolsLocator; |
33 | import org.gvsig.tools.dynform.AbortActionException; |
||
34 | 1031 | jbadia | 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 | 1098 | jbadia | import org.gvsig.tools.dynform.JDynFormSet.JDynFormSetListener; |
40 | 1405 | jjdelcerro | import org.gvsig.tools.dynform.spi.AbstractJDynForm; |
41 | import org.gvsig.tools.dynform.spi.AbstractJDynFormSet; |
||
42 | import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
||
43 | 1031 | jbadia | import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormField; |
44 | 1150 | jbadia | import org.gvsig.tools.dynobject.DynField; |
45 | 1031 | jbadia | 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 | 1098 | jbadia | public class JDynFormFieldDynObjectList extends AbstractJDynFormField implements JDynFormField, JDynFormListener, JDynFormSetListener, FocusListener { |
52 | 1031 | jbadia | |
53 | 1405 | jjdelcerro | protected List assignedValue = null; |
54 | protected List currentValue = null; |
||
55 | protected AbstractJDynFormSet jdynFormSet = null; |
||
56 | protected boolean readonly = false; |
||
57 | 1031 | jbadia | |
58 | 1405 | jjdelcerro | public JDynFormFieldDynObjectList(DynObject parameters,
|
59 | ServiceManager serviceManager) { |
||
60 | super(parameters, serviceManager);
|
||
61 | this.assignedValue = (List) this.getParameterValue(); |
||
62 | } |
||
63 | 1225 | jjdelcerro | |
64 | 1405 | jjdelcerro | public void setReadOnly(boolean readonly) { |
65 | super.setReadOnly(readonly);
|
||
66 | if (this.contents != null) { |
||
67 | this.jdynFormSet.setReadOnly(readonly);
|
||
68 | } |
||
69 | } |
||
70 | 1225 | jjdelcerro | |
71 | 1405 | jjdelcerro | 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 | 1031 | jbadia | // this.jdynForm.addFocusListener(this);
|
104 | |||
105 | 1405 | jjdelcerro | } |
106 | |||
107 | public void setValue(Object value) { |
||
108 | if (value == null) { |
||
109 | 1031 | jbadia | // TODO
|
110 | 1405 | jjdelcerro | // 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 | 1031 | jbadia | |
126 | 1405 | jjdelcerro | public Object getValue() { |
127 | return this.jdynFormSet.getValues(); |
||
128 | } |
||
129 | 1031 | jbadia | |
130 | 1405 | jjdelcerro | public boolean hasValidValue() { |
131 | return this.jdynFormSet.hasValidValues(); |
||
132 | } |
||
133 | 1031 | jbadia | |
134 | 1405 | jjdelcerro | public void focusGained(FocusEvent arg0) { |
135 | fireFieldEnterEvent(); |
||
136 | this.problemIndicator().restore();
|
||
137 | } |
||
138 | 1092 | jbadia | |
139 | 1405 | jjdelcerro | 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 | 1092 | jbadia | // TODO Auto-generated method stub
|
149 | 1098 | jbadia | |
150 | 1405 | jjdelcerro | } |
151 | |||
152 | public void formMessage(String message) { |
||
153 | 1098 | jbadia | // TODO Auto-generated method stub
|
154 | |||
155 | 1405 | jjdelcerro | } |
156 | |||
157 | public void formClose() { |
||
158 | 1098 | jbadia | // TODO Auto-generated method stub
|
159 | |||
160 | 1405 | jjdelcerro | } |
161 | |||
162 | public void formMovedTo(int currentPosition) { |
||
163 | 1098 | jbadia | // TODO Auto-generated method stub
|
164 | |||
165 | 1405 | jjdelcerro | } |
166 | |||
167 | public void formBeforeSave(JDynFormSet dynformSet) throws AbortActionException { |
||
168 | 1098 | jbadia | // TODO Auto-generated method stub
|
169 | |||
170 | 1405 | jjdelcerro | } |
171 | 1098 | jbadia | |
172 | 1405 | jjdelcerro | 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 | 1098 | jbadia | |
180 | 1405 | jjdelcerro | public void formBeforeCancelNew(JDynFormSet dynformSet) throws AbortActionException { |
181 | // TODO Auto-generated method stub
|
||
182 | 1098 | jbadia | |
183 | 1405 | jjdelcerro | } |
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 | 1098 | jbadia | // TODO Auto-generated method stub
|
203 | |||
204 | 1405 | jjdelcerro | } |
205 | |||
206 | public void formAfterSave(JDynFormSet dynformSet) { |
||
207 | 1098 | jbadia | // TODO Auto-generated method stub
|
208 | |||
209 | 1405 | jjdelcerro | } |
210 | |||
211 | public void formAfterNew(JDynFormSet dynformSet) { |
||
212 | 1098 | jbadia | // TODO Auto-generated method stub
|
213 | |||
214 | 1405 | jjdelcerro | } |
215 | |||
216 | public void formAfterCancelNew(JDynFormSet dynformSet) { |
||
217 | 1098 | jbadia | // TODO Auto-generated method stub
|
218 | |||
219 | 1405 | jjdelcerro | } |
220 | |||
221 | public void formAfterDelete(JDynFormSet dynformSet) { |
||
222 | 1098 | jbadia | // TODO Auto-generated method stub
|
223 | 1405 | jjdelcerro | |
224 | } |
||
225 | |||
226 | public void formAfterSearch(JDynFormSet dynformSet) { |
||
227 | // TODO Auto-generated method stub
|
||
228 | |||
229 | } |
||
230 | |||
231 | 1031 | jbadia | } |