use of org.eclipse.e4.core.contexts.ContextFunction in project eclipse.platform.runtime by eclipse.
the class ContextFunctionDynamicsTest method testBug315109.
@Test
public void testBug315109() throws Exception {
IEclipseContext appContext = EclipseContextFactory.create();
IEclipseContext windowContext = appContext.createChild();
IEclipseContext partContext = windowContext.createChild();
partContext.activateBranch();
appContext.set(SELECTION, new ContextFunction() {
@Override
public Object compute(IEclipseContext context, String contextKey) {
IEclipseContext parent = context.getParent();
while (parent != null) {
context = parent;
parent = context.getParent();
}
return context.getActiveLeaf().get("out.selection");
}
});
InjectTarget target = new InjectTarget();
ContextInjectionFactory.inject(target, partContext);
// $NON-NLS-1$
assertNull("No selection has been set, should be null", target.input);
Object o = new Object();
windowContext.set(SELECTION, o);
assertEquals(// $NON-NLS-1$
"A selection was set into the window, should have been injected into the part", o, target.input);
}
use of org.eclipse.e4.core.contexts.ContextFunction in project eclipse.platform.runtime by eclipse.
the class ContextFunctionDynamicsTest method testOverrideICF.
/**
* Overriding context function with a regular value on a child node
*/
@Test
public void testOverrideICF() {
IEclipseContext context1 = EclipseContextFactory.create("context1");
IEclipseContext context2 = context1.createChild("context2");
IEclipseContext context3 = context2.createChild("context3");
context1.set(SELECTION, new ContextFunction() {
@Override
public Object compute(IEclipseContext context, String contextKey) {
return "func1";
}
});
InjectTarget target = new InjectTarget();
ContextInjectionFactory.inject(target, context3);
assertEquals("func1", target.input);
Object o = new Object();
context2.set(SELECTION, o);
assertEquals(o, target.input);
}
use of org.eclipse.e4.core.contexts.ContextFunction in project eclipse.platform.runtime by eclipse.
the class ContextFunctionDynamicsTest method testLongChain.
/**
* Tests updates in a chain of 4 contexts
*/
@Test
public void testLongChain() {
IEclipseContext context1 = EclipseContextFactory.create("context1");
IEclipseContext context2 = context1.createChild("context2");
IEclipseContext context3 = context2.createChild("context3");
IEclipseContext context4 = context3.createChild("context4");
// ICF set on top context
context1.set(SELECTION, new ContextFunction() {
@Override
public Object compute(IEclipseContext context, String contextKey) {
return "func1";
}
});
InjectTarget target = new InjectTarget();
ContextInjectionFactory.inject(target, context4);
assertEquals("func1", target.input);
// Override ICF set on the 2nd context
context2.set(SELECTION, new ContextFunction() {
@Override
public Object compute(IEclipseContext context, String contextKey) {
return "func2";
}
});
assertEquals("func2", target.input);
// Override removed
context2.remove(SELECTION);
assertEquals("func1", target.input);
// Override simple value set on 3rd context
context3.set(SELECTION, "abc");
assertEquals("abc", target.input);
// Simple value override removed from 3rd context
context3.remove(SELECTION);
assertEquals("func1", target.input);
}
use of org.eclipse.e4.core.contexts.ContextFunction in project eclipse.platform.runtime by eclipse.
the class EclipseContextTest method testGetCFNotAValue.
@Test
public void testGetCFNotAValue() {
IEclipseContext context = EclipseContextFactory.create("ParentContext");
context.set("x", new ContextFunction() {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.e4.core.contexts.ContextFunction#compute(org.eclipse
* .e4.core.contexts.IEclipseContext, java.lang.String)
*/
@Override
public Object compute(IEclipseContext context, String contextKey) {
return IInjector.NOT_A_VALUE;
}
});
// must call several times as the underlying ValueComputation wrapper is
// created on the first time, but re-used for subsequent calls.
assertNull(context.get("x"));
assertNull(context.get("x"));
assertNull(context.get("x"));
context.dispose();
}
use of org.eclipse.e4.core.contexts.ContextFunction in project eclipse.platform.runtime by eclipse.
the class EclipseContextTest method testGetCFNotAValueToParent.
@Test
public void testGetCFNotAValueToParent() {
IEclipseContext parent = EclipseContextFactory.create("ParentContext");
IEclipseContext child = parent.createChild();
parent.set("x", Integer.valueOf(1));
child.set("x", new ContextFunction() {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.e4.core.contexts.ContextFunction#compute(org.eclipse
* .e4.core.contexts.IEclipseContext, java.lang.String)
*/
@Override
public Object compute(IEclipseContext context, String contextKey) {
return IInjector.NOT_A_VALUE;
}
});
assertEquals(1, child.get("x"));
parent.dispose();
}
Aggregations