2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.ui
.element
;
11 import org
.apache
.commons
.lang3
.StringUtils
;
14 * <p>NumberWithLabelElement class.</p>
17 * @created Mar 22, 2010
19 public abstract class NumberWithLabelElement
extends TextWithLabelElement
{
22 protected NumberFormatException exception
;
25 * <p>Constructor for NumberWithLabelElement.</p>
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.
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
);
41 * <p>Constructor for NumberWithLabelElement.</p>
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.
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
);
60 * @param number a {@link java.lang.Number} object.
62 public void setNumber(Number number
) {
63 super.setText(getStringRepresentation(number
));
67 * Get the value of this field as an {@link Integer}.
68 * @return the Integer value or null if {@link NumberFormatException} occurs.
70 public Integer
getInteger() {
71 if(super.getText()!=null){
72 String text
= super.getText().trim();
74 return StringUtils
.isBlank(text
) ?
null : new Integer(text
);
75 } catch (NumberFormatException e
) {
83 * Get the value of this field as a {@link Float}.
84 * @return the Float value or null if {@link NumberFormatException} occurs.
86 public Float
getFloat(){
87 String text
= super.getText();
89 return StringUtils
.isBlank(text
) ?
null : new Float(text
);
90 } catch (NumberFormatException e
) {
97 * Get the value of this field as an {@link Double}.
98 * @return the Double value or null if {@link NumberFormatException} occurs.
100 public Double
getDouble(){
101 String text
= super.getText();
103 return StringUtils
.isBlank(text
) ?
null : new Double(text
);
104 } catch (NumberFormatException e
) {
110 private String
getStringRepresentation(Object number
){
112 return number
.toString();
122 * <p>Getter for the field <code>exception</code>.</p>
124 * @return the exception
126 public NumberFormatException
getException() {