Search in sources :

Example 96 with IEclipseContext

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

Example 97 with IEclipseContext

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

Example 98 with IEclipseContext

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

Example 99 with IEclipseContext

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];
    }
}
Also used : Named(javax.inject.Named) Optional(org.eclipse.e4.core.di.annotations.Optional) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) AssertionFailedError(junit.framework.AssertionFailedError) Test(org.junit.Test)

Example 100 with IEclipseContext

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);
}
Also used : Named(javax.inject.Named) Execute(org.eclipse.e4.core.di.annotations.Execute) 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