use of org.eclipse.sirius.components.forms.SelectOption in project sirius-components by eclipse-sirius.
the class MultiSelectComponent method render.
@Override
public Element render() {
VariableManager variableManager = this.props.getVariableManager();
MultiSelectDescription multiSelectDescription = this.props.getMultiSelectDescription();
String id = multiSelectDescription.getIdProvider().apply(variableManager);
String label = multiSelectDescription.getLabelProvider().apply(variableManager);
List<?> optionCandidates = multiSelectDescription.getOptionsProvider().apply(variableManager);
List<String> values = multiSelectDescription.getValuesProvider().apply(variableManager);
List<Element> children = List.of(new Element(DiagnosticComponent.class, new DiagnosticComponentProps(multiSelectDescription, variableManager)));
List<SelectOption> options = new ArrayList<>(optionCandidates.size());
for (Object candidate : optionCandidates) {
VariableManager optionVariableManager = variableManager.createChild();
optionVariableManager.put(CANDIDATE_VARIABLE, candidate);
String optionId = multiSelectDescription.getOptionIdProvider().apply(optionVariableManager);
String optionLabel = multiSelectDescription.getOptionLabelProvider().apply(optionVariableManager);
// @formatter:off
SelectOption option = SelectOption.newSelectOption(optionId).label(optionLabel).build();
// @formatter:on
options.add(option);
}
Function<List<String>, IStatus> newValuesHandler = newValues -> {
return multiSelectDescription.getNewValuesHandler().apply(variableManager, newValues);
};
// @formatter:off
MultiSelectElementProps selectElementProps = MultiSelectElementProps.newMultiSelectElementProps(id).label(label).options(options).values(values).newValuesHandler(newValuesHandler).children(children).build();
return new Element(MultiSelectElementProps.TYPE, selectElementProps);
// @formatter:on
}
use of org.eclipse.sirius.components.forms.SelectOption in project sirius-components by eclipse-sirius.
the class EditSelectEventHandlerTests method testSelectEdition.
@Test
public void testSelectEdition() {
// $NON-NLS-1$
String id = "Select id";
// $NON-NLS-1$
var input = new EditSelectInput(UUID.randomUUID(), UUID.randomUUID().toString(), FORM_ID, id, "false");
AtomicBoolean hasBeenExecuted = new AtomicBoolean();
Function<String, IStatus> newValueHandler = newValue -> {
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();
Select select = Select.newSelect(id).label(// $NON-NLS-1$
"label").value(// $NON-NLS-1$
"true").newValueHandler(newValueHandler).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(select)).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(select);
}
};
EditSelectEventHandler handler = new EditSelectEventHandler(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(EditSelectSuccessPayload.class);
assertThat(hasBeenExecuted.get()).isTrue();
}
use of org.eclipse.sirius.components.forms.SelectOption 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.SelectOption in project sirius-components by eclipse-sirius.
the class WidgetAssert method assertSelect.
private void assertSelect(Select actualSelect, Select select, IdPolicy idPolicy) {
assertThat(actualSelect.getLabel()).isEqualTo(select.getLabel());
assertThat(actualSelect.getOptions().size()).isEqualTo(select.getOptions().size());
int size = actualSelect.getOptions().size();
for (int i = 0; i < size; i++) {
SelectOption actualSelectOption = actualSelect.getOptions().get(i);
SelectOption selectOption = select.getOptions().get(i);
assertThatObject(actualSelectOption).isNotNull();
if (idPolicy == IdPolicy.WITH_ID) {
assertThat(actualSelectOption.getId()).isEqualTo(selectOption.getId());
}
assertThat(actualSelectOption.getLabel()).isEqualTo(selectOption.getLabel());
}
}
use of org.eclipse.sirius.components.forms.SelectOption in project sirius-components by eclipse-sirius.
the class SelectComponent method render.
@Override
public Element render() {
VariableManager variableManager = this.props.getVariableManager();
SelectDescription selectDescription = this.props.getSelectDescription();
String id = selectDescription.getIdProvider().apply(variableManager);
String label = selectDescription.getLabelProvider().apply(variableManager);
List<?> optionCandidates = selectDescription.getOptionsProvider().apply(variableManager);
String value = selectDescription.getValueProvider().apply(variableManager);
List<Element> children = List.of(new Element(DiagnosticComponent.class, new DiagnosticComponentProps(selectDescription, variableManager)));
List<SelectOption> options = new ArrayList<>(optionCandidates.size());
for (Object candidate : optionCandidates) {
VariableManager optionVariableManager = variableManager.createChild();
optionVariableManager.put(CANDIDATE_VARIABLE, candidate);
String optionId = selectDescription.getOptionIdProvider().apply(optionVariableManager);
String optionLabel = selectDescription.getOptionLabelProvider().apply(optionVariableManager);
// @formatter:off
SelectOption option = SelectOption.newSelectOption(optionId).label(optionLabel).build();
// @formatter:on
options.add(option);
}
Function<String, IStatus> specializedHandler = newValue -> {
return selectDescription.getNewValueHandler().apply(variableManager, newValue);
};
// @formatter:off
SelectElementProps selectElementProps = SelectElementProps.newSelectElementProps(id).label(label).options(options).value(value).newValueHandler(specializedHandler).children(children).build();
return new Element(SelectElementProps.TYPE, selectElementProps);
// @formatter:on
}
Aggregations