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
e.printStackTrace();
}
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?