Search in sources :

Example 1 with RadioOption

use of org.eclipse.sirius.components.forms.RadioOption in project sirius-components by eclipse-sirius.

the class WidgetAssert method assertRadio.

private void assertRadio(Radio actualRadio, Radio radio, IdPolicy idPolicy) {
    assertThat(actualRadio.getLabel()).isEqualTo(radio.getLabel());
    assertThat(actualRadio.getOptions().size()).isEqualTo(radio.getOptions().size());
    int size = actualRadio.getOptions().size();
    for (int i = 0; i < size; i++) {
        RadioOption actualRadioOption = actualRadio.getOptions().get(i);
        RadioOption radioOption = radio.getOptions().get(i);
        assertThatObject(actualRadioOption).isNotNull();
        if (idPolicy == IdPolicy.WITH_ID) {
            assertThat(actualRadioOption.getId()).isEqualTo(radioOption.getId());
        }
        assertThat(actualRadioOption.getLabel()).isEqualTo(radioOption.getLabel());
        assertThat(actualRadioOption.isSelected()).isEqualTo(radioOption.isSelected());
    }
}
Also used : RadioOption(org.eclipse.sirius.components.forms.RadioOption)

Example 2 with RadioOption

use of org.eclipse.sirius.components.forms.RadioOption in project sirius-components by eclipse-sirius.

the class RadioComponent method render.

@Override
public Element render() {
    VariableManager variableManager = this.props.getVariableManager();
    RadioDescription radioDescription = this.props.getRadioDescription();
    String id = radioDescription.getIdProvider().apply(variableManager);
    String label = radioDescription.getLabelProvider().apply(variableManager);
    List<?> optionCandidates = radioDescription.getOptionsProvider().apply(variableManager);
    List<Element> children = List.of(new Element(DiagnosticComponent.class, new DiagnosticComponentProps(radioDescription, variableManager)));
    List<RadioOption> options = new ArrayList<>(optionCandidates.size());
    for (Object candidate : optionCandidates) {
        VariableManager optionVariableManager = variableManager.createChild();
        optionVariableManager.put(CANDIDATE_VARIABLE, candidate);
        String optionId = radioDescription.getOptionIdProvider().apply(optionVariableManager);
        String optionLabel = radioDescription.getOptionLabelProvider().apply(optionVariableManager);
        Boolean optionSelected = radioDescription.getOptionSelectedProvider().apply(optionVariableManager);
        // @formatter:off
        RadioOption option = RadioOption.newRadioOption(optionId).label(optionLabel).selected(optionSelected).build();
        // @formatter:on
        options.add(option);
    }
    BiFunction<VariableManager, String, IStatus> genericHandler = radioDescription.getNewValueHandler();
    Function<String, IStatus> specializedHandler = newValue -> {
        return genericHandler.apply(variableManager, newValue);
    };
    // @formatter:off
    RadioElementProps radioElementProps = RadioElementProps.newRadioElementProps(id).label(label).options(options).newValueHandler(specializedHandler).children(children).build();
    return new Element(RadioElementProps.TYPE, radioElementProps);
// @formatter:on
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) BiFunction(java.util.function.BiFunction) Function(java.util.function.Function) Element(org.eclipse.sirius.components.representations.Element) IComponent(org.eclipse.sirius.components.representations.IComponent) ArrayList(java.util.ArrayList) Objects(java.util.Objects) List(java.util.List) RadioElementProps(org.eclipse.sirius.components.forms.elements.RadioElementProps) IStatus(org.eclipse.sirius.components.representations.IStatus) DiagnosticComponentProps(org.eclipse.sirius.components.forms.validation.DiagnosticComponentProps) RadioDescription(org.eclipse.sirius.components.forms.description.RadioDescription) VariableManager(org.eclipse.sirius.components.representations.VariableManager) RadioOption(org.eclipse.sirius.components.forms.RadioOption) DiagnosticComponent(org.eclipse.sirius.components.forms.validation.DiagnosticComponent) IStatus(org.eclipse.sirius.components.representations.IStatus) RadioDescription(org.eclipse.sirius.components.forms.description.RadioDescription) Element(org.eclipse.sirius.components.representations.Element) DiagnosticComponentProps(org.eclipse.sirius.components.forms.validation.DiagnosticComponentProps) ArrayList(java.util.ArrayList) DiagnosticComponent(org.eclipse.sirius.components.forms.validation.DiagnosticComponent) RadioElementProps(org.eclipse.sirius.components.forms.elements.RadioElementProps) RadioOption(org.eclipse.sirius.components.forms.RadioOption)

Example 3 with RadioOption

use of org.eclipse.sirius.components.forms.RadioOption in project sirius-components by eclipse-sirius.

