Bug 208304 - [DataBinding] - Converted Value not updating tthe display
Summary: [DataBinding] - Converted Value not updating tthe display
Status: RESOLVED DUPLICATE of bug 238222
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.4   Edit
Hardware: PC Linux
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Boris Bokowski CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2007-10-31 15:08 EDT by Dave Smith CLA
Modified: 2008-07-31 16:21 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dave Smith CLA 2007-10-31 15:08:15 EDT
I have a simple text field that is supposed to be a Money field (ie max 9 digits 2 decimal places) and is stored in the model
as BigDecimal. What I want to do is set the scale to two decimal places so if the user enters 25 it will format the display as 
25.00. The set method sets the correct scale and stores it in the model but of course the display does not get updated. 

I would suggest that we add an option to the DataBinding that if the view is updated on model change regardless of the source of the model changee
Comment 1 Brad Reynolds CLA 2007-10-31 15:21:35 EDT
Can you attach a snippet displaying the issue?  I'm confused by your last statement.
Comment 2 Dave Smith CLA 2007-10-31 15:59:13 EDT
How about I try conceptually... You a have a text widget bound to a model attribute that is a BigDecimal. In your UpdateValueStrategy you have a converter that converts a String to a BigDecimal with 2 decimal places. 

Now 25 is entered into the text widget, the converter converts to a BigDecimal with  a scale of 2 and the model is set. The problem is that even though the model fires a property change , and the text widget should be updated to 25.00 it is not.  The issue is in the ValueBinding class once the updateValueStrategy.doSet is called the ValueBinding ignores any update requests from the model. Now for most cases this is correct (enter "9" do String->int  going the other way would be the same) so what I suggested was that we could have an override so that the view gets updated from the model on the PropertyChange even if the widget was the event that triggered the change.

Comment 3 Boris Bokowski CLA 2007-10-31 16:09:34 EDT
Note that it is not necessary to react to change events from the model. You could also (after successfully setting the value) convert the new model value using the model-to-target converter and update the target text field if its value is different.

The question then is how this interacts with what the user is doing. For example, you should not change the contents of a text field while the keyboard focus is still in that text field. (Unless you are very careful and handle all the different corner cases well.)

Do you have a simple SWT snippet that implements this?
Comment 4 Boris Bokowski CLA 2007-10-31 16:10:33 EDT
(In reply to comment #3)
> You could also

I should have written "Another possible solution is to change the framework so that...".
Comment 5 Dave Smith CLA 2007-10-31 19:59:56 EDT
Our design team discussed your option and decided for the reasons you stated in your second paragraph to opt for a programmer controlled option. For the majority of the cases the current implementation is sufficient.

The other reason we wanted to go "all the way to the model" was that if there was other conversion that happened at the model (We could not come up with a case but everyone liked the idea of the flexibility ) the view would be updated.

As far as a snippet , no we have not coded it. We could easily hack up ValueBinding to make it work but I'm not sure where you want to specify that model change always updates view.
Comment 6 Boris Bokowski CLA 2007-10-31 20:18:27 EDT
Have you looked at the FormattedText custom control from http://www.eclipse.org/nebula ?

If you don't have a use case for doing this on the model side, you might like FormattedText even better. Writing an IObservableValue implementation for it should be easy.
Comment 7 Brad Reynolds CLA 2007-10-31 21:45:51 EDT
(In reply to comment #6)
> Have you looked at the FormattedText custom control from
> http://www.eclipse.org/nebula ?
> 
> If you don't have a use case for doing this on the model side, you might like
> FormattedText even better. Writing an IObservableValue implementation for it
> should be easy.

I haven't used the Nebula widget but I was going to suggest this sort of approach as well.  The reason being that Bindings currently aren't the typical Controller as is expected in a MVC pattern.  Thus the Binding doesn't control the formatting of the user input.
Comment 8 Ovidio Mallo CLA 2008-07-27 13:56:16 EDT
I'd say this is a duplicate of bug #238222.
Comment 9 Boris Bokowski CLA 2008-07-31 16:21:55 EDT

*** This bug has been marked as a duplicate of bug 238222 ***