Skip to content
Snippets Groups Projects
Commit d13c663f authored by Simon Barner's avatar Simon Barner
Browse files

- getAnnotation(): Wrap creation of new Annotation into command since this...

- getAnnotation(): Wrap creation of new Annotation into command since this method might easily be called from a context that cannot directly manipulate the model (e.g., from the GUI context)
refs 2178
parent 5e8c0afb
No related branches found
No related tags found
No related merge requests found
......@@ -30,6 +30,8 @@ import org.eclipse.emf.ecore.util.EcoreUtil;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.model.element.IDerivedAnnotation;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.service.IPersistencyService;
// TODO: Some of the methods in this class also apply to {@link IModelElementSpecification}s, not only
// {@link IAnnotatedSpecification}s.
......@@ -72,19 +74,29 @@ public class AnnotationUtils {
* {@code modelElement}.
*/
@SuppressWarnings("unchecked")
private static <T extends IAnnotatedSpecification> T getAnnotation(IModelElement modelElement,
EClass eClass) {
private static <T extends IAnnotatedSpecification> T getAnnotation(
final IModelElement modelElement, EClass eClass) {
T annotation =
final T annotation =
(T)pickFirstInstanceOf((Class<IAnnotatedSpecification>)eClass.getInstanceClass(),
modelElement.getSpecifications());
if(annotation == null) {
annotation = (T)EcoreUtil.create(eClass);
modelElement.getSpecifications().add(annotation);
if(annotation != null) {
return annotation;
}
return annotation;
final T newAnnotation = (T)EcoreUtil.create(eClass);
ITopLevelElement modelContext =
IPersistencyService.INSTANCE.getTopLevelElementFor(modelElement);
modelContext.runAsCommand(new Runnable() {
@Override
public void run() {
modelElement.getSpecifications().add(newAnnotation);
}
});
return newAnnotation;
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment