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