Search in sources :

Example 1 with Default

use of org.eclipse.sirius.viewpoint.description.tool.Default in project sirius-components by eclipse-sirius.

the class SwitchOperationHandler method handle.

@Override
public IStatus handle(Map<String, Object> variables) {
    EList<Case> switchCases = this.switchOperation.getCases();
    Map<String, Object> childVariables = new HashMap<>(variables);
    IStatus status = new Success();
    boolean oneCaseHasBeenExecuted = false;
    for (Case switchCase : switchCases) {
        String conditionExpression = switchCase.getConditionExpression();
        if (conditionExpression != null) {
            Optional<Boolean> optionalValueObject = this.interpreter.evaluateExpression(variables, conditionExpression).asBoolean();
            if (optionalValueObject.isPresent() && optionalValueObject.get()) {
                List<ModelOperation> subModelOperations = switchCase.getSubModelOperations();
                status = this.childModelOperationHandler.handle(this.objectService, this.representationMetadataSearchService, this.identifierProvider, this.interpreter, childVariables, subModelOperations);
                oneCaseHasBeenExecuted = true;
                break;
            }
        }
    }
    if (!oneCaseHasBeenExecuted) {
        Default defaultCase = this.switchOperation.getDefault();
        if (defaultCase != null) {
            List<ModelOperation> subModelOperations = defaultCase.getSubModelOperations();
            status = this.childModelOperationHandler.handle(this.objectService, this.representationMetadataSearchService, this.identifierProvider, this.interpreter, childVariables, subModelOperations);
        }
    }
    return status;
}
Also used : IStatus(org.eclipse.sirius.components.representations.IStatus) HashMap(java.util.HashMap) Default(org.eclipse.sirius.viewpoint.description.tool.Default) Success(org.eclipse.sirius.components.representations.Success) Case(org.eclipse.sirius.viewpoint.description.tool.Case) ModelOperation(org.eclipse.sirius.viewpoint.description.tool.ModelOperation)

Aggregations

HashMap (java.util.HashMap)1 IStatus (org.eclipse.sirius.components.representations.IStatus)1 Success (org.eclipse.sirius.components.representations.Success)1 Case (org.eclipse.sirius.viewpoint.description.tool.Case)1 Default (org.eclipse.sirius.viewpoint.description.tool.Default)1 ModelOperation (org.eclipse.sirius.viewpoint.description.tool.ModelOperation)1