No hierarchy in TreeTable?

I recently got some help on how to populate my treetable given a List of beans. Here are the two relevant methods for populating the treetable:

private HorizontalLayout createNode (String name, boolean isChecked) {
    HorizontalLayout layout = new HorizontalLayout();
    layout.addComponent(new CheckBox(null, isChecked));
    layout.addComponent(new Label(name));
    return layout;

private void populateTreeTable (final TreeTable treeTable) {
    // Get a list of jobs on a particular date.
    LocalDate tempDate = new LocalDate(2016, 03, 01); // Remove this after we have the program get the current date.
    List<Job> jobsList = null;
    try {
        jobsList = JobManager.getJobsByDate(tempDate);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
    if (jobsList != null) {
        for (Job j : jobsList) {
            // Go through each item in the Jobs list and add it
            // (along with all of its OrderDetail items) to the TreeTable.
//                boolean firstOrderCompleted = j.getOrderDetailList().get(0).getItemCompleted() != null; // The first OrderDetail's completion status.
            final Object jobId = treeTable.addItem(new Object[] {createNode(j.getCustomerName(), j.getJobCompleted() != null), j.getJobId(),
                    "", null, null, null}, null);
            for (OrderDetail od : j.getOrderDetailList()) {
                final Object odId = treeTable.addItem(new Object[] {createNode(od.getProductId(), od.getItemCompleted() != null), od.getProductDetail(),
                        od.getPrintType().getValue(), od.getNumColors(), od.getQuantity(), (od.getNumColors() * od.getQuantity())}, null);
                treeTable.setParent(odId, jobId);
                treeTable.setChildrenAllowed(odId, false);
                treeTable.setCollapsed(odId, false);
            treeTable.setCollapsed(jobId, false);

Line 32 clearly shows that I am setting an OrderDetail item to be the child of the Job item. Yet I do not get any hierarchy in the TreeTable. They are all still just children of null, presumably:

What am I missing?

I might be totally wrong since I haven’t tested this, but on line 28 you are inserting null as the itemId (last param). If you input something unique there, does it work?

According to Table’s javadoc, if I leave the last parameter as null, then a new id is automatically assigned to the row (and returned):


public java.lang.Object addItem(java.lang.Object cells,
                                java.lang.Object itemId)
                         throws java.lang.UnsupportedOperationException

Adds the new row to table and fill the visible cells (except generated columns) with given values.

    cells - the Object array that is used for filling the visible cells new row. The types must be settable to visible column property types.
    itemId - the Id the new row. If null, a new id is automatically assigned. If given, the table cannot already have a item with given id.

    Returns item id for the new row. Returns null if operation fails.


Then I was totally wrong :slight_smile:

One interesting bit that may help someone to solve my dilemma: It seems the setParent() method is working, but there is still some issue with the heirarchy working. For example, when I comment-out lines 34 and 36 in my original post (un-setting the TreeTable’s branches as un-collapsed, thus making them collapsed), the OrderDetail items disappear. It’s as though they were parented to their respective Jobs (which they should be), and then those Jobs’ branches were collapsed:

However, as you can see, the arrows are not visible for expanding those branches (Jobs). So it seems that the TreeTable just doesn’t understand that it’s supposed to be hierarchical. Any thoughts?

At one time, I had tried to create a tri-state CheckBox, which required me to create a custom widgetset. Somewhere along the way, I’m sure I somehow broke the indention and triangle image references. Frustration with not being able to figure out where the problem lies led me to just create the entire project again.

I created a new project (this time without creating a custom widgetset for now) and mostly just copy-pasted the code from the original project. Voilà, the treetable looks as it is supposed to. So this barrier has been removed for now; I can focus on the next one (out of several dozen). I’ll likely post something about it tomorrow.