Container and Tree

Hello. I am super new to Vaadin. However, I found it impressive and I want to use it for my application.
I found a lot of documentation but really lack of good-practise advices.
My goal: I would like to build tree. The maximum tree “depth” is 3-4. I would like to update my data on change, set icons for items (implemented in tree, nice), filter data, and, query data for each node on click. So, tree should not load entire data on start, but load just “top” level nodes, then, load node childs on click.

My tree will look like:

  • ​type
    [list]
  • type_1
  • type_2



  • [/list]
  • subtype
    [list]
  • type_1
    [list]
  • subtype_1
  • subtype_2


  • [/list]
  • type_2
    [list]
  • subtype_3
  • subtype_4


  • [/list]

    [/list]
  • other data

I have a lot of questions:

  1. I read, it’s a good practise to use container as datasource. Should I use hierarchical container?
  2. Should all this nodes be in one container, tree, or it should be a composition of trees, containers?
  3. Proper way to get items which we added dynamically. Like get “type” in “subtype” to add childs to it.
  4. expand without if, now my code looks like:
Tree.ExpandListener expandListener = (Tree.ExpandListener) expandEvent -> {
if (expandEvent.getItemId().equals(TOTypes){
//do smg
}
//and then, as deeper I go, I should add loops to get the item which was invoked.
}
}

What I want is to perform special query, based on which type of tree was invoked and it’s id. Looks like tree for each type is good decision.

I appreciate your help a lot!