diff options
author | Adam Wagner <wbadam@users.noreply.github.com> | 2017-04-30 19:46:01 +0200 |
---|---|---|
committer | Pekka Hyvönen <pekka@vaadin.com> | 2017-04-30 20:46:01 +0300 |
commit | 9c443c9de42343a94df5f7040bfed731f8d8f84e (patch) | |
tree | e449fa0b8340e04031bc04b11a98cc68303ce44e /client | |
parent | 84d7ad78d47b998ed6b7f91d2f51d587aa1c7274 (diff) | |
download | vaadin-framework-9c443c9de42343a94df5f7040bfed731f8d8f84e.tar.gz vaadin-framework-9c443c9de42343a94df5f7040bfed731f8d8f84e.zip |
Ignore dragstart and dragend events if there are no items dragged (#9187)
Diffstat (limited to 'client')
-rw-r--r-- | client/src/main/java/com/vaadin/client/connectors/grid/GridDragSourceConnector.java | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/GridDragSourceConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/GridDragSourceConnector.java index 840afec107..2caa82e84e 100644 --- a/client/src/main/java/com/vaadin/client/connectors/grid/GridDragSourceConnector.java +++ b/client/src/main/java/com/vaadin/client/connectors/grid/GridDragSourceConnector.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.stream.Collectors; import com.google.gwt.animation.client.AnimationScheduler; +import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.NativeEvent; import com.google.gwt.dom.client.Style; @@ -86,6 +87,11 @@ public class GridDragSourceConnector extends DragSourceExtensionConnector { .map(row -> row.getString(GridState.JSONKEY_ROWKEY)) .collect(Collectors.toList()); + // Ignore event if there are no items dragged + if (draggedItemKeys.size() == 0) { + return; + } + // Add badge showing the number of dragged columns if (draggedItemKeys.size() > 1) { Element draggedRowElement = (Element) event.getTarget(); @@ -142,7 +148,7 @@ public class GridDragSourceConnector extends DragSourceExtensionConnector { private List<JsonObject> getDraggedRows(Event dragStartEvent) { List<JsonObject> draggedRows = new ArrayList<>(); - if (dragStartEvent.getTarget() instanceof TableRowElement) { + if (TableRowElement.is((JavaScriptObject) dragStartEvent.getTarget())) { TableRowElement row = (TableRowElement) dragStartEvent.getTarget(); int rowIndex = ((Escalator.AbstractRowContainer) getGridBody()) .getLogicalRowIndex(row); @@ -161,7 +167,10 @@ public class GridDragSourceConnector extends DragSourceExtensionConnector { @Override protected void onDragEnd(Event event) { - super.onDragEnd(event); + // Ignore event if there are no items dragged + if (draggedItemKeys.size() > 0) { + super.onDragEnd(event); + } // Clear item key list draggedItemKeys = null; @@ -181,9 +190,9 @@ public class GridDragSourceConnector extends DragSourceExtensionConnector { * allowed and a selected row is dragged. * * @param draggedRow - * Data of dragged row. + * Data of dragged row. * @return {@code true} if multiple rows are dragged, {@code false} - * otherwise. + * otherwise. */ private boolean dragMultipleRows(JsonObject draggedRow) { SelectionModel<JsonObject> selectionModel = getGrid() @@ -206,7 +215,7 @@ public class GridDragSourceConnector extends DragSourceExtensionConnector { * Get all selected rows from a subset of rows defined by {@code range}. * * @param range - * Range of indexes. + * Range of indexes. * @return List of data of all selected rows in the given range. */ private List<JsonObject> getSelectedRowsInRange(Range range) { @@ -226,7 +235,7 @@ public class GridDragSourceConnector extends DragSourceExtensionConnector { * Converts a list of {@link JsonObject}s to a {@link JsonArray}. * * @param objects - * List of json objects. + * List of json objects. * @return Json array containing all json objects. */ private JsonArray toJsonArray(List<JsonObject> objects) { @@ -242,7 +251,7 @@ public class GridDragSourceConnector extends DragSourceExtensionConnector { * otherwise. * * @param row - * Row data. + * Row data. * @return Drag data if present or row data otherwise. */ private JsonObject getDragData(JsonObject row) { |