Vaadin adding child item to treetable

4k Views Asked by At

I tried to add a child element to treetable (element is a Bean) but the somehow the result is weird. I put a small example together.

     BeanItemContainer<Project> bic = new BeanItemContainer<Project>(Project.class);
 TreeTable projectTable = new TreeTable();
 projectTable.setContainerDataSource(bic);

 bic.addBean(Root);
 bic.addBean(p1);
 bic.addBean(p2);
 bic.addBean(p3);

 projectTable.setParent(p1, Root);
 projectTable.setParent(p2, Root);
 projectTable.setParent(p3, p1);

As you can see in the last line p1 should be parent of p3, and the result :see the pic. (p3 become the children of p2)

Code can be accessed from here : goo.gl/BMXiv

There are 2 main files:

TttestApplication.class

Project.class

Cs

1

There are 1 best solutions below

1
On

Unfortunatelly, I could not get over the issue above, so I load beans by 'addProjectToTree' and everything happens as usually using addItem.

 .... beans' initialization
 Root = new Project("Projects","Indoor","HI", new Date(), new  Date(),this.getNextId(),null);
 ... 
 ... columns' creation
 projectTable.addContainerProperty("description", String.class, "");
 ... 
 ...
 addProjectToTree(Root);    

public Object addProjectToTree(Project p)
{
  Object id = projectTable.addItem(new Object[] {p.getDescription(),p.getKeyword() ...);
    if(p.getParentId()!=null)
    {
        projectTable.setParent(id, p.getParentId());
    }
    return id;
}

That's it.

Cs