use of org.eclipse.e4.core.contexts.ContextFunction in project eclipse.platform.runtime by eclipse.
the class ContextFunctionDynamicsTest method testChangeICF.
/**
* Changing context function should update injected values
*/
@Test
public void testChangeICF() {
IEclipseContext context1 = EclipseContextFactory.create("context1");
IEclipseContext context2 = context1.createChild("context2");
context1.set(SELECTION, new ContextFunction() {
@Override
public Object compute(IEclipseContext context, String contextKey) {
return "func1";
}
});
InjectTarget target = new InjectTarget();
ContextInjectionFactory.inject(target, context2);
assertEquals("func1", target.input);
context1.set(SELECTION, new ContextFunction() {
@Override
public Object compute(IEclipseContext context, String contextKey) {
return "func2";
}
});
assertEquals("func2", target.input);
}
use of org.eclipse.e4.core.contexts.ContextFunction in project eclipse.platform.runtime by eclipse.
the class ContextDynamicTest method testReplaceFunctionWithStaticValue.
@Test
public void testReplaceFunctionWithStaticValue() {
IEclipseContext parent = EclipseContextFactory.create();
IEclipseContext context = parent.createChild();
assertNull(context.getLocal("bar"));
context.set("bar", "baz1");
context.set("bar", new ContextFunction() {
@Override
public Object compute(IEclipseContext context, String contextKey) {
return "baz1";
}
});
parent.set("bar", "baz2");
assertEquals("baz1", context.get("bar"));
context.set("bar", "baz3");
assertEquals("baz3", context.get("bar"));
}
use of org.eclipse.e4.core.contexts.ContextFunction 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]);
}
use of org.eclipse.e4.core.contexts.ContextFunction in project eclipse.platform.runtime by eclipse.
the class ReparentingTest method testBug468048_injection.
@Test
public void testBug468048_injection() {
IEclipseContext p1 = EclipseContextFactory.create("parent1");
p1.set("sample", new ContextFunction() {
@Override
public Object compute(IEclipseContext context) {
return Integer.valueOf(1);
}
});
IEclipseContext p2 = EclipseContextFactory.create("parent2");
p2.set("sample", new ContextFunction() {
@Override
public Object compute(IEclipseContext context) {
return Integer.valueOf(2);
}
});
final IEclipseContext intermed = p1.createChild("intermed");
final IEclipseContext leaf = intermed.createChild("leaf");
Bug468048 b = ContextInjectionFactory.make(Bug468048.class, leaf);
assertEquals(Integer.valueOf(1), b.sample);
intermed.setParent(p2);
assertEquals(Integer.valueOf(2), b.sample);
}
use of org.eclipse.e4.core.contexts.ContextFunction in project eclipse.platform.runtime by eclipse.
the class ReparentingTest method testBug468048_contextFunction.
@Test
public void testBug468048_contextFunction() {
IEclipseContext p1 = EclipseContextFactory.create("parent1");
p1.set("sample", new ContextFunction() {
@Override
public Object compute(IEclipseContext context) {
return Integer.valueOf(1);
}
});
IEclipseContext p2 = EclipseContextFactory.create("parent2");
p2.set("sample", new ContextFunction() {
@Override
public Object compute(IEclipseContext context) {
return Integer.valueOf(2);
}
});
final IEclipseContext intermed = p1.createChild("intermed");
final IEclipseContext leaf = intermed.createChild("leaf");
assertEquals(Integer.valueOf(1), leaf.get("sample"));
intermed.setParent(p2);
assertEquals(Integer.valueOf(2), leaf.get("sample"));
}
Aggregations