table.addItem("Row 6");
table.addItem("Row 7");
h.addComponent(table);
final Tree tree = new Tree();
tree.setDropHandler(new DropHandler() {
@Override
public AcceptCriterion getAcceptCriterion() {
return TargetItemAllowsChildren.get();
}
@Override
public void drop(DragAndDropEvent dropEvent) {
// criteria verify that this is safe
DataBoundTransferable t = (DataBoundTransferable) dropEvent
.getTransferable();
Container sourceContainer = t.getSourceContainer();
Object sourceItemId = t.getItemId();
System.out.println(sourceItemId);
AbstractSelectTargetDetails dropData = ((AbstractSelectTargetDetails) dropEvent
.getTargetDetails());
Object targetItemId = dropData.getItemIdOver();
// move item from table to category'
tree.addItem(sourceItemId);
tree.setParent(sourceItemId, targetItemId);
tree.setChildrenAllowed(sourceItemId, false);
sourceContainer.removeItem(sourceItemId);
}
});
tree.addItem("Item 1");
tree.addItem("Item 11");
tree.setChildrenAllowed("Item 11", false);
tree.setParent("Item 11", "Item 1");
tree.addItem("Item 12");
tree.setChildrenAllowed("Item 12", false);
tree.setParent("Item 12", "Item 1");
tree.addItem("Item 13");
tree.setChildrenAllowed("Item 13", false);
tree.setParent("Item 13", "Item 1");
tree.addItem("Item 2");
tree.addItem("Item 21");
tree.setChildrenAllowed("Item 21", false);
tree.setParent("Item 21", "Item 2");
tree.addItem("Item 22");
tree.setChildrenAllowed("Item 22", false);
tree.setParent("Item 22", "Item 2");
tree.addItem("Item 23");
tree.setChildrenAllowed("Item 23", false);
tree.setParent("Item 23", "Item 2");
tree.addItem("Item 3");
tree.addItem("Item 31");
tree.setChildrenAllowed("Item 31", false);
tree.setParent("Item 31", "Item 3");
tree.addItem("Item 32");
tree.setChildrenAllowed("Item 32", false);
tree.setParent("Item 32", "Item 3");
tree.addItem("Item 33");
tree.setChildrenAllowed("Item 33", false);
tree.setParent("Item 33", "Item 3");
tree.expandItemsRecursively("Item 1");
tree.expandItemsRecursively("Item 2");
tree.expandItemsRecursively("Item 3");
h.addComponent(tree);
}