]> source.dussan.org Git - vaadin-framework.git/commitdiff
Create combined drop mode to allow both on_top and between drops (#9063)
authorAdam Wagner <wbadam@users.noreply.github.com>
Thu, 13 Apr 2017 08:47:45 +0000 (11:47 +0300)
committerHenri Sara <henri.sara@gmail.com>
Thu, 13 Apr 2017 08:47:45 +0000 (11:47 +0300)
Resolves #8932

client/src/main/java/com/vaadin/client/connectors/grid/GridDropTargetConnector.java
server/src/main/java/com/vaadin/ui/GridDropTarget.java
shared/src/main/java/com/vaadin/shared/ui/grid/DropMode.java
shared/src/main/java/com/vaadin/shared/ui/grid/GridDropTargetState.java

index 13767763f84a40ec6297c7adac97bd3a850b80a6..7814a812081ad53db596ff84fdb62c586db97aa2 100644 (file)
@@ -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;
     }
index 0cd51d8634e5e4eb36f310edc7d67fba5b5ccff6..97b9a80ac6d9d4b922a42233519d92014028afcb 100644 (file)
@@ -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(
index 2db639be7d2eb77a7b2cbee22e93f78942fe8512..1da17f1bba4553ca7c99737577adbb11fd67f018 100644 (file)
@@ -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
 }
index aae051b2990cfab520270f7ad37368eb15a16e01..36869bfd623833ae4d324a95d67b960e95e182a8 100644 (file)
@@ -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;
 }