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("");
}
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);
}
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);
}
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;
}
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("");
}
Aggregations