/*
* As we also accept only drops on folders, we know dropDetails
* is from Tree and it contains itemIdOver.
*/
AbstractSelectTargetDetails details = (AbstractSelectTargetDetails) event
.getTargetDetails();
Object idOver = details.getItemIdOver();
tree1.setParent(itemId, idOver);
}
@Override
public AcceptCriterion getAcceptCriterion() {
return and;
}
};
tree1.setDropHandler(dropHandler);
/*
* First step done. tree1 now accepts drags only from table and only
* over tree nodes aka "folders"
*/
/*
* Now set the rightmost tree accept any item drag. On drop, copy from
* source. Also make drags from tree1 possible.
*/
dropHandler = new DropHandler() {
@Override
public void drop(DragAndDropEvent event) {
AbstractSelectTargetDetails details = (AbstractSelectTargetDetails) event
.getTargetDetails();
Transferable transferable = event.getTransferable();
if (transferable instanceof DataBoundTransferable) {
DataBoundTransferable tr = (DataBoundTransferable) transferable;
Object itemId = tree2.addItem();
tree2.setParent(itemId, details.getItemIdOver());
if (tr.getSourceComponent() == tree1) {
// use item id from tree1 as caption
tree2.setItemCaption(itemId, (String) tr.getItemId());
// if comes from tree1, move subtree too
copySubTree(tr.getItemId(), itemId);