From d5c7d4b68a2befa3ec874eae8a456614d0333233 Mon Sep 17 00:00:00 2001 From: Adam Wagner Date: Tue, 2 May 2017 17:25:36 +0300 Subject: Add method for checking whether drag event was cancelled (#9214) --- documentation/advanced/advanced-dragndrop.asciidoc | 10 ++++++++-- server/src/main/java/com/vaadin/event/dnd/DragEndEvent.java | 11 +++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/documentation/advanced/advanced-dragndrop.asciidoc b/documentation/advanced/advanced-dragndrop.asciidoc index 732b020806..1b424ed167 100644 --- a/documentation/advanced/advanced-dragndrop.asciidoc +++ b/documentation/advanced/advanced-dragndrop.asciidoc @@ -45,11 +45,17 @@ The [classname]#DragStartEvent# is fired when the drag has started, and the [cla dragSource.addDragStartListener(event -> event.getComponent().addStyleName("dragged") ); -dragSource.addDragEndListener(event -> +dragSource.addDragEndListener(event -> { event.getComponent().removeStyleName("dragged") -); + + if (event.isCanceled()) { + Notification.show("Drag event was canceled"); + } +}); ---- +You can check whether the drag was canceled using the `isCanceled()` method. + It is possible to transfer any Object as server side data to the drop target if both the drag source and drop target are placed in the same UI. This data is available in the drop event via the `DropEvent.getDragData()` method. [source, java] diff --git a/server/src/main/java/com/vaadin/event/dnd/DragEndEvent.java b/server/src/main/java/com/vaadin/event/dnd/DragEndEvent.java index 7b304404de..5e0739d2d9 100644 --- a/server/src/main/java/com/vaadin/event/dnd/DragEndEvent.java +++ b/server/src/main/java/com/vaadin/event/dnd/DragEndEvent.java @@ -69,6 +69,17 @@ public class DragEndEvent extends Component.Event { return dropEffect; } + /** + * Returns whether the drag event was cancelled. This is a shorthand for + * {@code dropEffect == NONE}. + * + * @return {@code true} if the drop event was cancelled, {@code false} + * otherwise. + */ + public boolean isCanceled() { + return getDropEffect() == DropEffect.NONE; + } + /** * Returns the drag source component where the dragend event occurred. * -- cgit v1.2.3