Search in sources :

Example 56 with IEclipseContext

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

the class ContextInjectionFactory method inject.

/**
 * Injects a context into a domain object. See the class comment for details on the injection
 * algorithm that is used.
 *
 * @param object The object to perform injection on
 * @param context The context to obtain injected values from
 * @throws InjectionException if an exception occurred while performing this operation
 */
public static void inject(Object object, IEclipseContext context) throws InjectionException {
    PrimaryObjectSupplier supplier = ContextObjectSupplier.getObjectSupplier(context, injector);
    injector.inject(object, supplier);
}
Also used : PrimaryObjectSupplier(org.eclipse.e4.core.di.suppliers.PrimaryObjectSupplier)

Example 57 with IEclipseContext

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

the class ActivationTest method testGetActive.

@Test
public void testGetActive() {
    IEclipseContext root = EclipseContextFactory.create("root");
    IEclipseContext child1 = root.createChild("child1");
    IEclipseContext child11 = child1.createChild("child11");
    IEclipseContext child12 = child1.createChild("child12");
    IEclipseContext child2 = root.createChild("child2");
    IEclipseContext child21 = child2.createChild("child21");
    IEclipseContext child22 = child2.createChild("child22");
    child11.set("var", "1");
    child12.set("var", "2");
    child1.set("var", "3");
    child21.set("var", "4");
    child22.set("var", "5");
    child2.set("var", "6");
    root.set("var", "7");
    // nothing is active - we get value from the node
    assertEquals("3", child1.getActive("var"));
    child11.activateBranch();
    assertEquals("1", child1.getActive("var"));
    child12.activateBranch();
    assertEquals("2", child1.getActive("var"));
    child22.activateBranch();
    assertEquals("5", child2.getActive("var"));
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 58 with IEclipseContext

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

the class ActivationTest method testGetActiveRATNumberOfCalls2.

/**
 * A variation of {@link #testGetActiveRATNumberOfCalls()} that
 * uses distinct values in the leaf contexts.
 */
@Test
public void testGetActiveRATNumberOfCalls2() {
    IEclipseContext root = EclipseContextFactory.create("root");
    IEclipseContext child1 = root.createChild("child1");
    IEclipseContext child11 = child1.createChild("child11");
    IEclipseContext child12 = child1.createChild("child12");
    IEclipseContext child2 = root.createChild("child2");
    IEclipseContext child21 = child2.createChild("child21");
    IEclipseContext child22 = child2.createChild("child22");
    child11.set("var", "11");
    child12.set("var", "12");
    child1.set("var", "3");
    child21.set("var", "21");
    child22.set("var", "22");
    child2.set("var", "6");
    root.set("var", "7");
    final String[] result = new String[1];
    final int[] called = new int[1];
    called[0] = 0;
    child1.runAndTrack(new RunAndTrack() {

        @Override
        public boolean changed(IEclipseContext context) {
            result[0] = (String) context.getActive("var");
            called[0]++;
            return true;
        }
    });
    // nothing is active - we get value from the node
    assertEquals("3", result[0]);
    assertEquals(1, called[0]);
    child11.activateBranch();
    assertEquals("11", result[0]);
    assertEquals(2, called[0]);
    child12.activateBranch();
    assertEquals("12", result[0]);
    assertEquals(3, called[0]);
    child22.activateBranch();
    assertEquals("12", result[0]);
    assertEquals(3, called[0]);
    child21.activateBranch();
    assertEquals("12", result[0]);
    assertEquals(3, called[0]);
}
Also used : RunAndTrack(org.eclipse.e4.core.contexts.RunAndTrack) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 59 with IEclipseContext

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

the class ActivationTest method testContextActivation.

@Test
public void testContextActivation() {
    IEclipseContext rootContext = EclipseContextFactory.create("root");
    rootContext.set("testRAT", new TestRAT());
    IEclipseContext child1 = rootContext.createChild("child1");
    IEclipseContext child11 = child1.createChild("child11");
    IEclipseContext child12 = child1.createChild("child12");
    IEclipseContext child2 = rootContext.createChild("child2");
    IEclipseContext child21 = child2.createChild("child21");
    IEclipseContext child22 = child2.createChild("child22");
    assertEquals(rootContext, rootContext.getActiveLeaf());
    assertNull(rootContext.getActiveChild());
    assertEquals("root", rootContext.get("testRAT"));
    child12.activateBranch();
    assertEquals(child12, rootContext.getActiveLeaf());
    assertEquals(child1, rootContext.getActiveChild());
    assertEquals("child12", rootContext.get("testRAT"));
    assertEquals(child2, child2.getActiveLeaf());
    assertNull(child2.getActiveChild());
    assertEquals("child2", child2.get("testRAT"));
    child21.activateBranch();
    assertEquals(child21, rootContext.getActiveLeaf());
    assertEquals(child2, rootContext.getActiveChild());
    assertEquals("child21", rootContext.get("testRAT"));
    assertEquals(child12, child1.getActiveLeaf());
    assertEquals(child12, child1.getActiveChild());
    assertEquals("child12", child1.get("testRAT"));
    assertEquals(child21, child2.getActiveLeaf());
    assertEquals(child21, child2.getActiveChild());
    assertEquals("child21", child2.get("testRAT"));
    child21.deactivate();
    assertEquals(child2, rootContext.getActiveLeaf());
    assertEquals("child2", rootContext.get("testRAT"));
    assertEquals(child12, child1.getActiveLeaf());
    assertEquals("child12", child1.get("testRAT"));
    assertEquals(child2, child2.getActiveLeaf());
    assertNull(child2.getActiveChild());
    assertEquals("child2", child2.get("testRAT"));
    child22.activateBranch();
    assertEquals(child22, rootContext.getActiveLeaf());
    assertEquals("child22", rootContext.get("testRAT"));
    assertEquals(child12, child1.getActiveLeaf());
    assertEquals("child12", child1.get("testRAT"));
    assertEquals(child22, child2.getActiveLeaf());
    assertEquals("child22", child2.get("testRAT"));
    child11.activateBranch();
    assertEquals(child11, rootContext.getActiveLeaf());
    assertEquals("child11", rootContext.get("testRAT"));
    assertEquals(child11, child1.getActiveLeaf());
    assertEquals("child11", child1.get("testRAT"));
    assertEquals(child22, child2.getActiveLeaf());
    assertEquals("child22", child2.get("testRAT"));
    child11.deactivate();
    assertEquals(child1, rootContext.getActiveLeaf());
    assertEquals("child1", rootContext.get("testRAT"));
    assertEquals(child1, child1.getActiveLeaf());
    assertEquals("child1", child1.get("testRAT"));
    assertEquals(child22, child2.getActiveLeaf());
    assertEquals("child22", child2.get("testRAT"));
    child1.dispose();
    assertNull(rootContext.getActiveChild());
    child2.activateBranch();
    assertEquals(child22, rootContext.getActiveLeaf());
    assertEquals("child22", rootContext.get("testRAT"));
    assertEquals(child22, child2.getActiveLeaf());
    assertEquals("child22", child2.get("testRAT"));
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 60 with IEclipseContext

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

the class ActivationTest method testGetActiveRAT.

@Test
public void testGetActiveRAT() {
    IEclipseContext root = EclipseContextFactory.create("root");
    IEclipseContext child1 = root.createChild("child1");
    IEclipseContext child11 = child1.createChild("child11");
    IEclipseContext child12 = child1.createChild("child12");
    IEclipseContext child2 = root.createChild("child2");
    IEclipseContext child21 = child2.createChild("child21");
    IEclipseContext child22 = child2.createChild("child22");
    child11.set("var", "1");
    child12.set("var", "2");
    child1.set("var", "3");
    child21.set("var", "4");
    child22.set("var", "5");
    child2.set("var", "6");
    root.set("var", "7");
    final String[] result = new String[1];
    child1.runAndTrack(new RunAndTrack() {

        @Override
        public boolean changed(IEclipseContext context) {
            result[0] = (String) context.getActive("var");
            return true;
        }
    });
    // nothing is active - we get value from the node
    assertEquals("3", result[0]);
    child11.activateBranch();
    assertEquals("1", result[0]);
    child12.activateBranch();
    assertEquals("2", result[0]);
    child22.activateBranch();
    assertEquals("2", result[0]);
}
Also used : RunAndTrack(org.eclipse.e4.core.contexts.RunAndTrack) 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