Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » [DataBinding] Best practices for binding text control to Presentation Model
[DataBinding] Best practices for binding text control to Presentation Model [message #311643] Thu, 18 January 2007 17:05 Go to next message
Eclipse UserFriend
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 #311672 is a reply to message #311643] Fri, 19 January 2007 05:14 Go to previous messageGo to next message
Brad Reynolds is currently offline Brad ReynoldsFriend
Messages: 309
Registered: July 2009
Senior Member
martin wrote:
> 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?

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? Is this what
you want? Whether to bind using SWT.Modify or SWT.FocusOut is going to be
specific to you use case. In it's current state data binding forces this
parameter to mean that validation and updating of the model will occur
when the event fires. So if you want to validate and update on Modify
then use that event, if not use FocusOut. Depending upon your validation
it could be too expensive to perform on every Modify.

Also this weekend this is going to change a bit[1]. You're going to have
the ability to run validation but not update your model until you
explicity say so. You'll also be able to defer expensive validation.
This might make this decision a little easier for you.

-brad

[1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=159768
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 Go to previous messageGo to next message
Eclipse UserFriend
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 #311710 is a reply to message #311700] Fri, 19 January 2007 18:44 Go to previous messageGo to next message
Brad Reynolds is currently offline Brad ReynoldsFriend
Messages: 309
Registered: July 2009
Senior Member
What would be wrong with invoking dataBindingContext.updateModel()?

-brad
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 Go to previous messageGo to next message
Eclipse UserFriend
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
>
Re: [DataBinding] Best practices for binding text control to Presentation Model [message #311745 is a reply to message #311713] Sun, 21 January 2007 01:21 Go to previous messageGo to next message
Brad Reynolds is currently offline Brad ReynoldsFriend
Messages: 309
Registered: July 2009
Senior Member
If that doesn't work then you could try to invoke the update on the
binding directly. But since I don't have the code in front of me, and
it's not going to be updated, if it doesn't work it's not going to get
fixed for that version of the API. I know that this does work in the
latest data binding code.

-brad
Re: [DataBinding] Best practices for binding text control to Presentation Model [message #311762 is a reply to message #311643] Mon, 22 January 2007 15:46 Go to previous message
Dave Orme is currently offline Dave OrmeFriend
Messages: 424
Registered: July 2009
Senior Member
martin wrote:
> 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?

Brad asked me to jump in here. :-)

This is how I would code it.

Alternatively, you could try having your save action call
Display.getCurrent().getFocusControl().notifyListeners(SWT.F ocusOut, new
Event());



Best regards,

Dave Orme
Previous Topic:I want to remove Debug As option from Run menu & add all the sub-menu of Debug
Next Topic:Invoking non-plugin installs using update manager
Goto Forum:
  


Current Time: Fri Jul 19 14:17:26 GMT 2024

Powered by FUDForum. Page generated in 0.03223 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top