Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » [Databinding/E4] Binding of nested properties
[Databinding/E4] Binding of nested properties [message #1738752] Sat, 23 July 2016 00:05 Go to next message
Ralf Heydenreich is currently offline Ralf HeydenreichFriend
Messages: 193
Registered: July 2009
Senior Member
Hi all,
I've an editor (MPart) which has a bound model. The model is, e.g., a
person with an address and an alternative address.

Like so:

+----------------------------+
| Person |
+----------------------------+
| name: String |
| surname: String |
| alternativeAddress: Person |
+----------------------------+

(the alternativeAddress not only contains city and street, but also
names etc.)

So, I've created a binding:

IBeanValueProperty nameProperty = BeanProperties.value(Person.class,
"name");
IObservableValue<Person> model = nameProperty.observe(myEditor);
uiWidget = WidgetProperties.text(SWT.Modify).observe(personEditorName);

ctx.bindValue(uiWidget, model);

This works for "name". But if I want to bind "alternativeAddress.name"
nothing is stored. Do I have to write it in another way?

TIA,
Ralf.
Re: [Databinding/E4] Binding of nested properties [message #1740310 is a reply to message #1738752] Thu, 11 August 2016 13:09 Go to previous messageGo to next message
Ralf Heydenreich is currently offline Ralf HeydenreichFriend
Messages: 193
Registered: July 2009
Senior Member
Am 23.07.2016 um 02:05 schrieb Ralf Heydenreich:
> Hi all,
> I've an editor (MPart) which has a bound model. The model is, e.g., a
> person with an address and an alternative address.
>
> Like so:
>
> +----------------------------+
> | Person |
> +----------------------------+
> | name: String |
> | surname: String |
> | alternativeAddress: Person |
> +----------------------------+
>
> (the alternativeAddress not only contains city and street, but also
> names etc.)
>
> So, I've created a binding:
>
> IBeanValueProperty nameProperty = BeanProperties.value(Person.class,
> "name");
> IObservableValue<Person> model = nameProperty.observe(myEditor);
> uiWidget = WidgetProperties.text(SWT.Modify).observe(personEditorName);
> ctx.bindValue(uiWidget, model);
>
> This works for "name". But if I want to bind "alternativeAddress.name"
> nothing is stored. Do I have to write it in another way?
>
> TIA,
> Ralf.


Hi,
I found the solution for myself :-)
The problem was that the object for the nested property was created
*after* the binding. This doesn't work. You *always* have to bind editor
fields to an existing object (event if the fields are hidden).

So long,
Ralf.
Re: [Databinding/E4] Binding of nested properties [message #1740389 is a reply to message #1740310] Fri, 12 August 2016 07:32 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6417
Registered: July 2009
Senior Member
On 11.08.16 15:09, Ralf Heydenreich wrote:
> Am 23.07.2016 um 02:05 schrieb Ralf Heydenreich:
>> Hi all,
>> I've an editor (MPart) which has a bound model. The model is, e.g., a
>> person with an address and an alternative address.
>>
>> Like so:
>>
>> +----------------------------+
>> | Person |
>> +----------------------------+
>> | name: String |
>> | surname: String |
>> | alternativeAddress: Person |
>> +----------------------------+
>>
>> (the alternativeAddress not only contains city and street, but also
>> names etc.)
>>
>> So, I've created a binding:
>>
>> IBeanValueProperty nameProperty = BeanProperties.value(Person.class,
>> "name");
>> IObservableValue<Person> model = nameProperty.observe(myEditor);
>> uiWidget = WidgetProperties.text(SWT.Modify).observe(personEditorName);
>> ctx.bindValue(uiWidget, model);
>>
>> This works for "name". But if I want to bind "alternativeAddress.name"
>> nothing is stored. Do I have to write it in another way?
>>
>> TIA,
>> Ralf.
>
>
> Hi,
> I found the solution for myself :-)
> The problem was that the object for the nested property was created
> *after* the binding. This doesn't work. You *always* have to bind editor
> fields to an existing object (event if the fields are hidden).
>
> So long,
> Ralf.

That's not 100% true. You could have used a master-observable and change
your code to

class MyEditorPart {
ObservableValue<Person> master = new WritableValue();

// ...
IObservableValue<Person> model = nameProperty.observeDetail(master);
}

This has the advantage that you don't have to rebind if you change the
person eg because another one was selected. I find myself using this
master everytime even if I currently don't change the master because it
gives me much more flexibility.

Tom
Previous Topic:issue with tree node
Next Topic:[HiDPI icons] How to migrate from ImageDescriptor#createFromFile to #createFromURL?
Goto Forum:
  


Current Time: Mon Nov 19 04:51:56 GMT 2018

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

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

Back to the top