ASSIGNED - bug 285339: Models don't always properly close, handlers not updated.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=285339
diff --git a/org.eclipse.amp.axf/plugins/org.eclipse.amp.axf.ide/src/org/eclipse/amp/axf/ide/HandlerManager.java b/org.eclipse.amp.axf/plugins/org.eclipse.amp.axf.ide/src/org/eclipse/amp/axf/ide/HandlerManager.java
index f1ed938..ae17d0f 100644
--- a/org.eclipse.amp.axf/plugins/org.eclipse.amp.axf.ide/src/org/eclipse/amp/axf/ide/HandlerManager.java
+++ b/org.eclipse.amp.axf/plugins/org.eclipse.amp.axf.ide/src/org/eclipse/amp/axf/ide/HandlerManager.java
@@ -59,9 +59,6 @@
     protected synchronized void addHandler(String id, final ModelRunHandler handler) {

         handlers.add(handler);

         handlerActivations.add(handlerService.activateHandler(id, handler));

-        ModelViewManager manager = AXFWorkbenchPlugin.getDefault().getManager();

-        manager.getActiveModelListeners().addListener(handler);

-        manager.getManagerListeners().addModelManagerListener(handler);

     }

 

     public synchronized void notifyHandlers() {

diff --git a/org.eclipse.amp.axf/plugins/org.eclipse.amp.axf.ide/src/org/eclipse/amp/axf/ide/ModelViewManager.java b/org.eclipse.amp.axf/plugins/org.eclipse.amp.axf.ide/src/org/eclipse/amp/axf/ide/ModelViewManager.java
index 4db87c8..2ac12b8 100644
--- a/org.eclipse.amp.axf/plugins/org.eclipse.amp.axf.ide/src/org/eclipse/amp/axf/ide/ModelViewManager.java
+++ b/org.eclipse.amp.axf/plugins/org.eclipse.amp.axf.ide/src/org/eclipse/amp/axf/ide/ModelViewManager.java
@@ -25,6 +25,7 @@
 import org.eclipse.amp.axf.core.IModel;
 import org.eclipse.amp.axf.core.IObservationProvider;
 import org.eclipse.amp.axf.ide.handlers.CloseHandler;
+import org.eclipse.amp.axf.ide.handlers.ModelRunHandler;
 import org.eclipse.amp.axf.ide.handlers.PauseHandler;
 import org.eclipse.amp.axf.ide.handlers.RestartHandler;
 import org.eclipse.amp.axf.ide.handlers.ResumeHandler;
@@ -486,13 +487,19 @@
             }
         });
         handlers.activate();
-        handlers.addHandler("org.eclipse.amp.axf.ui.start", new StartHandler());
-        handlers.addHandler("org.eclipse.amp.axf.ui.stop", new StopHandler());
-        handlers.addHandler("org.eclipse.amp.axf.ui.pause", new PauseHandler());
-        handlers.addHandler("org.eclipse.amp.axf.ui.resume", new ResumeHandler());
-        handlers.addHandler("org.eclipse.amp.axf.ui.restart", new RestartHandler());
-        handlers.addHandler("org.eclipse.amp.axf.ui.close", new CloseHandler());
-        handlers.addHandler("org.eclipse.amp.axf.ui.step", new StepHandler());
+        addHandler("org.eclipse.amp.axf.ui.start", new StartHandler());
+        addHandler("org.eclipse.amp.axf.ui.stop", new StopHandler());
+        addHandler("org.eclipse.amp.axf.ui.pause", new PauseHandler());
+        addHandler("org.eclipse.amp.axf.ui.resume", new ResumeHandler());
+        addHandler("org.eclipse.amp.axf.ui.restart", new RestartHandler());
+        addHandler("org.eclipse.amp.axf.ui.close", new CloseHandler());
+        addHandler("org.eclipse.amp.axf.ui.step", new StepHandler());
+    }
+
+    public void addHandler(String id, ModelRunHandler handler) {
+        handlers.addHandler(id, handler);
+        getActiveModelListeners().addListener(handler);
+        getManagerListeners().addModelManagerListener(handler);
     }
 
     private void activatePerspective(final IWorkbench wb, final String perspectiveID, final boolean editors) {
diff --git a/org.eclipse.amp.axf/plugins/org.eclipse.amp.axf.ide/src/org/eclipse/amp/axf/ide/handlers/ModelRunHandler.java b/org.eclipse.amp.axf/plugins/org.eclipse.amp.axf.ide/src/org/eclipse/amp/axf/ide/handlers/ModelRunHandler.java
index 81dad3e..7b16d8d 100644
--- a/org.eclipse.amp.axf/plugins/org.eclipse.amp.axf.ide/src/org/eclipse/amp/axf/ide/handlers/ModelRunHandler.java
+++ b/org.eclipse.amp.axf/plugins/org.eclipse.amp.axf.ide/src/org/eclipse/amp/axf/ide/handlers/ModelRunHandler.java
@@ -105,7 +105,10 @@
     }

 

     public synchronized void observationEnd(IObservationProvider model) {

-        this.model = null;

+        // we may have a lagging model notification from another model

+        if (model == this.model) {

+            this.model = null;

+        }

     }

 

     public void stateChange(Object key, Object updated) {