Container for tree-like object structures

Hi all,

I have some trouble understandig the containers of vaadin. The analogy to a spreadsheet gets me crazy, because I need a tree-like structure not a table. I don’t really know how to implement a structure like the following:


ObjectTypeA() {
    String name;
    List ObjectTypeB;
}

ObjectTypeB() {
    String name;
    List ObjectTypeC;
}

ObjectTypeC() {
    String name;
    Map ConfigStrings;
}

In my app I have a list of ObjectTypeA and each ObjectTypeA will have a Tree within. Each ObjectType* must be unique. So if I add a new ObjectTypeA only the part is added, that is not already present in the tree/list.
At the moment I have TreeMaps of TreeMaps of standard Java but I would like to port it to vaadin code.

Any Ideas?

Thanks Kay

[Edit]
I found an example of filling an hierarchical container:
https://vaadin.com/de/forum/-/message_boards/view_message/961054#_19_message_961909

Am I right that the container stores all added items (of various types) in a flat hierarchie and I can wire the items via the setParent-Method?

Okay, I think now I understood the Idea behind the container. But I have another question related to the structure. When I’m right all objects are stored in “one big table”, but how should I find one concrete Item, when I dont have the Item-ID? So do I have to filter all items?

Hierarchical structures can be represented through the Container.Hierarchical interface. Vaadin comes with a couple of built-in hierarchical containers: HierarchicalContainer and FileSystemContainer.

Vaadin data model is based on interfaces, so it’s up to the implementation how it stores the data. Well, implementing a container is rather much work, so for simple cases, I’d suggest using the ready implementations. Implementing the Hierarchical interface is fairly easy. A typical case would be implementing it for BeanItemContainer. I don’t think there’s a ready add-on for that, but there’s
an example
, which should be readily copy-paste usable.

The point of the item ID is that it is what you use to find an item - you should choose suitable item IDs for that, perhaps using BeanContainer instead of BeanItemContainer so that you can explicitly define item IDs or have them generated from the beans instead of using the beans themselves as IDs.

As for Marko’s comment, note that there is also
ContainerHierarchicalWrapper
, which is used automatically when giving a non-hierarchical container to a TreeTable if I remember correctly. You should also be able to use it explicitly.

Thank you for your answers. But I think I need some more help. My problem is that I don’t really know how to find Items in an efficient way without using the ID. The reason is that I have to identify some items later on and append some new Items as children. Is there another way to find Items by their properties than to iterate over the whole container?
The only way to use the ID is to build them up from the names along the path of the tree but that doesn’t seem to be a good option.

Depends on the container, as searching is anyhow dependent on the data structure of the implementation. With some containers, iteration is the only option, be it built-in into the container or not. If it’s a JPAContainer or a database container, you could do a JPA or SQL query to find the item. The JPA entity ID acts as the item ID

One pattern is to maintain a separate index structure for searching, typically a HashMap from property values to the item IDs you need. Maintaining it is a bit extra effort though.