Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Binding the attribute of a bean object wrapped in a WritableValue object
Binding the attribute of a bean object wrapped in a WritableValue object [message #328347] Thu, 22 May 2008 14:58 Go to next message
Hao Missing name is currently offline Hao Missing nameFriend
Messages: 115
Registered: July 2009
Senior Member
I have a java bean such as Contact which has attributes such as name,
address, email. The object presented to my code is a Wrapped WritableValue
object, i.e. IObservableValue.
For instance,
IObservableValue contactObservable = new WritableValue(new Contact(),
Contact.class);

I tried to bind the name attributed of Contact bean wrapped in
contactObservable to a text field. I did the following:

IObservableValue bindedNameTextObserveWidget =
SWTObservables.observeText(text);
IObservableValue selectedContactNameObserveDetailValue =
BeansObservables.observeDetailValue(Realm.getDefault(), contactObservable,
"name", java.lang.String.class);

bindingContext.bindValue(bindedNameTextObserveWidget, contactObservable,
null, null);

I did not get any error but this kind of binding does not work.

Any one knows how to bind the attribute of a writableValue object to a gui
field instead of binding the attribute of a java bean to a gui field.
[DataBinding] Re: Binding the attribute of a bean object wrapped in a WritableValue object [message #328348 is a reply to message #328347] Thu, 22 May 2008 16:22 Go to previous messageGo to next message
Matthew Hall is currently offline Matthew HallFriend
Messages: 368
Registered: July 2009
Senior Member
Hao wrote:
> IObservableValue bindedNameTextObserveWidget =
> SWTObservables.observeText(text);
> IObservableValue selectedContactNameObserveDetailValue =
> BeansObservables.observeDetailValue(Realm.getDefault(),
> contactObservable, "name", java.lang.String.class);
>
> bindingContext.bindValue(bindedNameTextObserveWidget,
> contactObservable, null, null);

It looks like you're binding to the wrong observable. You have:

bindingContext.bindValue(bindingNameTextObserveWidget,
contactObservable, // <-- wrong observable
null,
null);

But I think it should be:

bindingContext.bindValue(bindingNameTextObserveWidget,
selectedContactNameObserveDetailValue,
null,
null);

Matthew
Re: [DataBinding] Re: Binding the attribute of a bean object wrapped in a WritableValue object [message #328352 is a reply to message #328348] Thu, 22 May 2008 20:02 Go to previous messageGo to next message
Hao Missing name is currently offline Hao Missing nameFriend
Messages: 115
Registered: July 2009
Senior Member
You are right. It is a typo. But it still does not work.
Re: Binding the attribute of a bean object wrapped in a WritableValue object [message #328367 is a reply to message #328347] Fri, 23 May 2008 11:37 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: malloovidio.bluewin.ch

Hi Hao,

are you binding the "name" attribute to an SWT Text instance (and not
a Label or so)? If so, SWTObservables#observeText(Control) is the wrong
method as it does not apply to Text instances. Instead, you should use
the method SWTObservables#observeText(Control, int). In the methods'
JavaDoc you can see which controls are supported by the individual
methods.

However, using the wrong method above should result in an exception being
thrown so maybe this is not your problem...

Regards,
Ovidio

Hao wrote:
> I have a java bean such as Contact which has attributes such as name,
> address, email. The object presented to my code is a Wrapped
> WritableValue object, i.e. IObservableValue. For instance,
> IObservableValue contactObservable = new WritableValue(new Contact(),
> Contact.class);
>
> I tried to bind the name attributed of Contact bean wrapped in
> contactObservable to a text field. I did the following:
>
> IObservableValue bindedNameTextObserveWidget =
> SWTObservables.observeText(text);
> IObservableValue selectedContactNameObserveDetailValue =
> BeansObservables.observeDetailValue(Realm.getDefault(),
> contactObservable, "name", java.lang.String.class);
>
> bindingContext.bindValue(bindedNameTextObserveWidget,
> contactObservable, null, null);
>
> I did not get any error but this kind of binding does not work.
>
> Any one knows how to bind the attribute of a writableValue object to a
> gui field instead of binding the attribute of a java bean to a gui field.
>
>
>
Re: Binding the attribute of a bean object wrapped in a WritableValue object [message #328393 is a reply to message #328367] Fri, 23 May 2008 19:04 Go to previous message
Matthew Hall is currently offline Matthew HallFriend
Messages: 368
Registered: July 2009
Senior Member
That could be the problem. Try this:

IObservableValue bindedNameTextObserveWidget =
SWTObservables.observeText(text, SWT.Modify);

Matthew

Ovidio Mallo wrote:
> Hi Hao,
>
> are you binding the "name" attribute to an SWT Text instance (and not
> a Label or so)? If so, SWTObservables#observeText(Control) is the wrong
> method as it does not apply to Text instances. Instead, you should use
> the method SWTObservables#observeText(Control, int). In the methods'
> JavaDoc you can see which controls are supported by the individual
> methods.
>
> However, using the wrong method above should result in an exception being
> thrown so maybe this is not your problem...
>
> Regards,
> Ovidio
>
> Hao wrote:
>> I have a java bean such as Contact which has attributes such as name,
>> address, email. The object presented to my code is a Wrapped
>> WritableValue object, i.e. IObservableValue. For instance,
>> IObservableValue contactObservable = new WritableValue(new Contact(),
>> Contact.class);
>>
>> I tried to bind the name attributed of Contact bean wrapped in
>> contactObservable to a text field. I did the following:
>>
>> IObservableValue bindedNameTextObserveWidget =
>> SWTObservables.observeText(text);
>> IObservableValue selectedContactNameObserveDetailValue =
>> BeansObservables.observeDetailValue(Realm.getDefault(),
>> contactObservable, "name", java.lang.String.class);
>>
>> bindingContext.bindValue(bindedNameTextObserveWidget,
>> contactObservable, null, null);
>>
>> I did not get any error but this kind of binding does not work.
>>
>> Any one knows how to bind the attribute of a writableValue object to a
>> gui field instead of binding the attribute of a java bean to a gui field.
>>
>>
>>
Previous Topic:Cannot add problem marker to project in custom classpath container code
Next Topic:classes appearing twice in my plugin
Goto Forum:
  


Current Time: Sun Oct 20 13:10:29 GMT 2024

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

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

Back to the top