aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnna Koskinen <Ansku@users.noreply.github.com>2020-03-26 10:51:19 +0200
committerGitHub <noreply@github.com>2020-03-26 10:51:19 +0200
commitb1ff64c6fd97359056adfccf7dc06eb3116e9e10 (patch)
tree45aeb8c3f059213b2a43544a67298e617e4f5439
parentf96263b21c3440f02d55c6d37a89a354c3093bdb (diff)
downloadvaadin-framework-b1ff64c6fd97359056adfccf7dc06eb3116e9e10.tar.gz
vaadin-framework-b1ff64c6fd97359056adfccf7dc06eb3116e9e10.zip
Add setters to Criterion to fix serialization. (#11926)
Fixes #11909
-rw-r--r--shared/src/main/java/com/vaadin/shared/ui/dnd/criteria/Criterion.java48
-rw-r--r--uitest/src/main/java/com/vaadin/tests/dnd/CriterionSerialization.java59
2 files changed, 103 insertions, 4 deletions
diff --git a/shared/src/main/java/com/vaadin/shared/ui/dnd/criteria/Criterion.java b/shared/src/main/java/com/vaadin/shared/ui/dnd/criteria/Criterion.java
index 73c022a033..e734a5edc1 100644
--- a/shared/src/main/java/com/vaadin/shared/ui/dnd/criteria/Criterion.java
+++ b/shared/src/main/java/com/vaadin/shared/ui/dnd/criteria/Criterion.java
@@ -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);
}
/**
@@ -132,6 +132,16 @@ public class Criterion implements Serializable {
}
/**
+ * 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.
*
* @return value of the payload to be compared
@@ -141,6 +151,16 @@ public class Criterion implements Serializable {
}
/**
+ * 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.
*
* @return type of the payload value to be compared
@@ -150,6 +170,16 @@ public class Criterion implements Serializable {
}
/**
+ * 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.
*
* @return operator to be used when comparing payload value with criterion
@@ -159,6 +189,16 @@ public class Criterion implements Serializable {
}
/**
+ * 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
* done with the payload whose key and value type match the criterion's key
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
index 0000000000..3cc508f64b
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/dnd/CriterionSerialization.java
@@ -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;
+ }
+}