Преглед на файлове

Ignore dragstart and dragend events if there are no items dragged (#9187)

tags/8.1.0.alpha7
Adam Wagner преди 7 години
родител
ревизия
9c443c9de4
променени са 1 файла, в които са добавени 16 реда и са изтрити 7 реда
  1. 16
    7
      client/src/main/java/com/vaadin/client/connectors/grid/GridDragSourceConnector.java

+ 16
- 7
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) {

Loading…
Отказ
Запис