aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Besedin2012-02-10 15:55:43 (EST)
committerOleg Besedin2012-02-10 15:55:43 (EST)
commitee416e9c5c1c6d14da0671c57a7e231fe7a88458 (patch)
tree367e7ea23da76158e1a4fcdc36df2e18c3fe1f2b
parent1634731aa1325e5c90be3be2b08384414b77f77e (diff)
downloadeclipse.platform.runtime-ee416e9c5c1c6d14da0671c57a7e231fe7a88458.zip
eclipse.platform.runtime-ee416e9c5c1c6d14da0671c57a7e231fe7a88458.tar.gz
eclipse.platform.runtime-ee416e9c5c1c6d14da0671c57a7e231fe7a88458.tar.bz2
Bug 371289 - Add "active" context variablesv20120210-2055
-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 7f0cbdb..50015f3 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 5554941..c5cce87 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);
+ }
}