Project

General

Profile

Download (3.53 KB) Statistics
| Branch: | Tag: | Revision:
1 cfcb0ce6 n.hoffmann
/**
2
* Copyright (C) 2007 EDIT
3 7c5ba8e0 Patric Plitzner
* European Distributed Institute of Taxonomy
4 cfcb0ce6 n.hoffmann
* http://www.e-taxonomy.eu
5 7c5ba8e0 Patric Plitzner
*
6 cfcb0ce6 n.hoffmann
* 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 78222507 n.hoffmann
package eu.etaxonomy.taxeditor.ui.element;
10 cfcb0ce6 n.hoffmann
11 3dfc2334 Andreas Müller
import org.apache.commons.lang3.StringUtils;
12 1d9ed6ce n.hoffmann
13 cfcb0ce6 n.hoffmann
/**
14 3be6ef3e n.hoffmann
 * <p>NumberWithLabelElement class.</p>
15
 *
16 cfcb0ce6 n.hoffmann
 * @author n.hoffmann
17
 * @created Mar 22, 2010
18
 */
19 bf20bbfd Katja Luther
public abstract class NumberWithLabelElement extends TextWithLabelElement {
20 cfcb0ce6 n.hoffmann
21 7c5ba8e0 Patric Plitzner
22 bf20bbfd Katja Luther
	protected NumberFormatException exception;
23 1d9ed6ce n.hoffmann
24 3be6ef3e n.hoffmann
	/**
25
	 * <p>Constructor for NumberWithLabelElement.</p>
26
	 *
27 78222507 n.hoffmann
	 * @param toolkit a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
28
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
29 3be6ef3e n.hoffmann
	 * @param labelString a {@link java.lang.String} object.
30 d2d8e95d Cherian Mathew
	 * @param initialNumber a {@link java.lang.Number} object.
31 3be6ef3e n.hoffmann
	 * @param style a int.
32
	 */
33 cfcb0ce6 n.hoffmann
	public NumberWithLabelElement(CdmFormFactory toolkit,
34
			ICdmFormElement parentElement, String labelString,
35 d2d8e95d Cherian Mathew
			Number initialNumber, int style) {
36 cfcb0ce6 n.hoffmann
		super(toolkit, parentElement, labelString, null, null, style);
37 d2d8e95d Cherian Mathew
		setNumber(initialNumber);
38 cfcb0ce6 n.hoffmann
	}
39 7c5ba8e0 Patric Plitzner
40 ae4ea023 Katja Luther
	/**
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 7c5ba8e0 Patric Plitzner
57 3be6ef3e n.hoffmann
	/**
58 d2d8e95d Cherian Mathew
	 * <p>setNumber</p>
59 3be6ef3e n.hoffmann
	 *
60 d2d8e95d Cherian Mathew
	 * @param number a {@link java.lang.Number} object.
61 3be6ef3e n.hoffmann
	 */
62 d2d8e95d Cherian Mathew
	public void setNumber(Number number) {
63 cfcb0ce6 n.hoffmann
		super.setText(getStringRepresentation(number));
64
	}
65 7c5ba8e0 Patric Plitzner
66 3be6ef3e n.hoffmann
	/**
67 63b961d3 Patric Plitzner
	 * Get the value of this field as an {@link Integer}.
68
	 * @return the Integer value or null if {@link NumberFormatException} occurs.
69 3be6ef3e n.hoffmann
	 */
70 cfcb0ce6 n.hoffmann
	public Integer getInteger() {
71 f4a95c6e Patric Plitzner
	    if(super.getText()!=null){
72
	        String text = super.getText().trim();
73
	        try {
74 df566daf Andreas Müller
	            return StringUtils.isBlank(text) ? null : new Integer(text);
75 f4a95c6e Patric Plitzner
	        } catch (NumberFormatException e) {
76
	            exception = e;
77
	        }
78
	    }
79 63b961d3 Patric Plitzner
		return null;
80 cfcb0ce6 n.hoffmann
	}
81 7c5ba8e0 Patric Plitzner
82 3be6ef3e n.hoffmann
	/**
83 63b961d3 Patric Plitzner
	 * Get the value of this field as a {@link Float}.
84
	 * @return the Float value or null if {@link NumberFormatException} occurs.
85 3be6ef3e n.hoffmann
	 */
86 cfcb0ce6 n.hoffmann
	public Float getFloat(){
87 63b961d3 Patric Plitzner
	    String text = super.getText();
88
	    try {
89 df566daf Andreas Müller
	    	return StringUtils.isBlank(text) ? null : new Float(text);
90 63b961d3 Patric Plitzner
	    } catch (NumberFormatException e) {
91
	        exception = e;
92
	    }
93
	    return null;
94 cfcb0ce6 n.hoffmann
	}
95 7c5ba8e0 Patric Plitzner
96 d2d8e95d Cherian Mathew
	/**
97 63b961d3 Patric Plitzner
	 * Get the value of this field as an {@link Double}.
98
	 * @return the Double value or null if {@link NumberFormatException} occurs.
99 d2d8e95d Cherian Mathew
	 */
100 5a26bee6 Cherian Mathew
	public Double getDouble(){
101 63b961d3 Patric Plitzner
	    String text = super.getText();
102
	    try {
103 66b9cc46 Andreas Müller
	    	return StringUtils.isBlank(text) ? null : new Double(text);
104 63b961d3 Patric Plitzner
	    } catch (NumberFormatException e) {
105
	        exception = e;
106
	    }
107
	    return null;
108 d2d8e95d Cherian Mathew
	}
109 63b961d3 Patric Plitzner
110 cfcb0ce6 n.hoffmann
	private String getStringRepresentation(Object number){
111
		if(number != null){
112
			return number.toString();
113 7c5ba8e0 Patric Plitzner
		}
114 cfcb0ce6 n.hoffmann
		return null;
115
	}
116 7c5ba8e0 Patric Plitzner
117
118
119
120
121 1d9ed6ce n.hoffmann
	/**
122 3be6ef3e n.hoffmann
	 * <p>Getter for the field <code>exception</code>.</p>
123
	 *
124 1d9ed6ce n.hoffmann
	 * @return the exception
125
	 */
126
	public NumberFormatException getException() {
127
		return exception;
128
	}
129 cfcb0ce6 n.hoffmann
}