Hi Ernst,
you are right, this is a restriction of ULCNumberDataType, which currently
supports only Double and Integer, whenever the input from a text field is
converted back to a value.
However you can write an extension of ULCNumberDataType (IDataType), which
deals with BigDecimals instead. The attached code snippet
demonstrates this idea and parses BigDecimals as intended.
(Note that my suggestion is based on the method
java.util.text.DecimalFormat.setParseBigDecimal(),
which only exists as of JDK 1.5.)
Greetings,
Daniel
---------------------------------------------------
public class Hey extends AbstractApplication {
public void start() {
final ULCFrame frame = new ULCFrame();
frame.setDefaultCloseOperation(ULCFrame.TERMINATE_ON_CLOSE);
final ULCBoxPane pane = new ULCBoxPane();
frame.add(pane);
final ULCTextField textField1 = new ULCTextField();
// commenting out the next two lines makes valueChanged
// returning a string
ULCNumberDataType dataType = new ULCBigDecimalDataType();
textField1.setDataType(dataType);
textField1.setValue(new BigDecimal(1234.00));
ULCLabel label1 = new ULCLabel("Label1");
label1.setLabelFor(textField1);
textField1.addValueChangedListener(new IValueChangedListener() {
public void valueChanged(ValueChangedEvent arg0) {
System.out.println(textField1.getValue().getClass());
System.out.println(textField1.getValue());
}
});
pane.set(0, 0, ULCBoxPane.BOX_LEFT_CENTER, label1);
pane.set(0, 1, ULCBoxPane.BOX_EXPAND_CENTER, textField1);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
DevelopmentRunner.setApplicationClass(Hey.class);
DevelopmentRunner.run();
}
public static class UIBigDecimalConverter implements IStringConverter {
private final DecimalFormat fFormat;
public UIBigDecimalConverter() {
fFormat = (DecimalFormat)NumberFormat.getInstance();
fFormat.setParseBigDecimal(true);
}
public String convertToString(Object object) {
return fFormat.format(object);
}
public String convertToEditString(Object object) {
return convertToString(object);
}
public Object convertToObject(String string) throws
DataTypeConversionException {
ParsePosition start = new ParsePosition(0);
Object result = fFormat.parse(string, start);
if (start.getErrorIndex() > -1 || start.getIndex() <
string.length()) {
throw new DataTypeConversionException("Unable to convert
String: \"" + string + "\" to Number");
}
return result;
}
}
public static class ULCBigDecimalDataType extends ULCNumberDataType {
public String typeString() {
return UIBigDecimalDataType.class.getName();
}
}
public static class UIBigDecimalDataType extends UINumberDataType {
public void initConverter() {
fConverter = new UIBigDecimalConverter();
}
}
}
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Plüss Ernst, Bedag
Sent: Freitag, 14. Juli 2006 13:59
To: [EMAIL PROTECTED]
Subject: [ULC-developer] BigDezimal gets convertet to Double or String
Hi All
We have a ULCTextField witch represents a BigDecimal value. As of ULC 6.1
it's no problem to set the BigDecimal via the setValue Method. But as soon
we get a ValueChanged event and call getValue we get a String value (or in
the case of a NumberDataType a Double value). IMHO it should return a
BigDecimal value.
TIA
Ernst
<<BigDecimalSnippet.java>>
_______________________________________________
ULC-developer mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/ulc-developer