use of org.eclipse.e4.core.contexts.IEclipseContext 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.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class EclipseContextTest method testRemoveValueComputationOnDispose.
@Test
public void testRemoveValueComputationOnDispose() {
IEclipseContext parent = EclipseContextFactory.create("ParentContext");
IEclipseContext child = parent.createChild("ChildContext");
parent.set("x", Integer.valueOf(1));
parent.set("y", Integer.valueOf(1));
parent.set("sum", new AddContextFunction());
child.get("sum");
assertEquals(1, listenersCount(child));
child.dispose();
assertEquals(0, listenersCount(parent));
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class EclipseContextTest method testNullInheritance.
@Test
public void testNullInheritance() {
IEclipseContext parent = EclipseContextFactory.create("ParentContext");
IEclipseContext child = parent.createChild("ChildContext");
parent.set("x", Integer.valueOf(1));
child.set("x", null);
assertNull(child.get("x"));
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class EclipseContextTest method testRunAndTrackMultipleValues.
@Test
public void testRunAndTrackMultipleValues() {
IEclipseContext parent = EclipseContextFactory.create("ParentContext");
final IEclipseContext child = parent.createChild("ChildContext");
parent.set("parentValue", "x");
child.set("childValue", "x");
RunAndTrack runnable = new RunAndTrack() {
@Override
public boolean changed(IEclipseContext context) {
runCounter++;
if (runCounter < 2) {
child.get("childValue");
return true;
}
if (runCounter < 3) {
child.get("parentValue");
return true;
}
return false;
}
};
child.runAndTrack(runnable);
assertEquals(1, runCounter);
child.set("childValue", "z");
assertEquals(2, runCounter);
parent.set("parentValue", "z");
assertEquals(3, runCounter);
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class RunAndTrackTest method testActiveChange.
@Test
public void testActiveChange() throws Exception {
final IEclipseContext workbenchContext = getGlobalContext();
workbenchContext.set("activePart", new ActivePartLookupFunction());
final IEclipseContext[] windows = createNextLevel(workbenchContext, "window", 1);
final IEclipseContext[] parts = createNextLevel(windows[0], "part", 2);
assertEquals("part0", workbenchContext.get(ACTIVE_PART));
windows[0].set(ACTIVE_CHILD, parts[1]);
assertEquals("part1", workbenchContext.get(ACTIVE_PART));
}
Aggregations