use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class ContextExample method run2.
public void run2() {
IEclipseContext parent = EclipseContextFactory.create();
parent.set("complement", new ComplementaryColor());
IEclipseContext child = parent.createChild();
child.set("color", Color.RED);
System.out.println(child.get("color"));
System.out.println(child.get("complement"));
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class ContextExample method price.
public void price() {
final IEclipseContext context = EclipseContextFactory.create();
context.set("price", 19.99);
context.set("tax", 0.05);
context.runAndTrack(new RunAndTrack() {
@Override
public boolean changed(IEclipseContext context) {
total = (Double) context.get("price") * (1.0 + (Double) context.get("tax"));
return true;
}
@Override
public String toString() {
return "calculator";
}
});
print(total);
context.set("tax", 0.07);
print(total);
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class InjectionEventTest method testEventInjection.
@Test
public void testEventInjection() throws InvocationTargetException, InstantiationException {
IInjector injector = InjectorFactory.getDefault();
injector.addBinding(MyBinding.class);
IEclipseContext context = EclipseContextFactory.create();
InjectTarget target = ContextInjectionFactory.make(InjectTarget.class, context);
// initial state
assertEquals(0, target.counter1);
assertNull(target.string1);
assertEquals(1, target.counter3);
assertNull(target.string3);
assertNotNull(target.myBinding);
// send event1
helper.sendEvent("e4/test/event1", "event1data");
assertEquals(1, target.counter1);
assertEquals("event1data", target.string1);
assertEquals(1, target.counter3);
assertNull(target.string3);
assertNotNull(target.myBinding);
// send event2
helper.sendEvent("e4/test/event2", "event2data");
assertEquals(1, target.counter1);
assertEquals("event1data", target.string1);
assertEquals(1, target.counter3);
assertNull(target.string3);
assertNotNull(target.myBinding);
// send event3
helper.sendEvent("e4/test/event3", "event3data");
assertEquals(1, target.counter1);
assertEquals("event1data", target.string1);
assertEquals(2, target.counter3);
assertEquals("event3data", target.string3);
assertNotNull(target.myBinding);
// send event1 again
helper.sendEvent("e4/test/event1", "abc");
assertEquals(2, target.counter1);
assertEquals("abc", target.string1);
assertEquals(2, target.counter3);
assertEquals("event3data", target.string3);
assertNotNull(target.myBinding);
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class InjectionOSGiHandlerTest method testInjectBCinExecute.
@Test
public void testInjectBCinExecute() {
final BundleContext bundleContext = CoreTestsActivator.getDefault().getBundleContext();
final IEclipseContext localContext = EclipseContextFactory.getServiceContext(bundleContext);
TestHandler handler = new TestHandler();
ContextInjectionFactory.invoke(handler, Execute.class, localContext);
assertNotNull(handler.getCtx());
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class ExtendedSupplierInjectionTests method testBug430041.
@Test
public void testBug430041() {
IEclipseContext context = EclipseContextFactory.create();
context.set(Object.class, new Object());
assertEquals(0, EventTestObject_430041.count);
EventTestObject_430041 target = ContextInjectionFactory.make(EventTestObject_430041.class, context);
context.set(EventTestObject_430041.class, target);
// should be 0 since we haven't posted an event with this topic yet
assertEquals(0, EventTestObject_430041.count);
helper.sendEvent(TOPIC_430041, "event1data");
assertEquals(1, EventTestObject_430041.count);
assertEquals("event1data", target.injectedObject);
context.dispose();
assertTrue(target.destroyed);
helper.sendEvent(TOPIC_430041, "event1data_disposed");
assertEquals(1, EventTestObject_430041.count);
assertEquals("event1data", target.injectedObject);
}
Aggregations