use of org.eclipse.e4.core.contexts.RunAndTrack in project eclipse.platform.runtime by eclipse.
the class ActivationTest method testGetActiveRAT.
@Test
public void testGetActiveRAT() {
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", "2");
child1.set("var", "3");
child21.set("var", "4");
child22.set("var", "5");
child2.set("var", "6");
root.set("var", "7");
final String[] result = new String[1];
child1.runAndTrack(new RunAndTrack() {
@Override
public boolean changed(IEclipseContext context) {
result[0] = (String) context.getActive("var");
return true;
}
});
// nothing is active - we get value from the node
assertEquals("3", result[0]);
child11.activateBranch();
assertEquals("1", result[0]);
child12.activateBranch();
assertEquals("2", result[0]);
child22.activateBranch();
assertEquals("2", result[0]);
}
use of org.eclipse.e4.core.contexts.RunAndTrack in project eclipse.platform.runtime by eclipse.
the class ContextInjectionTest method testBug374421.
@Test
public void testBug374421() {
try {
IEclipseContext context = EclipseContextFactory.create();
context.runAndTrack(new RunAndTrack() {
@Override
public boolean changed(IEclipseContext context) {
IEclipseContext staticContext = EclipseContextFactory.create();
ContextInjectionFactory.make(Object.class, context, staticContext);
return true;
}
});
} catch (StackOverflowError e) {
fail("See bug 374421 for details.");
}
}
use of org.eclipse.e4.core.contexts.RunAndTrack in project eclipse.platform.runtime by eclipse.
the class ReparentingTest method testRunAndTrackSwitchParent.
@Test
public void testRunAndTrackSwitchParent() {
final String[] value = new String[1];
IEclipseContext parent = EclipseContextFactory.create();
final IEclipseContext child = parent.createChild();
parent.set("x", "oldParent");
child.runAndTrack(new RunAndTrack() {
@Override
public boolean changed(IEclipseContext context) {
value[0] = (String) child.get("x");
return true;
}
});
assertEquals("oldParent", value[0]);
IEclipseContext newParent = EclipseContextFactory.create();
newParent.set("x", "newParent");
child.setParent(newParent);
assertEquals("newParent", value[0]);
}
use of org.eclipse.e4.core.contexts.RunAndTrack in project eclipse.platform.runtime by eclipse.
the class ReparentingTest method testUpdateSameParent.
@Test
public void testUpdateSameParent() {
final Boolean[] called = new Boolean[1];
IEclipseContext parent = EclipseContextFactory.create("parent");
IEclipseContext newParent = EclipseContextFactory.create("newParent");
IEclipseContext child = parent.createChild("child");
parent.set("x", "1");
newParent.set("x", "2");
child.runAndTrack(new RunAndTrack() {
@Override
public boolean changed(IEclipseContext context) {
called[0] = true;
// creates a link
context.get("x");
return true;
}
});
called[0] = false;
// make sure setting parent to the same value does not trigger updates
child.setParent(parent);
assertFalse(called[0]);
child.setParent(newParent);
assertTrue(called[0]);
}
use of org.eclipse.e4.core.contexts.RunAndTrack in project eclipse.platform.runtime by eclipse.
the class EclipseContextTest method testRunAndTrack.
@Test
public void testRunAndTrack() {
final Object[] value = new Object[1];
context.runAndTrack(new RunAndTrack() {
@Override
public boolean changed(IEclipseContext context) {
runCounter++;
value[0] = context.get("foo");
return true;
}
});
assertEquals(1, runCounter);
assertEquals(null, value[0]);
context.set("foo", "bar");
assertEquals(2, runCounter);
assertEquals("bar", value[0]);
context.remove("foo");
assertEquals(3, runCounter);
assertEquals(null, value[0]);
context.set("foo", new ContextFunction() {
@Override
public Object compute(IEclipseContext context, String contextKey) {
return context.get("bar");
}
});
assertEquals(4, runCounter);
assertEquals(null, value[0]);
context.set("bar", "baz");
assertEquals(5, runCounter);
assertEquals("baz", value[0]);
context.set("bar", "baf");
assertEquals(6, runCounter);
assertEquals("baf", value[0]);
context.remove("bar");
assertEquals(7, runCounter);
assertEquals(null, value[0]);
parentContext.set("bar", "bam");
assertEquals(8, runCounter);
assertEquals("bam", value[0]);
}
Aggregations