aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Wagner <wbadam@users.noreply.github.com>2017-06-07 14:50:38 +0300
committerTeemu Suo-Anttila <tsuoanttila@users.noreply.github.com>2017-06-07 14:50:38 +0300
commit8ff23ad10859132e5015f6372e623ed7ce8e05cc (patch)
tree92874f7b52ede7ac54526d8f3c40e5d4da825e69
parent3b3c647e5b732a7e9e6109193a11e665270ffe2f (diff)
downloadvaadin-framework-8ff23ad10859132e5015f6372e623ed7ce8e05cc.tar.gz
vaadin-framework-8ff23ad10859132e5015f6372e623ed7ce8e05cc.zip
Add mouse event details to the drop event (#9485)
Fixes #9483
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/grid/GridDropTargetConnector.java7
-rw-r--r--client/src/main/java/com/vaadin/client/extensions/DropTargetExtensionConnector.java10
-rw-r--r--server/src/main/java/com/vaadin/ui/components/grid/GridDropEvent.java9
-rw-r--r--server/src/main/java/com/vaadin/ui/components/grid/GridDropTarget.java5
-rw-r--r--server/src/main/java/com/vaadin/ui/dnd/DropTargetExtension.java19
-rw-r--r--server/src/main/java/com/vaadin/ui/dnd/event/DropEvent.java19
-rw-r--r--shared/src/main/java/com/vaadin/shared/ui/dnd/DropTargetRpc.java6
-rw-r--r--shared/src/main/java/com/vaadin/shared/ui/grid/GridDropTargetRpc.java6
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/grid/GridDragAndDrop.java4
-rw-r--r--uitest/src/main/java/com/vaadin/tests/dnd/DragAndDropCardShuffle.java3
10 files changed, 71 insertions, 17 deletions
diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/GridDropTargetConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/GridDropTargetConnector.java
index 33729afe77..5b409e3174 100644
--- a/client/src/main/java/com/vaadin/client/connectors/grid/GridDropTargetConnector.java
+++ b/client/src/main/java/com/vaadin/client/connectors/grid/GridDropTargetConnector.java
@@ -23,12 +23,14 @@ import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.dom.client.TableRowElement;
import com.google.gwt.user.client.Window;
+import com.vaadin.client.MouseEventDetailsBuilder;
import com.vaadin.client.ServerConnector;
import com.vaadin.client.WidgetUtil;
import com.vaadin.client.extensions.DropTargetExtensionConnector;
import com.vaadin.client.widget.escalator.RowContainer;
import com.vaadin.client.widget.escalator.RowContainer.BodyRowContainer;
import com.vaadin.client.widgets.Escalator;
+import com.vaadin.shared.MouseEventDetails;
import com.vaadin.shared.ui.Connect;
import com.vaadin.shared.ui.grid.DropLocation;
import com.vaadin.shared.ui.grid.DropMode;
@@ -115,8 +117,11 @@ public class GridDropTargetConnector extends DropTargetExtensionConnector {
dropLocation = DropLocation.EMPTY;
}
+ MouseEventDetails mouseEventDetails = MouseEventDetailsBuilder
+ .buildMouseEventDetails(dropEvent, targetElement);
+
getRpcProxy(GridDropTargetRpc.class).drop(types, data, dropEffect,
- rowKey, dropLocation);
+ rowKey, dropLocation, mouseEventDetails);
}
private JsonObject getRowData(TableRowElement row) {
diff --git a/client/src/main/java/com/vaadin/client/extensions/DropTargetExtensionConnector.java b/client/src/main/java/com/vaadin/client/extensions/DropTargetExtensionConnector.java
index cd7cc7026b..7e64b0d305 100644
--- a/client/src/main/java/com/vaadin/client/extensions/DropTargetExtensionConnector.java
+++ b/client/src/main/java/com/vaadin/client/extensions/DropTargetExtensionConnector.java
@@ -26,8 +26,10 @@ import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.BrowserInfo;
+import com.vaadin.client.MouseEventDetailsBuilder;
import com.vaadin.client.ServerConnector;
import com.vaadin.client.ui.AbstractComponentConnector;
+import com.vaadin.shared.MouseEventDetails;
import com.vaadin.shared.ui.Connect;
import com.vaadin.shared.ui.dnd.DropEffect;
import com.vaadin.shared.ui.dnd.DropTargetRpc;
@@ -362,7 +364,13 @@ public class DropTargetExtensionConnector extends AbstractExtensionConnector {
protected void sendDropEventToServer(List<String> types,
Map<String, String> data, String dropEffect,
NativeEvent dropEvent) {
- getRpcProxy(DropTargetRpc.class).drop(types, data, dropEffect);
+ // Build mouse event details for the drop event
+ MouseEventDetails mouseEventDetails = MouseEventDetailsBuilder
+ .buildMouseEventDetails(dropEvent, getDropTargetElement());
+
+ // Send data to server with RPC
+ getRpcProxy(DropTargetRpc.class)
+ .drop(types, data, dropEffect, mouseEventDetails);
}
/**
diff --git a/server/src/main/java/com/vaadin/ui/components/grid/GridDropEvent.java b/server/src/main/java/com/vaadin/ui/components/grid/GridDropEvent.java
index aa80cdc7b8..11d56713f8 100644
--- a/server/src/main/java/com/vaadin/ui/components/grid/GridDropEvent.java
+++ b/server/src/main/java/com/vaadin/ui/components/grid/GridDropEvent.java
@@ -18,6 +18,7 @@ package com.vaadin.ui.components.grid;
import java.util.Map;
import java.util.Optional;
+import com.vaadin.shared.MouseEventDetails;
import com.vaadin.shared.ui.dnd.DropEffect;
import com.vaadin.shared.ui.grid.DropLocation;
import com.vaadin.shared.ui.grid.DropMode;
@@ -59,12 +60,16 @@ public class GridDropEvent<T> extends DropEvent<Grid<T>> {
* on empty grid
* @param dropLocation
* Location of the drop within the target row.
+ * @param mouseEventDetails
+ * mouse event details object containing information about the
+ * drop event
*/
public GridDropEvent(Grid<T> target, Map<String, String> data,
DropEffect dropEffect,
DragSourceExtension<? extends AbstractComponent> dragSourceExtension,
- T dropTargetRow, DropLocation dropLocation) {
- super(target, data, dropEffect, dragSourceExtension);
+ T dropTargetRow, DropLocation dropLocation,
+ MouseEventDetails mouseEventDetails) {
+ super(target, data, dropEffect, dragSourceExtension, mouseEventDetails);
this.dropTargetRow = dropTargetRow;
this.dropLocation = dropLocation;
diff --git a/server/src/main/java/com/vaadin/ui/components/grid/GridDropTarget.java b/server/src/main/java/com/vaadin/ui/components/grid/GridDropTarget.java
index b86ca13080..342946d5c9 100644
--- a/server/src/main/java/com/vaadin/ui/components/grid/GridDropTarget.java
+++ b/server/src/main/java/com/vaadin/ui/components/grid/GridDropTarget.java
@@ -145,7 +145,7 @@ public class GridDropTarget<T> extends DropTargetExtension<Grid<T>> {
@Override
protected void registerDropTargetRpc() {
registerRpc((GridDropTargetRpc) (types, data, dropEffect, rowKey,
- dropLocation) -> {
+ dropLocation, mouseEventDetails) -> {
// Create a linked map that preserves the order of types
Map<String, String> dataPreserveOrder = new LinkedHashMap<>();
@@ -157,7 +157,8 @@ public class GridDropTarget<T> extends DropTargetExtension<Grid<T>> {
GridDropEvent<T> event = new GridDropEvent<>(getParent(),
dataPreserveOrder,
DropEffect.valueOf(dropEffect.toUpperCase()),
- getUI().getActiveDragSource(), dropTargetRow, dropLocation);
+ getUI().getActiveDragSource(), dropTargetRow, dropLocation,
+ mouseEventDetails);
fireEvent(event);
});
diff --git a/server/src/main/java/com/vaadin/ui/dnd/DropTargetExtension.java b/server/src/main/java/com/vaadin/ui/dnd/DropTargetExtension.java
index fddb636f70..1f5c675b21 100644
--- a/server/src/main/java/com/vaadin/ui/dnd/DropTargetExtension.java
+++ b/server/src/main/java/com/vaadin/ui/dnd/DropTargetExtension.java
@@ -21,6 +21,7 @@ import java.util.Map;
import java.util.Objects;
import com.vaadin.server.AbstractExtension;
+import com.vaadin.shared.MouseEventDetails;
import com.vaadin.shared.Registration;
import com.vaadin.shared.ui.dnd.DropEffect;
import com.vaadin.shared.ui.dnd.DropTargetRpc;
@@ -65,12 +66,15 @@ public class DropTargetExtension<T extends AbstractComponent>
* Override this method if you need to have a custom RPC interface for
* transmitting the drop event with more data. If just need to do additional
* things before firing the drop event, then you should override
- * {@link #onDrop(List, Map, DropEffect)} instead.
+ * {@link #onDrop(List, Map, DropEffect, MouseEventDetails)} instead.
*/
protected void registerDropTargetRpc() {
- registerRpc((DropTargetRpc) (types, data, dropEffect) -> {
- onDrop(types, data, DropEffect.valueOf(dropEffect.toUpperCase()));
- });
+ registerRpc(
+ (DropTargetRpc) (types, data, dropEffect, mouseEventDetails) -> {
+ onDrop(types, data,
+ DropEffect.valueOf(dropEffect.toUpperCase()),
+ mouseEventDetails);
+ });
}
/**
@@ -84,16 +88,19 @@ public class DropTargetExtension<T extends AbstractComponent>
* DataTransfer} object.
* @param dropEffect
* the drop effect
+ * @param mouseEventDetails
+ * mouse event details object containing information about the drop
+ * event
*/
protected void onDrop(List<String> types, Map<String, String> data,
- DropEffect dropEffect) {
+ DropEffect dropEffect, MouseEventDetails mouseEventDetails) {
// Create a linked map that preserves the order of types
Map<String, String> dataPreserveOrder = new LinkedHashMap<>();
types.forEach(type -> dataPreserveOrder.put(type, data.get(type)));
DropEvent<T> event = new DropEvent<>(getParent(), dataPreserveOrder,
- dropEffect, getUI().getActiveDragSource());
+ dropEffect, getUI().getActiveDragSource(), mouseEventDetails);
fireEvent(event);
}
diff --git a/server/src/main/java/com/vaadin/ui/dnd/event/DropEvent.java b/server/src/main/java/com/vaadin/ui/dnd/event/DropEvent.java
index ed70e8265b..275498f320 100644
--- a/server/src/main/java/com/vaadin/ui/dnd/event/DropEvent.java
+++ b/server/src/main/java/com/vaadin/ui/dnd/event/DropEvent.java
@@ -18,6 +18,7 @@ package com.vaadin.ui.dnd.event;
import java.util.Map;
import java.util.Optional;
+import com.vaadin.shared.MouseEventDetails;
import com.vaadin.shared.ui.dnd.DragSourceState;
import com.vaadin.shared.ui.dnd.DropEffect;
import com.vaadin.ui.AbstractComponent;
@@ -39,6 +40,7 @@ public class DropEvent<T extends AbstractComponent> extends Component.Event {
private final DragSourceExtension<? extends AbstractComponent> dragSourceExtension;
private final AbstractComponent dragSource;
private final DropEffect dropEffect;
+ private final MouseEventDetails mouseEventDetails;
/**
* Creates a server side drop event.
@@ -53,9 +55,13 @@ public class DropEvent<T extends AbstractComponent> extends Component.Event {
* @param dragSourceExtension
* Drag source extension of the component that initiated the drop
* event.
+ * @param mouseEventDetails
+ * Mouse event details object containing information about the drop
+ * event
*/
public DropEvent(T target, Map<String, String> data, DropEffect dropEffect,
- DragSourceExtension<? extends AbstractComponent> dragSourceExtension) {
+ DragSourceExtension<? extends AbstractComponent> dragSourceExtension,
+ MouseEventDetails mouseEventDetails) {
super(target);
this.data = data;
@@ -63,6 +69,7 @@ public class DropEvent<T extends AbstractComponent> extends Component.Event {
this.dragSourceExtension = dragSourceExtension;
this.dragSource = Optional.ofNullable(dragSourceExtension)
.map(DragSourceExtension::getParent).orElse(null);
+ this.mouseEventDetails = mouseEventDetails;
}
/**
@@ -165,6 +172,16 @@ public class DropEvent<T extends AbstractComponent> extends Component.Event {
}
/**
+ * Gets the mouse event details for the drop event.
+ *
+ * @return Mouse event details object containing information about the drop
+ * event.
+ */
+ public MouseEventDetails getMouseEventDetails() {
+ return mouseEventDetails;
+ }
+
+ /**
* Returns the drop target component where the drop event occurred.
*
* @return Component on which a drag source was dropped.
diff --git a/shared/src/main/java/com/vaadin/shared/ui/dnd/DropTargetRpc.java b/shared/src/main/java/com/vaadin/shared/ui/dnd/DropTargetRpc.java
index 2d475f51e7..eb53d1e9e7 100644
--- a/shared/src/main/java/com/vaadin/shared/ui/dnd/DropTargetRpc.java
+++ b/shared/src/main/java/com/vaadin/shared/ui/dnd/DropTargetRpc.java
@@ -18,6 +18,7 @@ package com.vaadin.shared.ui.dnd;
import java.util.List;
import java.util.Map;
+import com.vaadin.shared.MouseEventDetails;
import com.vaadin.shared.communication.ServerRpc;
/**
@@ -39,7 +40,10 @@ public interface DropTargetRpc extends ServerRpc {
* DataTransfer} object.
* @param dropEffect
* The desired drop effect.
+ * @param mouseEventDetails
+ * mouse event details object containing information about the drop
+ * event
*/
public void drop(List<String> types, Map<String, String> data,
- String dropEffect);
+ String dropEffect, MouseEventDetails mouseEventDetails);
}
diff --git a/shared/src/main/java/com/vaadin/shared/ui/grid/GridDropTargetRpc.java b/shared/src/main/java/com/vaadin/shared/ui/grid/GridDropTargetRpc.java
index 1e1242be5a..8309608ca6 100644
--- a/shared/src/main/java/com/vaadin/shared/ui/grid/GridDropTargetRpc.java
+++ b/shared/src/main/java/com/vaadin/shared/ui/grid/GridDropTargetRpc.java
@@ -18,6 +18,7 @@ package com.vaadin.shared.ui.grid;
import java.util.List;
import java.util.Map;
+import com.vaadin.shared.MouseEventDetails;
import com.vaadin.shared.communication.ServerRpc;
/**
@@ -43,8 +44,11 @@ public interface GridDropTargetRpc extends ServerRpc {
* Key of the row on which the drop event occured.
* @param dropLocation
* Location of the drop within the row.
+ * @param mouseEventDetails
+ * Mouse event details object containing information about the drop
+ * event
*/
public void drop(List<String> types, Map<String, String> data,
String dropEffect, String rowKey,
- DropLocation dropLocation);
+ DropLocation dropLocation, MouseEventDetails mouseEventDetails);
}
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridDragAndDrop.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridDragAndDrop.java
index 7ccb808618..a71952d53e 100644
--- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridDragAndDrop.java
+++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridDragAndDrop.java
@@ -203,7 +203,9 @@ public class GridDragAndDrop extends AbstractTestUIWithLog {
+ event.getDropTargetRow().get()
.getLastName()
: "[BODY]")
- + ", location=" + event.getDropLocation());
+ + ", location=" + event.getDropLocation()
+ + ", mouseEventDetails="
+ + event.getMouseEventDetails());
}
});
});
diff --git a/uitest/src/main/java/com/vaadin/tests/dnd/DragAndDropCardShuffle.java b/uitest/src/main/java/com/vaadin/tests/dnd/DragAndDropCardShuffle.java
index bf37cf0e82..493b57226e 100644
--- a/uitest/src/main/java/com/vaadin/tests/dnd/DragAndDropCardShuffle.java
+++ b/uitest/src/main/java/com/vaadin/tests/dnd/DragAndDropCardShuffle.java
@@ -151,7 +151,8 @@ public class DragAndDropCardShuffle extends AbstractTestUIWithLog {
log(event.getComponent().getValue() + " drop received "
+ source.getValue() + ", dropEffect="
- + event.getDropEffect());
+ + event.getDropEffect() + ", mouseEventDetails="
+ + event.getMouseEventDetails());
} else {
log(event.getComponent().getValue()
+ " drop received something else than card");