Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/contexts/IEclipseContext.java19
-rw-r--r--bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/EclipseContext.java28
2 files changed, 47 insertions, 0 deletions
diff --git a/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/contexts/IEclipseContext.java b/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/contexts/IEclipseContext.java
index 7f0cbdb06..50015f3c6 100644
--- a/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/contexts/IEclipseContext.java
+++ b/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/contexts/IEclipseContext.java
@@ -284,4 +284,23 @@ public interface IEclipseContext {
* will have no effect.
*/
public void dispose();
+
+ /**
+ * <STRONG>EXPERIMENTAL, DO NOT USE</STRONG>
+ * Returns the value stored on the active leaf node of the context's tree.
+ * @param clazz the class that needs to be found in the active context
+ * @return an object corresponding to the given class, or <code>null</code>
+ * @see IEclipseContext#getActiveLeaf()
+ */
+ public <T> T getActive(Class<T> clazz);
+
+ /**
+ * <STRONG>EXPERIMENTAL, DO NOT USE</STRONG>
+ * Returns the named value stored on the active leaf node of the context's tree.
+ * @param name the name of the value to return
+ * @return an object corresponding to the given name, or <code>null</code>
+ * @see IEclipseContext#getActiveLeaf()
+ */
+ public Object getActive(final String name);
+
}
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 5554941c0..c5cce8788 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
@@ -693,4 +693,32 @@ public class EclipseContext implements IEclipseContext {
protected Object lookup(String name, EclipseContext originatingContext) {
return null;
}
+
+ /**
+ * Prefix used to distinguish active variables
+ */
+ static private final String ACTIVE_VARIABLE = "org.eclipse.ui.active_"; //$NON-NLS-1$
+
+ public <T> T getActive(Class<T> clazz) {
+ return clazz.cast(getActive(clazz.getName()));
+ }
+
+ public Object getActive(final String name) {
+ final String internalName = ACTIVE_VARIABLE + name;
+ trackAccess(internalName);
+
+ if (containsKey(internalName, false))
+ return internalGet(this, internalName, false);
+
+ final EclipseContext originatingContext = this;
+ runAndTrack(new RunAndTrack() {
+ public boolean changed(IEclipseContext context) {
+ IEclipseContext activeContext = getRoot().getActiveLeaf();
+ Object result = activeContext.get(name);
+ originatingContext.set(internalName, result);
+ return true;
+ }
+ });
+ return internalGet(this, internalName, true);
+ }
}

Back to the top