diff options
author | Adam Wagner <wbadam@users.noreply.github.com> | 2017-04-07 09:52:06 +0300 |
---|---|---|
committer | Henri Sara <henri.sara@gmail.com> | 2017-04-12 14:58:11 +0300 |
commit | a773c8c7b365e4041db87b5d9ddaad0bdc244a91 (patch) | |
tree | 422ce4db5bde123c7dc775d70e49e259c17b2dce /server | |
parent | 659313e8c35e68d14fe2599b9bbb4dbba35fb4a3 (diff) | |
download | vaadin-framework-a773c8c7b365e4041db87b5d9ddaad0bdc244a91.tar.gz vaadin-framework-a773c8c7b365e4041db87b5d9ddaad0bdc244a91.zip |
Make it possible to drop things between Grid rows (#8979)
Fixes #8401
Diffstat (limited to 'server')
-rw-r--r-- | server/src/main/java/com/vaadin/event/dnd/grid/GridDropEvent.java | 27 | ||||
-rw-r--r-- | server/src/main/java/com/vaadin/ui/GridDropTargetExtension.java | 62 |
2 files changed, 74 insertions, 15 deletions
diff --git a/server/src/main/java/com/vaadin/event/dnd/grid/GridDropEvent.java b/server/src/main/java/com/vaadin/event/dnd/grid/GridDropEvent.java index 07ba1327a6..98d1b3495b 100644 --- a/server/src/main/java/com/vaadin/event/dnd/grid/GridDropEvent.java +++ b/server/src/main/java/com/vaadin/event/dnd/grid/GridDropEvent.java @@ -17,11 +17,12 @@ package com.vaadin.event.dnd.grid; import com.vaadin.event.dnd.DragSourceExtension; import com.vaadin.event.dnd.DropEvent; +import com.vaadin.shared.ui.grid.DropLocation; import com.vaadin.ui.AbstractComponent; import com.vaadin.ui.Grid; /** - * Server side drop event on an HTML5 drop target {@link Grid} row. + * Drop event on an HTML5 drop target {@link Grid} row. * * @param <T> * The Grid bean type. @@ -32,9 +33,10 @@ import com.vaadin.ui.Grid; public class GridDropEvent<T> extends DropEvent<Grid<T>> { private final T dropTargetRow; + private final DropLocation dropLocation; /** - * Creates a server side Grid row drop event. + * Creates a Grid row drop event. * * @param target * Grid that received the drop. @@ -44,16 +46,18 @@ public class GridDropEvent<T> extends DropEvent<Grid<T>> { * @param dragSourceExtension * Drag source extension of the component that initiated the drop * event. - * @param dropTargetRowKey - * Key of the target row that received the drop. + * @param dropTargetRow + * Target row that received the drop. + * @param dropLocation + * Location of the drop within the target row. */ public GridDropEvent(Grid<T> target, String dataTransferText, DragSourceExtension<? extends AbstractComponent> dragSourceExtension, - String dropTargetRowKey) { + T dropTargetRow, DropLocation dropLocation) { super(target, dataTransferText, dragSourceExtension); - dropTargetRow = target.getDataCommunicator().getKeyMapper() - .get(dropTargetRowKey); + this.dropTargetRow = dropTargetRow; + this.dropLocation = dropLocation; } /** @@ -64,4 +68,13 @@ public class GridDropEvent<T> extends DropEvent<Grid<T>> { public T getDropTargetRow() { return dropTargetRow; } + + /** + * Get the location of the drop within the row. + * + * @return Location of the drop within the row. + */ + public DropLocation getDropLocation() { + return dropLocation; + } } diff --git a/server/src/main/java/com/vaadin/ui/GridDropTargetExtension.java b/server/src/main/java/com/vaadin/ui/GridDropTargetExtension.java index 1fcb7160f4..17633fa5ce 100644 --- a/server/src/main/java/com/vaadin/ui/GridDropTargetExtension.java +++ b/server/src/main/java/com/vaadin/ui/GridDropTargetExtension.java @@ -19,6 +19,7 @@ import com.vaadin.event.dnd.DropTargetExtension; import com.vaadin.event.dnd.grid.GridDropEvent; import com.vaadin.event.dnd.grid.GridDropListener; import com.vaadin.shared.Registration; +import com.vaadin.shared.ui.grid.DropMode; import com.vaadin.shared.ui.grid.GridDropTargetExtensionRpc; import com.vaadin.shared.ui.grid.GridDropTargetExtensionState; @@ -32,18 +33,47 @@ import com.vaadin.shared.ui.grid.GridDropTargetExtensionState; * @since */ public class GridDropTargetExtension<T> extends DropTargetExtension<Grid<T>> { - public GridDropTargetExtension(Grid<T> target) { + + /** + * Extends a Grid and makes it's rows drop targets for HTML5 drag and drop. + * + * @param target + * Grid to be extended. + * @param dropMode + * Drop mode that describes the allowed drop locations within the + * Grid's row. + * @see GridDropEvent#getDropLocation() + */ + public GridDropTargetExtension(Grid<T> target, DropMode dropMode) { super(target); + + setDropMode(dropMode); } - @Override - protected void registerDropTargetRpc(Grid<T> target) { - registerRpc((GridDropTargetExtensionRpc) (dataTransferText, rowKey) -> { - GridDropEvent<T> event = new GridDropEvent<>(target, - dataTransferText, getUI().getActiveDragSource(), rowKey); + /** + * Sets the drop mode of this drop target. + * + * @param dropMode + * Drop mode that describes the allowed drop locations within the + * Grid's row. + * @see GridDropEvent#getDropLocation() + */ + public void setDropMode(DropMode dropMode) { + if (dropMode == null) { + throw new IllegalArgumentException("Drop mode cannot be null"); + } + + getState().dropMode = dropMode; + } - fireEvent(event); - }); + /** + * Gets the drop mode of this drop target. + * + * @return Drop mode that describes the allowed drop locations within the + * Grid's row. + */ + public DropMode getDropMode() { + return getState(false).dropMode; } /** @@ -61,6 +91,22 @@ public class GridDropTargetExtension<T> extends DropTargetExtension<Grid<T>> { } @Override + protected void registerDropTargetRpc(Grid<T> target) { + registerRpc( + (GridDropTargetExtensionRpc) (dataTransferText, rowKey, dropLocation) -> { + + T dropTargetRow = target.getDataCommunicator() + .getKeyMapper().get(rowKey); + + GridDropEvent<T> event = new GridDropEvent<>(target, + dataTransferText, getUI().getActiveDragSource(), + dropTargetRow, dropLocation); + + fireEvent(event); + }); + } + + @Override protected GridDropTargetExtensionState getState() { return (GridDropTargetExtensionState) super.getState(); } |