Search in sources :

Example 41 with IEclipseContext

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"));
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext)

Example 42 with IEclipseContext

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);
}
Also used : RunAndTrack(org.eclipse.e4.core.contexts.RunAndTrack) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext)

Example 43 with IEclipseContext

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);
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) IInjector(org.eclipse.e4.core.di.IInjector) Test(org.junit.Test)

Example 44 with IEclipseContext

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());
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 45 with IEclipseContext

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);
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Aggregations

IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)195 Test (org.junit.Test)142 RunAndTrack (org.eclipse.e4.core.contexts.RunAndTrack)18 ContextFunction (org.eclipse.e4.core.contexts.ContextFunction)17 BundleContext (org.osgi.framework.BundleContext)15 IEntity (org.whole.lang.model.IEntity)11 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)9 Execute (org.eclipse.e4.core.di.annotations.Execute)7 MPart (org.eclipse.e4.ui.model.application.ui.basic.MPart)6 IImportAsModelDialogFactory (org.whole.lang.ui.dialogs.IImportAsModelDialogFactory)6 Hashtable (java.util.Hashtable)5 PrimaryObjectSupplier (org.eclipse.e4.core.di.suppliers.PrimaryObjectSupplier)4 Named (javax.inject.Named)3 PerformanceTestRunner (org.eclipse.core.tests.harness.PerformanceTestRunner)3 InjectionException (org.eclipse.e4.core.di.InjectionException)3 CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)3 Optional (org.eclipse.e4.core.di.annotations.Optional)3 UISynchronize (org.eclipse.e4.ui.di.UISynchronize)3 ContextMenuProvider (org.eclipse.gef.ContextMenuProvider)3 IMenuManager (org.eclipse.jface.action.IMenuManager)3