diff options
9 files changed, 39 insertions, 41 deletions
diff --git a/client/src/main/java/com/vaadin/client/extensions/DragSourceExtensionConnector.java b/client/src/main/java/com/vaadin/client/extensions/DragSourceExtensionConnector.java index da14466666..3094042826 100644 --- a/client/src/main/java/com/vaadin/client/extensions/DragSourceExtensionConnector.java +++ b/client/src/main/java/com/vaadin/client/extensions/DragSourceExtensionConnector.java @@ -25,6 +25,7 @@ import com.vaadin.event.dnd.DragSourceExtension; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.dnd.DragSourceRpc; import com.vaadin.shared.ui.dnd.DragSourceState; +import com.vaadin.shared.ui.dnd.DropEffect; import elemental.events.Event; import elemental.events.EventListener; @@ -113,12 +114,19 @@ public class DragSourceExtensionConnector extends AbstractExtensionConnector { * event occurs. * * @param event + * browser event to be handled */ protected void onDragEnd(Event event) { // Initiate server start dragend event when there is a DragEndListener // attached on the server side if (hasEventListener(DragSourceState.EVENT_DRAGEND)) { - getRpcProxy(DragSourceRpc.class).dragEnd(); + String dropEffect = getDropEffect( + ((NativeEvent) event).getDataTransfer()); + + assert dropEffect != null : "Drop effect should never be null"; + + getRpcProxy(DragSourceRpc.class) + .dragEnd(DropEffect.valueOf(dropEffect.toUpperCase())); } } @@ -137,6 +145,10 @@ public class DragSourceExtensionConnector extends AbstractExtensionConnector { dataTransfer.effectAllowed = effectAllowed; }-*/; + private native String getDropEffect(DataTransfer dataTransfer)/*-{ + return dataTransfer.dropEffect; + }-*/; + @Override public DragSourceState getState() { return (DragSourceState) super.getState(); 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 a1ac662987..5f8ca243c7 100644 --- a/client/src/main/java/com/vaadin/client/extensions/DropTargetExtensionConnector.java +++ b/client/src/main/java/com/vaadin/client/extensions/DropTargetExtensionConnector.java @@ -182,8 +182,7 @@ public class DropTargetExtensionConnector extends AbstractExtensionConnector { String dataTransferText = nativeEvent.getDataTransfer().getData( DragSourceState.DATA_TYPE_TEXT); - getRpcProxy(DropTargetRpc.class) - .drop(dataTransferText, getState().dropEffect); + getRpcProxy(DropTargetRpc.class).drop(dataTransferText); } removeTargetIndicator(getDropTargetElement()); 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 f1176e1880..57f111e848 100644 --- a/server/src/main/java/com/vaadin/event/dnd/DragEndEvent.java +++ b/server/src/main/java/com/vaadin/event/dnd/DragEndEvent.java @@ -15,7 +15,7 @@ */ package com.vaadin.event.dnd; -import com.vaadin.shared.ui.dnd.EffectAllowed; +import com.vaadin.shared.ui.dnd.DropEffect; import com.vaadin.ui.AbstractComponent; import com.vaadin.ui.Component; @@ -30,7 +30,7 @@ import com.vaadin.ui.Component; */ public class DragEndEvent<T extends AbstractComponent> extends Component.Event { private final String dataTransferText; - private final EffectAllowed effectAllowed; + private final DropEffect dropEffect; /** * Creates a server side dragend event. @@ -40,16 +40,16 @@ public class DragEndEvent<T extends AbstractComponent> extends Component.Event { * @param dataTransferText * Data of type {@code "text"} from the {@code DataTransfer} * object. - * @param effectAllowed - * Allowed effects from {@code DataTransfer.effectAllowed} object. + * @param dropEffect + * Drop effect from {@code DataTransfer.dropEffect} object. */ public DragEndEvent(T source, String dataTransferText, - EffectAllowed effectAllowed) { + DropEffect dropEffect) { super(source); this.dataTransferText = dataTransferText; - this.effectAllowed = effectAllowed; + this.dropEffect = dropEffect; } /** @@ -64,12 +64,13 @@ public class DragEndEvent<T extends AbstractComponent> extends Component.Event { } /** - * Returns the {@code effectAllowed} parameter of this event. + * Get drop effect of the dragend event. * - * @return This event's {@code effectAllowed} parameter. + * @return The {@code DataTransfer.dropEffect} parameter of the client side + * dragend event. */ - public EffectAllowed getEffectAllowed() { - return effectAllowed; + public DropEffect getDropEffect() { + return dropEffect; } /** 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 6a6a8a8c64..bce643ffdb 100644 --- a/server/src/main/java/com/vaadin/event/dnd/DragSourceExtension.java +++ b/server/src/main/java/com/vaadin/event/dnd/DragSourceExtension.java @@ -21,6 +21,7 @@ import com.vaadin.server.AbstractExtension; import com.vaadin.shared.Registration; import com.vaadin.shared.ui.dnd.DragSourceRpc; import com.vaadin.shared.ui.dnd.DragSourceState; +import com.vaadin.shared.ui.dnd.DropEffect; import com.vaadin.shared.ui.dnd.EffectAllowed; import com.vaadin.ui.AbstractComponent; @@ -62,10 +63,9 @@ public class DragSourceExtension<T extends AbstractComponent> extends } @Override - public void dragEnd() { + public void dragEnd(DropEffect dropEffect) { DragEndEvent<T> event = new DragEndEvent<>(target, - getState(false).dataTransferText, - getState(false).effectAllowed); + getState(false).dataTransferText, dropEffect); fireEvent(event); } }); 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 c2b4943d0f..932f5577a5 100644 --- a/server/src/main/java/com/vaadin/event/dnd/DropEvent.java +++ b/server/src/main/java/com/vaadin/event/dnd/DropEvent.java @@ -32,7 +32,6 @@ import com.vaadin.ui.Component; */ public class DropEvent<T extends AbstractComponent> extends Component.Event { private final String dataTransferText; - private final DropEffect dropEffect; private final DragSourceExtension<? extends AbstractComponent> dragSourceExtension; private final AbstractComponent dragSource; @@ -44,20 +43,16 @@ public class DropEvent<T extends AbstractComponent> extends Component.Event { * @param dataTransferText * Data of type {@code "text"} from the {@code DataTransfer} * object. - * @param dropEffect - * Drop effect from {@code DataTransfer.dropEffect} object. * @param dragSourceExtension * Drag source extension of the component that initiated the drop * event. */ - public DropEvent(T target, String dataTransferText, DropEffect dropEffect, + public DropEvent(T target, String dataTransferText, DragSourceExtension<? extends AbstractComponent> dragSourceExtension) { super(target); this.dataTransferText = dataTransferText; - this.dropEffect = dropEffect; - this.dragSourceExtension = dragSourceExtension; this.dragSource = Optional.ofNullable(dragSourceExtension) .map(DragSourceExtension::getParent).orElse(null); @@ -75,15 +70,6 @@ public class DropEvent<T extends AbstractComponent> extends Component.Event { } /** - * Get drop effect set for the current drop target. - * - * @return {@code dropEffect} parameter set for the current drop target. - */ - public DropEffect getDropEffect() { - return dropEffect; - } - - /** * Returns the drag source component if the drag originated from a * component in the same UI as the drop target component, or an empty * optional. diff --git a/server/src/main/java/com/vaadin/event/dnd/DropTargetExtension.java b/server/src/main/java/com/vaadin/event/dnd/DropTargetExtension.java index 2df43027a1..c4a5f981ff 100644 --- a/server/src/main/java/com/vaadin/event/dnd/DropTargetExtension.java +++ b/server/src/main/java/com/vaadin/event/dnd/DropTargetExtension.java @@ -43,9 +43,9 @@ public class DropTargetExtension<T extends AbstractComponent> extends * Component to be extended. */ public DropTargetExtension(T target) { - registerRpc((DropTargetRpc) (dataTransferText, dropEffect) -> { + registerRpc((DropTargetRpc) dataTransferText -> { DropEvent<T> event = new DropEvent<>(target, dataTransferText, - dropEffect, getUI().getActiveDragSource()); + getUI().getActiveDragSource()); fireEvent(event); }); diff --git a/shared/src/main/java/com/vaadin/shared/ui/dnd/DragSourceRpc.java b/shared/src/main/java/com/vaadin/shared/ui/dnd/DragSourceRpc.java index 178028b423..4faf7ca139 100644 --- a/shared/src/main/java/com/vaadin/shared/ui/dnd/DragSourceRpc.java +++ b/shared/src/main/java/com/vaadin/shared/ui/dnd/DragSourceRpc.java @@ -33,6 +33,10 @@ public interface DragSourceRpc extends ServerRpc { /** * Called when dragend event happens on client side. + * + * @param dropEffect + * Drop effect of the dragend event, extracted from {@code + * DataTransfer.dropEffect} parameter. */ - public void dragEnd(); + public void dragEnd(DropEffect dropEffect); } 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 b74fd3a949..7a608068a1 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 @@ -32,8 +32,6 @@ public interface DropTargetRpc extends ServerRpc { * @param dataTransferText * Data of type {@code "text"} from the {@code DataTransfer} * object. - * @param dropEffect - * Drop effect set for the drop target where drop happened. */ - public void drop(String dataTransferText, DropEffect dropEffect); + public void drop(String dataTransferText); } 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 745297cde8..415dbf945d 100644 --- a/uitest/src/main/java/com/vaadin/tests/dnd/DragAndDropCardShuffle.java +++ b/uitest/src/main/java/com/vaadin/tests/dnd/DragAndDropCardShuffle.java @@ -19,7 +19,6 @@ import com.vaadin.event.dnd.DragSourceExtension; import com.vaadin.event.dnd.DropTargetExtension; import com.vaadin.server.Page; import com.vaadin.server.VaadinRequest; -import com.vaadin.shared.ui.dnd.DropEffect; import com.vaadin.tests.components.AbstractTestUIWithLog; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; @@ -76,7 +75,8 @@ public class DragAndDropCardShuffle extends AbstractTestUIWithLog { dragSource.addDragEndListener(event -> { event.getComponent().removeStyleName("dragged"); - log(event.getComponent().getValue() + " dragend"); + log(event.getComponent().getValue() + " dragend, dropEffect=" + + event.getDropEffect()); }); } @@ -85,8 +85,6 @@ public class DragAndDropCardShuffle extends AbstractTestUIWithLog { DropTargetExtension<Label> dropTarget = new DropTargetExtension<>( target); - dropTarget.setDropEffect(DropEffect.MOVE); - // Add listener dropTarget.addDropListener(event -> { event.getDragSourceExtension().ifPresent(dragSource -> { |