Tree with multiple item classes

Hi,

I am facing issues trying to create my
tree
.
The problem is that each
item
of my tree is an
instance of a specific class
.

For example the root node is a
Test
object, its
children
are
TestPart
objects, etc …

I know that usually, you have to make your container
extend BeanItemContainer<>
but in my case it is not suitable.

Could somebody help ?

I finally got trough it, but in a way that I don’t really like.
Anyway, for those who are stuck, this is how I did the trick :

  • Create a Form object for each of your item Classes in your tree.
  • Add manually textfields for those forms
  • Add listener for your “save” button
  • Do your data saving in that listener

Indeed, the setItemDataSource is not working in that case, because our nav Tree contains items with different classes.
This solution is still a crutch, and I am looking forward to know better solution(s).

Hi,

I am actually looking solution for a similar problem. Basically I would like to have a general purpose hierarchical bean container that could host beans of any type. I would love to be able to do the following (obvious stuff omitted):


public class Foo {
  private List<Bar> bars;
}

Foo foo = new Foo();
Bar b = new Bar();
f.getBars().add(b);

FooContainer container = new FooContainer();
container.addObject(b);

tree.setContainerDataSource(container);

… and then just do my model updates to foo object.

Is there such container available already?

As the Tree keeps its state across requests (for the already opened and visible nodes at least), it must be notified of any changes to the underlying data. Otherwise, no updates are seen by the user.

If performing the modifications through the Container or the Item, they can handle the notifications. Otherwise, one of them has to be notified after making modifications to the underlying bean so that they can in turn notify any UI components and other listeners.

See also
this recent thread
about almost the same issue with a Table.

As for the obvious stuff, if notifications are handled correctly, the container still needs to know which fields to recurse into - or use a heuristic such as anything that implements Collection.