What i would like to do, is create TreeViewer
using databinding for a POJO class, which has multiple list properties, and all of them needs to be observed, and displayed in the viewer.
I would like to display a tree like:
Person
\
|- Dog // dogs list
|- Dog
|- Cat // cats list
|- Cat
|- Cat
Example:
public class Cat {
// ...
}
public class Dog {
// ...
}
The class which has a list reference with both types:
public class Person {
private List<Dog> dogs = Lists.newArrayList();
private List<Cat> cats = Lists.newArrayList();
// getters and setters which fire property change listeners.
}
And then i create the TreeViewer, and set the content provider:
treeViewer = new TreeViewer(parent);
IObservableFactory observableFactory = new IObservableFactory() {
public IObservable createObservable(final Object target) {
// target is a Person. What should I return here?
// If I return for example the observed dogs, cats wont be bound:
return BeanProperties.list("dogs").observe(target);
}
};
IContentProvider provider = new ObservableListTreeContentProvider(observableFactory, null);
treeViewer.setContentProvider(provider);
But because the factory can only return one IObservable, I can't observe both cats
and dogs
. How could i do that?