Search in sources :

Example 1 with ExternalJavaActionParameter

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

Aggregations

HashMap (java.util.HashMap)1 EObject (org.eclipse.emf.ecore.EObject)1 Failure (org.eclipse.sirius.components.representations.Failure)1 IExternalJavaAction (org.eclipse.sirius.tools.api.ui.IExternalJavaAction)1 ExternalJavaActionParameter (org.eclipse.sirius.viewpoint.description.tool.ExternalJavaActionParameter)1 ModelOperation (org.eclipse.sirius.viewpoint.description.tool.ModelOperation)1