use of org.osate.ge.businessobjecthandling.CustomDeleteContext in project osate2 by osate.
the class DeleteHandler method createBusinessObjectRemovalOrRemoveDiagramElement.
/**
* Creates a BusinessObjectRemoval object which can be used to remove the business object for the diagram element.
* If the diagram element's business object is an embedded business object, remove the element.
* @param de
* @return
*/
private static BusinessObjectRemoval createBusinessObjectRemovalOrRemoveDiagramElement(final DiagramElement de) {
// Remove the EObject from the model
final Object bo = de.getBusinessObject();
final Object boHandler = de.getBusinessObjectHandler();
if (bo instanceof EObject) {
EObject boEObj = (EObject) bo;
if (boHandler instanceof CustomDeleter) {
final CustomDeleter deleter = (CustomDeleter) boHandler;
final EObject ownerBo = boEObj.eContainer();
return new BusinessObjectRemoval(ownerBo, (boToModify) -> {
deleter.delete(new CustomDeleteContext(boToModify, bo));
});
}
// When deleting AnnexSubclauses, the deletion must executed on the container DefaultAnnexSubclause
if (boEObj instanceof AnnexSubclause && boEObj.eContainer() instanceof DefaultAnnexSubclause) {
boEObj = boEObj.eContainer();
}
return new BusinessObjectRemoval(boEObj, (boToModify) -> EcoreUtil.remove(boToModify));
} else if (bo instanceof EmfContainerProvider) {
if (!(boHandler instanceof CustomDeleter)) {
throw new RuntimeException("Business object handler '" + boHandler + "' for " + EmfContainerProvider.class.getName() + " based business object must implement " + CustomDeleter.class.getCanonicalName() + ".");
}
final CustomDeleter deleter = (CustomDeleter) boHandler;
final EObject ownerBo = ((EmfContainerProvider) bo).getEmfContainer();
return new BusinessObjectRemoval(ownerBo, (boToModify) -> {
deleter.delete(new CustomDeleteContext(boToModify, bo));
});
} else if (bo instanceof EmbeddedBusinessObject) {
// For embedded business objects, there isn't a model from which to remove the business object.
// Instead, we remove the diagram element and return null.
final AgeDiagram diagram = DiagramElementUtil.getDiagram(de);
diagram.modify("Delete Element", m -> m.removeElement(de));
return null;
} else {
// canDelete() should have returned false in this case
throw new RuntimeException("Unhandled case: " + bo);
}
}
Aggregations