use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class RunAndTrackTest method createContext.
private IEclipseContext createContext(IEclipseContext parentContext, String level) {
IEclipseContext childContext = parentContext.createChild(level);
createdContexts.add(childContext);
return childContext;
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class RunAndTrackTest method getGlobalContext.
private IEclipseContext getGlobalContext() {
IEclipseContext serviceContext = EclipseContextFactory.getServiceContext(CoreTestsActivator.getDefault().getBundleContext());
// global initialization and setup, usually done by workbench
IEclipseContext appContext = createContext(serviceContext, "globalContext");
appContext.set("globalContext", appContext);
return appContext;
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class RunAndTrackTest method testActiveChain.
@Test
public void testActiveChain() throws Exception {
final IEclipseContext workbenchContext = getGlobalContext();
workbenchContext.set("activePart", new ActivePartLookupFunction());
final IEclipseContext[] windows = createNextLevel(workbenchContext, "window", 1);
createNextLevel(windows[0], "part", 2);
assertEquals("part0", workbenchContext.get(ACTIVE_PART));
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class AnnotationsInjectionTest method testFieldMethodOrder.
/**
* Tests that fields are injected before methods.
*/
@Test
public void testFieldMethodOrder() {
final AssertionFailedError[] error = new AssertionFailedError[1];
class TestData {
// empty
}
class Injected {
@Inject
@Named("valueField")
Object injectedField;
Object methodValue;
@Inject
public void injectedMethod(@Optional @Named("valueMethod") Object arg) {
try {
assertTrue(injectedField != null);
} catch (AssertionFailedError e) {
error[0] = e;
}
methodValue = arg;
}
}
IEclipseContext context = EclipseContextFactory.create();
TestData fieldValue = new TestData();
TestData methodValue = new TestData();
context.set("valueField", fieldValue);
context.set("valueMethod", methodValue);
Injected object = new Injected();
ContextInjectionFactory.inject(object, context);
if (error[0] != null) {
throw error[0];
}
assertEquals(fieldValue, object.injectedField);
assertEquals(methodValue, object.methodValue);
// removing method value, the field should still have value
context.remove("valueMethod");
if (error[0] != null) {
throw error[0];
}
assertEquals(fieldValue, object.injectedField);
assertNull(object.methodValue);
context.dispose();
if (error[0] != null) {
throw error[0];
}
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class AnnotationsInjectionTest method testInvoke.
@Test
public void testInvoke() {
class TestData {
public String value;
public TestData(String tmp) {
value = tmp;
}
}
class Injected {
public String myString;
public Injected() {
// placeholder
}
@Execute
public String something(@Named("testing123") TestData data) {
myString = data.value;
return "true";
}
}
IEclipseContext context = EclipseContextFactory.create();
TestData methodValue = new TestData("abc");
context.set("testing123", methodValue);
Injected object = new Injected();
assertNull(object.myString);
assertEquals("true", ContextInjectionFactory.invoke(object, Execute.class, context, null));
assertEquals("abc", object.myString);
}
Aggregations