use of org.eclipse.sirius.components.forms.description.RadioDescription in project sirius-components by eclipse-sirius.
the class WidgetComponent method render.
@Override
public Element render() {
VariableManager variableManager = this.props.getVariableManager();
AbstractWidgetDescription widgetDescription = this.props.getWidgetDescription();
Element element = null;
if (widgetDescription instanceof TextfieldDescription) {
TextfieldComponentProps textfieldProps = new TextfieldComponentProps(variableManager, (TextfieldDescription) widgetDescription);
element = new Element(TextfieldComponent.class, textfieldProps);
} else if (widgetDescription instanceof TextareaDescription) {
TextareaComponentProps textareaProps = new TextareaComponentProps(variableManager, (TextareaDescription) widgetDescription);
element = new Element(TextareaComponent.class, textareaProps);
} else if (widgetDescription instanceof CheckboxDescription) {
CheckboxComponentProps checkboxProps = new CheckboxComponentProps(variableManager, (CheckboxDescription) widgetDescription);
element = new Element(CheckboxComponent.class, checkboxProps);
} else if (widgetDescription instanceof SelectDescription) {
SelectComponentProps selectProps = new SelectComponentProps(variableManager, (SelectDescription) widgetDescription);
element = new Element(SelectComponent.class, selectProps);
} else if (widgetDescription instanceof MultiSelectDescription) {
MultiSelectComponentProps multiSelectProps = new MultiSelectComponentProps(variableManager, (MultiSelectDescription) widgetDescription);
element = new Element(MultiSelectComponent.class, multiSelectProps);
} else if (widgetDescription instanceof RadioDescription) {
RadioComponentProps radioProps = new RadioComponentProps(variableManager, (RadioDescription) widgetDescription);
element = new Element(RadioComponent.class, radioProps);
} else if (widgetDescription instanceof ListDescription) {
ListComponentProps listProps = new ListComponentProps(variableManager, (ListDescription) widgetDescription);
element = new Element(ListComponent.class, listProps);
} else if (widgetDescription instanceof LinkDescription) {
LinkComponentProps linkProps = new LinkComponentProps(variableManager, (LinkDescription) widgetDescription);
element = new Element(LinkComponent.class, linkProps);
} else {
// $NON-NLS-1$
String pattern = "Unsupported widget description: {}";
this.logger.warn(pattern, widgetDescription.getClass().getSimpleName());
}
return element;
}
use of org.eclipse.sirius.components.forms.description.RadioDescription 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
}
use of org.eclipse.sirius.components.forms.description.RadioDescription in project sirius-components by eclipse-sirius.
the class WidgetDescriptionConverter method convertRadio.
private RadioDescription convertRadio(org.eclipse.sirius.properties.RadioDescription radioDescription) {
// $NON-NLS-1$
String labelExpression = Optional.ofNullable(radioDescription.getLabelExpression()).orElse("");
StringValueProvider labelProvider = new StringValueProvider(this.interpreter, labelExpression);
Function<VariableManager, String> optionIdProvider = variableManager -> {
Object candidate = variableManager.getVariables().get(RadioComponent.CANDIDATE_VARIABLE);
return this.objectService.getId(candidate);
};
Function<VariableManager, Boolean> optionSelectedProvider = variableManager -> {
Optional<Object> optionalResult = this.interpreter.evaluateExpression(variableManager.getVariables(), radioDescription.getValueExpression()).asObject();
Object candidate = variableManager.getVariables().get(RadioComponent.CANDIDATE_VARIABLE);
return optionalResult.map(candidate::equals).orElse(Boolean.FALSE);
};
Function<VariableManager, List<?>> optionsProvider = variableManager -> {
Optional<List<Object>> optional = this.interpreter.evaluateExpression(variableManager.getVariables(), radioDescription.getCandidatesExpression()).asObjects();
return optional.orElse(Collections.emptyList());
};
// $NON-NLS-1$
String candidateDisplayExpression = Optional.ofNullable(radioDescription.getCandidateDisplayExpression()).orElse("");
StringValueProvider optionLabelProvider = new StringValueProvider(this.interpreter, candidateDisplayExpression);
BiFunction<VariableManager, String, IStatus> newValueHandler = (variableManager, newValue) -> {
VariableManager childVariableManager = variableManager.createChild();
var optionalEditingContext = variableManager.get(IEditingContext.EDITING_CONTEXT, IEditingContext.class);
Optional<Object> optionalObject = optionalEditingContext.flatMap(context -> this.objectService.getObject(context, newValue));
if (optionalObject.isPresent()) {
childVariableManager.put(NEW_VALUE, optionalObject.get());
} else {
childVariableManager.put(NEW_VALUE, newValue);
}
InitialOperation initialOperation = radioDescription.getInitialOperation();
ModelOperation modelOperation = initialOperation.getFirstModelOperations();
var modelOperationHandlerSwitch = this.modelOperationHandlerSwitchProvider.getModelOperationHandlerSwitch(this.interpreter);
Optional<IModelOperationHandler> optionalModelOperationHandler = modelOperationHandlerSwitch.apply(modelOperation);
return optionalModelOperationHandler.map(handler -> {
return handler.handle(childVariableManager.getVariables());
}).orElse(// $NON-NLS-1$
new Failure(""));
};
// @formatter:off
return RadioDescription.newRadioDescription(this.identifierProvider.getIdentifier(radioDescription)).idProvider(new WidgetIdProvider()).labelProvider(labelProvider).optionIdProvider(optionIdProvider).optionLabelProvider(optionLabelProvider).optionSelectedProvider(optionSelectedProvider).optionsProvider(optionsProvider).newValueHandler(newValueHandler).diagnosticsProvider((variableManager) -> List.of()).kindProvider(// $NON-NLS-1$
(object) -> "").messageProvider(// $NON-NLS-1$
(object) -> "").build();
// @formatter:on
}
Aggregations