Search in sources :

Example 1 with ModelOperation

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

the class DeleteViewOperationHandler method handle.

@Override
public IStatus handle(Map<String, Object> variables) {
    Object self = variables.get(VariableManager.SELF);
    if (self instanceof Node) {
        String elementId = ((Node) self).getId();
        // @formatter:off
        ViewDeletionRequest viewDeletionRequest = ViewDeletionRequest.newViewDeletionRequest().elementId(elementId).build();
        Optional.ofNullable(variables.get(IDiagramContext.DIAGRAM_CONTEXT)).filter(IDiagramContext.class::isInstance).map(IDiagramContext.class::cast).ifPresent(diagramContext -> diagramContext.getViewDeletionRequests().add(viewDeletionRequest));
        // @formatter:on
        Map<String, Object> childVariables = new HashMap<>(variables);
        List<ModelOperation> subModelOperations = this.deleteView.getSubModelOperations();
        return this.childModelOperationHandler.handle(this.objectService, this.representationMetadataSearchService, this.identifierProvider, this.interpreter, childVariables, subModelOperations);
    }
    // $NON-NLS-1$
    return new Failure("");
}
Also used : ModelOperation(org.eclipse.sirius.viewpoint.description.tool.ModelOperation) HashMap(java.util.HashMap) Node(org.eclipse.sirius.components.diagrams.Node) IDiagramContext(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext) ViewDeletionRequest(org.eclipse.sirius.components.diagrams.ViewDeletionRequest) Failure(org.eclipse.sirius.components.representations.Failure)

Example 2 with ModelOperation

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

the class ExternalJavaActionOperationHandler method handle.

@Override
public IStatus handle(Map<String, Object> variables) {
    // @formatter:off
    var optionalExternalJavaAction = this.externalJavaActionProviders.stream().map(provider -> provider.findById(this.externalJavaAction.getId())).flatMap(Optional::stream).findFirst();
    if (optionalExternalJavaAction.isEmpty()) {
        // $NON-NLS-1$
        this.logger.warn("Unable to find external java action from id:{}", this.externalJavaAction.getId());
        // $NON-NLS-1$
        return new Failure("");
    } else {
        IExternalJavaAction javaAction = optionalExternalJavaAction.get();
        Map<String, Object> parameters = new HashMap<>();
        for (ExternalJavaActionParameter parameter : this.externalJavaAction.getParameters()) {
            Optional<Object> value = this.interpreter.evaluateExpression(variables, parameter.getValue()).asObject();
            value.ifPresent(it -> parameters.put(parameter.getName(), it));
        }
        Object object = variables.get(VariableManager.SELF);
        if (object instanceof EObject && javaAction.canExecute(List.of((EObject) object))) {
            javaAction.execute(List.of((EObject) object), parameters);
        }
    }
    List<ModelOperation> subModelOperations = this.externalJavaAction.getSubModelOperations();
    return this.childModelOperationHandler.handle(this.objectService, this.representationMetadataSearchService, this.identifierProvider, this.interpreter, variables, subModelOperations);
}
Also used : ModelOperation(org.eclipse.sirius.viewpoint.description.tool.ModelOperation) HashMap(java.util.HashMap) EObject(org.eclipse.emf.ecore.EObject) EObject(org.eclipse.emf.ecore.EObject) IExternalJavaAction(org.eclipse.sirius.tools.api.ui.IExternalJavaAction) Failure(org.eclipse.sirius.components.representations.Failure) ExternalJavaActionParameter(org.eclipse.sirius.viewpoint.description.tool.ExternalJavaActionParameter)

Example 3 with ModelOperation

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

the class SetValueOperationHandler method handle.

@Override
public IStatus handle(Map<String, Object> variables) {
    String featureName = this.setValue.getFeatureName();
    if (featureName != null && !featureName.isBlank()) {
        String valueExpression = this.setValue.getValueExpression();
        Optional<Object> optionalValueObject = this.interpreter.evaluateExpression(variables, valueExpression).asObject();
        // @formatter:off
        Optional<EObject> optionalOwnerObject = Optional.ofNullable(variables.get(VariableManager.SELF)).filter(EObject.class::isInstance).map(EObject.class::cast);
        if (optionalValueObject.isPresent() && optionalOwnerObject.isPresent()) {
            EObject ownerObject = optionalOwnerObject.get();
            Object valueObject = optionalValueObject.get();
            new EcoreIntrinsicExtender().eAdd(ownerObject, featureName, valueObject);
        }
    }
    Map<String, Object> childVariables = new HashMap<>(variables);
    List<ModelOperation> subModelOperations = this.setValue.getSubModelOperations();
    return this.childModelOperationHandler.handle(this.objectService, this.representationMetadataSearchService, this.identifierProvider, this.interpreter, childVariables, subModelOperations);
}
Also used : ModelOperation(org.eclipse.sirius.viewpoint.description.tool.ModelOperation) HashMap(java.util.HashMap) EObject(org.eclipse.emf.ecore.EObject) EcoreIntrinsicExtender(org.eclipse.sirius.ecore.extender.business.internal.accessor.ecore.EcoreIntrinsicExtender) EObject(org.eclipse.emf.ecore.EObject)

Example 4 with ModelOperation

use of org.eclipse.sirius.viewpoint.description.tool.ModelOperation 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)

Example 5 with ModelOperation

use of org.eclipse.sirius.viewpoint.description.tool.ModelOperation 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)

Aggregations

ModelOperation (org.eclipse.sirius.viewpoint.description.tool.ModelOperation)11 HashMap (java.util.HashMap)7 Failure (org.eclipse.sirius.components.representations.Failure)7 IStatus (org.eclipse.sirius.components.representations.IStatus)5 List (java.util.List)4 Map (java.util.Map)4 Objects (java.util.Objects)4 Optional (java.util.Optional)4 EObject (org.eclipse.emf.ecore.EObject)4 IIdentifierProvider (org.eclipse.sirius.components.compatibility.api.IIdentifierProvider)4 IModelOperationHandler (org.eclipse.sirius.components.compatibility.api.IModelOperationHandler)4 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)4 IObjectService (org.eclipse.sirius.components.core.api.IObjectService)4 AQLInterpreter (org.eclipse.sirius.components.interpreter.AQLInterpreter)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