Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » [DataBinding] Problem with 2 different class model in a TreeViewer
[DataBinding] Problem with 2 different class model in a TreeViewer [message #332707] Thu, 06 November 2008 11:27 Go to next message
Eclipse UserFriend
Originally posted by: filippo.c.evinco.it

Hi

I've a TreeViewer where the root nodes are of class Person and all leaf
are of class Email:

-person1
---email1
---email2
---email3
-person2
---email1
---email2
.....

where:
Person have 3 properties : String name String surname ArrayList<Email> email
and Email have 1 property : String address

I have a composite with 3 Text : nameText surnameText addressText
When i select a person in the Tree i want bind name and surname on
nameText and surnameText and when i select email bind address on
addressText.
This is my code:

IObservableValue selection = ViewersObservables.observeSingleSelection(treeview);
selection.addChangeListener(new IChangeListener(){

public void handleChange(ChangeEvent event) {
IViewerObservableValue observable = (IViewerObservableValue)event.getSource();
Object obj = observable.getValue();
if(obj instanceof Person){
bindingContext.removeBinding(address);
bindingContext.addBinding(name);
bindingContext.addBinding(surname);
bindingContext.dispose();
}else if(obj instanceof Email){
bindingContext.removeBinding(name);
bindingContext.removeBinding(surname);
bindingContext.addBinding(address);
bindingContext.dispose();
}
}

});
//v is the view where are the Text and getters method return Texts
name = bindingContext.bindValue(SWTObservables.observeText(v.getNam eText(),SWT.Modify),
BeansObservables.observeDetailValue(Realm.getDefault(), selection, "name",String.class)
,null,null);
surname = bindingContext.bindValue(SWTObservables.observeText(v.getSur nameText(),SWT.Modify),
BeansObservables.observeDetailValue(Realm.getDefault(), selection, "surname",String.class),
null,null);
address = bindingContext.bindValue(SWTObservables.observeText(v.getAdd ressText(),SWT.Modify),
BeansObservables.observeDetailValue(Realm.getDefault(), selection, "address",String.class),
null,null);

When i select a person i have this error: "Could not find property with name address in class class databindingprova.model.Person".
Re: [DataBinding] Problem with 2 different class model in a TreeViewer [message #332708 is a reply to message #332707] Thu, 06 November 2008 12:20 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
This is a know "problem" or just works by as designed currently. You
can't mix class types.

The bugzilla you are interested in is:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=247997

Tom

filippo schrieb:
> Hi
>
> I've a TreeViewer where the root nodes are of class Person and all leaf
> are of class Email:
>
> -person1
> ---email1
> ---email2
> ---email3
> -person2
> ---email1
> ---email2
> ....
>
> where:
> Person have 3 properties : String name String surname ArrayList<Email>
> email
> and Email have 1 property : String address
>
> I have a composite with 3 Text : nameText surnameText addressText
> When i select a person in the Tree i want bind name and surname on
> nameText and surnameText and when i select email bind address on
> addressText.
> This is my code:
>
> IObservableValue selection =
> ViewersObservables.observeSingleSelection(treeview);
> selection.addChangeListener(new IChangeListener(){
>
> public void handleChange(ChangeEvent event) {
> IViewerObservableValue observable =
> (IViewerObservableValue)event.getSource();
> Object obj = observable.getValue();
> if(obj instanceof Person){
> bindingContext.removeBinding(address);
> bindingContext.addBinding(name);
> bindingContext.addBinding(surname);
> bindingContext.dispose();
> }else if(obj instanceof Email){
> bindingContext.removeBinding(name);
> bindingContext.removeBinding(surname);
> bindingContext.addBinding(address);
> bindingContext.dispose();
> }
> }
>
> });
> //v is the view where are the Text and getters method return Texts
> name =
> bindingContext.bindValue(SWTObservables.observeText(v.getNam eText(),SWT.Modify),
>
> BeansObservables.observeDetailValue(Realm.getDefault(),
> selection, "name",String.class)
> ,null,null);
> surname =
> bindingContext.bindValue(SWTObservables.observeText(v.getSur nameText(),SWT.Modify),
>
> BeansObservables.observeDetailValue(Realm.getDefault(),
> selection, "surname",String.class),
> null,null);
> address =
> bindingContext.bindValue(SWTObservables.observeText(v.getAdd ressText(),SWT.Modify),
>
> BeansObservables.observeDetailValue(Realm.getDefault(),
> selection, "address",String.class),
> null,null);
>
> When i select a person i have this error: "Could not find property with
> name address in class class databindingprova.model.Person".
>
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: [DataBinding] Problem with 2 different class model in a TreeViewer [message #332740 is a reply to message #332707] Fri, 07 November 2008 07:50 Go to previous messageGo to next message
Sebastian Paul is currently offline Sebastian PaulFriend
Messages: 106
Registered: July 2009
Senior Member
Hi
see question below.

> public void handleChange(ChangeEvent event) {
> IViewerObservableValue observable =
> (IViewerObservableValue)event.getSource();
> Object obj = observable.getValue();
> if(obj instanceof Person){
> bindingContext.removeBinding(address);
> bindingContext.addBinding(name);
> bindingContext.addBinding(surname);
> bindingContext.dispose();
> }else if(obj instanceof Email){
> bindingContext.removeBinding(name);
> bindingContext.removeBinding(surname);
> bindingContext.addBinding(address);
> bindingContext.dispose();
> }
> }

Why do you dispose the context after adding or removing bindings?

Regards, Sebastian
Re: [DataBinding] Problem with 2 different class model in a TreeViewer [message #332742 is a reply to message #332740] Fri, 07 November 2008 08:37 Go to previous message
Eclipse UserFriend
Originally posted by: filippo.c.evinco.it

Cause adding and removing bindings seems have not effect in DataBindingContext. In effect dispose is not a solution.

Sebastian Paul ha scritto:
> Hi
> see question below.
>
>> public void handleChange(ChangeEvent event) {
>> IViewerObservableValue observable =
>> (IViewerObservableValue)event.getSource();
>> Object obj = observable.getValue();
>> if(obj instanceof Person){
>> bindingContext.removeBinding(address);
>> bindingContext.addBinding(name);
>> bindingContext.addBinding(surname);
>> bindingContext.dispose();
>> }else if(obj instanceof Email){
>> bindingContext.removeBinding(name);
>> bindingContext.removeBinding(surname);
>> bindingContext.addBinding(address);
>> bindingContext.dispose();
>> }
>> }
>
> Why do you dispose the context after adding or removing bindings?
>
> Regards, Sebastian
Previous Topic:needs help to setup our org.eclipse.ui.navigator.navigatorContent
Next Topic:Extension point problem
Goto Forum:
  


Current Time: Mon Aug 26 02:56:52 GMT 2024

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

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

Back to the top