From d8010612f73907c048c77fd09ebdceb8f4360366 Mon Sep 17 00:00:00 2001
From: Simon Barner <barner@fortiss.org>
Date: Wed, 8 May 2019 10:50:27 +0200
Subject: [PATCH] Avoid NPE when switching model to be displayed in the
 annotation view

* Dispose columns created for previous model before setting the editor
  input.
* Otherwise, the old label providers might try to access annotations
  that are not presented in the new model

Issue-Ref: 3696
Issue-Url: https://af3-developer.fortiss.org/issues/3696

Signed-off-by: Simon Barner <barner@fortiss.org>
---
 .../tooling/base/ui/annotation/view/generic/.ratings   |  2 +-
 .../annotation/view/generic/GenericAnnotationView.java | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/.ratings b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/.ratings
index 6903af774..220632fe4 100644
--- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/.ratings
+++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/.ratings
@@ -1,2 +1,2 @@
 ColumnHandle.java 8fc5f04cbb0127e5df8c7a9e3b2620502bf93716 GREEN
-GenericAnnotationView.java 3986c6ab6f1b5f9ec04780c3d6256e7c70b91c1d GREEN
+GenericAnnotationView.java 494cbcade7fd5d66b9629b86549eb25d4d4c93dd YELLOW
diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/GenericAnnotationView.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/GenericAnnotationView.java
index 3986c6ab6..494cbcade 100644
--- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/GenericAnnotationView.java
+++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/view/generic/GenericAnnotationView.java
@@ -220,11 +220,6 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
 			// Minimize flickering while updating the table
 			tableViewer.getTable().setRedraw(false);
 
-			// Input must be set before the construction of the columns, since the editing support
-			// for a given cell might need to query the contents of other model elements (e.g., in
-			// order to aggregate a set of admissible choices for its value).
-			tableViewer.setInput(annotationEntries);
-
 			// Sorted set of {@link ColumnHandle} used to instantiate this {@link
 			// GenericAnnotationView}'s columns in the right order.
 			Set<ColumnHandle<?>> sortedColumnHandles = new TreeSet<ColumnHandle<?>>();
@@ -236,6 +231,11 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
 				column.dispose();
 			}
 
+			// Input must be set before the construction of the columns, since the editing support
+			// for a given cell might need to query the contents of other model elements (e.g., in
+			// order to aggregate a set of admissible choices for its value).
+			tableViewer.setInput(annotationEntries);
+
 			// Aggregate required columns. Column order is defined by ColumnHandle.compareTo().
 			for(AnnotationEntry entry : annotationEntries) {
 				for(IAnnotatedSpecification spec : entry.getSpecificationsList()) {
-- 
GitLab