Browse Source

Add setters to Criterion to fix serialization. (#11926) (#11931)

Fixes #11909
tags/8.10.3
Anna Koskinen 4 years ago
parent
commit
76291c6ff3
No account linked to committer's email address

+ 44
- 4
shared/src/main/java/com/vaadin/shared/ui/dnd/criteria/Criterion.java View File

*/ */
private Criterion(String key, ComparisonOperator operator, String value, private Criterion(String key, ComparisonOperator operator, String value,
Payload.ValueType valueType) { Payload.ValueType valueType) {
this.key = key;
this.value = value;
this.valueType = valueType;
this.operator = operator;
setKey(key);
setValue(value);
setValueType(valueType);
setOperator(operator);
} }


/** /**
return key; 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. * Gets the value of the payload to be compared.
* *
return value; 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. * Gets the type of the payload value to be compared.
* *
return valueType; 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. * Gets the comparison operator.
* *
return operator; 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 * Compares this criterion's value to the given payload's value and returns
* whether the result matches the criterion's operator. The comparison is * whether the result matches the criterion's operator. The comparison is

+ 59
- 0
uitest/src/main/java/com/vaadin/tests/dnd/CriterionSerialization.java View File

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;
}
}

Loading…
Cancel
Save