Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 317917 - option to format null as zero in Decimal and NumericTextRidget
Summary: option to format null as zero in Decimal and NumericTextRidget
Status: RESOLVED FIXED
Alias: None
Product: Riena
Classification: RT
Component: ridget (show other bugs)
Version: unspecified   Edit
Hardware: PC All
: P3 enhancement (vote)
Target Milestone: 3.0.0.M4   Edit
Assignee: Elias Volanakis CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-25 02:21 EDT by Steffen Kriese CLA
Modified: 2010-12-14 09:19 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Steffen Kriese CLA 2010-06-25 02:21:41 EDT
The Decimal and NumericTextRidget need a setFormat-method to supply a custom format-string like the DatetextRidget provides.
I would like to have something similar to the JDK DecimalFormat: http://java.sun.com/j2se/1.4.2/docs/api/java/text/DecimalFormat.html
Comment 1 Elias Volanakis CLA 2010-06-28 16:50:47 EDT
Curious: what are the features your are currently missing?

(providing support for any format is going to be quite difficult)
Comment 2 Steffen Kriese CLA 2010-06-29 01:57:33 EDT
It would be sufficient, if we could force the Ridget to show zeros when a zero or null is bound. At the moment a empty string with a comma is shown. I don't need all these scientific notations, but the formats # and 0.
Comment 3 Elias Volanakis CLA 2010-11-18 13:43:40 EST
We are already padding a too-short value in the decimal text field. There is always at least one digit before the dec.separator and max.precision digits after the dec.separator. i.e.

 ,1   -> 0,10
 0    -> 0,00
 1,2  -> 1,20 (assuming precision of two)

The only thing missing is how to treat the null-value. Currently:
- in NumericTextRidget null -> empty 
- in DecimalTextRidget null -> , 

Next steps:

(a) With regard to Steffen's comment: from my POV it would be sufficient to have a flag that will treat null as zero, example: ridget.setFormatNullAsZero(true). If set to true the formatting would be as follows:

- in NumericTextRidget null -> 0
- in DecimalTextRidget null -> 0,0..0

(b) a general setFormat method is not needed at this time
Comment 4 Elias Volanakis CLA 2010-11-18 13:46:21 EST
Adjusting bug summary.
Comment 5 Elias Volanakis CLA 2010-11-19 02:31:13 EST
This has proven a bit tricky, due to all the other stuff happening in the text widgets (markers, hiding of text, ...). Here's the sketch of the current solution:

ridget.setConvertEmptyToZero(true/false); // default is false

When set to true (assuming decimal ridget, precision 2) :
- null -> ridget.getText() is "", control.getText() is "0,00" (previously ",")
- ""   -> ridget.getText() is "", control.getText() is "0,00" (previously ",")
- "0"  -> ridget.getText() is "0", control.getText() is "0,00" 

When set to false (assuming decimal ridget, precision 2) the behavior is as before:
- null -> ridget.getText() is "", control.getText() is ","
- ""   -> ridget.getText() is "", control.getText() is ","
- "0"  -> ridget.getText() is "0", control.getText() is "0,00" 

For NumericTextRidget the behavior is similar (minus the decimal part, i.e. "0" instead of "0,00").

Summary: nothing should change, except the way the value is shown in the control.
Comment 6 Elias Volanakis CLA 2010-11-19 19:06:55 EST
One clarification: the algorithm described in comment #5 to handly empty value, applies only when the value is coming via r.setText(...) or r.updateFromModel(...). When setConvertEmptyToZero is on, and the user focuses on the widget, it is not possible to leave the widget empty. I.e. empty (",") will always be converted to ("0,00") and will become the value of the ridget.

See SnippetNumericTextRidget002 for an example.

Resolving.