diff options
author | Adam Wagner <wbadam@users.noreply.github.com> | 2017-03-24 10:32:48 +0200 |
---|---|---|
committer | Pekka Hyvönen <pekka@vaadin.com> | 2017-03-24 10:32:48 +0200 |
commit | b32d7b0e45ddc9d7b720bc603ce5374404381a81 (patch) | |
tree | e139cd9301ecec46ce06d063109abefc70f36801 /server | |
parent | 6f1f83d4b95a45db03c5a74ad09b22541fb06e64 (diff) | |
download | vaadin-framework-b32d7b0e45ddc9d7b720bc603ce5374404381a81.tar.gz vaadin-framework-b32d7b0e45ddc9d7b720bc603ce5374404381a81.zip |
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
Diffstat (limited to 'server')
-rw-r--r-- | server/src/main/java/com/vaadin/event/dnd/DragSourceExtension.java | 29 | ||||
-rw-r--r-- | server/src/main/java/com/vaadin/event/dnd/DropEvent.java | 13 |
2 files changed, 42 insertions, 0 deletions
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 @@ -40,6 +40,12 @@ public class DragSourceExtension<T extends AbstractComponent> extends 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. * * @param target @@ -146,6 +152,29 @@ public class DragSourceExtension<T extends AbstractComponent> extends } /** + * 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 * event happens on the client side. 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 @@ -106,6 +106,19 @@ public class DropEvent<T extends AbstractComponent> extends Component.Event { } /** + * 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<Object> getDragData() { + return getDragSourceExtension().map(DragSourceExtension::getDragData); + } + + /** * Returns the drop target component where the drop event occurred. * * @return Component on which a drag source was dropped. |