container.addContainerProperty("value", String.class, "");
final TreeTable tt = new TreeTable(null, container);
tt.setSizeFull();
int parentId = counter++;
Item parent = container.addItem(parentId);
tt.setCollapsed(parentId, false);
parent.getItemProperty("value").setValue("parent " + (counter++) + "");
addComponent(tt);
Button repopulate = new Button("Repopulate", new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
// repopulate the container and expand root item
container.removeAllItems();
int parentId = counter++;
Item parent = container.addItem(parentId);
tt.setCollapsed(parentId, false);
parent.getItemProperty("value").setValue(
"parent " + (counter++) + "");
for (int i = 0; i < 4; i++) {
int childId = counter++;
Item child = container.addItem(childId);
child.getItemProperty("value").setValue(childId + "");
container.setParent(childId, parentId);
}
}
});
addComponent(repopulate);