List of usage examples for com.vaadin.event Transferable getSourceComponent
public Component getSourceComponent();
From source file:org.lucidj.browser.AbstractCell.java
License:Apache License
@Override // DropHandler public void drop(DragAndDropEvent dragAndDropEvent) { log.info("**** DROP! {}", dragAndDropEvent); final Transferable transferable = dragAndDropEvent.getTransferable(); final Component sourceComponent = transferable.getSourceComponent(); log.info("sourceComponent = {}", sourceComponent); final TargetDetails dropTargetData = dragAndDropEvent.getTargetDetails(); final DropTarget target = dropTargetData.getTarget(); log.info("DROP: source={} target={}", sourceComponent, target); String pos = (String) dropTargetData.getData("verticalLocation"); String canonical_name = sourceComponent.getId(); Object source_cell = ((DragAndDropWrapper) sourceComponent).getData(); Object source_object = (source_cell instanceof AbstractCell) ? ((AbstractCell) source_cell).getSourceObject() : null;//from w w w .j a va 2s . c o m Object target_cell = ((DragAndDropWrapper) target).getData(); Object target_object = (target_cell instanceof AbstractCell) ? ((AbstractCell) target_cell).getSourceObject() : null; log.info("D&D: source=[{}, {}] => target=[{}, {}]", source_cell, source_object, target_cell, target_object); if (target_object == null) { insertNewObjectBefore(canonical_name, null); } else if (pos.equals(VerticalDropLocation.BOTTOM.toString())) { if (source_cell instanceof AbstractCell) { if (source_object != target_object) { log.info("Move AFTER component #{}: {} {}", target_object, source_cell, canonical_name); moveObjectAfter(source_object, target_object); } } else { log.info("Drop AFTER component #{}: {} {}", target_object, source_cell, canonical_name); insertNewObjectAfter(canonical_name, target_object); } } else if (pos.equals(VerticalDropLocation.TOP.toString())) { if (source_cell instanceof AbstractCell) { if (source_object != target_object) { log.info("Move BEFORE component #{}: {} {}", target_object, source_cell, canonical_name); moveObjectBefore(source_object, target_object); } } else { log.info("Drop BEFORE component #{}: {} {}", target_object, source_cell, canonical_name); insertNewObjectBefore(canonical_name, target_object); } } }
From source file:pl.exsio.frameset.vaadin.module.management.frames.FramesTree.java
License:Open Source License
private void setTreeDropHandler(final JPAContainer<Frame> frames) { this.tree.setDropHandler(new DropHandler() { @Override//from w w w . j a v a2 s . com public AcceptCriterion getAcceptCriterion() { return AcceptAll.get(); } @Override public void drop(DragAndDropEvent event) { Transferable t = event.getTransferable(); if (t.getSourceComponent() != tree) { return; } TreeTargetDetails target = (TreeTargetDetails) event.getTargetDetails(); Object sourceItemId = t.getData("itemId"); Object targetItemId = target.getItemIdOver(); Frame sourceFrame = frames.getItem(sourceItemId).getEntity(); Frame targetFrame = frames.getItem(targetItemId).getEntity(); VerticalDropLocation location = target.getDropLocation(); FrameDao<Frame> frameDao = coreRepositories.getFrameRepository(); try { // Drop right on an item -> make it a child if (location == VerticalDropLocation.MIDDLE) { frameDao.insertAsLastChildOf(sourceFrame, targetFrame); } // Drop at the top of a subtree -> make it previous else if (location == VerticalDropLocation.TOP && !targetFrame.isRoot()) { frameDao.insertAsPrevSiblingOf(sourceFrame, targetFrame); } // Drop below another item -> make it next else if (location == VerticalDropLocation.BOTTOM && !targetFrame.isRoot()) { frameDao.insertAsNextSiblingOf(sourceFrame, targetFrame); } frames.refresh(); } catch (InvalidNodesHierarchyException ex) { Notification.show(t("core.management.frames.tree.wrong_operation"), Notification.Type.ERROR_MESSAGE); } } }); }