aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Wagner <wbadam@users.noreply.github.com>2017-05-02 17:25:36 +0300
committerPekka Hyvönen <pekka@vaadin.com>2017-05-02 17:25:36 +0300
commitd5c7d4b68a2befa3ec874eae8a456614d0333233 (patch)
tree07da146d62e5c8b29abb484d430f24d71a67fa37
parent1f070e124d628ea439a3369e99bbc07bdd917e8d (diff)
downloadvaadin-framework-d5c7d4b68a2befa3ec874eae8a456614d0333233.tar.gz
vaadin-framework-d5c7d4b68a2befa3ec874eae8a456614d0333233.zip
Add method for checking whether drag event was cancelled (#9214)
-rw-r--r--documentation/advanced/advanced-dragndrop.asciidoc10
-rw-r--r--server/src/main/java/com/vaadin/event/dnd/DragEndEvent.java11
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
@@ -70,6 +70,17 @@ public class DragEndEvent<T extends AbstractComponent> extends Component.Event {
}
/**
+ * 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.
*
* @return Component which was dragged.