Databinding a Bean as a property of another bean

SWT Designer allows you to create the views, editors, perspectives, pref pages, composites, etc. that comprise Eclipse SWT & RCP applications and plug-ins.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

Databinding a Bean as a property of another bean

Postby tch » Tue Apr 29, 2008 9:41 am

I would like to bind a property from another bean, however the UI only lets me selects a bean that exists, not step through an existing bean.

So in order to bind a simple value like a Department from an Employee bean named employee I have to do:

Code: Select all
Department department = employee.getDepartment();


Now I can select the department bean and end up with generated code like:

Code: Select all
IObservableValue observeValue = BeansObservables.observeValue(department, "labelNm");


What I would like to be able to do is simply:
Code: Select all
IObservableValue boProjMgrIdObserveValue = BeansObservables.observeValue(employee.getDepartment(), "labelNm");


That saves me the work of having to put Department into it's own seperate bean first.
tch
 
Posts: 2
Joined: Tue Apr 29, 2008 9:37 am

Re: Databinding a Bean as a property of another bean

Postby Eric Clayberg » Wed Apr 30, 2008 9:37 am

We don't plan to supported binding to nested attributes until the Eclipse DB API supports that directly. See the following for more detail...

https://bugs.eclipse.org/bugs/show_bug.cgi?id=195222

The approach you are suggesting:

Code: Select all
IObservableValue boProjMgrIdObserveValue = BeansObservables.observeValue(employee.getDepartment(), "labelNm");

is fragile and generaly not what you want. In your example, you are binding directly to a child object or the employee object. If the employee object later changes, you will stil be bound ot the old department object rather than the new department object held by the employee.

In the future, the Eclipse DB API will likely support something like the following:

Code: Select all
IObservableValue boProjMgrIdObserveValue = BeansObservables.observeValue(employee, "department.labelNm");

This will allow for nested bindings that will correctly update as the main object changes.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Re: Databinding a Bean as a property of another bean

Postby urferr » Mon Jun 15, 2009 3:51 am

With 3.5 this works now when using Properties-API):

IObservableValue v = BeanProperties.value("address.street").observe(person);


Will this kind of databinding made available in SWTDesigner in the near future? As i read in the jface newsgroup it should also work with tables and trees

regards
Reto
urferr
 
Posts: 2
Joined: Fri May 23, 2008 1:58 am

Re: Databinding a Bean as a property of another bean

Postby Eric Clayberg » Mon Jun 15, 2009 12:55 pm

urferr wrote:With 3.5 this works now when using Properties-API):
IObservableValue v = BeanProperties.value("address.street").observe(person);
Will this kind of databinding made available in SWTDesigner in the near future?

Yes. That style will be fully supported next week when Eclipse 3.5 is formally released.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to SWT Designer

Who is online

Users browsing this forum: No registered users and 2 guests