]> source.dussan.org Git - vaadin-framework.git/commitdiff
Add setters to Criterion to fix serialization. (#11926)
authorAnna Koskinen <Ansku@users.noreply.github.com>
Thu, 26 Mar 2020 08:51:19 +0000 (10:51 +0200)
committerGitHub <noreply@github.com>
Thu, 26 Mar 2020 08:51:19 +0000 (10:51 +0200)
Fixes #11909

shared/src/main/java/com/vaadin/shared/ui/dnd/criteria/Criterion.java
uitest/src/main/java/com/vaadin/tests/dnd/CriterionSerialization.java [new file with mode: 0644]

index 73c022a033cabc676592f8a4e94f5d730c09cabd..e734a5edc1617179af3d66e76801a5bd21ab7e65 100644 (file)
@@ -116,10 +116,10 @@ public class Criterion implements Serializable {
      */
     private Criterion(String key, ComparisonOperator operator, String value,
             Payload.ValueType valueType) {
-        this.key = key;
-        this.value = value;
-        this.valueType = valueType;
-        this.operator = operator;
+        setKey(key);
+        setValue(value);
+        setValueType(valueType);
+        setOperator(operator);
     }
 
     /**
@@ -131,6 +131,16 @@ public class Criterion implements Serializable {
         return key;
     }
 
+    /**
+     * Sets the key of the payload to be compared.
+     *
+     * @param key
+     *            key of the payload to be compared
+     */
+    public void setKey(String key) {
+        this.key = key;
+    }
+
     /**
      * Gets the value of the payload to be compared.
      *
@@ -140,6 +150,16 @@ public class Criterion implements Serializable {
         return value;
     }
 
+    /**
+     * Sets the value of the payload to be compared.
+     *
+     * @param value
+     *            value of the payload to be compared
+     */
+    public void setValue(String value) {
+        this.value = value;
+    }
+
     /**
      * Gets the type of the payload value to be compared.
      *
@@ -149,6 +169,16 @@ public class Criterion implements Serializable {
         return valueType;
     }
 
+    /**
+     * Sets the type of the payload value to be compared.
+     *
+     * @param valueType
+     *            type of the payload to be compared
+     */
+    public void setValueType(Payload.ValueType valueType) {
+        this.valueType = valueType;
+    }
+
     /**
      * Gets the comparison operator.
      *
@@ -158,6 +188,16 @@ public class Criterion implements Serializable {
         return operator;
     }
 
+    /**
+     * Sets the comparison operator.
+     *
+     * @param operator
+     *            comparison operator
+     */
+    public void setOperator(ComparisonOperator operator) {
+        this.operator = operator;
+    }
+
     /**
      * Compares this criterion's value to the given payload's value and returns
      * whether the result matches the criterion's operator. The comparison is
diff --git a/uitest/src/main/java/com/vaadin/tests/dnd/CriterionSerialization.java b/uitest/src/main/java/com/vaadin/tests/dnd/CriterionSerialization.java
new file mode 100644 (file)
index 0000000..3cc508f
--- /dev/null
@@ -0,0 +1,59 @@
+package com.vaadin.tests.dnd;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.dnd.DragSourceExtension;
+import com.vaadin.ui.dnd.DropTargetExtension;
+
+public class CriterionSerialization extends AbstractTestUIWithLog {
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        Button button = new Button();
+        button.setCaption("drag me");
+        button.setId("drag");
+        DragSourceExtension<Button> dragSource = new DragSourceExtension<>(
+                button);
+        dragSource.setPayload("test", "value");
+        dragSource.addDragStartListener(e -> {
+            log("drag started");
+        });
+        dragSource.addDragEndListener(e -> {
+            log("drag ended");
+        });
+
+        Button dropArea1 = new Button();
+        dropArea1.setCaption("drop here works");
+        dropArea1.setId("dropWorks");
+        DropTargetExtension<Button> dropTarget = new DropTargetExtension<>(
+                dropArea1);
+        dropTarget.addDropListener(e -> {
+            log("dropArea1 drop listener invoked (expected to happen)");
+        });
+        dropTarget.setDropCriterion("test", "value");
+
+        Button dropArea2 = new Button();
+        dropArea2.setCaption("drop here fails");
+        dropArea2.setId("dropFails");
+        DropTargetExtension<Button> dropTarget2 = new DropTargetExtension<>(
+                dropArea2);
+        dropTarget2.addDropListener(e -> {
+            log("dropArea2 drop listener invoked (should not happen)");
+        });
+        dropTarget2.setDropCriterion("test", "value2");
+
+        getLayout().addComponents(button, dropArea1, dropArea2);
+    }
+
+    @Override
+    protected String getTestDescription() {
+        return "Dropping the draggable button on the button without matching "
+                + "Criterion should not trigger drop listener.";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 11909;
+    }
+}