Revision 1947 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/Char/JDynFormFieldChar.java
JDynFormFieldChar.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.tools.dynform.services.dynformfield.Char; |
25 | 25 |
|
26 |
import javax.swing.JComboBox; |
|
27 |
import javax.swing.JTextField; |
|
26 |
import org.apache.commons.lang3.StringUtils; |
|
28 | 27 |
import org.gvsig.tools.dynform.DynFormFieldDefinition; |
29 | 28 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
30 | 29 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager.ComponentsFactory; |
31 | 30 |
import org.gvsig.tools.dynform.spi.dynformfield.JDynFormFieldFactory; |
32 | 31 |
|
33 | 32 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormFieldWithValueList; |
34 |
import org.gvsig.tools.dynobject.DynObjectValueItem; |
|
35 | 33 |
import org.gvsig.tools.dynobject.exception.DynFieldValidateException; |
36 | 34 |
|
37 | 35 |
public class JDynFormFieldChar extends AbstractJDynFormFieldWithValueList { |
38 |
|
|
39 |
|
|
40 |
public JDynFormFieldChar( |
|
41 |
DynFormSPIManager serviceManager, |
|
36 |
|
|
37 |
public JDynFormFieldChar( |
|
38 |
DynFormSPIManager serviceManager, |
|
42 | 39 |
ComponentsFactory componentsFactory, |
43 |
JDynFormFieldFactory factory,
|
|
40 |
JDynFormFieldFactory factory, |
|
44 | 41 |
DynFormFieldDefinition definition, |
45 | 42 |
Object value |
46 |
) {
|
|
47 |
super(serviceManager, componentsFactory, factory, definition, value);
|
|
48 |
}
|
|
43 |
) { |
|
44 |
super(serviceManager, componentsFactory, factory, definition, value); |
|
45 |
}
|
|
49 | 46 |
|
50 |
public Object getValue() { |
|
51 |
Object value = null; |
|
52 |
if( this.contents instanceof JTextField ) { |
|
53 |
String s = getJTextField().getText(); |
|
54 |
if( s.trim().length()==0 ) { |
|
55 |
value = this.getDefinition().getDefaultValue(); |
|
56 |
} else { |
|
57 |
try { |
|
58 |
value = s.charAt(0); |
|
59 |
} catch(Exception ex) { |
|
60 |
throw new IllegalFieldValue(this, "Is not a valid char."); |
|
61 |
} |
|
62 |
} |
|
63 |
} else { |
|
64 |
DynObjectValueItem x = (DynObjectValueItem) ((JComboBox)this.contents).getSelectedItem(); |
|
65 |
if( x==null) { |
|
66 |
value = null; |
|
67 |
} else { |
|
68 |
if(x.getValue().toString().length()>0) |
|
69 |
value = x.getValue().toString().charAt(0); |
|
70 |
else |
|
71 |
value = null; |
|
72 |
} |
|
73 |
} |
|
74 |
try { |
|
75 |
this.getDefinition().validate(value); |
|
76 |
this.problemIndicator().clear(); |
|
77 |
} catch (DynFieldValidateException e) { |
|
78 |
throw new IllegalFieldValue(this, e.getLocalizedMessage()); |
|
79 |
} |
|
80 |
return value; |
|
81 |
} |
|
82 |
|
|
47 |
@Override |
|
48 |
public Object getValue() { |
|
49 |
Object value = null; |
|
50 |
String s = this.getValueFromJComponent(); |
|
51 |
if (StringUtils.isBlank(s)) { |
|
52 |
value = this.getDefinition().getDefaultValue(); |
|
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 |
|
|
83 | 69 |
} |
Also available in: Unified diff