use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class ReparentingTest method testContextFunctionSwitchParent.
@Test
public void testContextFunctionSwitchParent() {
IEclipseContext parent = EclipseContextFactory.create();
final IEclipseContext child = parent.createChild();
parent.set("x", Integer.valueOf(3));
parent.set("y", Integer.valueOf(3));
child.set("sum", new AddContextFunction());
assertEquals(6, ((Integer) child.get("sum")).intValue());
IEclipseContext newParent = EclipseContextFactory.create();
newParent.set("x", Integer.valueOf(1));
newParent.set("y", Integer.valueOf(1));
child.setParent(newParent);
assertEquals(2, ((Integer) child.get("sum")).intValue());
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class ReparentingTest method testContextFunctionInParentAdd.
/**
* Tests handling of a context function defined in the parent when the parent is changed to have
* the function
*/
@Test
public void testContextFunctionInParentAdd() {
// setup
IEclipseContext parent = EclipseContextFactory.create();
final IEclipseContext child = parent.createChild();
child.set("x", Integer.valueOf(1));
child.set("y", Integer.valueOf(1));
assertEquals(null, parent.get("sum"));
assertEquals(null, child.get("sum"));
// switch parent
IEclipseContext newParent = EclipseContextFactory.create();
child.setParent(newParent);
newParent.set("sum", new AddContextFunction());
assertEquals(0, ((Integer) newParent.get("sum")).intValue());
assertEquals(2, ((Integer) child.get("sum")).intValue());
// changed values in parent shouldn't affect child
newParent.set("x", Integer.valueOf(3));
newParent.set("y", Integer.valueOf(3));
assertEquals(6, ((Integer) newParent.get("sum")).intValue());
assertEquals(2, ((Integer) child.get("sum")).intValue());
}
use of org.eclipse.e4.core.contexts.IEclipseContext 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.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class ReparentingTest method testContextFunctionNullBecomeParent.
@Test
public void testContextFunctionNullBecomeParent() {
final IEclipseContext child = EclipseContextFactory.create();
child.set("sum", new AddContextFunction());
assertEquals(0, ((Integer) child.get("sum")).intValue());
IEclipseContext parent = EclipseContextFactory.create();
parent.set("x", Integer.valueOf(3));
parent.set("y", Integer.valueOf(3));
child.setParent(parent);
assertEquals(6, ((Integer) child.get("sum")).intValue());
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class ReparentingTest method testContextFunctionInParentRemove.
/**
* Tests handling of a context function defined in the parent when the parent is changed to no
* longer have the function.
*/
@Test
public void testContextFunctionInParentRemove() {
IEclipseContext parent = EclipseContextFactory.create("parent");
final IEclipseContext child = parent.createChild("child");
parent.set("sum", new AddContextFunction());
parent.set("x", Integer.valueOf(3));
parent.set("y", Integer.valueOf(3));
child.set("x", Integer.valueOf(1));
child.set("y", Integer.valueOf(1));
assertEquals(6, ((Integer) parent.get("sum")).intValue());
assertEquals(2, ((Integer) child.get("sum")).intValue());
child.setParent(EclipseContextFactory.create());
assertEquals(6, ((Integer) parent.get("sum")).intValue());
assertNull("Expected null but was: " + child.get("sum"), child.get("sum"));
}
Aggregations