Bug 558411 - Guard against disposed master in WindowEditor

For some reason sometimes the master object is disposed when
the main menu changes. This change prevents a crash in this weird
case, but doesn't solve the root problem.

After this change also the virtual entry list is not updated when
createRemoveMainMenu is disposed. This should be okay, because in
that case the GUI is not functional and it doesn't matter if the
update is not performed, as long as we don't crash.


Change-Id: I072bc49f50062d884c7d00e44b4d1e03a93e8001
Signed-off-by: Jens Lidestrom <jens@lidestrom.se>
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/WindowEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/WindowEditor.java
index a9d113e..36a76d7 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/WindowEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/WindowEditor.java
@@ -366,16 +366,20 @@
 		}
 
 		E4Properties.mainMenu().observe(window).addValueChangeListener(event -> {
+			if (createRemoveMainMenu.isDisposed() || getMaster().isDisposed()) {
+				return;
+			}
+
 			if (event.diff.getOldValue() != null) {
 				list.remove(event.diff.getOldValue());
-				if (getMaster().getValue() == element && !createRemoveMainMenu.isDisposed()) {
+				if (getMaster().getValue() == element) {
 					createRemoveMainMenu.setSelection(false);
 				}
 			}
 
 			if (event.diff.getNewValue() != null) {
 				list.add(0, event.diff.getNewValue());
-				if (getMaster().getValue() == element && !createRemoveMainMenu.isDisposed()) {
+				if (getMaster().getValue() == element) {
 					createRemoveMainMenu.setSelection(true);
 				}
 			}