Search in sources :

Example 1 with IModelOperationHandler

use of org.eclipse.sirius.components.compatibility.api.IModelOperationHandler in project sirius-components by eclipse-sirius.

the class ChildModelOperationHandler method handle.

public IStatus handle(IObjectService objectService, IRepresentationMetadataSearchService representationMetadataSearchService, IIdentifierProvider identifierProvider, AQLInterpreter interpreter, Map<String, Object> variables, List<ModelOperation> modelOperations) {
    Success success = new Success();
    boolean hasBeenSuccessfullyExecuted = true;
    ModelOperationHandlerSwitch modelOperationHandlerSwitch = new ModelOperationHandlerSwitch(objectService, representationMetadataSearchService, identifierProvider, this.externalJavaActionProviders, interpreter);
    for (ModelOperation modelOperation : modelOperations) {
        Optional<IModelOperationHandler> optionalModelOperationHandler = modelOperationHandlerSwitch.apply(modelOperation);
        IStatus status = optionalModelOperationHandler.map(handler -> {
            return handler.handle(variables);
        }).orElse(// $NON-NLS-1$
        new Failure(""));
        hasBeenSuccessfullyExecuted = hasBeenSuccessfullyExecuted && status instanceof Success;
        if (hasBeenSuccessfullyExecuted) {
            // @formatter:off
            var optionalChildModelOperationNewSelection = Optional.of(status).filter(Success.class::isInstance).map(Success.class::cast).map(result -> result.getParameters().get(Success.NEW_SELECTION)).filter(WorkbenchSelection.class::isInstance).map(WorkbenchSelection.class::cast);
            if (optionalChildModelOperationNewSelection.isPresent()) {
                WorkbenchSelection childWorkbenchSelection = optionalChildModelOperationNewSelection.get();
                Object newSelection = success.getParameters().get(Success.NEW_SELECTION);
                if (newSelection instanceof WorkbenchSelection) {
                    ((WorkbenchSelection) newSelection).getEntries().addAll(childWorkbenchSelection.getEntries());
                } else if (newSelection == null) {
                    success.getParameters().put(Success.NEW_SELECTION, new WorkbenchSelection(childWorkbenchSelection.getEntries()));
                }
            }
        }
    }
    if (hasBeenSuccessfullyExecuted) {
        return success;
    }
    // $NON-NLS-1$
    return new Failure("");
}
Also used : Failure(org.eclipse.sirius.components.representations.Failure) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) Success(org.eclipse.sirius.components.representations.Success) IModelOperationHandler(org.eclipse.sirius.components.compatibility.api.IModelOperationHandler) WorkbenchSelection(org.eclipse.sirius.components.core.api.WorkbenchSelection) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) IRepresentationMetadataSearchService(org.eclipse.sirius.components.core.api.IRepresentationMetadataSearchService) Objects(java.util.Objects) List(java.util.List) IStatus(org.eclipse.sirius.components.representations.IStatus) ModelOperation(org.eclipse.sirius.viewpoint.description.tool.ModelOperation) Map(java.util.Map) Optional(java.util.Optional) IExternalJavaActionProvider(org.eclipse.sirius.components.emf.compatibility.api.IExternalJavaActionProvider) IIdentifierProvider(org.eclipse.sirius.components.compatibility.api.IIdentifierProvider) IModelOperationHandler(org.eclipse.sirius.components.compatibility.api.IModelOperationHandler) IStatus(org.eclipse.sirius.components.representations.IStatus) ModelOperation(org.eclipse.sirius.viewpoint.description.tool.ModelOperation) WorkbenchSelection(org.eclipse.sirius.components.core.api.WorkbenchSelection) Success(org.eclipse.sirius.components.representations.Success) Failure(org.eclipse.sirius.components.representations.Failure)

Example 2 with IModelOperationHandler

use of org.eclipse.sirius.components.compatibility.api.IModelOperationHandler 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
}
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) ArrayList(java.util.ArrayList) ModelOperation(org.eclipse.sirius.viewpoint.description.tool.ModelOperation) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Failure(org.eclipse.sirius.components.representations.Failure)

Example 3 with IModelOperationHandler

use of org.eclipse.sirius.components.compatibility.api.IModelOperationHandler 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 4 with IModelOperationHandler

use of org.eclipse.sirius.components.compatibility.api.IModelOperationHandler 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
}
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) ModelOperation(org.eclipse.sirius.viewpoint.description.tool.ModelOperation) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) ArrayList(java.util.ArrayList) List(java.util.List) Failure(org.eclipse.sirius.components.representations.Failure)

Aggregations

List (java.util.List)4 Map (java.util.Map)4 Objects (java.util.Objects)4 Optional (java.util.Optional)4 IIdentifierProvider (org.eclipse.sirius.components.compatibility.api.IIdentifierProvider)4 IModelOperationHandler (org.eclipse.sirius.components.compatibility.api.IModelOperationHandler)4 IObjectService (org.eclipse.sirius.components.core.api.IObjectService)4 AQLInterpreter (org.eclipse.sirius.components.interpreter.AQLInterpreter)4 Failure (org.eclipse.sirius.components.representations.Failure)4 IStatus (org.eclipse.sirius.components.representations.IStatus)4 ModelOperation (org.eclipse.sirius.viewpoint.description.tool.ModelOperation)4 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 BiFunction (java.util.function.BiFunction)3 Function (java.util.function.Function)3 IModelOperationHandlerSwitchProvider (org.eclipse.sirius.components.compatibility.api.IModelOperationHandlerSwitchProvider)3 BooleanValueProvider (org.eclipse.sirius.components.compatibility.utils.BooleanValueProvider)3 StringValueProvider (org.eclipse.sirius.components.compatibility.utils.StringValueProvider)3 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)3 RadioComponent (org.eclipse.sirius.components.forms.components.RadioComponent)3