summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/grid/GridDropTargetConnector.java9
-rw-r--r--server/src/main/java/com/vaadin/ui/GridDropTarget.java37
-rw-r--r--shared/src/main/java/com/vaadin/shared/ui/grid/DropMode.java14
-rw-r--r--shared/src/main/java/com/vaadin/shared/ui/grid/GridDropTargetState.java8
4 files changed, 68 insertions, 0 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 13767763f8..7814a81208 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
@@ -117,6 +117,15 @@ public class GridDropTargetConnector extends
} else {
return DropLocation.BELOW;
}
+ } else if (getState().dropMode == DropMode.ON_TOP_OR_BETWEEN) {
+ if (getRelativeY(target, event) < getState().dropThreshold) {
+ return DropLocation.ABOVE;
+ } else if (target.getOffsetHeight() - getRelativeY(target, event)
+ < getState().dropThreshold) {
+ return DropLocation.BELOW;
+ } else {
+ return DropLocation.ON_TOP;
+ }
}
return DropLocation.ON_TOP;
}
diff --git a/server/src/main/java/com/vaadin/ui/GridDropTarget.java b/server/src/main/java/com/vaadin/ui/GridDropTarget.java
index 0cd51d8634..97b9a80ac6 100644
--- a/server/src/main/java/com/vaadin/ui/GridDropTarget.java
+++ b/server/src/main/java/com/vaadin/ui/GridDropTarget.java
@@ -90,6 +90,43 @@ public class GridDropTarget<T> extends DropTargetExtension<Grid<T>> {
GridDropListener.DROP_METHOD);
}
+ /**
+ * Sets the threshold between drop locations from the top and the bottom of
+ * a row in pixels.
+ * <p>
+ * Dropping an element
+ * <ul>
+ * <li>within {@code threshold} pixels from the top of a row results in a
+ * drop event with {@link com.vaadin.shared.ui.grid.DropLocation#ABOVE
+ * DropLocation.ABOVE}</li>
+ * <li>within {@code threshold} pixels from the bottom of a row results in
+ * a drop event with {@link com.vaadin.shared.ui.grid.DropLocation#BELOW
+ * DropLocation.BELOW}</li>
+ * <li>anywhere else within the row results in a drop event with {@link
+ * com.vaadin.shared.ui.grid.DropLocation#ON_TOP DropLocation.ON_TOP}</li>
+ * </ul>
+ * The value only has an effect when drop mode is set to {@link
+ * DropMode#ON_TOP_OR_BETWEEN}.
+ * <p>
+ * Default is 5 pixels.
+ *
+ * @param threshold
+ * The threshold from the top and bottom of the row in pixels.
+ */
+ public void setDropThreshold(int threshold) {
+ getState().dropThreshold = threshold;
+ }
+
+ /**
+ * Gets the threshold between drop locations from the top and the bottom of
+ * the row.
+ *
+ * @return The threshold in pixels.
+ */
+ public int getDropThreshold() {
+ return getState(false).dropThreshold;
+ }
+
@Override
protected void registerDropTargetRpc(Grid<T> target) {
registerRpc(
diff --git a/shared/src/main/java/com/vaadin/shared/ui/grid/DropMode.java b/shared/src/main/java/com/vaadin/shared/ui/grid/DropMode.java
index 2db639be7d..1da17f1bba 100644
--- a/shared/src/main/java/com/vaadin/shared/ui/grid/DropMode.java
+++ b/shared/src/main/java/com/vaadin/shared/ui/grid/DropMode.java
@@ -35,4 +35,18 @@ public enum DropMode {
* is the row under the cursor at the time of the drop event.
*/
ON_TOP,
+
+ /**
+ * The drop event can happen either on top of or between Grid rows. The drop
+ * is either
+ * <ul>
+ * <li><i>above</i> a row when the cursor is over a specified portion of
+ * the top part of the row,</li>
+ * <li><i>below</i> when the cursor is over a specified portion of the
+ * bottom part of the row, or</li>
+ * <li><i>on top</i> when the cursor is over the row but doesn't match the
+ * above conditions.</li>
+ * </ul>
+ */
+ ON_TOP_OR_BETWEEN
}
diff --git a/shared/src/main/java/com/vaadin/shared/ui/grid/GridDropTargetState.java b/shared/src/main/java/com/vaadin/shared/ui/grid/GridDropTargetState.java
index aae051b299..36869bfd62 100644
--- a/shared/src/main/java/com/vaadin/shared/ui/grid/GridDropTargetState.java
+++ b/shared/src/main/java/com/vaadin/shared/ui/grid/GridDropTargetState.java
@@ -29,4 +29,12 @@ public class GridDropTargetState extends DropTargetState {
* Stores the drop mode of the drop target Grid.
*/
public DropMode dropMode;
+
+ /**
+ * Stores the threshold between drop locations within a row in pixels.
+ * Defaults to 5px.
+ *
+ * @see DropMode#ON_TOP_OR_BETWEEN
+ */
+ public int dropThreshold = 5;
}