Bug 374534 - IEventBroker instances are not actually allocated and destroyed on a per-context basis

Change EventBrokerFactory to IEclipseContext.getLocal() rather than
get() and thus avoid picking up an ancestor's IEventBroker.  Added
a test to verify the IEB is removed on context disposal.
diff --git a/bundles/org.eclipse.e4.ui.services/src/org/eclipse/e4/ui/services/events/EventBrokerFactory.java b/bundles/org.eclipse.e4.ui.services/src/org/eclipse/e4/ui/services/events/EventBrokerFactory.java
index f4f61b7..fd0fbdd 100644
--- a/bundles/org.eclipse.e4.ui.services/src/org/eclipse/e4/ui/services/events/EventBrokerFactory.java
+++ b/bundles/org.eclipse.e4.ui.services/src/org/eclipse/e4/ui/services/events/EventBrokerFactory.java
@@ -28,10 +28,10 @@
 public class EventBrokerFactory extends ContextFunction {
 	@Override
 	public Object compute(IEclipseContext context) {
-		EventBroker broker = context.get(EventBroker.class);
+        EventBroker broker = context.getLocal(EventBroker.class);
 		if (broker == null) {
-			broker = ContextInjectionFactory.make(EventBroker.class, context);
-			context.set(EventBroker.class, broker);
+            broker = ContextInjectionFactory.make(EventBroker.class, context);
+            context.set(EventBroker.class, broker);
 		}
 		return broker;
 	}
diff --git a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/UIEventsTest.java b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/UIEventsTest.java
index 6676ad6..20ecce0 100644
--- a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/UIEventsTest.java
+++ b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/UIEventsTest.java
@@ -327,6 +327,33 @@
 		checkForFailures(allTesters, windowTester);
 	}
 
+	// Verify bug 374534
+	public void testBrokerCleanup() {
+		final String testTopic = "test/374534";
+		IEventBroker appEB = applicationContext.get(IEventBroker.class);
+
+		IEclipseContext childContext = applicationContext.createChild();
+		IEventBroker childEB = childContext.get(IEventBroker.class);
+		assertFalse("child context has same IEventBroker", appEB == childEB);
+
+		final boolean seen[] = { false };
+		childEB.subscribe(testTopic, new EventHandler() {
+			public void handleEvent(Event event) {
+				seen[0] = true;
+			}
+		});
+
+		// ensure the EBs are wired up
+		assertFalse(seen[0]);
+		appEB.send(testTopic, null);
+		assertTrue(seen[0]);
+
+		seen[0] = false;
+		childContext.dispose();
+		appEB.send(testTopic, null);
+		assertFalse(seen[0]);
+	}
+
 	/**
 	 * @param allTesters
 	 * @param tester