Search in sources :

Example 1 with BooleanValueProvider

use of org.eclipse.sirius.components.compatibility.utils.BooleanValueProvider in project sirius-components by eclipse-sirius.

the class WidgetDescriptionConverter method convertCheckbox.

private CheckboxDescription convertCheckbox(org.eclipse.sirius.properties.CheckboxDescription checkboxDescription) {
    StringValueProvider labelProvider = new StringValueProvider(this.interpreter, checkboxDescription.getLabelExpression());
    BiFunction<VariableManager, Boolean, IStatus> newValueHandler = (variableManager, newValue) -> {
        Map<String, Object> variables = variableManager.getVariables();
        variables.put(NEW_VALUE, newValue);
        InitialOperation initialOperation = checkboxDescription.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(""));
    };
    // $NON-NLS-1$
    String valueExpression = Optional.ofNullable(checkboxDescription.getValueExpression()).orElse("");
    Function<VariableManager, Boolean> valueProvider = new BooleanValueProvider(this.interpreter, valueExpression);
    // @formatter:off
    return CheckboxDescription.newCheckboxDescription(this.identifierProvider.getIdentifier(checkboxDescription)).idProvider(new WidgetIdProvider()).labelProvider(labelProvider).valueProvider(valueProvider).newValueHandler(newValueHandler).diagnosticsProvider((variableManager) -> List.of()).kindProvider(// $NON-NLS-1$
    (object) -> "").messageProvider(// $NON-NLS-1$
    (object) -> "").build();
// @formatter:on
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) BiFunction(java.util.function.BiFunction) InitialOperation(org.eclipse.sirius.viewpoint.description.tool.InitialOperation) LoggerFactory(org.slf4j.LoggerFactory) SelectComponent(org.eclipse.sirius.components.forms.components.SelectComponent) Function(java.util.function.Function) ArrayList(java.util.ArrayList) TextareaDescription(org.eclipse.sirius.components.forms.description.TextareaDescription) IStatus(org.eclipse.sirius.components.representations.IStatus) StringValueProvider(org.eclipse.sirius.components.compatibility.utils.StringValueProvider) TextfieldDescription(org.eclipse.sirius.components.forms.description.TextfieldDescription) Map(java.util.Map) WidgetDescription(org.eclipse.sirius.properties.WidgetDescription) CheckboxDescription(org.eclipse.sirius.components.forms.description.CheckboxDescription) Logger(org.slf4j.Logger) AbstractWidgetDescription(org.eclipse.sirius.components.forms.description.AbstractWidgetDescription) Failure(org.eclipse.sirius.components.representations.Failure) IModelOperationHandlerSwitchProvider(org.eclipse.sirius.components.compatibility.api.IModelOperationHandlerSwitchProvider) SelectDescription(org.eclipse.sirius.components.forms.description.SelectDescription) BooleanValueProvider(org.eclipse.sirius.components.compatibility.utils.BooleanValueProvider) IModelOperationHandler(org.eclipse.sirius.components.compatibility.api.IModelOperationHandler) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) Objects(java.util.Objects) RadioComponent(org.eclipse.sirius.components.forms.components.RadioComponent) List(java.util.List) ModelOperation(org.eclipse.sirius.viewpoint.description.tool.ModelOperation) Optional(java.util.Optional) RadioDescription(org.eclipse.sirius.components.forms.description.RadioDescription) VariableManager(org.eclipse.sirius.components.representations.VariableManager) Collections(java.util.Collections) IIdentifierProvider(org.eclipse.sirius.components.compatibility.api.IIdentifierProvider) InitialOperation(org.eclipse.sirius.viewpoint.description.tool.InitialOperation) IStatus(org.eclipse.sirius.components.representations.IStatus) StringValueProvider(org.eclipse.sirius.components.compatibility.utils.StringValueProvider) Optional(java.util.Optional) BooleanValueProvider(org.eclipse.sirius.components.compatibility.utils.BooleanValueProvider) ModelOperation(org.eclipse.sirius.viewpoint.description.tool.ModelOperation) Map(java.util.Map) Failure(org.eclipse.sirius.components.representations.Failure)

Example 2 with BooleanValueProvider

use of org.eclipse.sirius.components.compatibility.utils.BooleanValueProvider in project sirius-components by eclipse-sirius.

the class IfDescriptionConverter method convert.

public Optional<IfDescription> convert(org.eclipse.sirius.properties.DynamicMappingIfDescription siriusIfDescription) {
    BooleanValueProvider predicate = new BooleanValueProvider(this.interpreter, siriusIfDescription.getPredicateExpression());
    WidgetDescriptionConverter converter = new WidgetDescriptionConverter(this.interpreter, this.objectService, this.identifierProvider, this.modelOperationHandlerSwitchProvider);
    Optional<AbstractWidgetDescription> optionalWidgetDescription = converter.convert(siriusIfDescription.getWidget());
    return optionalWidgetDescription.map(widgetDescription -> {
        // @formatter:off
        return IfDescription.newIfDescription(this.identifierProvider.getIdentifier(siriusIfDescription)).predicate(predicate).widgetDescription(widgetDescription).build();
    // @formatter:on
    });
}
Also used : BooleanValueProvider(org.eclipse.sirius.components.compatibility.utils.BooleanValueProvider) AbstractWidgetDescription(org.eclipse.sirius.components.forms.description.AbstractWidgetDescription)

Aggregations

BooleanValueProvider (org.eclipse.sirius.components.compatibility.utils.BooleanValueProvider)2 AbstractWidgetDescription (org.eclipse.sirius.components.forms.description.AbstractWidgetDescription)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 BiFunction (java.util.function.BiFunction)1 Function (java.util.function.Function)1 IIdentifierProvider (org.eclipse.sirius.components.compatibility.api.IIdentifierProvider)1 IModelOperationHandler (org.eclipse.sirius.components.compatibility.api.IModelOperationHandler)1 IModelOperationHandlerSwitchProvider (org.eclipse.sirius.components.compatibility.api.IModelOperationHandlerSwitchProvider)1 StringValueProvider (org.eclipse.sirius.components.compatibility.utils.StringValueProvider)1 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)1 IObjectService (org.eclipse.sirius.components.core.api.IObjectService)1 RadioComponent (org.eclipse.sirius.components.forms.components.RadioComponent)1 SelectComponent (org.eclipse.sirius.components.forms.components.SelectComponent)1 CheckboxDescription (org.eclipse.sirius.components.forms.description.CheckboxDescription)1 RadioDescription (org.eclipse.sirius.components.forms.description.RadioDescription)1