[DataBinding] Best practices for binding text control to Presentation Model [message #311643] |
Thu, 18 January 2007 17:05 |
Eclipse User |
|
|
|
Originally posted by: mbayly.nospam.telus.net
Hi
I have an Eclipse RCP app which is using JFace databinding 3.2.
One window in the app contains text controls and the user can click a save
button on the tool bar to save the contents.
I'm using the Presentation Model approach in the GUI tier so my SWT controls
know about the presentation model but the model doesn't know about the controls.
By default it seems that JFace DataBinding sets up binding between text controls
and your model to fire changes on SWT.FocusOut. However, clicking on a toolbar
button doesn't cause a FocusOut on the text control so by default, the latest
changes don't get picked up when clicking Save.
I noticed that SWTObservableFactory has a ctor parameter to make it sync
the binding on the SWT.Modify event instead. So using this ensures that the
Presentation Model is always kept up to date.
I'm wondering if this is the best approach for this kind of scenario? I don't
really want to have to add code to the view to force a sync when the Save
is pressed as the Save is currently handled by the Save action talking directly
to the PM. Also I don't want the PM to have to pull the data from the view
in the Save action as the PM shouldn't know about the view.
So is using SWT.Modify the best approach in this case? Should I be concerned
about the overhead of synchronizing on each keystroke?
Thanks
Martin
|
|
|
|
Re: [DataBinding] Best practices for binding text control to Presentation Model [message #311700 is a reply to message #311672] |
Fri, 19 January 2007 15:09 |
Eclipse User |
|
|
|
Originally posted by: mbayly.nospam.telus.net
Hi Brad,
> What is Save suppose to do? Are you keeping your PM always up to date
> with the UI (on every modify) and then persisting on Save?
Yes Save persists. I'd be quite happy to leave updating the PM until the
user clicks Save as well. But I found that because its possible to edit
a text control, and then click the toolbar Save button, without the text
control losing focus, I couldn't rely on FocusOut. And I couldn't think
of another way to ensure the PM has up to date data when pressing Save, other
than to update the PM on every Modify.
Cheers
Martin
|
|
|
|
Re: [DataBinding] Best practices for binding text control to Presentation Model [message #311713 is a reply to message #311710] |
Fri, 19 January 2007 19:22 |
Eclipse User |
|
|
|
Originally posted by: mbayly.nospam.telus.net
That sounds like it would be an appropriate approach only it doesn't seem
to be implemented in the version I have:
org.eclipse.jface.databinding_1.0.0.I20060605-1400.jar
Maybe I should check to see if there is a later version. I have updated Eclipse
to 3.2.1 but maybe the update didn't update the databinding?
Thanks
Martin
Hello Brad,
> What would be wrong with invoking dataBindingContext.updateModel()?
>
> -brad
>
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03385 seconds