use of org.eclipse.sirius.components.forms.Checkbox in project sirius-components by eclipse-sirius.
the class WidgetAssert method matches.
public WidgetAssert matches(AbstractWidget widget, IdPolicy idPolicy) {
this.isNotNull();
if (idPolicy == IdPolicy.WITH_ID) {
assertThat(this.actual.getId()).isEqualTo(widget.getId());
}
if (this.actual instanceof List && widget instanceof List) {
List actualList = (List) this.actual;
List list = (List) widget;
assertThat(actualList.getLabel()).isEqualTo(list.getLabel());
assertThat(actualList.getItems().size()).isEqualTo(list.getItems().size());
int size = actualList.getItems().size();
for (int i = 0; i < size; i++) {
ListItem actualListItem = actualList.getItems().get(i);
ListItem listItem = list.getItems().get(i);
assertThat(actualListItem).matches(listItem, idPolicy);
}
} else if (this.actual instanceof Checkbox && widget instanceof Checkbox) {
Checkbox actualCheckbox = (Checkbox) this.actual;
Checkbox checkbox = (Checkbox) widget;
assertThat(actualCheckbox.getLabel()).isEqualTo(checkbox.getLabel());
assertThat(actualCheckbox.isValue()).isEqualTo(checkbox.isValue());
} else if (this.actual instanceof Radio && widget instanceof Radio) {
this.assertRadio((Radio) this.actual, (Radio) widget, idPolicy);
} else if (this.actual instanceof Select && widget instanceof Select) {
this.assertSelect((Select) this.actual, (Select) widget, idPolicy);
} else if (this.actual instanceof Textarea && widget instanceof Textarea) {
Textarea actualTextarea = (Textarea) this.actual;
Textarea textarea = (Textarea) widget;
assertThat(actualTextarea.getLabel()).isEqualTo(textarea.getLabel());
assertThat(actualTextarea.getValue()).isEqualTo(textarea.getValue());
} else if (this.actual instanceof Textfield && widget instanceof Textfield) {
Textfield actualTextfield = (Textfield) this.actual;
Textfield textfield = (Textfield) widget;
assertThat(actualTextfield.getLabel()).isEqualTo(textfield.getLabel());
assertThat(actualTextfield.getValue()).isEqualTo(textfield.getValue());
}
return this;
}
use of org.eclipse.sirius.components.forms.Checkbox in project sirius-components by eclipse-sirius.
the class EditCheckboxEventHandler method handle.
@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, Form form, IFormInput formInput) {
this.counter.increment();
String message = this.messageService.invalidInput(formInput.getClass().getSimpleName(), EditCheckboxInput.class.getSimpleName());
IPayload payload = new ErrorPayload(formInput.getId(), message);
ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, formInput.getRepresentationId(), formInput);
if (formInput instanceof EditCheckboxInput) {
EditCheckboxInput input = (EditCheckboxInput) formInput;
// @formatter:off
var optionalCheckbox = this.formQueryService.findWidget(form, input.getCheckboxId()).filter(Checkbox.class::isInstance).map(Checkbox.class::cast);
IStatus status = optionalCheckbox.map(Checkbox::getNewValueHandler).map(handler -> handler.apply(input.getNewValue())).orElse(// $NON-NLS-1$
new Failure(""));
if (status instanceof Success) {
payload = new EditCheckboxSuccessPayload(formInput.getId());
changeDescription = new ChangeDescription(ChangeKind.SEMANTIC_CHANGE, formInput.getRepresentationId(), formInput);
} else if (status instanceof Failure) {
payload = new ErrorPayload(formInput.getId(), ((Failure) status).getMessage());
}
}
changeDescriptionSink.tryEmitNext(changeDescription);
payloadSink.tryEmitValue(payload);
}
use of org.eclipse.sirius.components.forms.Checkbox in project sirius-components by eclipse-sirius.
the class EditCheckboxEventHandlerTests method testCheckboxEdition.
@Test
public void testCheckboxEdition() {
// $NON-NLS-1$
String id = "Checkbox id";
var input = new EditCheckboxInput(UUID.randomUUID(), UUID.randomUUID().toString(), FORM_ID, id, true);
AtomicBoolean hasBeenExecuted = new AtomicBoolean();
Function<Boolean, IStatus> newValueHandler = newValue -> {
hasBeenExecuted.set(true);
return new Success();
};
// @formatter:off
Checkbox checkbox = Checkbox.newCheckbox(id).label(// $NON-NLS-1$
"label").newValueHandler(newValueHandler).diagnostics(List.of()).build();
Group group = // $NON-NLS-1$
Group.newGroup("groupId").label(// $NON-NLS-1$
"group label").widgets(List.of(checkbox)).build();
Page page = // $NON-NLS-1$
Page.newPage("pageId").label(// $NON-NLS-1$
"page label").groups(List.of(group)).build();
Form form = Form.newForm(FORM_ID).targetObjectId(// $NON-NLS-1$
"targetObjectId").descriptionId(UUID.randomUUID()).label(// $NON-NLS-1$
"form label").pages(List.of(page)).build();
// @formatter:on
IFormQueryService formQueryService = new IFormQueryService.NoOp() {
@Override
public Optional<AbstractWidget> findWidget(Form form, String widgetId) {
return Optional.of(checkbox);
}
};
EditCheckboxEventHandler handler = new EditCheckboxEventHandler(formQueryService, new ICollaborativeFormMessageService.NoOp(), new SimpleMeterRegistry());
assertThat(handler.canHandle(input)).isTrue();
Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
One<IPayload> payloadSink = Sinks.one();
handler.handle(payloadSink, changeDescriptionSink, form, input);
ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.SEMANTIC_CHANGE);
IPayload payload = payloadSink.asMono().block();
assertThat(payload).isInstanceOf(EditCheckboxSuccessPayload.class);
assertThat(hasBeenExecuted.get()).isTrue();
}
Aggregations