Bug 317183 - Toolbar buttons seem to do nothing (but are enabled)
diff --git a/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/EclipseContext.java b/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/EclipseContext.java
index a84cc2d..d8ba2e7 100644
--- a/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/EclipseContext.java
+++ b/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/EclipseContext.java
@@ -320,7 +320,7 @@
public void runAndTrack(final RunAndTrack runnable) {
ContextChangeEvent event = new ContextChangeEvent(this, ContextChangeEvent.INITIAL, null, null, null);
- TrackableComputationExt computation = new TrackableComputationExt(runnable);
+ TrackableComputationExt computation = new TrackableComputationExt(runnable, this);
computation.update(event);
}
diff --git a/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/TrackableComputationExt.java b/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/TrackableComputationExt.java
index e6a8e98..18d865d 100644
--- a/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/TrackableComputationExt.java
+++ b/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/TrackableComputationExt.java
@@ -11,16 +11,19 @@
package org.eclipse.e4.core.internal.contexts;
import java.util.List;
+import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.contexts.RunAndTrack;
import org.eclipse.e4.core.internal.contexts.EclipseContext.Scheduled;
public class TrackableComputationExt extends Computation implements IContextRecorder {
+ final private IEclipseContext originatingContext;
private RunAndTrack runnable;
private ContextChangeEvent cachedEvent;
- public TrackableComputationExt(RunAndTrack runnable) {
+ public TrackableComputationExt(RunAndTrack runnable, IEclipseContext originatingContext) {
this.runnable = runnable;
+ this.originatingContext = originatingContext;
}
public int hashCode() {
@@ -96,7 +99,14 @@
EclipseContext.localComputation().set(oldComputation);
}
EclipseContext eventsContext = (EclipseContext) event.getContext();
- if (result && eventType != ContextChangeEvent.DISPOSE)
+
+ if (eventType == ContextChangeEvent.DISPOSE) {
+ if (originatingContext.equals(eventsContext)) {
+ removeAll(eventsContext);
+ return false;
+ }
+ }
+ if (result)
startListening(eventsContext);
else
removeAll(eventsContext);
diff --git a/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/Bug317183Test.java b/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/Bug317183Test.java
new file mode 100644
index 0000000..f828372
--- /dev/null
+++ b/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/Bug317183Test.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2010 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.e4.core.internal.tests.contexts.inject;
+
+import junit.framework.TestCase;
+import org.eclipse.e4.core.contexts.EclipseContextFactory;
+import org.eclipse.e4.core.contexts.IContextConstants;
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.core.contexts.RunAndTrack;
+
+public class Bug317183Test extends TestCase {
+
+ public void testX() {
+ IEclipseContext appContext = EclipseContextFactory.create();
+ IEclipseContext windowContext = appContext.createChild();
+ IEclipseContext partContextA = windowContext.createChild();
+ IEclipseContext partContextB = windowContext.createChild();
+
+ appContext.set(IContextConstants.ACTIVE_CHILD, windowContext);
+ windowContext.set(IContextConstants.ACTIVE_CHILD, partContextA);
+
+ RunAndTrackImpl impl = new RunAndTrackImpl();
+ windowContext.runAndTrack(impl);
+
+ impl.called = false;
+
+ partContextA.dispose();
+ windowContext.set(IContextConstants.ACTIVE_CHILD, partContextB);
+ assertTrue(impl.called); // this fails
+ }
+
+ public void testY() {
+ IEclipseContext appContext = EclipseContextFactory.create();
+ IEclipseContext windowContext = appContext.createChild();
+ IEclipseContext partContextA = windowContext.createChild();
+ IEclipseContext partContextB = windowContext.createChild();
+ IEclipseContext partContextC = windowContext.createChild();
+
+ appContext.set(IContextConstants.ACTIVE_CHILD, windowContext);
+ windowContext.set(IContextConstants.ACTIVE_CHILD, partContextA);
+
+ RunAndTrackImpl impl = new RunAndTrackImpl();
+ windowContext.runAndTrack(impl);
+
+ windowContext.set(IContextConstants.ACTIVE_CHILD, partContextB);
+ partContextA.dispose();
+
+ impl.called = false;
+
+ windowContext.set(IContextConstants.ACTIVE_CHILD, partContextC);
+ assertTrue(impl.called); // this fails
+ }
+
+ static class RunAndTrackImpl extends RunAndTrack {
+
+ boolean called = false;
+
+ @Override
+ public boolean changed(IEclipseContext context) {
+ IEclipseContext child = (IEclipseContext) context
+ .getLocal(IContextConstants.ACTIVE_CHILD);
+ while (child != null) {
+ child = (IEclipseContext) child
+ .getLocal(IContextConstants.ACTIVE_CHILD);
+ }
+ called = true;
+ return true;
+ }
+
+ }
+
+}
+
diff --git a/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/tests/CoreTestSuite.java b/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/tests/CoreTestSuite.java
index 62bba57..3a2abd0 100644
--- a/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/tests/CoreTestSuite.java
+++ b/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/tests/CoreTestSuite.java
@@ -20,6 +20,7 @@
import org.eclipse.e4.core.internal.tests.contexts.RunAndTrackTest;
import org.eclipse.e4.core.internal.tests.contexts.inject.AnnotationsInjectionTest;
import org.eclipse.e4.core.internal.tests.contexts.inject.Bug304585Test;
+import org.eclipse.e4.core.internal.tests.contexts.inject.Bug317183Test;
import org.eclipse.e4.core.internal.tests.contexts.inject.ComplexDisposalTest;
import org.eclipse.e4.core.internal.tests.contexts.inject.ContextFunctionDynamicsTest;
import org.eclipse.e4.core.internal.tests.contexts.inject.ContextInjectionDisposeTest;
@@ -88,5 +89,6 @@
addTestSuite(ContextFunctionDynamicsTest.class);
addTestSuite(InjectArraysTest.class);
addTestSuite(InvokeInRATTest.class);
+ addTestSuite(Bug317183Test.class);
}
}