[DataBinding] Problem with 2 different class model in a TreeViewer [message #332707] |
Thu, 06 November 2008 11:27  |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.03481 seconds