1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.ui.element;
|
10
|
|
11
|
import org.apache.commons.lang3.StringUtils;
|
12
|
|
13
|
/**
|
14
|
* <p>NumberWithLabelElement class.</p>
|
15
|
*
|
16
|
* @author n.hoffmann
|
17
|
* @created Mar 22, 2010
|
18
|
*/
|
19
|
public abstract class NumberWithLabelElement extends TextWithLabelElement {
|
20
|
|
21
|
|
22
|
protected NumberFormatException exception;
|
23
|
|
24
|
/**
|
25
|
* <p>Constructor for NumberWithLabelElement.</p>
|
26
|
*
|
27
|
* @param toolkit a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
|
28
|
* @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
|
29
|
* @param labelString a {@link java.lang.String} object.
|
30
|
* @param initialNumber a {@link java.lang.Number} object.
|
31
|
* @param style a int.
|
32
|
*/
|
33
|
public NumberWithLabelElement(CdmFormFactory toolkit,
|
34
|
ICdmFormElement parentElement, String labelString,
|
35
|
Number initialNumber, int style) {
|
36
|
super(toolkit, parentElement, labelString, null, null, style);
|
37
|
setNumber(initialNumber);
|
38
|
}
|
39
|
|
40
|
/**
|
41
|
* <p>Constructor for NumberWithLabelElement.</p>
|
42
|
*
|
43
|
* @param toolkit a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
|
44
|
* @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
|
45
|
* @param labelString a {@link java.lang.String} object.
|
46
|
* @param initialNumber a {@link java.lang.Number} object.
|
47
|
* @param style a int.
|
48
|
*/
|
49
|
public NumberWithLabelElement(CdmFormFactory toolkit,
|
50
|
ICdmFormElement parentElement, String labelString,
|
51
|
Number initialNumber, Integer height, Integer length, int style) {
|
52
|
super(toolkit, parentElement, labelString, null, null, style);
|
53
|
setNumber(initialNumber);
|
54
|
}
|
55
|
|
56
|
|
57
|
/**
|
58
|
* <p>setNumber</p>
|
59
|
*
|
60
|
* @param number a {@link java.lang.Number} object.
|
61
|
*/
|
62
|
public void setNumber(Number number) {
|
63
|
super.setText(getStringRepresentation(number));
|
64
|
}
|
65
|
|
66
|
/**
|
67
|
* Get the value of this field as an {@link Integer}.
|
68
|
* @return the Integer value or null if {@link NumberFormatException} occurs.
|
69
|
*/
|
70
|
public Integer getInteger() {
|
71
|
if(super.getText()!=null){
|
72
|
String text = super.getText().trim();
|
73
|
try {
|
74
|
return StringUtils.isBlank(text) ? null : new Integer(text);
|
75
|
} catch (NumberFormatException e) {
|
76
|
exception = e;
|
77
|
}
|
78
|
}
|
79
|
return null;
|
80
|
}
|
81
|
|
82
|
/**
|
83
|
* Get the value of this field as a {@link Float}.
|
84
|
* @return the Float value or null if {@link NumberFormatException} occurs.
|
85
|
*/
|
86
|
public Float getFloat(){
|
87
|
String text = super.getText();
|
88
|
try {
|
89
|
return StringUtils.isBlank(text) ? null : new Float(text);
|
90
|
} catch (NumberFormatException e) {
|
91
|
exception = e;
|
92
|
}
|
93
|
return null;
|
94
|
}
|
95
|
|
96
|
/**
|
97
|
* Get the value of this field as an {@link Double}.
|
98
|
* @return the Double value or null if {@link NumberFormatException} occurs.
|
99
|
*/
|
100
|
public Double getDouble(){
|
101
|
String text = super.getText();
|
102
|
try {
|
103
|
return StringUtils.isBlank(text) ? null : new Double(text);
|
104
|
} catch (NumberFormatException e) {
|
105
|
exception = e;
|
106
|
}
|
107
|
return null;
|
108
|
}
|
109
|
|
110
|
private String getStringRepresentation(Object number){
|
111
|
if(number != null){
|
112
|
return number.toString();
|
113
|
}
|
114
|
return null;
|
115
|
}
|
116
|
|
117
|
|
118
|
|
119
|
|
120
|
|
121
|
/**
|
122
|
* <p>Getter for the field <code>exception</code>.</p>
|
123
|
*
|
124
|
* @return the exception
|
125
|
*/
|
126
|
public NumberFormatException getException() {
|
127
|
return exception;
|
128
|
}
|
129
|
}
|