Search in sources :

Example 76 with IEclipseContext

use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.

the class Bug317183Test method testY.

@Test
public void testY() {
    IEclipseContext appContext = EclipseContextFactory.create();
    IEclipseContext windowContext = appContext.createChild();
    IEclipseContext partContextA = windowContext.createChild();
    IEclipseContext partContextB = windowContext.createChild();
    IEclipseContext partContextC = windowContext.createChild();
    partContextA.activateBranch();
    RunAndTrackImpl impl = new RunAndTrackImpl();
    windowContext.runAndTrack(impl);
    partContextB.activate();
    partContextA.dispose();
    impl.called = false;
    partContextC.activate();
    // this fails
    assertTrue(impl.called);
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 77 with IEclipseContext

use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.

the class ContextFunctionDynamicsTest method testChangeICF.

/**
 * Changing context function should update injected values
 */
@Test
public void testChangeICF() {
    IEclipseContext context1 = EclipseContextFactory.create("context1");
    IEclipseContext context2 = context1.createChild("context2");
    context1.set(SELECTION, new ContextFunction() {

        @Override
        public Object compute(IEclipseContext context, String contextKey) {
            return "func1";
        }
    });
    InjectTarget target = new InjectTarget();
    ContextInjectionFactory.inject(target, context2);
    assertEquals("func1", target.input);
    context1.set(SELECTION, new ContextFunction() {

        @Override
        public Object compute(IEclipseContext context, String contextKey) {
            return "func2";
        }
    });
    assertEquals("func2", target.input);
}
Also used : ContextFunction(org.eclipse.e4.core.contexts.ContextFunction) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 78 with IEclipseContext

use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.

the class ContextInjectionFactoryTest method testConstructorInjectionBasic.

/**
 * If no other constructors are available, the default constructor should be used
 */
@Test
public void testConstructorInjectionBasic() {
    IEclipseContext context = EclipseContextFactory.create();
    // add an extra argument for the inner class constructors
    context.set(ContextInjectionFactoryTest.class.getName(), this);
    Object basicResult = ContextInjectionFactory.make(TestConstructorObjectBasic.class, context);
    assertNotNull(basicResult);
    assertTrue(basicResult instanceof TestConstructorObjectBasic);
    assertTrue(((TestConstructorObjectBasic) basicResult).defaultConstructorCalled);
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 79 with IEclipseContext

use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.

the class DisposingReferencedContextTest method testContextDisposeCausesCompleteUninjection_Mandatory.

private void testContextDisposeCausesCompleteUninjection_Mandatory(boolean disposeFirst) {
    IEclipseContext windowContext = EclipseContextFactory.create("windowContext");
    IEclipseContext partContext = windowContext.createChild("partContext");
    partContext.activate();
    Object o = new Object();
    windowContext.set("object", o);
    MandatoryTarget target = new MandatoryTarget();
    ContextInjectionFactory.inject(target, windowContext);
    assertEquals("The object should have been injected", o, target.object);
    partContext.dispose();
    assertEquals("The object should not have been uninjected", o, target.object);
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext)

Example 80 with IEclipseContext

use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.

the class GenericsInjectionTest method testGenericInjection.

@Test
public synchronized void testGenericInjection() {
    Animal testAnimal = new Animal();
    Bird testBird = new Bird();
    BirdHouse testBirdHouse = new BirdHouse();
    // create context
    IEclipseContext context = EclipseContextFactory.create();
    context.set(Animal.class, testAnimal);
    context.set(Bird.class, testBird);
    // note that BirdHouse is
    context.set(Feeder.class, testBirdHouse);
    // added as Feeder class
    TestGenericObject userObject = new TestGenericObject();
    ContextInjectionFactory.inject(userObject, context);
    // check field injection
    assertEquals(testBirdHouse, userObject.field);
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Aggregations

IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)197 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 MApplication (org.eclipse.e4.ui.model.application.MApplication)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