Revision bf20bbfd
Added by Katja Luther almost 4 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/NumberWithLabelElement.java | ||
---|---|---|
10 | 10 |
package eu.etaxonomy.taxeditor.ui.element; |
11 | 11 |
|
12 | 12 |
import org.apache.commons.lang.StringUtils; |
13 |
import org.eclipse.swt.SWT; |
|
14 |
import org.eclipse.swt.events.ModifyEvent; |
|
15 |
import org.eclipse.swt.widgets.Display; |
|
16 | 13 |
|
17 | 14 |
|
18 | 15 |
/** |
... | ... | |
21 | 18 |
* @author n.hoffmann |
22 | 19 |
* @created Mar 22, 2010 |
23 | 20 |
*/ |
24 |
public class NumberWithLabelElement extends TextWithLabelElement { |
|
21 |
public abstract class NumberWithLabelElement extends TextWithLabelElement {
|
|
25 | 22 |
|
26 |
private Float start; |
|
27 |
private Float end; |
|
28 | 23 |
|
29 |
private NumberFormatException exception;
|
|
24 |
protected NumberFormatException exception;
|
|
30 | 25 |
|
31 | 26 |
/** |
32 | 27 |
* <p>Constructor for NumberWithLabelElement.</p> |
... | ... | |
121 | 116 |
return null; |
122 | 117 |
} |
123 | 118 |
|
124 |
/** {@inheritDoc} */ |
|
125 |
@Override |
|
126 |
public void modifyText(ModifyEvent event) { |
|
127 |
String value = text.getText(); |
|
128 |
if(StringUtils.isBlank(value)){ |
|
129 |
text.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
|
130 |
super.modifyText(event); |
|
131 |
return; |
|
132 |
} |
|
133 |
|
|
134 |
try{ |
|
135 |
Float number = Float.parseFloat(value); |
|
136 |
if((start != null && number < start) || (end != null && number > end)){ |
|
137 |
exception = new NumberFormatException("You entered a number that is not within the allowed bounds."); |
|
138 |
throw exception; |
|
139 |
} |
|
140 |
}catch(NumberFormatException e){ |
|
141 |
text.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED)); |
|
142 |
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, event)); |
|
143 |
exception = e; |
|
144 |
return; |
|
145 |
} |
|
146 | 119 |
|
147 |
exception = null; |
|
148 |
text.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
|
149 | 120 |
|
150 |
super.modifyText(event); |
|
151 |
} |
|
152 | 121 |
|
153 |
/** |
|
154 |
* <p>setLimits</p> |
|
155 |
* |
|
156 |
* @param numberOfDigits a int. |
|
157 |
* @param start a {@link java.lang.Integer} object. |
|
158 |
* @param end a {@link java.lang.Integer} object. |
|
159 |
*/ |
|
160 |
public void setLimits(int numberOfDigits, Integer start, Integer end){ |
|
161 |
setLimits(numberOfDigits, start.floatValue(), end.floatValue()); |
|
162 |
} |
|
163 |
|
|
164 |
/** |
|
165 |
* <p>setLimits</p> |
|
166 |
* |
|
167 |
* @param numberOfDigits a int. |
|
168 |
* @param start a {@link java.lang.Float} object. |
|
169 |
* @param end a {@link java.lang.Float} object. |
|
170 |
*/ |
|
171 |
public void setLimits(int numberOfDigits, Float start, Float end){ |
|
172 |
text.setTextLimit(numberOfDigits); |
|
173 |
this.start = start; |
|
174 |
this.end = end; |
|
175 |
} |
|
176 | 122 |
|
177 | 123 |
/** |
178 | 124 |
* <p>Getter for the field <code>exception</code>.</p> |
Also available in: Unified diff
adapt editor to value of statisticalMeasurementValue as BigDecimal