use of org.eclipse.sirius.ecore.extender.business.internal.accessor.ecore.EcoreIntrinsicExtender 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.ecore.extender.business.internal.accessor.ecore.EcoreIntrinsicExtender in project sirius-components by eclipse-sirius.
the class CreateInstanceOperationHandler method handle.
@Override
public IStatus handle(Map<String, Object> variables) {
String typeName = this.createInstance.getTypeName();
String referenceName = this.createInstance.getReferenceName();
String variableName = this.createInstance.getVariableName();
Map<String, Object> childVariables = new HashMap<>(variables);
if (typeName != null && !typeName.isBlank() && referenceName != null && !referenceName.isBlank()) {
// @formatter:off
Optional<EObject> optionalOwnerEObject = Optional.ofNullable(variables.get(VariableManager.SELF)).filter(EObject.class::isInstance).map(EObject.class::cast);
Optional<EditingDomain> optionalEditingDomain = Optional.of(variables.get(IEditingContext.EDITING_CONTEXT)).filter(EditingContext.class::isInstance).map(EditingContext.class::cast).map(EditingContext::getDomain);
// @formatter:on
Matcher matcher = SEPARATOR.matcher(typeName);
if (optionalEditingDomain.isPresent() && optionalOwnerEObject.isPresent() && matcher.find()) {
EditingDomain editingDomain = optionalEditingDomain.get();
EObject ownerEObject = optionalOwnerEObject.get();
String packageName = typeName.substring(0, matcher.start());
String className = typeName.substring(matcher.end());
Optional<EPackage> optionalEPackage = this.ePackageService.findEPackage(editingDomain.getResourceSet().getPackageRegistry(), packageName);
EcoreIntrinsicExtender ecoreIntrinsicExtender = new EcoreIntrinsicExtender();
if (optionalEPackage.isPresent()) {
EPackage ePackage = optionalEPackage.get();
ecoreIntrinsicExtender.updateMetamodels(Collections.singleton(new EcoreMetamodelDescriptor(ePackage)));
}
EObject createdInstance = ecoreIntrinsicExtender.createInstance(className);
if (createdInstance == null) {
// $NON-NLS-1$
this.logger.warn("The creation of an instance of Type {} failed.", typeName);
} else {
Object addedObject = ecoreIntrinsicExtender.eAdd(ownerEObject, referenceName, createdInstance);
if (addedObject == null) {
// $NON-NLS-1$
this.logger.warn("The feature {} does not exist on {}.", referenceName, typeName);
} else if (variableName != null && !variableName.isBlank()) {
childVariables.put(variableName, createdInstance);
}
// Sub-operations are executed in the context of the new element
childVariables.put(VariableManager.SELF, createdInstance);
}
}
}
List<ModelOperation> subModelOperations = this.createInstance.getSubModelOperations();
return this.childModelOperationHandler.handle(this.objectService, this.representationMetadataSearchService, this.identifierProvider, this.interpreter, childVariables, subModelOperations);
}
use of org.eclipse.sirius.ecore.extender.business.internal.accessor.ecore.EcoreIntrinsicExtender in project sirius-components by eclipse-sirius.
the class MoveElementOperationHandler method doMoveElement.
/**
* This implementation is based on implementations of
* org.eclipse.sirius.ecore.extender.business.api.accessor.ModelAccessor.eIsMany(EObject, String) and
* org.eclipse.sirius.ecore.extender.business.api.accessor.CompositeMetamodelExtender.eIsMany(EObject, String)
*/
private void doMoveElement(EObject newContainer, EObject valueObject, String featureName) {
EcoreIntrinsicExtender ecoreIntrinsicExtender = new EcoreIntrinsicExtender();
Boolean isMany = ecoreIntrinsicExtender.eIsMany(newContainer, featureName);
if (isMany == null) {
// $NON-NLS-1$
this.logger.warn("The feature {} is unknown on the object {}", featureName, newContainer);
} else {
if (!isMany) {
Object currentValueOnContainer = ecoreIntrinsicExtender.eGet(newContainer, featureName);
if (currentValueOnContainer == null) {
// $NON-NLS-1$
this.logger.warn("Impossible to add a value to the reference {} of the object {}", featureName, newContainer);
return;
}
} else {
ecoreIntrinsicExtender.eAdd(newContainer, featureName, valueObject);
}
}
}
use of org.eclipse.sirius.ecore.extender.business.internal.accessor.ecore.EcoreIntrinsicExtender in project sirius-components by eclipse-sirius.
the class RemoveElementOperationHandler method handle.
@Override
public IStatus handle(Map<String, Object> variables) {
// @formatter:off
Optional<EObject> optionalObjectToRemove = Optional.ofNullable(variables.get(VariableManager.SELF)).filter(EObject.class::isInstance).map(EObject.class::cast);
if (optionalObjectToRemove.isPresent()) {
EObject objectToRemove = optionalObjectToRemove.get();
EcoreIntrinsicExtender ecoreIntrinsicExtender = new EcoreIntrinsicExtender();
String containingFeatureName = ecoreIntrinsicExtender.eContainingFeatureName(objectToRemove);
EObject container = ecoreIntrinsicExtender.eContainer(objectToRemove);
Object removedElement = ecoreIntrinsicExtender.eRemove(container, containingFeatureName, objectToRemove);
if (removedElement == null) {
// $NON-NLS-1$
this.logger.warn("The removal of the object {} from the instance {} on the feature {} failed.", objectToRemove, container, containingFeatureName);
}
}
Map<String, Object> childVariables = new HashMap<>(variables);
List<ModelOperation> subModelOperations = this.removeElementOperation.getSubModelOperations();
return this.childModelOperationHandler.handle(this.objectService, this.representationMetadataSearchService, this.identifierProvider, this.interpreter, childVariables, subModelOperations);
}
use of org.eclipse.sirius.ecore.extender.business.internal.accessor.ecore.EcoreIntrinsicExtender in project sirius-components by eclipse-sirius.
the class ToolImageProvider method getInstance.
private Optional<EObject> getInstance(String domainClass) {
Matcher matcher = SEPARATOR.matcher(domainClass);
if (matcher.find()) {
String packageName = domainClass.substring(0, matcher.start());
String className = domainClass.substring(matcher.end());
var optionalEPackage = new EPackageService().findEPackage(this.ePackageRegistry, packageName);
if (optionalEPackage.isPresent()) {
EPackage ePackage = optionalEPackage.get();
EcoreIntrinsicExtender ecoreIntrinsicExtender = new EcoreIntrinsicExtender();
ecoreIntrinsicExtender.updateMetamodels(List.of(new EcoreMetamodelDescriptor(ePackage)));
EObject instance = ecoreIntrinsicExtender.createInstance(className);
return Optional.ofNullable(instance);
}
}
return Optional.empty();
}
Aggregations