2 * Copyright (C) 2020 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
;
12 import org
.eclipse
.swt
.SWT
;
13 import org
.eclipse
.swt
.events
.ModifyEvent
;
14 import org
.eclipse
.swt
.widgets
.Display
;
20 public class FloatWithLabelElement
extends NumberWithLabelElement
{
25 public FloatWithLabelElement(CdmFormFactory toolkit
, ICdmFormElement parentElement
, String labelString
,
26 Number initialNumber
, int style
) {
27 super(toolkit
, parentElement
, labelString
, initialNumber
, style
);
31 public void modifyText(ModifyEvent event
) {
32 String value
= text
.getText();
33 if(StringUtils
.isBlank(value
)){
34 text
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
35 super.modifyText(event
);
40 Float number
= Float
.parseFloat(value
);
41 if((start
!= null && number
< start
) || (end
!= null && number
> end
)){
42 exception
= new NumberFormatException("You entered a number that is not within the allowed bounds.");
45 }catch(NumberFormatException e
){
46 text
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_RED
));
47 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, event
));
53 text
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
55 super.modifyText(event
);
61 * @param numberOfDigits a int.
62 * @param start a {@link java.lang.Float} object.
63 * @param end a {@link java.lang.Float} object.
65 public void setLimits(int numberOfDigits
, Float start
, Float end
){
66 text
.setTextLimit(numberOfDigits
);
71 public void setLimits(int numberOfDigits
, Integer start
, Integer end
){
72 setLimits(numberOfDigits
, start
.floatValue(), end
.floatValue());