diff options
author | Adam Wagner <wbadam@users.noreply.github.com> | 2017-06-07 14:50:38 +0300 |
---|---|---|
committer | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2017-06-07 14:50:38 +0300 |
commit | 8ff23ad10859132e5015f6372e623ed7ce8e05cc (patch) | |
tree | 92874f7b52ede7ac54526d8f3c40e5d4da825e69 /server | |
parent | 3b3c647e5b732a7e9e6109193a11e665270ffe2f (diff) | |
download | vaadin-framework-8ff23ad10859132e5015f6372e623ed7ce8e05cc.tar.gz vaadin-framework-8ff23ad10859132e5015f6372e623ed7ce8e05cc.zip |
Add mouse event details to the drop event (#9485)
Fixes #9483
Diffstat (limited to 'server')
4 files changed, 41 insertions, 11 deletions
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. |