From fdde6fd1cea76759820778e1fb0974951c818215 Mon Sep 17 00:00:00 2001
From: Simon Barner <barner@fortiss.org>
Date: Fri, 5 Sep 2014 08:03:23 +0000
Subject: [PATCH] - Ensure that independently of the currently selected model
 element type, annotations are shown for the entire sub-model below the
 IProjectRoot element above that currently selected model element. E.g., in
 the LA, show annotations for Channels in case a Component is currently
 selected refs 1841

---
 .../view/AnnotationViewPartBase.java          | 51 ++++++++-----------
 1 file changed, 22 insertions(+), 29 deletions(-)

diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/AnnotationViewPartBase.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/AnnotationViewPartBase.java
index fc4edd5f9..ef1bb3c3d 100644
--- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/AnnotationViewPartBase.java
+++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/AnnotationViewPartBase.java
@@ -123,33 +123,18 @@ public abstract class AnnotationViewPartBase extends ViewPart implements ISelect
 	}
 
 	/** Update registration of model listeners. */
-	private void updateChangeListener(Collection<AnnotationEntry> annotationEntryList) {
-		// Determine all root elements
-		Set<EObject> rootElements = new HashSet<EObject>();
-		for(AnnotationEntry entry : annotationEntryList) {
-			EObject rootElement = entry.getModelElement();
-			while(!(rootElement instanceof IProjectRootElement)) {
-				rootElement = rootElement.eContainer();
-			}
-			rootElements.add(rootElement);
-		}
-
+	private void updateChangeListener(EObject rootElement) {
 		// Determine all IModelElements, and their specifications below the current root elements.
 		// Specifications must be watched, too, since the state of an editing support for a given
 		// specification can depend on the state of one or more other specifications.
 		Set<EObject> currentWatchedModelElements = new HashSet<EObject>();
-		for(EObject rootElement : rootElements) {
-			for(EObject modelElement : EcoreUtils.getChildrenWithType(rootElement,
-					IModelElement.class)) {
-				currentWatchedModelElements.add(modelElement);
-				currentWatchedModelElements.addAll(((IModelElement)modelElement)
-						.getSpecifications());
-			}
-			if(rootElement instanceof IModelElement) {
-				currentWatchedModelElements.add(rootElement);
-				currentWatchedModelElements
-						.addAll(((IModelElement)rootElement).getSpecifications());
-			}
+		for(EObject modelElement : EcoreUtils.getChildrenWithType(rootElement, IModelElement.class)) {
+			currentWatchedModelElements.add(modelElement);
+			currentWatchedModelElements.addAll(((IModelElement)modelElement).getSpecifications());
+		}
+		if(rootElement instanceof IModelElement) {
+			currentWatchedModelElements.add(rootElement);
+			currentWatchedModelElements.addAll(((IModelElement)rootElement).getSpecifications());
 		}
 
 		// Add change listeners to IModelElements that are about to appear in the view
@@ -189,17 +174,25 @@ public abstract class AnnotationViewPartBase extends ViewPart implements ISelect
 					}
 				});
 
-		// Collect all AnnotationEntries for the current model element and its offspring
-		annotationEntries.addAll(IAnnotationValueService.INSTANCE.getValues(modelElement));
-		for(IModelElement childModelElement : EcoreUtils.getChildrenWithType(modelElement,
+		// Determine root element of selected / modified model element
+		EObject rootElement = modelElement;
+		while(!(rootElement instanceof IProjectRootElement)) {
+			rootElement = rootElement.eContainer();
+		}
+
+		// Collect all AnnotationEntries for the current root element and its offspring
+		if(rootElement instanceof IModelElement) {
+			annotationEntries.addAll(IAnnotationValueService.INSTANCE
+					.getValues((IModelElement)rootElement));
+		}
+		for(IModelElement childModelElement : EcoreUtils.getChildrenWithType(rootElement,
 				IModelElement.class)) {
 			annotationEntries.addAll(IAnnotationValueService.INSTANCE.getValues(childModelElement));
 		}
 
-		// Update the view
+		// Update the view and change listener registration
 		update(annotationEntries);
-
-		updateChangeListener(annotationEntries);
+		updateChangeListener(rootElement);
 	}
 
 	/** Update concrete view */
-- 
GitLab