Revision 2493
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.280/org.gvsig.tools.dynform/org.gvsig.tools.dynform.services/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.tools.dynform.services.BasicDynFormFieldsLibrary |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.280/org.gvsig.tools.dynform/org.gvsig.tools.dynform.services/src/main/java/org/gvsig/tools/dynform/services/dynform/AbeilleJDynFormFactory.java | ||
---|---|---|
1 |
package org.gvsig.tools.dynform.services.dynform; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.FileInputStream; |
|
5 |
import org.apache.commons.io.FilenameUtils; |
|
6 |
import org.apache.commons.lang3.StringUtils; |
|
7 |
import org.gvsig.tools.dynform.DynFormDefinition; |
|
8 |
import org.gvsig.tools.dynform.JDynForm; |
|
9 |
import org.gvsig.tools.dynform.JDynForm.DynFormContext; |
|
10 |
import org.gvsig.tools.dynform.spi.dynform.AbstractJDynFormFactory; |
|
11 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
|
12 |
import org.gvsig.tools.resourcesstorage.ResourcesStorage; |
|
13 |
|
|
14 |
public class AbeilleJDynFormFactory extends AbstractJDynFormFactory { |
|
15 |
|
|
16 |
public static final String NAME = "abeille"; |
|
17 |
|
|
18 |
public AbeilleJDynFormFactory() { |
|
19 |
super(NAME); |
|
20 |
} |
|
21 |
|
|
22 |
@Override |
|
23 |
public JDynForm create(DynFormSPIManager manager, DynFormContext context, DynFormDefinition definition) { |
|
24 |
return new AbeilleJDynForm(manager, this, context, definition); |
|
25 |
} |
|
26 |
|
|
27 |
@Override |
|
28 |
public boolean isApplicableTo(DynFormContext context, DynFormDefinition definition) { |
|
29 |
String resourceName = (String) definition.getTags().get(DynFormSPIManager.TAG_DYNFORM_ABEILLE_FORM); |
|
30 |
if( !StringUtils.isBlank(resourceName) ) { |
|
31 |
File f = new File(resourceName); |
|
32 |
if( f.isAbsolute() && f.exists() ) { |
|
33 |
return true; |
|
34 |
} |
|
35 |
ResourcesStorage storage = context.getResourcesStorage(); |
|
36 |
if( storage.exists(FilenameUtils.getName(resourceName)) ) { |
|
37 |
return true; |
|
38 |
} |
|
39 |
} |
|
40 |
ResourcesStorage storage = context.getResourcesStorage(); |
|
41 |
if( storage.exists("jetaform") || storage.exists("jfrm")) { |
|
42 |
return true; |
|
43 |
} |
|
44 |
return false; |
|
45 |
} |
|
46 |
|
|
47 |
|
|
48 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.280/org.gvsig.tools.dynform/org.gvsig.tools.dynform.services/src/main/java/org/gvsig/tools/dynform/services/dynform/AbeilleJDynForm.java | ||
---|---|---|
1 |
package org.gvsig.tools.dynform.services.dynform; |
|
2 |
|
|
3 |
import java.awt.Component; |
|
4 |
import java.io.FileInputStream; |
|
5 |
import java.io.InputStream; |
|
6 |
import java.util.HashMap; |
|
7 |
import java.util.Map; |
|
8 |
|
|
9 |
import javax.swing.JCheckBox; |
|
10 |
import javax.swing.JComboBox; |
|
11 |
import javax.swing.JComponent; |
|
12 |
import javax.swing.JSpinner; |
|
13 |
import javax.swing.text.JTextComponent; |
|
14 |
|
|
15 |
import org.gvsig.tools.dynform.DynFormDefinition; |
|
16 |
import org.gvsig.tools.dynform.DynFormFieldDefinition; |
|
17 |
import org.gvsig.tools.dynform.JDynFormField; |
|
18 |
import org.gvsig.tools.dynform.JDynFormField.JDynFormFieldListener; |
|
19 |
import org.gvsig.tools.dynform.spi.dynform.AbstractJDynForm; |
|
20 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
|
21 |
|
|
22 |
import com.jeta.forms.components.panel.FormPanel; |
|
23 |
import java.awt.event.ActionEvent; |
|
24 |
import java.awt.event.ActionListener; |
|
25 |
import java.io.File; |
|
26 |
import java.util.ArrayList; |
|
27 |
import java.util.Iterator; |
|
28 |
import java.util.List; |
|
29 |
import javax.swing.JButton; |
|
30 |
import javax.swing.JLabel; |
|
31 |
import javax.swing.JList; |
|
32 |
import javax.swing.JScrollPane; |
|
33 |
import javax.swing.JTable; |
|
34 |
import javax.swing.JTextArea; |
|
35 |
import javax.swing.JViewport; |
|
36 |
import org.apache.commons.io.FilenameUtils; |
|
37 |
import org.apache.commons.io.IOUtils; |
|
38 |
import org.apache.commons.lang3.StringUtils; |
|
39 |
import org.gvsig.tools.dataTypes.CoercionException; |
|
40 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager.ComponentsFactory; |
|
41 |
import static org.gvsig.tools.dynform.spi.DynFormSPIManager.TAG_DYNFORM_ABEILLE_FORM; |
|
42 |
import static org.gvsig.tools.dynform.spi.DynFormSPIManager.USERCODE_FORM_CLEAR; |
|
43 |
import static org.gvsig.tools.dynform.spi.DynFormSPIManager.USERCODE_FORM_ISMODIFIED; |
|
44 |
import static org.gvsig.tools.dynform.spi.DynFormSPIManager.USERCODE_FORM_ISREADONLY; |
|
45 |
import static org.gvsig.tools.dynform.spi.DynFormSPIManager.USERCODE_FORM_ONFIELDCHANGED; |
|
46 |
import static org.gvsig.tools.dynform.spi.DynFormSPIManager.USERCODE_FORM_ONFIELDENTER; |
|
47 |
import static org.gvsig.tools.dynform.spi.DynFormSPIManager.USERCODE_FORM_ONFIELDEXIT; |
|
48 |
import static org.gvsig.tools.dynform.spi.DynFormSPIManager.USERCODE_FORM_ONLOAD; |
|
49 |
import static org.gvsig.tools.dynform.spi.DynFormSPIManager.USERCODE_FORM_ONSETVALUES; |
|
50 |
import static org.gvsig.tools.dynform.spi.DynFormSPIManager.USERCODE_FORM_VALIDATE; |
|
51 |
import org.gvsig.tools.dynform.spi.dynform.JDynFormFactory; |
|
52 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormField; |
|
53 |
import org.gvsig.tools.dynform.spi.dynformfield.JDynFormFieldFactory; |
|
54 |
import org.gvsig.tools.dynobject.DynObject; |
|
55 |
import org.gvsig.tools.resourcesstorage.ResourcesStorage; |
|
56 |
import org.gvsig.tools.resourcesstorage.ResourcesStorage.Resource; |
|
57 |
import org.gvsig.tools.script.Script; |
|
58 |
|
|
59 |
@SuppressWarnings("UseSpecificCatch") |
|
60 |
public class AbeilleJDynForm extends AbstractJDynForm implements JDynFormFieldListener { |
|
61 |
|
|
62 |
private class AbeilleComponentsFactory implements ComponentsFactory { |
|
63 |
|
|
64 |
private class DefaultScrolledComponent<T> implements ScrolledComponent<T> { |
|
65 |
private final T component; |
|
66 |
|
|
67 |
public DefaultScrolledComponent(T component) { |
|
68 |
this.component = component; |
|
69 |
} |
|
70 |
|
|
71 |
@Override |
|
72 |
public JScrollPane getScrollPane() { |
|
73 |
try { |
|
74 |
Object p1 = ((JComponent) component).getParent(); |
|
75 |
if( p1 instanceof JViewport ) { |
|
76 |
p1 = ((JComponent) component).getParent(); |
|
77 |
} |
|
78 |
if( p1 instanceof JScrollPane ) { |
|
79 |
return (JScrollPane) p1; |
|
80 |
} |
|
81 |
} catch(Exception ex) { |
|
82 |
|
|
83 |
} |
|
84 |
return null; |
|
85 |
} |
|
86 |
|
|
87 |
@Override |
|
88 |
public T getComponent() { |
|
89 |
return this.component; |
|
90 |
} |
|
91 |
} |
|
92 |
|
|
93 |
private static final String PREFIX_JCHECKBOX = "chk"; |
|
94 |
private static final String PREFIX_JLABEL = "lbl"; |
|
95 |
private static final String PREFIX_DROPDOWN = "lblDdn"; |
|
96 |
private static final String PREFIX_JCOMBOBOX = "cbo"; |
|
97 |
private static final String PREFIX_JSPINNER = "spn"; |
|
98 |
private static final String PREFIX_JTEXTFIELD = "txt"; |
|
99 |
private static final String PREFIX_JTEXTAREA = "txt"; |
|
100 |
private static final String PREFIX_JBUTTON = "btn"; |
|
101 |
private static final String PREFIX_JLIST = "lst"; |
|
102 |
private static final String PREFIX_JTABLE = "tbl"; |
|
103 |
|
|
104 |
private final FormPanel form; |
|
105 |
|
|
106 |
public AbeilleComponentsFactory(FormPanel form) { |
|
107 |
this.form = form; |
|
108 |
} |
|
109 |
|
|
110 |
@Override |
|
111 |
public boolean containsComponents(DynFormFieldDefinition definition) { |
|
112 |
String[] prefixes = new String[] { |
|
113 |
PREFIX_JCHECKBOX, |
|
114 |
PREFIX_JLABEL, |
|
115 |
PREFIX_DROPDOWN, |
|
116 |
PREFIX_JCOMBOBOX, |
|
117 |
PREFIX_JSPINNER, |
|
118 |
PREFIX_JTEXTFIELD, |
|
119 |
PREFIX_JTEXTAREA, |
|
120 |
PREFIX_JBUTTON, |
|
121 |
PREFIX_JLIST, |
|
122 |
PREFIX_JTABLE |
|
123 |
}; |
|
124 |
for (String prefix : prefixes) { |
|
125 |
Component component = this.form.getComponentByName(prefix + definition.getName()); |
|
126 |
if( component!=null ) { |
|
127 |
return true; |
|
128 |
} |
|
129 |
} |
|
130 |
return false; |
|
131 |
} |
|
132 |
|
|
133 |
@Override |
|
134 |
public boolean containsJComboBox(DynFormFieldDefinition definition, String prefix) { |
|
135 |
Component component = this.form.getComponentByName(PREFIX_JCOMBOBOX+StringUtils.defaultIfBlank(prefix, "") + definition.getName()); |
|
136 |
return component!=null; |
|
137 |
} |
|
138 |
|
|
139 |
@Override |
|
140 |
public boolean containsJButton(DynFormFieldDefinition definition, String prefix) { |
|
141 |
Component component = this.form.getComponentByName(PREFIX_JBUTTON+StringUtils.defaultIfBlank(prefix, "") + definition.getName()); |
|
142 |
return component!=null; |
|
143 |
} |
|
144 |
|
|
145 |
@Override |
|
146 |
public boolean containsJLabel(DynFormFieldDefinition definition, String prefix) { |
|
147 |
Component component = this.form.getComponentByName(PREFIX_JLABEL+StringUtils.defaultIfBlank(prefix, "") + definition.getName()); |
|
148 |
return component!=null; |
|
149 |
} |
|
150 |
|
|
151 |
@Override |
|
152 |
public boolean containsJSpinner(DynFormFieldDefinition definition, String prefix) { |
|
153 |
Component component = this.form.getComponentByName(PREFIX_JSPINNER+StringUtils.defaultIfBlank(prefix, "") + definition.getName()); |
|
154 |
return component!=null; |
|
155 |
} |
|
156 |
|
|
157 |
@Override |
|
158 |
public boolean containsJTextField(DynFormFieldDefinition definition, String prefix) { |
|
159 |
Component component = this.form.getComponentByName(PREFIX_JTEXTFIELD+StringUtils.defaultIfBlank(prefix, "") + definition.getName()); |
|
160 |
return component!=null; |
|
161 |
} |
|
162 |
|
|
163 |
@Override |
|
164 |
public JCheckBox getJCheckBox(DynFormFieldDefinition definition, String prefix) { |
|
165 |
try { |
|
166 |
Component component = this.form.getComponentByName(PREFIX_JCHECKBOX+StringUtils.defaultIfBlank(prefix, "") + definition.getName()); |
|
167 |
return (JCheckBox) component; |
|
168 |
} catch(Throwable th) { |
|
169 |
return null; |
|
170 |
} |
|
171 |
} |
|
172 |
|
|
173 |
@Override |
|
174 |
public JLabel getJLabel(DynFormFieldDefinition definition, String prefix) { |
|
175 |
try { |
|
176 |
Component component = this.form.getComponentByName(PREFIX_JLABEL+StringUtils.defaultIfBlank(prefix, "") + definition.getName()); |
|
177 |
return (JLabel) component; |
|
178 |
} catch(Throwable th) { |
|
179 |
return null; |
|
180 |
} |
|
181 |
} |
|
182 |
|
|
183 |
@Override |
|
184 |
public JComboBox getJComboBox(DynFormFieldDefinition definition, String prefix) { |
|
185 |
try { |
|
186 |
Component component = this.form.getComponentByName(PREFIX_JCOMBOBOX+StringUtils.defaultIfBlank(prefix, "") + definition.getName()); |
|
187 |
return (JComboBox) component; |
|
188 |
} catch(Throwable th) { |
|
189 |
return null; |
|
190 |
} |
|
191 |
} |
|
192 |
|
|
193 |
@Override |
|
194 |
public JTextComponent getJTextField(DynFormFieldDefinition definition, String prefix) { |
|
195 |
try { |
|
196 |
Component component = this.form.getComponentByName(PREFIX_JTEXTFIELD+StringUtils.defaultIfBlank(prefix, "") + definition.getName()); |
|
197 |
return (JTextComponent) component; |
|
198 |
} catch(Throwable th) { |
|
199 |
return null; |
|
200 |
} |
|
201 |
} |
|
202 |
|
|
203 |
@Override |
|
204 |
public ScrolledComponent<JTextArea> getJTextArea(DynFormFieldDefinition definition, String prefix) { |
|
205 |
try { |
|
206 |
JTextArea component = (JTextArea) this.form.getComponentByName( |
|
207 |
PREFIX_JTEXTAREA + StringUtils.defaultIfBlank(prefix, "") + definition.getName() |
|
208 |
); |
|
209 |
return new DefaultScrolledComponent<>(component); |
|
210 |
} catch(Throwable th) { |
|
211 |
return null; |
|
212 |
} |
|
213 |
} |
|
214 |
|
|
215 |
@Override |
|
216 |
public ScrolledComponent<JList> getJList(DynFormFieldDefinition definition, String prefix) { |
|
217 |
try { |
|
218 |
JList component = (JList) this.form.getComponentByName( |
|
219 |
PREFIX_JLIST+StringUtils.defaultIfBlank(prefix, "") + definition.getName() |
|
220 |
); |
|
221 |
return new DefaultScrolledComponent<>(component); |
|
222 |
} catch(Throwable th) { |
|
223 |
return null; |
|
224 |
} |
|
225 |
} |
|
226 |
|
|
227 |
@Override |
|
228 |
public ScrolledComponent<JTable> getJTable(DynFormFieldDefinition definition, String prefix) { |
|
229 |
try { |
|
230 |
JTable component = (JTable) this.form.getComponentByName( |
|
231 |
PREFIX_JTABLE+StringUtils.defaultIfBlank(prefix, "") + definition.getName() |
|
232 |
); |
|
233 |
return new DefaultScrolledComponent<>(component); |
|
234 |
} catch(Throwable th) { |
|
235 |
return null; |
|
236 |
} |
|
237 |
} |
|
238 |
|
|
239 |
|
|
240 |
@Override |
|
241 |
public JSpinner getJSpinner(DynFormFieldDefinition definition, String prefix) { |
|
242 |
try { |
|
243 |
Component component = this.form.getComponentByName(PREFIX_JSPINNER+StringUtils.defaultIfBlank(prefix, "") + definition.getName()); |
|
244 |
return (JSpinner) component; |
|
245 |
} catch(Throwable th) { |
|
246 |
return null; |
|
247 |
} |
|
248 |
} |
|
249 |
|
|
250 |
@Override |
|
251 |
public JButton getJButton(DynFormFieldDefinition definition, String prefix) { |
|
252 |
try { |
|
253 |
Component component = this.form.getComponentByName(PREFIX_JBUTTON+StringUtils.defaultIfBlank(prefix, "") + definition.getName()); |
|
254 |
return (JButton) component; |
|
255 |
} catch(Throwable th) { |
|
256 |
return null; |
|
257 |
} |
|
258 |
} |
|
259 |
|
|
260 |
|
|
261 |
} |
|
262 |
private Map<String,JDynFormField> components = null; |
|
263 |
private String resourceName = null; |
|
264 |
private AbeilleComponentsFactory componentsFactory; |
|
265 |
|
|
266 |
|
|
267 |
public AbeilleJDynForm( |
|
268 |
DynFormSPIManager manager, |
|
269 |
JDynFormFactory factory, |
|
270 |
DynFormContext context, |
|
271 |
DynFormDefinition definition |
|
272 |
) { |
|
273 |
super(manager, factory, definition, context); |
|
274 |
this.components = new HashMap(); |
|
275 |
resourceName = (String) definition.getTags().get(DynFormSPIManager.TAG_DYNFORM_ABEILLE_FORM); |
|
276 |
if (resourceName == null) { |
|
277 |
ResourcesStorage storage = context.getResourcesStorage(); |
|
278 |
if( storage.exists("jetaform") ) { |
|
279 |
this.resourceName = "jetaform"; |
|
280 |
} else if( storage.exists("jfrm") ) { |
|
281 |
this.resourceName = "jfrm"; |
|
282 |
} else { |
|
283 |
throw new IllegalArgumentException("Can't locate form resource. Need tag '"+TAG_DYNFORM_ABEILLE_FORM+"' or resource 'jetaform'."); |
|
284 |
} |
|
285 |
} |
|
286 |
this.componentsFactory = null; |
|
287 |
} |
|
288 |
|
|
289 |
@Override |
|
290 |
protected JComponent getFieldsContainer() { |
|
291 |
InputStream is = null; |
|
292 |
FormPanel form = null; |
|
293 |
Resource resource = null; |
|
294 |
try { |
|
295 |
File f = new File(resourceName); |
|
296 |
if( f.isAbsolute() && f.exists() ) { |
|
297 |
is = new FileInputStream(f); |
|
298 |
} else { |
|
299 |
ResourcesStorage storage = this.getContext().getResourcesStorage(); |
|
300 |
resource = storage.getResource(FilenameUtils.getName(resourceName)); |
|
301 |
if( resource == null || !resource.exists() ) { |
|
302 |
throw new IllegalArgumentException("Can't locate abeille form '"+resourceName+"'."); |
|
303 |
} |
|
304 |
is = resource.asInputStream(); |
|
305 |
} |
|
306 |
form = new FormPanel(is); |
|
307 |
this.componentsFactory = new AbeilleComponentsFactory(form); |
|
308 |
for (DynFormFieldDefinition definition : this.getDefinition().getDefinitions()) { |
|
309 |
if( definition==null ) { |
|
310 |
continue; |
|
311 |
} |
|
312 |
if (definition.isHidden()) { |
|
313 |
continue; |
|
314 |
} |
|
315 |
if( !this.componentsFactory.containsComponents(definition) ) { |
|
316 |
continue; |
|
317 |
} |
|
318 |
try { |
|
319 |
JDynFormFieldFactory factory = this.getServiceManager() |
|
320 |
.getJDynFormFieldFactory(this.getContext(),definition); |
|
321 |
JDynFormField jfield = factory.create( |
|
322 |
this.getServiceManager(), |
|
323 |
this.componentsFactory, |
|
324 |
definition, |
|
325 |
null |
|
326 |
); |
|
327 |
if (jfield instanceof AbstractJDynFormField) { |
|
328 |
((AbstractJDynFormField) jfield).setForm(this); |
|
329 |
} |
|
330 |
if (this.isReadOnly()) { |
|
331 |
jfield.setReadOnly(true); |
|
332 |
} else { |
|
333 |
jfield.setReadOnly(definition.isReadOnly()); |
|
334 |
} |
|
335 |
jfield.addListener(this); |
|
336 |
|
|
337 |
this.configurePopupMenu(jfield); |
|
338 |
|
|
339 |
this.components.put(jfield.getName(), jfield); |
|
340 |
jfield.asJComponent(); // Forzamos que se inicialize |
|
341 |
jfield.getJLabel(); // Forzamos que se inicialize |
|
342 |
} catch(Throwable th1) { |
|
343 |
LOGGER.warn("Can't load field '"+definition.getName()+"' for abeille form '"+resourceName+"'.", th1); |
|
344 |
} |
|
345 |
} |
|
346 |
this.bindUserCode(form); |
|
347 |
this.callUserEvent(USERCODE_FORM_ONLOAD, this); |
|
348 |
} catch (Throwable th) { |
|
349 |
LOGGER.warn("Can't load abeille form '"+resourceName+"'.", th); |
|
350 |
} finally { |
|
351 |
IOUtils.closeQuietly(is); |
|
352 |
IOUtils.closeQuietly(resource); |
|
353 |
} |
|
354 |
|
|
355 |
return form; |
|
356 |
} |
|
357 |
|
|
358 |
public Iterator getFieldsIterator() { |
|
359 |
if (!this.isContentsInitialized()) { |
|
360 |
this.initComponents(); |
|
361 |
} |
|
362 |
return this.components.values().iterator(); |
|
363 |
} |
|
364 |
|
|
365 |
@Override |
|
366 |
public void setReadOnly(boolean readOnly) { |
|
367 |
if( this.isReadOnly() == readOnly ) { |
|
368 |
return; |
|
369 |
} |
|
370 |
super.setReadOnly(readOnly); |
|
371 |
if (this.isContentsInitialized()) { |
|
372 |
Iterator it = this.getFieldsIterator(); |
|
373 |
while (it.hasNext()) { |
|
374 |
JDynFormField field = (JDynFormField) it.next(); |
|
375 |
if( readOnly ) { |
|
376 |
field.setReadOnly(true); |
|
377 |
} else if( field.getDefinition().isReadOnly() ) { |
|
378 |
field.setReadOnly(true); |
|
379 |
} else { |
|
380 |
field.setReadOnly(false); |
|
381 |
} |
|
382 |
} |
|
383 |
} |
|
384 |
} |
|
385 |
|
|
386 |
private void bindUserCode(FormPanel form) { |
|
387 |
Script theScript = this.getScript(); |
|
388 |
if( theScript==null ) { |
|
389 |
return; |
|
390 |
} |
|
391 |
List<String> names = theScript.getNames(); |
|
392 |
if( names == null ) { |
|
393 |
return; |
|
394 |
} |
|
395 |
for(String name : names ) { |
|
396 |
if( name.endsWith("_click") ) { |
|
397 |
String componentName = name.substring(0, name.length()-6); |
|
398 |
Component c = form.getComponentByName(componentName); |
|
399 |
if( c instanceof JButton ) { |
|
400 |
JButton button = (JButton) c; |
|
401 |
final String fnName = name; |
|
402 |
button.addActionListener(new ActionListener() { |
|
403 |
@Override |
|
404 |
public void actionPerformed(ActionEvent e) { |
|
405 |
callUserEvent(fnName, e); |
|
406 |
} |
|
407 |
}); |
|
408 |
} |
|
409 |
} |
|
410 |
} |
|
411 |
} |
|
412 |
|
|
413 |
@Override |
|
414 |
public void setValues(DynObject values) { |
|
415 |
if (!this.isContentsInitialized()) { |
|
416 |
this.values = values; |
|
417 |
return; |
|
418 |
} |
|
419 |
for (JDynFormField jfield : this.getFields()) { |
|
420 |
String name = "unknown"; |
|
421 |
try { |
|
422 |
name = jfield.getName(); |
|
423 |
jfield.setValue(values.getDynValue(jfield.getName())); |
|
424 |
} catch(Exception ex) { |
|
425 |
LOGGER.warn("Can't set value to field '"+name+"'.",ex); |
|
426 |
} |
|
427 |
} |
|
428 |
this.callUserEvent(USERCODE_FORM_ONSETVALUES, this, values); |
|
429 |
try { |
|
430 |
if( (boolean) this.callUserFunction(USERCODE_FORM_ISREADONLY, this) ) { |
|
431 |
this.setReadOnly(true); |
|
432 |
} |
|
433 |
} catch (Exception ex) { |
|
434 |
} |
|
435 |
|
|
436 |
} |
|
437 |
|
|
438 |
public Iterable<JDynFormField> getFields() { |
|
439 |
if (!this.isContentsInitialized()) { |
|
440 |
this.initComponents(); |
|
441 |
} |
|
442 |
return this.components.values(); |
|
443 |
} |
|
444 |
|
|
445 |
@Override |
|
446 |
public JDynFormField getField(String fieldName) { |
|
447 |
if (!this.isContentsInitialized()) { |
|
448 |
this.initComponents(); |
|
449 |
} |
|
450 |
JDynFormField field = this.components.get(fieldName); |
|
451 |
return field; |
|
452 |
} |
|
453 |
|
|
454 |
@Override |
|
455 |
public void getValues(DynObject values) { |
|
456 |
if (values == null) { |
|
457 |
return; |
|
458 |
} |
|
459 |
for (JDynFormField jfield : this.getFields()) { |
|
460 |
try { |
|
461 |
jfield.fetch(values); |
|
462 |
} catch (Exception ex) { |
|
463 |
LOGGER.warn("Can't get value of field '" + jfield.getName() + "'.", ex); |
|
464 |
} |
|
465 |
} |
|
466 |
} |
|
467 |
|
|
468 |
@Override |
|
469 |
public Object getValue(String fieldName) { |
|
470 |
JDynFormField field = (JDynFormField) this.getField(fieldName); |
|
471 |
return field.getValue(); |
|
472 |
} |
|
473 |
|
|
474 |
@Override |
|
475 |
public void setValue(String fieldName, Object value) { |
|
476 |
JDynFormField field = (JDynFormField) this.getField(fieldName); |
|
477 |
try { |
|
478 |
value = field.getDefinition().getDataType().coerce(value); |
|
479 |
} catch (CoercionException e) { |
|
480 |
String msg = "Invalid value '" + ((value == null) ? "(null)" : value.toString()) + "' for field '" + fieldName + "'."; |
|
481 |
LOGGER.warn(msg, e); |
|
482 |
throw new RuntimeException(msg, e); |
|
483 |
} |
|
484 |
field.setValue(value); |
|
485 |
} |
|
486 |
|
|
487 |
@Override |
|
488 |
public boolean hasValidValues() { |
|
489 |
for (JDynFormField jfield : this.getFields()) { |
|
490 |
if (!jfield.hasValidValue()) { |
|
491 |
return false; |
|
492 |
} |
|
493 |
} |
|
494 |
try { |
|
495 |
return (boolean) this.callUserFunction(USERCODE_FORM_VALIDATE, this); |
|
496 |
} catch (Exception ex) { |
|
497 |
} |
|
498 |
return true; |
|
499 |
} |
|
500 |
|
|
501 |
@Override |
|
502 |
public boolean hasValidValues(List<String> fieldsName) { |
|
503 |
if (fieldsName == null) { |
|
504 |
fieldsName = new ArrayList<>(); |
|
505 |
} |
|
506 |
for (JDynFormField jfield : this.getFields()) { |
|
507 |
if (!jfield.hasValidValue()) { |
|
508 |
fieldsName.add(jfield.getName()); |
|
509 |
} |
|
510 |
} |
|
511 |
return fieldsName.isEmpty(); |
|
512 |
} |
|
513 |
|
|
514 |
@Override |
|
515 |
public boolean isModified() { |
|
516 |
if( this.isReadOnly() ) { |
|
517 |
return false; |
|
518 |
} |
|
519 |
try { |
|
520 |
if( this.getScript()!=null ) { |
|
521 |
return (boolean) this.callUserFunction(USERCODE_FORM_ISMODIFIED, this, values); |
|
522 |
} |
|
523 |
} catch (NoSuchMethodException ex) { |
|
524 |
} catch (Exception ex) { |
|
525 |
LOGGER.warn("Error calling user function form_IsModified.",ex); |
|
526 |
} |
|
527 |
for (JDynFormField jfield : this.getFields()) { |
|
528 |
if (jfield.isModified()) { |
|
529 |
return true; |
|
530 |
} |
|
531 |
} |
|
532 |
return false; |
|
533 |
} |
|
534 |
|
|
535 |
@Override |
|
536 |
public void clear() { |
|
537 |
for (JDynFormField jfield : this.getFields()) { |
|
538 |
jfield.clear(); |
|
539 |
} |
|
540 |
this.callUserEvent(USERCODE_FORM_CLEAR, this); |
|
541 |
} |
|
542 |
|
|
543 |
@Override |
|
544 |
public void fieldEnter(JDynFormField field) { |
|
545 |
message(field.getDefinition().getDescription()); |
|
546 |
this.callUserEvent(USERCODE_FORM_ONFIELDENTER, this, field); |
|
547 |
} |
|
548 |
|
|
549 |
@Override |
|
550 |
public void fieldExit(JDynFormField field) { |
|
551 |
message(); |
|
552 |
this.callUserEvent(USERCODE_FORM_ONFIELDEXIT, this, field); |
|
553 |
} |
|
554 |
|
|
555 |
@Override |
|
556 |
public void fieldChanged(JDynFormField field) { |
|
557 |
fireFieldChangeEvent(field); |
|
558 |
this.callUserEvent(USERCODE_FORM_ONFIELDCHANGED, this, field); |
|
559 |
} |
|
560 |
|
|
561 |
@Override |
|
562 |
public void message(JDynFormField field, String message) { |
|
563 |
message(message); |
|
564 |
} |
|
565 |
|
|
566 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.280/org.gvsig.tools.dynform/org.gvsig.tools.dynform.services/src/main/java/org/gvsig/tools/dynform/services/dynformfield/Double/JDynFormFieldDoubleFactory.java | ||
---|---|---|
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 |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.tools.dynform.services.dynformfield.Double; |
|
25 |
|
|
26 |
import org.gvsig.tools.dynform.services.dynformfield.Decimal.JDynFormFieldDecimal; |
|
27 |
import org.gvsig.tools.dataTypes.DataTypes; |
|
28 |
import org.gvsig.tools.dynform.DynFormFieldDefinition; |
|
29 |
import org.gvsig.tools.dynform.JDynFormField; |
|
30 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
|
31 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormFieldFactory; |
|
32 |
|
|
33 |
public class JDynFormFieldDoubleFactory extends AbstractJDynFormFieldFactory { |
|
34 |
|
|
35 |
public JDynFormFieldDoubleFactory() { |
|
36 |
super("DOUBLE", DataTypes.DOUBLE); |
|
37 |
} |
|
38 |
|
|
39 |
@Override |
|
40 |
public JDynFormField create( |
|
41 |
DynFormSPIManager serviceManager, |
|
42 |
DynFormSPIManager.ComponentsFactory componentsFactory, |
|
43 |
DynFormFieldDefinition fieldDefinition, |
|
44 |
Object value |
|
45 |
) { |
|
46 |
return new JDynFormFieldDecimal(serviceManager, componentsFactory, this, fieldDefinition, value); |
|
47 |
} |
|
48 |
|
|
49 |
} |
|
0 | 50 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.280/org.gvsig.tools.dynform/org.gvsig.tools.dynform.services/src/main/java/org/gvsig/tools/dynform/services/dynformfield/Double/JDynFormFieldDouble.java | ||
---|---|---|
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 |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.tools.dynform.services.dynformfield.Double; |
|
25 |
|
|
26 |
import javax.swing.JComboBox; |
|
27 |
import javax.swing.JTextField; |
|
28 |
import org.apache.commons.lang3.StringUtils; |
|
29 |
import org.gvsig.tools.dynform.DynFormFieldDefinition; |
|
30 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
|
31 |
import org.gvsig.tools.dynform.spi.dynformfield.JDynFormFieldFactory; |
|
32 |
|
|
33 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormFieldWithValueList; |
|
34 |
import org.gvsig.tools.dynobject.DynObjectValueItem; |
|
35 |
import org.gvsig.tools.dynobject.exception.DynFieldValidateException; |
|
36 |
|
|
37 |
public class JDynFormFieldDouble extends AbstractJDynFormFieldWithValueList { |
|
38 |
|
|
39 |
public JDynFormFieldDouble( |
|
40 |
DynFormSPIManager serviceManager, |
|
41 |
DynFormSPIManager.ComponentsFactory componentsFactory, |
|
42 |
JDynFormFieldFactory factory, |
|
43 |
DynFormFieldDefinition definition, |
|
44 |
Object value |
|
45 |
) { |
|
46 |
super(serviceManager, componentsFactory, factory, definition, value); |
|
47 |
} |
|
48 |
|
|
49 |
@Override |
|
50 |
@SuppressWarnings("UseSpecificCatch") |
|
51 |
public Object getValue() { |
|
52 |
Object value = null; |
|
53 |
String s = this.getValueFromJComponent(); |
|
54 |
if (StringUtils.isBlank(s)) { |
|
55 |
value = null; |
|
56 |
} else { |
|
57 |
try { |
|
58 |
value = Double.valueOf(s); |
|
59 |
} catch (Exception ex) { |
|
60 |
throw new IllegalFieldValue(this, "Is not a valid double."); |
|
61 |
} |
|
62 |
} |
|
63 |
try { |
|
64 |
this.getDefinition().validate(value); |
|
65 |
this.problemIndicator().clear(); |
|
66 |
} catch (DynFieldValidateException e) { |
|
67 |
throw new IllegalFieldValue(this, e.getLocalizedMessage()); |
|
68 |
} |
|
69 |
return value; |
|
70 |
} |
|
71 |
|
|
72 |
} |
|
0 | 73 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.280/org.gvsig.tools.dynform/org.gvsig.tools.dynform.services/src/main/java/org/gvsig/tools/dynform/services/dynformfield/Folder/JDynFormFieldFolderFactory.java | ||
---|---|---|
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 |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.tools.dynform.services.dynformfield.Folder; |
|
25 |
|
|
26 |
import org.gvsig.tools.dataTypes.DataTypes; |
|
27 |
import org.gvsig.tools.dynform.DynFormFieldDefinition; |
|
28 |
import org.gvsig.tools.dynform.JDynFormField; |
|
29 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
|
30 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormFieldFactory; |
|
31 |
|
|
32 |
public class JDynFormFieldFolderFactory extends AbstractJDynFormFieldFactory { |
|
33 |
|
|
34 |
public JDynFormFieldFolderFactory() { |
|
35 |
super("FOLDER", DataTypes.FOLDER); |
|
36 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
public JDynFormField create( |
|
40 |
DynFormSPIManager serviceManager, |
|
41 |
DynFormSPIManager.ComponentsFactory componentsFactory, |
|
42 |
DynFormFieldDefinition fieldDefinition, |
|
43 |
Object value |
|
44 |
) { |
|
45 |
return new JDynFormFieldFolder(serviceManager, componentsFactory, this, fieldDefinition, value); |
|
46 |
} |
|
47 |
} |
|
0 | 48 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.280/org.gvsig.tools.dynform/org.gvsig.tools.dynform.services/src/main/java/org/gvsig/tools/dynform/services/dynformfield/Folder/JDynFormFieldFolder.java | ||
---|---|---|
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 |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.tools.dynform.services.dynformfield.Folder; |
|
25 |
|
|
26 |
import java.io.File; |
|
27 |
|
|
28 |
import javax.swing.JFileChooser; |
|
29 |
import org.gvsig.tools.dynform.DynFormFieldDefinition; |
|
30 |
|
|
31 |
import org.gvsig.tools.dynform.services.dynformfield.File.JDynFormFieldFile; |
|
32 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
|
33 |
import org.gvsig.tools.dynform.spi.dynformfield.JDynFormFieldFactory; |
|
34 |
|
|
35 |
public class JDynFormFieldFolder extends JDynFormFieldFile { |
|
36 |
|
|
37 |
public JDynFormFieldFolder( |
|
38 |
DynFormSPIManager serviceManager, |
|
39 |
DynFormSPIManager.ComponentsFactory componentsFactory, |
|
40 |
JDynFormFieldFactory factory, |
|
41 |
DynFormFieldDefinition definition, |
|
42 |
Object value |
|
43 |
) { |
|
44 |
super(serviceManager, componentsFactory, factory, definition, value); |
|
45 |
} |
|
46 |
|
|
47 |
public void setValue(Object value) { |
|
48 |
if (value == null) { |
|
49 |
this.jtext.setText(""); |
|
50 |
} else { |
|
51 |
if (!(value instanceof File)) { |
|
52 |
LOGGER.info("setValue invoked with non Folder value (" + value.toString() + ")."); |
|
53 |
return; |
|
54 |
} |
|
55 |
this.jtext.setText(((File) value).getPath()); |
|
56 |
} |
|
57 |
this.assignedValue = (File) value; |
|
58 |
this.currentValue = this.assignedValue; |
|
59 |
} |
|
60 |
|
|
61 |
public File[] showOpenFileDialog(String title, File initialPath) { |
|
62 |
return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.DIRECTORIES_ONLY, false, initialPath, null, false); |
|
63 |
} |
|
64 |
|
|
65 |
} |
|
0 | 66 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.280/org.gvsig.tools.dynform/org.gvsig.tools.dynform.services/src/main/java/org/gvsig/tools/dynform/services/dynformfield/Char/JDynFormFieldCharFactory.java | ||
---|---|---|
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 |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.tools.dynform.services.dynformfield.Char; |
|
25 |
|
|
26 |
import org.gvsig.tools.dataTypes.DataTypes; |
|
27 |
import org.gvsig.tools.dynform.DynFormFieldDefinition; |
|
28 |
import org.gvsig.tools.dynform.JDynFormField; |
|
29 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
|
30 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormFieldFactory; |
|
31 |
|
|
32 |
public class JDynFormFieldCharFactory extends AbstractJDynFormFieldFactory { |
|
33 |
|
|
34 |
public JDynFormFieldCharFactory() { |
|
35 |
super("CHAR", DataTypes.CHAR); |
|
36 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
public JDynFormField create( |
|
40 |
DynFormSPIManager serviceManager, |
|
41 |
DynFormSPIManager.ComponentsFactory componentsFactory, |
|
42 |
DynFormFieldDefinition fieldDefinition, |
|
43 |
Object value |
|
44 |
) { |
|
45 |
return new JDynFormFieldChar(serviceManager, componentsFactory, this, fieldDefinition, value); |
|
46 |
} |
|
47 |
} |
|
0 | 48 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.280/org.gvsig.tools.dynform/org.gvsig.tools.dynform.services/src/main/java/org/gvsig/tools/dynform/services/dynformfield/Char/JDynFormFieldChar.java | ||
---|---|---|
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 |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.tools.dynform.services.dynformfield.Char; |
|
25 |
|
|
26 |
import org.apache.commons.lang3.StringUtils; |
|
27 |
import org.gvsig.tools.dynform.DynFormFieldDefinition; |
|
28 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
|
29 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager.ComponentsFactory; |
|
30 |
import org.gvsig.tools.dynform.spi.dynformfield.JDynFormFieldFactory; |
|
31 |
|
|
32 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormFieldWithValueList; |
|
33 |
import org.gvsig.tools.dynobject.exception.DynFieldValidateException; |
|
34 |
|
|
35 |
public class JDynFormFieldChar extends AbstractJDynFormFieldWithValueList { |
|
36 |
|
|
37 |
public JDynFormFieldChar( |
|
38 |
DynFormSPIManager serviceManager, |
|
39 |
ComponentsFactory componentsFactory, |
|
40 |
JDynFormFieldFactory factory, |
|
41 |
DynFormFieldDefinition definition, |
|
42 |
Object value |
|
43 |
) { |
|
44 |
super(serviceManager, componentsFactory, factory, definition, value); |
|
45 |
} |
|
46 |
|
|
47 |
@Override |
|
48 |
public Object getValue() { |
|
49 |
Object value = null; |
|
50 |
String s = this.getValueFromJComponent(); |
|
51 |
if (StringUtils.isEmpty(s)) { |
|
52 |
value = null; |
|
53 |
} else { |
|
54 |
try { |
|
55 |
value = s.charAt(0); |
|
56 |
} catch (Exception ex) { |
|
57 |
throw new IllegalFieldValue(this, "Is not a valid char."); |
|
58 |
} |
|
59 |
} |
|
60 |
try { |
|
61 |
this.getDefinition().validate(value); |
|
62 |
this.problemIndicator().clear(); |
|
63 |
} catch (DynFieldValidateException e) { |
|
64 |
throw new IllegalFieldValue(this, e.getLocalizedMessage()); |
|
65 |
} |
|
66 |
return value; |
|
67 |
} |
|
68 |
|
|
69 |
} |
|
0 | 70 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.280/org.gvsig.tools.dynform/org.gvsig.tools.dynform.services/src/main/java/org/gvsig/tools/dynform/services/dynformfield/Date/JDynFormFieldDate.java | ||
---|---|---|
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 |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.tools.dynform.services.dynformfield.Date; |
|
25 |
|
|
26 |
import java.awt.BorderLayout; |
|
27 |
import java.awt.event.ActionEvent; |
|
28 |
import java.awt.event.ActionListener; |
|
29 |
import java.awt.event.FocusEvent; |
|
30 |
import java.awt.event.FocusListener; |
|
31 |
import java.net.URL; |
|
32 |
import java.text.DateFormat; |
|
33 |
import java.text.SimpleDateFormat; |
|
34 |
import java.util.Date; |
|
35 |
import java.util.Locale; |
|
36 |
import javax.swing.ImageIcon; |
|
37 |
|
|
38 |
import javax.swing.JButton; |
|
39 |
import javax.swing.JComponent; |
|
40 |
import javax.swing.JPanel; |
|
41 |
import javax.swing.JPopupMenu; |
|
42 |
import javax.swing.JSpinner; |
|
43 |
import javax.swing.event.ChangeEvent; |
|
44 |
|
|
45 |
import org.freixas.jcalendar.DateEvent; |
|
46 |
import org.freixas.jcalendar.DateListener; |
|
47 |
import org.freixas.jcalendar.JCalendar; |
|
48 |
import org.gvsig.tools.dynform.DynFormFieldDefinition; |
|
49 |
|
|
50 |
import org.gvsig.tools.dynform.JDynFormField; |
|
51 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
|
52 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager.ComponentsFactory; |
|
53 |
import org.gvsig.tools.dynform.spi.dynformfield.JDynFormFieldFactory; |
|
54 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormField; |
|
55 |
import org.gvsig.tools.dynform.spi.dynformfield.CustomSpinnerDateModel; |
|
56 |
import org.gvsig.tools.dynobject.DynObjectValueItem; |
|
57 |
import org.gvsig.tools.dynobject.exception.DynFieldValidateException; |
|
58 |
|
|
59 |
/** |
|
60 |
* @author gvSIG team |
|
61 |
* |
|
62 |
*/ |
|
63 |
public class JDynFormFieldDate extends AbstractJDynFormField implements JDynFormField, FocusListener { |
|
64 |
|
|
65 |
protected Object assignedValue = null; |
|
66 |
private JCalendar jcalendar = null; |
|
67 |
private JSpinner timeSpinner = null; |
|
68 |
private JButton button = null; |
|
69 |
private static final String DATE_PANEL_NAME = "Date panel"; |
|
70 |
|
|
71 |
public JDynFormFieldDate( |
|
72 |
DynFormSPIManager serviceManager, |
|
73 |
ComponentsFactory componentsFactory, |
|
74 |
JDynFormFieldFactory factory, |
|
75 |
DynFormFieldDefinition definition, |
|
76 |
Object value |
|
77 |
) { |
|
78 |
super(serviceManager, componentsFactory, factory, definition, value); |
|
79 |
this.assignedValue = value; |
|
80 |
} |
|
81 |
|
|
82 |
@Override |
|
83 |
public void setReadOnly(boolean readonly) { |
|
84 |
JComponent theJlabel = this.getJLabel(); |
|
85 |
if( theJlabel !=null ) { |
|
86 |
theJlabel.setEnabled(!readonly); |
|
87 |
} |
|
88 |
this.readOnly = readonly; |
|
89 |
if (this.contents != null) { |
|
90 |
if (this.readOnly ) { |
|
91 |
this.timeSpinner.setEnabled(false); |
|
92 |
this.button.setEnabled(false); |
|
93 |
} else { |
|
94 |
this.timeSpinner.setEnabled(true); |
|
95 |
this.button.setEnabled(true); |
|
96 |
} |
|
97 |
} |
|
98 |
} |
|
99 |
|
|
100 |
public Object getAssignedValue() { |
|
101 |
return this.assignedValue; |
|
102 |
} |
|
103 |
|
|
104 |
protected JSpinner getJSpinner() { |
|
105 |
return (JSpinner) this.timeSpinner; |
|
106 |
} |
|
107 |
|
|
108 |
protected JButton getJButton() { |
|
109 |
return (JButton) this.button; |
|
110 |
} |
|
111 |
|
|
112 |
protected JCalendar getJCalendar() { |
|
113 |
if (this.jcalendar == null) { |
|
114 |
this.jcalendar = new JCalendar(); |
|
115 |
this.jcalendar.addDateListener(new DateListener() { |
|
116 |
public void dateChanged(DateEvent arg0) { |
|
117 |
getJSpinner().setValue(getJCalendar().getDate()); |
|
118 |
} |
|
119 |
}); |
|
120 |
} |
|
121 |
return (JCalendar) this.jcalendar; |
|
122 |
} |
|
123 |
|
|
124 |
public void initComponent() { |
|
125 |
DynObjectValueItem[] availableValues = this.getDefinition().getAvailableValues(); |
|
126 |
if (availableValues == null) { |
|
127 |
this.contents = new JPanel(); |
|
128 |
this.contents.setName(DATE_PANEL_NAME); |
|
129 |
this.contents.setLayout(new BorderLayout()); |
|
130 |
timeSpinner = this.getComponentsFactory().getJSpinner(this.getDefinition(), null); |
|
131 |
CustomSpinnerDateModel model = new CustomSpinnerDateModel(true); |
|
132 |
timeSpinner.setModel(model); |
|
133 |
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault()); |
|
134 |
String pattern = "dd-MM-yyyy"; |
|
135 |
try { |
|
136 |
SimpleDateFormat sdf = (SimpleDateFormat) dateFormat; |
|
137 |
pattern = sdf.toPattern(); |
|
138 |
} catch (ClassCastException e) { |
|
139 |
LOGGER.warn("Can't determinate date format pattern, using default pattern:" + pattern); |
|
140 |
} |
|
141 |
|
|
142 |
NullDateEditor timeEditor = new NullDateEditor(timeSpinner, pattern); |
|
143 |
timeSpinner.setEditor(timeEditor); |
|
144 |
// timeEditor.dismiss(timeSpinner); |
|
145 |
button = this.getComponentsFactory().getJButton(this.getDefinition(), null); |
|
146 |
if( button.getIcon()==null ) { |
|
147 |
URL imageResource = this.getClass().getClassLoader().getResource("org/gvsig/tools/swing/picker/picker-date.png"); |
|
148 |
if (imageResource != null) { |
|
149 |
button.setIcon(new ImageIcon(imageResource)); |
|
150 |
} |
|
151 |
} |
|
152 |
if( button.getText().trim().equals("...") ) { |
|
153 |
button.setText(""); |
|
154 |
} |
|
155 |
// button.setText("\u2026"); |
|
156 |
button.addActionListener(new ActionListener() { |
|
157 |
public void actionPerformed(ActionEvent event) { |
|
158 |
JPopupMenu menu = new JPopupMenu(); |
|
159 |
menu.add(getJCalendar()); |
|
160 |
Date value = (Date) getJSpinner().getValue(); |
|
161 |
if (value != null) { |
|
162 |
getJCalendar().setDate(value); |
|
163 |
} |
|
164 |
JComponent thisComp = (JComponent) event.getSource(); |
|
165 |
menu.show(thisComp, 0, thisComp.getY() + 22); |
|
166 |
setValue(getJCalendar().getDate()); |
|
167 |
} |
|
168 |
}); |
|
169 |
|
|
170 |
if (this.getDefinition().isReadOnly()) { |
|
171 |
this.getJSpinner().setEnabled(false); |
|
172 |
this.getJButton().setEnabled(false); |
|
173 |
} |
|
174 |
this.getJSpinner().addFocusListener(this); |
|
175 |
|
|
176 |
if( !this.getComponentsFactory().containsJSpinner(this.getDefinition(), null) ) { |
|
177 |
this.contents.add(timeSpinner, BorderLayout.CENTER); |
|
178 |
this.contents.add(button, BorderLayout.LINE_END); |
|
179 |
} |
|
180 |
} |
|
181 |
this.setValue(this.assignedValue); |
|
182 |
} |
|
183 |
|
|
184 |
public void setValue(Object value) { |
|
185 |
if (value == null) { |
|
186 |
value = this.getDefinition().getDefaultValue(); |
|
187 |
if (value == null) { |
|
188 |
value = null; |
|
189 |
} |
|
190 |
} else { |
|
191 |
try { |
|
192 |
this.getDefinition().validate(value); |
|
193 |
this.problemIndicator().clear(); |
|
194 |
} catch (DynFieldValidateException e) { |
|
195 |
this.problemIndicator().set(e.getLocalizedMessage()); |
|
196 |
} |
|
197 |
} |
|
198 |
if (this.contents instanceof JPanel && this.contents.getName().equalsIgnoreCase(DATE_PANEL_NAME)) { |
|
199 |
try { |
|
200 |
this.getJSpinner().setValue(value); |
|
201 |
} catch (Exception ex) { |
|
202 |
|
|
203 |
} |
|
204 |
} |
|
205 |
this.assignedValue = value; |
|
206 |
} |
|
207 |
|
|
208 |
/* |
|
209 |
* Métodos específicos de cada tipo de datos |
|
210 |
*/ |
|
211 |
public Object getValue() { |
|
212 |
Object value = null; |
|
213 |
if (this.contents instanceof JPanel && this.contents.getName().equalsIgnoreCase(DATE_PANEL_NAME)) { |
|
214 |
value = getJSpinner().getValue(); |
|
215 |
} |
|
216 |
try { |
|
217 |
this.getDefinition().validate(value); |
|
218 |
this.problemIndicator().clear(); |
|
219 |
} catch (DynFieldValidateException e) { |
|
220 |
throw new IllegalFieldValue(this, e.getLocalizedMessage()); |
|
221 |
} |
|
222 |
return value; |
|
223 |
} |
|
224 |
|
|
225 |
@SuppressWarnings("unused") |
|
226 |
public boolean hasValidValue() { |
|
227 |
try { |
|
228 |
Object value = this.getValue(); |
|
229 |
} catch (Exception e) { |
|
230 |
return false; |
|
231 |
} |
|
232 |
return true; |
|
233 |
} |
|
234 |
|
|
235 |
public void focusGained(FocusEvent arg0) { |
|
236 |
fireFieldEnterEvent(); |
|
237 |
this.problemIndicator().restore(); |
|
238 |
} |
|
239 |
|
|
240 |
public void focusLost(FocusEvent arg0) { |
|
241 |
if (this.hasValidValue()) { |
|
242 |
this.problemIndicator().clear(); |
|
243 |
} else { |
|
244 |
try { |
|
245 |
Object value = this.getValue(); |
|
246 |
} catch (Exception e) { |
|
247 |
this.problemIndicator().set(e.getLocalizedMessage()); |
|
248 |
} |
|
249 |
} |
|
250 |
fireFieldExitEvent(); |
|
251 |
} |
|
252 |
|
|
253 |
public void clear() { |
|
254 |
setValue(null); |
|
255 |
// Object value = this.getDefinition().getDefaultValue(); |
|
256 |
// if( value != null ) { |
|
257 |
// if (!(value instanceof Date)){ |
|
258 |
// try { |
|
259 |
// value = DateFormat.getInstance().parse(value.toString()); |
|
260 |
// } catch (ParseException e) { |
|
261 |
// this.problemIndicator().set(e.getLocalizedMessage()); |
|
262 |
// } |
|
263 |
// } |
|
264 |
// } else { |
|
265 |
// value = ""; |
|
266 |
// } |
|
267 |
// try { |
|
268 |
// this.timeSpinner.setValue(value); |
|
269 |
// } catch (RuntimeException e) { |
|
270 |
// this.timeSpinner.setValue(getJCalendar().getDate()); |
|
271 |
// } |
|
272 |
} |
|
273 |
|
|
274 |
private class NullDateEditor extends JSpinner.DateEditor { |
|
275 |
|
|
276 |
/** |
|
277 |
* |
|
278 |
*/ |
|
279 |
private static final long serialVersionUID = -522934985228645970L; |
|
280 |
|
|
281 |
/** |
|
282 |
* @param jspinner |
|
283 |
* @param pattern |
|
284 |
* |
|
285 |
*/ |
|
286 |
public NullDateEditor(JSpinner jspinner, String pattern) { |
|
287 |
super(jspinner, pattern); |
|
288 |
} |
|
289 |
|
|
290 |
public NullDateEditor(JSpinner jspinner) { |
|
291 |
super(jspinner); |
|
292 |
} |
|
293 |
|
|
294 |
public void stateChanged(ChangeEvent e) { |
|
295 |
Object value = getSpinner().getValue(); |
|
296 |
|
|
297 |
String text = ""; |
|
298 |
if (value != null) { |
|
299 |
text = getFormat().format((Date) value); |
|
300 |
} |
|
301 |
getTextField().setText(text); |
|
302 |
} |
|
303 |
} |
|
304 |
} |
|
0 | 305 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.280/org.gvsig.tools.dynform/org.gvsig.tools.dynform.services/src/main/java/org/gvsig/tools/dynform/services/dynformfield/Date/JDynFormFieldDateFactory.java | ||
---|---|---|
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 |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.tools.dynform.services.dynformfield.Date; |
|
25 |
|
|
26 |
import org.gvsig.tools.dataTypes.DataTypes; |
|
27 |
import org.gvsig.tools.dynform.DynFormFieldDefinition; |
|
28 |
import org.gvsig.tools.dynform.JDynFormField; |
|
29 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
|
30 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormFieldFactory; |
|
31 |
|
|
32 |
public class JDynFormFieldDateFactory extends AbstractJDynFormFieldFactory { |
|
33 |
|
|
34 |
public JDynFormFieldDateFactory() { |
|
35 |
super("DATE", DataTypes.DATE); |
|
36 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
public JDynFormField create( |
|
40 |
DynFormSPIManager serviceManager, |
|
41 |
DynFormSPIManager.ComponentsFactory componentsFactory, |
|
42 |
DynFormFieldDefinition fieldDefinition, |
|
43 |
Object value |
|
44 |
) { |
|
45 |
return new JDynFormFieldDate(serviceManager, componentsFactory, this, fieldDefinition, value); |
|
46 |
} |
|
47 |
|
|
48 |
} |
|
0 | 49 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.280/org.gvsig.tools.dynform/org.gvsig.tools.dynform.services/src/main/java/org/gvsig/tools/dynform/services/dynformfield/DynObjectList/JDynFormFieldDynObjectListFactory.java | ||
---|---|---|
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 |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.tools.dynform.services.dynformfield.DynObjectList; |
|
25 |
|
|
26 |
import org.gvsig.tools.dataTypes.DataTypes; |
|
27 |
import org.gvsig.tools.dynform.DynFormFieldDefinition; |
|
28 |
import org.gvsig.tools.dynform.JDynFormField; |
|
29 |
import org.gvsig.tools.dynform.services.dynformfield.DynObject.JDynFormFieldDynObject; |
|
30 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
|
31 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormFieldFactory; |
|
32 |
|
|
33 |
public class JDynFormFieldDynObjectListFactory extends AbstractJDynFormFieldFactory { |
|
34 |
|
|
35 |
public JDynFormFieldDynObjectListFactory() { |
|
36 |
super("LIST_DYNOBJECT", DataTypes.LIST, "DynObject"); |
|
37 |
} |
|
38 |
|
|
39 |
@Override |
|
40 |
public JDynFormField create( |
|
41 |
DynFormSPIManager serviceManager, |
|
42 |
DynFormSPIManager.ComponentsFactory componentsFactory, |
|
43 |
DynFormFieldDefinition fieldDefinition, |
|
44 |
Object value |
|
45 |
) { |
|
46 |
return new JDynFormFieldDynObjectList(serviceManager, componentsFactory, this, fieldDefinition, value); |
|
47 |
} |
|
48 |
} |
|
0 | 49 |
Also available in: Unified diff