List of usage examples for com.vaadin.event.dd TargetDetails getData
public Object getData(String key);
From source file:com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.AbstractDefaultLayoutDropHandler.java
License:Apache License
/** * Handles a drop by a component which has an absolute layout as parent. In * this case the component is moved.//w ww .j a v a 2s . co m * * @param event * The drag and drop event */ protected void handleDropFromAbsoluteParentLayout(DragAndDropEvent event) { LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable(); TargetDetails details = event.getTargetDetails(); MouseEventDetails mouseDown = transferable.getMouseDownEvent(); MouseEventDetails mouseUp = MouseEventDetails .deSerialize((String) details.getData(Constants.DROP_DETAIL_MOUSE_EVENT)); int movex = mouseUp.getClientX() - mouseDown.getClientX(); int movey = mouseUp.getClientY() - mouseDown.getClientY(); Component comp = transferable.getComponent(); DDAbsoluteLayout parent = (DDAbsoluteLayout) comp.getParent(); ComponentPosition position = parent.getPosition(comp); if (position.getLeftValue() != null) { float x = position.getLeftValue() + movex; position.setLeft(x, Sizeable.UNITS_PIXELS); } if (position.getRightValue() != null) { float x = position.getRightValue() - movex; position.setRight(x, Sizeable.UNITS_PIXELS); } if (position.getTopValue() != null) { float y = position.getTopValue() + movey; position.setTop(y, Sizeable.UNITS_PIXELS); } if (position.getBottomValue() != null) { float y = position.getBottomValue() - movey; position.setBottom(y, Sizeable.UNITS_PIXELS); } }
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;// w w w .jav a 2 s . 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:org.peergreen.vaadin.diagram.DiagramDropHandler.java
License:Apache License
@Override public void drop(final DragAndDropEvent event) { TargetDetails targetDetails = event.getTargetDetails(); Transferable transferable = event.getTransferable(); MouseEventDetails mouseEventDetails = MouseEventDetails .deSerialize((String) targetDetails.getData("mouseEvent")); Integer absoluteLeft = (Integer) targetDetails.getData("absoluteLeft"); Integer absoluteTop = (Integer) targetDetails.getData("absoluteTop"); diagram.drop(mouseEventDetails.getClientX() - absoluteLeft, mouseEventDetails.getClientY() - absoluteTop, (String) transferable.getData("component-type")); }