Bug 370219 - Selection service could use an ability to pause dependency
recording
diff --git a/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/contexts/RunAndTrack.java b/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/contexts/RunAndTrack.java
index 3022a34..ac87164 100644
--- a/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/contexts/RunAndTrack.java
+++ b/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/contexts/RunAndTrack.java
@@ -21,8 +21,6 @@
  */
 abstract public class RunAndTrack {
 
-	private boolean isRecordingPaused = false;
-
 	/**
 	 * Creates a new instance of trackable computation
 	 */
@@ -43,31 +41,19 @@
 	abstract public boolean changed(IEclipseContext context);
 
 	/**
-	 * This method can be called to pause dependency recording while {@link #changed(IEclipseContext)}
-	 * does its processing. This can be especially useful if external code
-	 * has to be called. The method {@link #resumeRecoding()} must be called before RunAndTrack
-	 * returns control to its caller.  
+	 * Use this method to wrap calls to external code. For instance, while in {@link #changed(IEclipseContext)}.
+	 * consider calling listeners from this method. This wrapper will pause dependency recording while
+	 * in the 3rd party code, reducing potential dependency circularity issues.
+	 * @param runnable
 	 */
-	synchronized protected void pauseRecording() {
-		if (isRecordingPaused)
-			return;
-		Stack<Computation> current = EclipseContext.getCalculatedComputations();
-		current.push(null);
-		isRecordingPaused = true;
-	}
-
-	/**
-	 * Call this method to resume dependency recording previously paused by 
-	 * the {@link #pauseRecording()}.
-	 */
-	synchronized protected void resumeRecoding() {
-		if (!isRecordingPaused)
-			return;
-		Stack<Computation> current = EclipseContext.getCalculatedComputations();
-		Computation plug = current.pop();
-		if (plug != null)
-			throw new IllegalArgumentException("Internal error in nested computation processing"); //$NON-NLS-1$
-		isRecordingPaused = false;
+	synchronized protected void runExternalCode(Runnable runnable) {
+		Stack<Computation> computationStack = EclipseContext.getCalculatedComputations();
+		computationStack.push(null);
+		try {
+			runnable.run();
+		} finally {
+			computationStack.pop();
+		}
 	}
 
 }