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