Search in sources :

Example 91 with IEclipseContext

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

the class EclipseContextTest method testRunAndTrack.

@Test
public void testRunAndTrack() {
    final Object[] value = new Object[1];
    context.runAndTrack(new RunAndTrack() {

        @Override
        public boolean changed(IEclipseContext context) {
            runCounter++;
            value[0] = context.get("foo");
            return true;
        }
    });
    assertEquals(1, runCounter);
    assertEquals(null, value[0]);
    context.set("foo", "bar");
    assertEquals(2, runCounter);
    assertEquals("bar", value[0]);
    context.remove("foo");
    assertEquals(3, runCounter);
    assertEquals(null, value[0]);
    context.set("foo", new ContextFunction() {

        @Override
        public Object compute(IEclipseContext context, String contextKey) {
            return context.get("bar");
        }
    });
    assertEquals(4, runCounter);
    assertEquals(null, value[0]);
    context.set("bar", "baz");
    assertEquals(5, runCounter);
    assertEquals("baz", value[0]);
    context.set("bar", "baf");
    assertEquals(6, runCounter);
    assertEquals("baf", value[0]);
    context.remove("bar");
    assertEquals(7, runCounter);
    assertEquals(null, value[0]);
    parentContext.set("bar", "bam");
    assertEquals(8, runCounter);
    assertEquals("bam", value[0]);
}
Also used : ContextFunction(org.eclipse.e4.core.contexts.ContextFunction) RunAndTrack(org.eclipse.e4.core.contexts.RunAndTrack) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 92 with IEclipseContext

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

the class EclipseContextTest method testRemoveValueComputationOnDispose.

@Test
public void testRemoveValueComputationOnDispose() {
    IEclipseContext parent = EclipseContextFactory.create("ParentContext");
    IEclipseContext child = parent.createChild("ChildContext");
    parent.set("x", Integer.valueOf(1));
    parent.set("y", Integer.valueOf(1));
    parent.set("sum", new AddContextFunction());
    child.get("sum");
    assertEquals(1, listenersCount(child));
    child.dispose();
    assertEquals(0, listenersCount(parent));
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 93 with IEclipseContext

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

the class EclipseContextTest method testNullInheritance.

@Test
public void testNullInheritance() {
    IEclipseContext parent = EclipseContextFactory.create("ParentContext");
    IEclipseContext child = parent.createChild("ChildContext");
    parent.set("x", Integer.valueOf(1));
    child.set("x", null);
    assertNull(child.get("x"));
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 94 with IEclipseContext

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

the class EclipseContextTest method testRunAndTrackMultipleValues.

@Test
public void testRunAndTrackMultipleValues() {
    IEclipseContext parent = EclipseContextFactory.create("ParentContext");
    final IEclipseContext child = parent.createChild("ChildContext");
    parent.set("parentValue", "x");
    child.set("childValue", "x");
    RunAndTrack runnable = new RunAndTrack() {

        @Override
        public boolean changed(IEclipseContext context) {
            runCounter++;
            if (runCounter < 2) {
                child.get("childValue");
                return true;
            }
            if (runCounter < 3) {
                child.get("parentValue");
                return true;
            }
            return false;
        }
    };
    child.runAndTrack(runnable);
    assertEquals(1, runCounter);
    child.set("childValue", "z");
    assertEquals(2, runCounter);
    parent.set("parentValue", "z");
    assertEquals(3, runCounter);
}
Also used : RunAndTrack(org.eclipse.e4.core.contexts.RunAndTrack) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 95 with IEclipseContext

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

the class RunAndTrackTest method testActiveChange.

@Test
public void testActiveChange() throws Exception {
    final IEclipseContext workbenchContext = getGlobalContext();
    workbenchContext.set("activePart", new ActivePartLookupFunction());
    final IEclipseContext[] windows = createNextLevel(workbenchContext, "window", 1);
    final IEclipseContext[] parts = createNextLevel(windows[0], "part", 2);
    assertEquals("part0", workbenchContext.get(ACTIVE_PART));
    windows[0].set(ACTIVE_CHILD, parts[1]);
    assertEquals("part1", workbenchContext.get(ACTIVE_PART));
}
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