Bug 534612 - add ACTIVATED/DEACTIVATED event types and report them

Change-Id: I273d34cec39a31920bcdd4a38f8eb3ce448e296d
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
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 2addd36..d73fc69 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
@@ -50,6 +50,12 @@
 	 */
 	public static final String DEBUG_STRING = "debugString"; //$NON-NLS-1$
 
+	/**
+	 * String used in {@link #toString()} to name contexts not providing the value
+	 * for the {@link #DEBUG_STRING} variable
+	 */
+	public static final String ANONYMOUS_CONTEXT_NAME = "Anonymous Context"; //$NON-NLS-1$
+
 	static class Scheduled {
 
 		public TrackableComputationExt runnable;
@@ -218,8 +224,9 @@
 			}
 		}
 
-		if (debugAddOn != null)
+		if (debugAddOn != null) {
 			debugAddOn.notify(this, IEclipseContextDebugger.EventType.DISPOSED, null);
+		}
 	}
 
 	@Override
@@ -437,7 +444,7 @@
 	@Override
 	public String toString() {
 		Object debugString = localValues.get(DEBUG_STRING);
-		return debugString instanceof String ? ((String) debugString) : "Anonymous Context"; //$NON-NLS-1$
+		return debugString instanceof String ? ((String) debugString) : ANONYMOUS_CONTEXT_NAME;
 	}
 
 	private void trackAccess(String name) {
@@ -672,6 +679,9 @@
 		if (this == parent.getActiveChild())
 			return;
 		parent.set(ACTIVE_CHILD, this);
+		if (debugAddOn != null) {
+			debugAddOn.notify(this, IEclipseContextDebugger.EventType.ACTIVATED, null);
+		}
 	}
 
 	@Override
@@ -689,6 +699,9 @@
 		if (this != parent.getActiveChild())
 			return; // this is not an active context; return
 		parent.set(ACTIVE_CHILD, null);
+		if (debugAddOn != null) {
+			debugAddOn.notify(this, IEclipseContextDebugger.EventType.DEACTIVATED, null);
+		}
 	}
 
 	// This method is for debug only, do not use externally
diff --git a/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/IEclipseContextDebugger.java b/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/IEclipseContextDebugger.java
index df862ee..0d7afd5 100644
--- a/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/IEclipseContextDebugger.java
+++ b/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/IEclipseContextDebugger.java
@@ -15,7 +15,7 @@
 	String SERVICE_NAME = IEclipseContextDebugger.class.getName();
 
 	public enum EventType {
-		CONSTRUCTED, DISPOSED, LISTENER_ADDED
+		CONSTRUCTED, DISPOSED, LISTENER_ADDED, ACTIVATED, DEACTIVATED
 	}
 
 	void notify(EclipseContext context, EventType type, Object data);