@@ -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) { |
@@ -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); | |||
} | |||
/** |
@@ -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; |
@@ -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); | |||
}); |
@@ -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); | |||
} |
@@ -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; | |||
} | |||
/** | |||
@@ -164,6 +171,16 @@ public class DropEvent<T extends AbstractComponent> extends Component.Event { | |||
return getDragSourceExtension().map(DragSourceExtension::getDragData); | |||
} | |||
/** | |||
* 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. | |||
* |
@@ -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); | |||
} |
@@ -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); | |||
} |
@@ -203,7 +203,9 @@ public class GridDragAndDrop extends AbstractTestUIWithLog { | |||
+ event.getDropTargetRow().get() | |||
.getLastName() | |||
: "[BODY]") | |||
+ ", location=" + event.getDropLocation()); | |||
+ ", location=" + event.getDropLocation() | |||
+ ", mouseEventDetails=" | |||
+ event.getMouseEventDetails()); | |||
} | |||
}); | |||
}); |
@@ -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"); |