use of org.eclipse.sirius.components.forms.description.SelectDescription 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.SelectDescription in project sirius-components by eclipse-sirius.
the class WidgetDescriptionConverter method convertSelect.
private SelectDescription convertSelect(org.eclipse.sirius.properties.SelectDescription selectDescription) {
// @formatter:off
StringValueProvider labelProvider = new StringValueProvider(this.interpreter, selectDescription.getLabelExpression());
Function<VariableManager, String> valueProvider = variableManager -> {
String valueExpression = selectDescription.getValueExpression();
return this.interpreter.evaluateExpression(variableManager.getVariables(), valueExpression).asObject().map(this.objectService::getId).orElse(null);
};
// @formatter:on
Function<VariableManager, List<?>> optionsProvider = (variableManager) -> {
String candidateExpression = selectDescription.getCandidatesExpression();
return this.interpreter.evaluateExpression(variableManager.getVariables(), candidateExpression).asObjects().orElse(new ArrayList<>());
};
// $NON-NLS-1$
String candidateDisplayExpression = Optional.ofNullable(selectDescription.getCandidateDisplayExpression()).orElse("");
StringValueProvider optionLabelProvider = new StringValueProvider(this.interpreter, candidateDisplayExpression);
Function<VariableManager, String> optionIdProvider = variableManager -> {
Object candidate = variableManager.getVariables().get(SelectComponent.CANDIDATE_VARIABLE);
return this.objectService.getId(candidate);
};
BiFunction<VariableManager, String, IStatus> newValueHandler = (variableManager, newValue) -> {
Map<String, Object> variables = variableManager.getVariables();
variables.put(NEW_VALUE, newValue);
InitialOperation initialOperation = selectDescription.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(variables);
}).orElse(// $NON-NLS-1$
new Failure(""));
};
// @formatter:off
return SelectDescription.newSelectDescription(this.identifierProvider.getIdentifier(selectDescription)).idProvider(new WidgetIdProvider()).labelProvider(labelProvider).valueProvider(valueProvider).optionsProvider(optionsProvider).optionIdProvider(optionIdProvider).optionLabelProvider(optionLabelProvider).newValueHandler(newValueHandler).diagnosticsProvider((variableManager) -> List.of()).kindProvider(// $NON-NLS-1$
(object) -> "").messageProvider(// $NON-NLS-1$
(object) -> "").build();
// @formatter:on
}
use of org.eclipse.sirius.components.forms.description.SelectDescription 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