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

- Replace getRootElement() method with KernelModelElementUtils.getParentElement()

- Make update(IModelElement modelElement) more robust by tolerating null input which might occur during model modifications
refs 2289
parent 93349bd4
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,7 @@ package org.fortiss.tooling.base.ui.annotation.view;
import static org.fortiss.tooling.kernel.ui.util.SelectionUtils.checkAndPickFirst;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getChildrenWithType;
import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.getParentElement;
import java.util.Collection;
import java.util.Comparator;
......@@ -57,7 +58,7 @@ import org.fortiss.tooling.kernel.service.IPersistencyService;
* @author barner
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: B55BAC235E8E1237779F65D244BDC2F5
* @ConQAT.Rating YELLOW Hash: 37981DA46553DAAD045452E37DC2B324
*/
public abstract class AnnotationViewPartBase extends ViewPart implements ISelectionListener,
IAnnotationViewPart {
......@@ -144,7 +145,9 @@ public abstract class AnnotationViewPartBase extends ViewPart implements ISelect
if(isAddOrRemoveEvent) {
// Invalidate cache if elements are added to / removed from the model
lastAnnotationEntriesMap.put(getRootElement(modelElement), null);
lastAnnotationEntriesMap
.put(getParentElement(modelElement, IProjectRootElement.class,
true), null);
}
// Ensure that refresh is run in the UI thread
......@@ -188,17 +191,6 @@ public abstract class AnnotationViewPartBase extends ViewPart implements ISelect
processingSectionChanged = false;
}
// TODO (#2289) Consider if this method could be moved to EcoreUtils
/** Determines root element of the given model element. */
private EObject getRootElement(IModelElement modelElement) {
EObject rootElement = modelElement;
while(!(rootElement instanceof IProjectRootElement)) {
rootElement = rootElement.eContainer();
}
return rootElement;
}
/**
* Adds an AnnotationEntry for a given {@code modelElement} to a list of
* {@code annotationEntries} in case the acquired annotation is not empty, i.e. if it
......@@ -218,7 +210,10 @@ public abstract class AnnotationViewPartBase extends ViewPart implements ISelect
* {@link #update(Collection)}, and update model change listeners.
*/
protected void update(IModelElement modelElement) {
EObject rootElement = getRootElement(modelElement);
EObject rootElement = getParentElement(modelElement, IProjectRootElement.class, true);
if(rootElement == null) {
return;
}
// Check cache if annotation entries for the given root element have already been determined
Collection<AnnotationEntry> annotationEntries = lastAnnotationEntriesMap.get(rootElement);
......
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