From b32d7b0e45ddc9d7b720bc603ce5374404381a81 Mon Sep 17 00:00:00 2001 From: Adam Wagner Date: Fri, 24 Mar 2017 10:32:48 +0200 Subject: Add API support for setting server side drag data (#8915) * Add API support for setting server side drag data * Fix javadocs * Add server side drag data API to ASCII doc * Fix some javadocs and documentation details --- .../com/vaadin/event/dnd/DragSourceExtension.java | 29 ++++++++++++++++++++++ .../main/java/com/vaadin/event/dnd/DropEvent.java | 13 ++++++++++ 2 files changed, 42 insertions(+) (limited to 'server') diff --git a/server/src/main/java/com/vaadin/event/dnd/DragSourceExtension.java b/server/src/main/java/com/vaadin/event/dnd/DragSourceExtension.java index f7089c9b9e..6a6a8a8c64 100644 --- a/server/src/main/java/com/vaadin/event/dnd/DragSourceExtension.java +++ b/server/src/main/java/com/vaadin/event/dnd/DragSourceExtension.java @@ -39,6 +39,12 @@ public class DragSourceExtension extends private Registration dragStartListenerHandle; private Registration dragEndListenerHandle; + /** + * Stores the server side drag data that is available for the drop target if + * it is in the same UI. + */ + private Object dragData; + /** * Extends {@code target} component and makes it a drag source. * @@ -145,6 +151,29 @@ public class DragSourceExtension extends getState().dataTransferText = null; } + /** + * Set server side drag data. This data is available in the drop event and + * can be used to transfer data between drag source and drop target if they + * are in the same UI. + * + * @param data + * Data to transfer to drop event. + */ + public void setDragData(Object data) { + dragData = data; + } + + /** + * Get server side drag data. This data is available in the drop event and + * can be used to transfer data between drag source and drop target if they + * are in the same UI. + * + * @return Server side drag data if set, otherwise {@literal null}. + */ + public Object getDragData() { + return dragData; + } + /** * Attaches dragstart listener for the current drag source. {@link * DragStartListener#dragStart(DragStartEvent)} is called when dragstart diff --git a/server/src/main/java/com/vaadin/event/dnd/DropEvent.java b/server/src/main/java/com/vaadin/event/dnd/DropEvent.java index 3fb655f176..c2b4943d0f 100644 --- a/server/src/main/java/com/vaadin/event/dnd/DropEvent.java +++ b/server/src/main/java/com/vaadin/event/dnd/DropEvent.java @@ -105,6 +105,19 @@ public class DropEvent extends Component.Event { return Optional.ofNullable(dragSourceExtension); } + /** + * Gets the server side drag data. This data can be set during the drag + * start event on the server side and can be used to transfer data between + * drag source and drop target when they are in the same UI. + * + * @return Optional server side drag data if set and the drag source and the + * drop target are in the same UI, otherwise empty {@code Optional}. + * @see DragSourceExtension#setDragData(Object) + */ + public Optional getDragData() { + return getDragSourceExtension().map(DragSourceExtension::getDragData); + } + /** * Returns the drop target component where the drop event occurred. * -- cgit v1.2.3