summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--shared/src/main/java/com/vaadin/shared/ui/dnd/criteria/Payload.java30
-rw-r--r--uitest/src/main/java/com/vaadin/tests/dnd/DragAndDropPayload.java55
2 files changed, 85 insertions, 0 deletions
diff --git a/shared/src/main/java/com/vaadin/shared/ui/dnd/criteria/Payload.java b/shared/src/main/java/com/vaadin/shared/ui/dnd/criteria/Payload.java
index 45be1533b9..ecaa045577 100644
--- a/shared/src/main/java/com/vaadin/shared/ui/dnd/criteria/Payload.java
+++ b/shared/src/main/java/com/vaadin/shared/ui/dnd/criteria/Payload.java
@@ -76,6 +76,16 @@ public class Payload implements Serializable {
}
/**
+ * Sets the key of this payload.
+ *
+ * @param key
+ * key that identifies the payload
+ */
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ /**
* Gets the value of this payload.
*
* @return value of this payload
@@ -85,6 +95,16 @@ public class Payload implements Serializable {
}
/**
+ * Sets the value of this payload.
+ *
+ * @param value
+ * value of the payload
+ */
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ /**
* Gets the value type of this payload.
*
* @return the type of the value of this payload
@@ -94,6 +114,16 @@ public class Payload implements Serializable {
}
/**
+ * Sets the value type of this payload.
+ *
+ * @param valueType
+ * type of the payload value
+ */
+ public void setValueType(ValueType valueType) {
+ this.valueType = valueType;
+ }
+
+ /**
* Returns the string representation of this payload. It is used as the data
* type in the {@code DataTransfer} object.
*
diff --git a/uitest/src/main/java/com/vaadin/tests/dnd/DragAndDropPayload.java b/uitest/src/main/java/com/vaadin/tests/dnd/DragAndDropPayload.java
new file mode 100644
index 0000000000..050317358e
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/dnd/DragAndDropPayload.java
@@ -0,0 +1,55 @@
+package com.vaadin.tests.dnd;
+
+import com.vaadin.annotations.Widgetset;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.shared.ui.dnd.criteria.Payload;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.dnd.DragSourceExtension;
+import com.vaadin.ui.dnd.DropTargetExtension;
+
+@Widgetset("com.vaadin.DefaultWidgetSet")
+public class DragAndDropPayload extends AbstractTestUIWithLog {
+
+ private final Label stringLabel = new Label(
+ "Drag source with string payload");
+ private final Label integerLabel = new Label(
+ "Drag source with integer payload");
+ private final Label doubleLabel = new Label(
+ "Drag source with double payload");
+
+ private final Label targetLabel = new Label("Drop target");
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ DragSourceExtension<Label> stringDragSource = new DragSourceExtension<>(
+ stringLabel);
+ stringDragSource.setPayload("payload_key", "string_value");
+
+ DragSourceExtension<Label> integerDragSource = new DragSourceExtension<>(
+ integerLabel);
+ integerDragSource.setPayload("payload_key", 42);
+
+ DragSourceExtension<Label> doubleDragSource = new DragSourceExtension<>(
+ doubleLabel);
+ doubleDragSource.setPayload("payload_key", 3.14);
+
+ DropTargetExtension<Label> dropTarget = new DropTargetExtension<>(
+ targetLabel);
+ dropTarget.addDropListener(event ->
+ event.getDataTransferData().entrySet().stream()
+ .filter(entry -> entry.getKey()
+ .startsWith(Payload.ITEM_PREFIX)).forEach(
+ entry -> log.log(entry.getKey() + " -> " + entry
+ .getValue()))
+ );
+
+ VerticalLayout dragSources = new VerticalLayout(stringLabel,
+ integerLabel, doubleLabel);
+ VerticalLayout dropTargets = new VerticalLayout(targetLabel);
+ getLayout()
+ .addComponent(new HorizontalLayout(dragSources, dropTargets));
+ }
+}