use of org.eclipse.sirius.components.forms.MultiSelect in project sirius-components by eclipse-sirius.
the class EditMultiSelectEventHandlerTests method testMultiSelectEdition.
@Test
public void testMultiSelectEdition() {
// $NON-NLS-1$
String id = "MultiSelect id";
// $NON-NLS-1$ //$NON-NLS-2$
var input = new EditMultiSelectInput(UUID.randomUUID(), UUID.randomUUID().toString(), FORM_ID, id, List.of("true", "false"));
AtomicBoolean hasBeenExecuted = new AtomicBoolean();
Function<List<String>, IStatus> newValuesHandler = newValues -> {
hasBeenExecuted.set(true);
return new Success();
};
// @formatter:off
SelectOption trueOption = // $NON-NLS-1$
SelectOption.newSelectOption("true").label(// $NON-NLS-1$
"True").build();
SelectOption falseOption = // $NON-NLS-1$
SelectOption.newSelectOption("false").label(// $NON-NLS-1$
"False").build();
MultiSelect multiSelect = MultiSelect.newMultiSelect(id).label(// $NON-NLS-1$
"label").values(List.of()).newValuesHandler(newValuesHandler).options(List.of(trueOption, falseOption)).diagnostics(List.of()).build();
Group group = // $NON-NLS-1$
Group.newGroup("groupId").label(// $NON-NLS-1$
"group label").widgets(List.of(multiSelect)).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(multiSelect);
}
};
EditMultiSelectEventHandler handler = new EditMultiSelectEventHandler(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(EditMultiSelectSuccessPayload.class);
assertThat(hasBeenExecuted.get()).isTrue();
}
use of org.eclipse.sirius.components.forms.MultiSelect in project sirius-components by eclipse-sirius.
the class EditMultiSelectEventHandler 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(), EditMultiSelectInput.class.getSimpleName());
IPayload payload = new ErrorPayload(formInput.getId(), message);
ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, formInput.getRepresentationId(), formInput);
if (formInput instanceof EditMultiSelectInput) {
EditMultiSelectInput input = (EditMultiSelectInput) formInput;
// @formatter:off
Optional<MultiSelect> optionalMultiSelect = this.formQueryService.findWidget(form, input.getSelectId()).filter(MultiSelect.class::isInstance).map(MultiSelect.class::cast);
IStatus status = optionalMultiSelect.map(MultiSelect::getNewValuesHandler).map(handler -> handler.apply(input.getNewValues())).orElse(// $NON-NLS-1$
new Failure(""));
if (status instanceof Success) {
payload = new EditMultiSelectSuccessPayload(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);
}
Aggregations