aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Besedin2012-02-16 10:27:44 (EST)
committerOleg Besedin2012-02-16 10:27:44 (EST)
commit1118172a15be799e5e4076a28bb66887f2aaa9d7 (patch)
tree82e881987b2a278982aa1d4a22494963eb9e1ae0
parent4c234aebf3f0816838898b88a2b46747cfb1f8c4 (diff)
downloadeclipse.platform.runtime-1118172a15be799e5e4076a28bb66887f2aaa9d7.zip
eclipse.platform.runtime-1118172a15be799e5e4076a28bb66887f2aaa9d7.tar.gz
eclipse.platform.runtime-1118172a15be799e5e4076a28bb66887f2aaa9d7.tar.bz2
Bug 371289 - Add "active" context variablesv20120216-1527I20120216-1110
-rw-r--r--bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/EclipseContext.java12
-rw-r--r--tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/ActivationTest.java63
2 files changed, 64 insertions, 11 deletions
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 c5cce87..25705f6 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 IBM Corporation and others.
+ * Copyright (c) 2009, 2012 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
@@ -705,20 +705,22 @@ public class EclipseContext implements IEclipseContext {
public Object getActive(final String name) {
final String internalName = ACTIVE_VARIABLE + name;
- trackAccess(internalName);
-
- if (containsKey(internalName, false))
+ if (containsKey(internalName, false)) {
+ trackAccess(internalName);
return internalGet(this, internalName, false);
+ }
final EclipseContext originatingContext = this;
+
runAndTrack(new RunAndTrack() {
public boolean changed(IEclipseContext context) {
- IEclipseContext activeContext = getRoot().getActiveLeaf();
+ IEclipseContext activeContext = getActiveLeaf();
Object result = activeContext.get(name);
originatingContext.set(internalName, result);
return true;
}
});
+ trackAccess(internalName);
return internalGet(this, internalName, true);
}
}
diff --git a/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/ActivationTest.java b/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/ActivationTest.java
index b33efd4..ca14f5f 100644
--- a/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/ActivationTest.java
+++ b/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/ActivationTest.java
@@ -130,12 +130,12 @@ public class ActivationTest extends TestCase {
root.set("var", "7");
// nothing is active - we get value from the node
- assertEquals("7", child2.getActive("var"));
+ assertEquals("3", child1.getActive("var"));
child11.activateBranch();
- assertEquals("1", child2.getActive("var"));
+ assertEquals("1", child1.getActive("var"));
child12.activateBranch();
- assertEquals("2", child2.getActive("var"));
+ assertEquals("2", child1.getActive("var"));
child22.activateBranch();
assertEquals("5", child2.getActive("var"));
}
@@ -161,23 +161,74 @@ public class ActivationTest extends TestCase {
final String[] result = new String[1];
- child2.runAndTrack(new RunAndTrack() {
+ child1.runAndTrack(new RunAndTrack() {
public boolean changed(IEclipseContext context) {
result[0] = (String) context.getActive("var");
return true;
}});
// nothing is active - we get value from the node
- assertEquals("7", result[0]);
+ assertEquals("3", result[0]);
child11.activateBranch();
assertEquals("1", result[0]);
child12.activateBranch();
assertEquals("2", result[0]);
child22.activateBranch();
- assertEquals("5", result[0]);
+ assertEquals("2", result[0]);
}
+ public void testGetActiveRATNumberOfCalls() {
+ IEclipseContext root = EclipseContextFactory.create("root");
+
+ IEclipseContext child1 = root.createChild("child1");
+ IEclipseContext child11 = child1.createChild("child11");
+ IEclipseContext child12 = child1.createChild("child12");
+
+ IEclipseContext child2 = root.createChild("child2");
+ IEclipseContext child21 = child2.createChild("child21");
+ IEclipseContext child22 = child2.createChild("child22");
+
+ child11.set("var", "1");
+ child12.set("var", "1");
+ child1.set("var", "3");
+ child21.set("var", "4");
+ child22.set("var", "4");
+ child2.set("var", "6");
+ root.set("var", "7");
+
+ final String[] result = new String[1];
+ final int[] called = new int[1];
+ called[0] = 0;
+
+ child1.runAndTrack(new RunAndTrack() {
+ public boolean changed(IEclipseContext context) {
+ result[0] = (String) context.getActive("var");
+ called[0]++;
+ return true;
+ }});
+
+ // nothing is active - we get value from the node
+ assertEquals("3", result[0]);
+ assertEquals(1, called[0]);
+
+ child11.activateBranch();
+ assertEquals("1", result[0]);
+ assertEquals(2, called[0]);
+
+ child12.activateBranch();
+ assertEquals("1", result[0]);
+ assertEquals(2, called[0]);
+
+ child22.activateBranch();
+ assertEquals("1", result[0]);
+ assertEquals(2, called[0]);
+
+ child21.activateBranch();
+ assertEquals("1", result[0]);
+ assertEquals(2, called[0]);
+ }
+
public static class ActiveInject {
//@Inject @Named("var")
public String value;