the class EditRadioEventHandlerTests method testRadioEdition.

@Test
public void testRadioEdition() {
    // $NON-NLS-1$
    String id = "Radio id";
    // $NON-NLS-1$
    var input = new EditRadioInput(UUID.randomUUID(), UUID.randomUUID().toString(), FORM_ID, id, "optionId");
    AtomicBoolean hasBeenExecuted = new AtomicBoolean();
    Function<String, IStatus> newValueHandler = newValue -> {
        hasBeenExecuted.set(true);
        return new Success();
    };
    // @formatter:off
    RadioOption option = // $NON-NLS-1$
    RadioOption.newRadioOption("optionId").label(// $NON-NLS-1$
    "Option label").selected(false).build();
    Radio radio = Radio.newRadio(id).label(// $NON-NLS-1$
    "label").newValueHandler(newValueHandler).options(List.of(option)).diagnostics(List.of()).build();
    Group group = // $NON-NLS-1$
    Group.newGroup("groupId").label(// $NON-NLS-1$
    "group label").widgets(List.of(radio)).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(radio);
        }
    };
    EditRadioEventHandler handler = new EditRadioEventHandler(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(EditRadioSuccessPayload.class);
    assertThat(hasBeenExecuted.get()).isTrue();
}
Also used : EditRadioInput(org.eclipse.sirius.components.collaborative.forms.dto.EditRadioInput) Sinks(reactor.core.publisher.Sinks) Form(org.eclipse.sirius.components.forms.Form) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) One(reactor.core.publisher.Sinks.One) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Function(java.util.function.Function) AbstractWidget(org.eclipse.sirius.components.forms.AbstractWidget) IFormQueryService(org.eclipse.sirius.components.collaborative.forms.api.IFormQueryService) EditRadioSuccessPayload(org.eclipse.sirius.components.collaborative.forms.dto.EditRadioSuccessPayload) IStatus(org.eclipse.sirius.components.representations.IStatus) Radio(org.eclipse.sirius.components.forms.Radio) Page(org.eclipse.sirius.components.forms.Page) RadioOption(org.eclipse.sirius.components.forms.RadioOption) ChangeKind(org.eclipse.sirius.components.collaborative.api.ChangeKind) Success(org.eclipse.sirius.components.representations.Success) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test) List(java.util.List) ICollaborativeFormMessageService(org.eclipse.sirius.components.collaborative.forms.messages.ICollaborativeFormMessageService) IPayload(org.eclipse.sirius.components.core.api.IPayload) Group(org.eclipse.sirius.components.forms.Group) Many(reactor.core.publisher.Sinks.Many) Optional(java.util.Optional) Group(org.eclipse.sirius.components.forms.Group) IStatus(org.eclipse.sirius.components.representations.IStatus) ICollaborativeFormMessageService(org.eclipse.sirius.components.collaborative.forms.messages.ICollaborativeFormMessageService) Form(org.eclipse.sirius.components.forms.Form) IFormQueryService(org.eclipse.sirius.components.collaborative.forms.api.IFormQueryService) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Radio(org.eclipse.sirius.components.forms.Radio) Page(org.eclipse.sirius.components.forms.Page) Success(org.eclipse.sirius.components.representations.Success) IPayload(org.eclipse.sirius.components.core.api.IPayload) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EditRadioInput(org.eclipse.sirius.components.collaborative.forms.dto.EditRadioInput) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) AbstractWidget(org.eclipse.sirius.components.forms.AbstractWidget) RadioOption(org.eclipse.sirius.components.forms.RadioOption) Test(org.junit.jupiter.api.Test)

Aggregations

RadioOption (org.eclipse.sirius.components.forms.RadioOption)3 List (java.util.List)2 Function (java.util.function.Function)2 IStatus (org.eclipse.sirius.components.representations.IStatus)2 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)1 ArrayList (java.util.ArrayList)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 BiFunction (java.util.function.BiFunction)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)1 ChangeKind (org.eclipse.sirius.components.collaborative.api.ChangeKind)1 IFormQueryService (org.eclipse.sirius.components.collaborative.forms.api.IFormQueryService)1 EditRadioInput (org.eclipse.sirius.components.collaborative.forms.dto.EditRadioInput)1 EditRadioSuccessPayload (org.eclipse.sirius.components.collaborative.forms.dto.EditRadioSuccessPayload)1 ICollaborativeFormMessageService (org.eclipse.sirius.components.collaborative.forms.messages.ICollaborativeFormMessageService)1 IPayload (org.eclipse.sirius.components.core.api.IPayload)1 AbstractWidget (org.eclipse.sirius.components.forms.AbstractWidget)1