TreeTable with HierarchicalContainer - does not work??

Hi guys,

I tried to set up a TreeTable with a HierarchicalContainer, but I will not work!
The Items I add will be displayed, but not within a hierarchy but on root level…

The code looks correct for me, many eyes see more than two … :wink:

Hope someone can give me a hint!


package com.example.test_treetable;

import com.vaadin.Application;
import com.vaadin.data.Item;
import com.vaadin.data.util.HierarchicalContainer;
import com.vaadin.ui.TreeTable;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;

@SuppressWarnings("serial")
public class Test_treetableApplication extends Application {
	@Override
	public void init() {
		Window mainWindow = new Window("Test_treetable Application");
		VerticalLayout vl = new VerticalLayout();
		mainWindow.setContent(vl);
		setMainWindow(mainWindow);
		
		TreeTable tt = new TreeTable();
		tt.setHeight("200px");
		tt.setWidth("400px");
		
		HierarchicalContainer hc = new HierarchicalContainer();
		hc.addContainerProperty("CAPTION", String.class, "--");
		tt.setContainerDataSource(hc);
		
		Item a = hc.addItem("a");
		a.getItemProperty("CAPTION").setValue("a");
		Item b = hc.addItem("b");
		b.getItemProperty("CAPTION").setValue("b");
		Item c = hc.addItem("c");
		c.getItemProperty("CAPTION").setValue("c");
		
		hc.setChildrenAllowed(a, true);
		hc.setChildrenAllowed(b, true);
		hc.setChildrenAllowed(c, false);
		
		hc.setParent(b, a);
		hc.setParent(c, b);
		
		vl.addComponent(tt);
	}
}

I have tested with 6.7.3 and also latest 6.7.4 nightly build …

Hello

I have the same problem! I actually commented my own code and pasted source directly from TreeTableTestApplication.java and from WorkLogApp.java (from add-on demo), and the hierarchy is flattened in EVERY example!

I am out of ideas on what else to try, I am very new to vaadin and I am still learning how to use widgets…

Thanks in advance!

Hi Martin,

You just did a little mistake.

When you do this :

Item a = hc.addItem("a");

You add an item to the container and specify that the new item identifier is “a” (not the variable
Item a
).

So, if you want to create the hierarchy , you simply change your call to the setParent method .

hc.setParent("b", "a");
hc.setParent("c", "b");

Hope it’s help.

Éric

Hi

Thank you for the hints! Having to dig deeper into this widget source was very educational for me,

We actually figured out what was wrong with great help from css developers on my team. The css styles v-treetable-treespacer, v-treetable-node-closed etc used by TreeTable were missing from my project, as well as the expand/collapse icon images! Once these were restored, all the controls and the hierarchy are working!

Yeah, same here, had to comment out this line:

$v-included-components: remove($v-included-components, treetable)