Search in sources :

Example 71 with IEclipseContext

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

the class ReparentingTest method testContextFunctionSwitchParent.

@Test
public void testContextFunctionSwitchParent() {
    IEclipseContext parent = EclipseContextFactory.create();
    final IEclipseContext child = parent.createChild();
    parent.set("x", Integer.valueOf(3));
    parent.set("y", Integer.valueOf(3));
    child.set("sum", new AddContextFunction());
    assertEquals(6, ((Integer) child.get("sum")).intValue());
    IEclipseContext newParent = EclipseContextFactory.create();
    newParent.set("x", Integer.valueOf(1));
    newParent.set("y", Integer.valueOf(1));
    child.setParent(newParent);
    assertEquals(2, ((Integer) child.get("sum")).intValue());
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 72 with IEclipseContext

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

the class ReparentingTest method testContextFunctionInParentAdd.

/**
 * Tests handling of a context function defined in the parent when the parent is changed to have
 * the function
 */
@Test
public void testContextFunctionInParentAdd() {
    // setup
    IEclipseContext parent = EclipseContextFactory.create();
    final IEclipseContext child = parent.createChild();
    child.set("x", Integer.valueOf(1));
    child.set("y", Integer.valueOf(1));
    assertEquals(null, parent.get("sum"));
    assertEquals(null, child.get("sum"));
    // switch parent
    IEclipseContext newParent = EclipseContextFactory.create();
    child.setParent(newParent);
    newParent.set("sum", new AddContextFunction());
    assertEquals(0, ((Integer) newParent.get("sum")).intValue());
    assertEquals(2, ((Integer) child.get("sum")).intValue());
    // changed values in parent shouldn't affect child
    newParent.set("x", Integer.valueOf(3));
    newParent.set("y", Integer.valueOf(3));
    assertEquals(6, ((Integer) newParent.get("sum")).intValue());
    assertEquals(2, ((Integer) child.get("sum")).intValue());
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 73 with IEclipseContext

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

the class ReparentingTest method testUpdateSameParent.

@Test
public void testUpdateSameParent() {
    final Boolean[] called = new Boolean[1];
    IEclipseContext parent = EclipseContextFactory.create("parent");
    IEclipseContext newParent = EclipseContextFactory.create("newParent");
    IEclipseContext child = parent.createChild("child");
    parent.set("x", "1");
    newParent.set("x", "2");
    child.runAndTrack(new RunAndTrack() {

        @Override
        public boolean changed(IEclipseContext context) {
            called[0] = true;
            // creates a link
            context.get("x");
            return true;
        }
    });
    called[0] = false;
    // make sure setting parent to the same value does not trigger updates
    child.setParent(parent);
    assertFalse(called[0]);
    child.setParent(newParent);
    assertTrue(called[0]);
}
Also used : RunAndTrack(org.eclipse.e4.core.contexts.RunAndTrack) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 74 with IEclipseContext

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

the class ReparentingTest method testContextFunctionNullBecomeParent.

@Test
public void testContextFunctionNullBecomeParent() {
    final IEclipseContext child = EclipseContextFactory.create();
    child.set("sum", new AddContextFunction());
    assertEquals(0, ((Integer) child.get("sum")).intValue());
    IEclipseContext parent = EclipseContextFactory.create();
    parent.set("x", Integer.valueOf(3));
    parent.set("y", Integer.valueOf(3));
    child.setParent(parent);
    assertEquals(6, ((Integer) child.get("sum")).intValue());
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 75 with IEclipseContext

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

the class ReparentingTest method testContextFunctionInParentRemove.

/**
 * Tests handling of a context function defined in the parent when the parent is changed to no
 * longer have the function.
 */
@Test
public void testContextFunctionInParentRemove() {
    IEclipseContext parent = EclipseContextFactory.create("parent");
    final IEclipseContext child = parent.createChild("child");
    parent.set("sum", new AddContextFunction());
    parent.set("x", Integer.valueOf(3));
    parent.set("y", Integer.valueOf(3));
    child.set("x", Integer.valueOf(1));
    child.set("y", Integer.valueOf(1));
    assertEquals(6, ((Integer) parent.get("sum")).intValue());
    assertEquals(2, ((Integer) child.get("sum")).intValue());
    child.setParent(EclipseContextFactory.create());
    assertEquals(6, ((Integer) parent.get("sum")).intValue());
    assertNull("Expected null but was: " + child.get("sum"), child.get("sum"));
}
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