Search in sources :

Example 16 with RunAndTrack

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

the class RunAndTrackTest method testRunAndTrackSimple.

@Test
public void testRunAndTrackSimple() throws Exception {
    final IEclipseContext workbenchContext = getGlobalContext();
    workbenchContext.set("activePart", new ActivePartLookupFunction());
    final IEclipseContext[] windows = createNextLevel(workbenchContext, "window", 1);
    windows[0].runAndTrack(new RunAndTrack() {

        @Override
        public boolean changed(IEclipseContext context) {
            final Object part = windows[0].get(ACTIVE_PART);
            windows[0].set(ACTIVE_PART_ID, part);
            return true;
        }

        @Override
        public String toString() {
            return ACTIVE_PART_ID;
        }
    });
    final IEclipseContext[] parts = createNextLevel(windows[0], "part", 2);
    assertEquals("part0", workbenchContext.get(ACTIVE_PART));
    assertEquals("part0", windows[0].get(ACTIVE_PART_ID));
    windows[0].set(ACTIVE_CHILD, parts[1]);
    assertEquals("part1", windows[0].get(ACTIVE_PART));
    assertEquals("part1", windows[0].get(ACTIVE_PART_ID));
}
Also used : RunAndTrack(org.eclipse.e4.core.contexts.RunAndTrack) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 17 with RunAndTrack

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

the class RunAndTrackTest method testRunAndTrackComplex.

/**
 * There was a failing scenario in the legacy workbench support. This captures the hierarchy and
 * function (without any workbench level references). It should be updated when we figure out
 * the failing scenario :-)
 *
 * @throws Exception
 */
@Test
public void testRunAndTrackComplex() throws Exception {
    final IEclipseContext workbenchContext = getGlobalContext();
    workbenchContext.set("activePart", new ActivePartLookupFunction());
    final IEclipseContext[] windows = createNextLevel(workbenchContext, "window", 1);
    windows[0].runAndTrack(new RunAndTrack() {

        @Override
        public boolean changed(IEclipseContext context) {
            final Object part = windows[0].get(ACTIVE_PART);
            windows[0].set(ACTIVE_PART_ID, part);
            return true;
        }

        @Override
        public String toString() {
            return ACTIVE_PART_ID;
        }
    });
    final IEclipseContext[] mainSashes = createNextLevel(windows[0], "mainSash", 2);
    createNextLevel(mainSashes[1], "editorArea", 1);
    final IEclipseContext[] viewSashes = createNextLevel(mainSashes[0], "viewSashes", 2);
    // create package explorer stack
    final IEclipseContext[] packageStack = createNextLevel(viewSashes[0], "packageStack", 1);
    final IEclipseContext[] packageViews = createNextLevel(packageStack[0], "packageViews", 3);
    assertNotNull(packageViews);
    assertEquals("packageViews0", windows[0].get(ACTIVE_PART));
    assertEquals("packageViews0", windows[0].get(ACTIVE_PART_ID));
    // create problems stack
    final IEclipseContext[] problemsStack = createNextLevel(viewSashes[1], "problemsStack", 1);
    final IEclipseContext[] problemsViews = createNextLevel(problemsStack[0], "problemViews", 5);
    assertNotNull(problemsViews);
    assertEquals("packageViews0", windows[0].get(ACTIVE_PART));
    assertEquals("packageViews0", windows[0].get(ACTIVE_PART_ID));
    assertEquals("problemViews0", problemsStack[0].get(ACTIVE_PART));
    // this won't change since it is a "runAndTrack" at the window context
    // level
    assertEquals("packageViews0", problemsStack[0].get(ACTIVE_PART_ID));
    // set the "problems view" active, propagating the information up
    // the active chain.
    problemsStack[0].set(ACTIVE_CHILD, problemsViews[0]);
    viewSashes[1].set(ACTIVE_CHILD, problemsStack[0]);
    mainSashes[0].set(ACTIVE_CHILD, viewSashes[1]);
    windows[0].set(ACTIVE_CHILD, mainSashes[0]);
    workbenchContext.set(ACTIVE_CHILD, windows[0]);
    assertEquals("problemViews0", windows[0].get(ACTIVE_PART));
    assertEquals("problemViews0", windows[0].get(ACTIVE_PART_ID));
    assertEquals("packageViews0", packageStack[0].get(ACTIVE_PART));
    assertEquals("problemViews0", packageStack[0].get(ACTIVE_PART_ID));
}
Also used : RunAndTrack(org.eclipse.e4.core.contexts.RunAndTrack) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 18 with RunAndTrack

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

the class ServiceContextTest method testRecursiveServiceRemoval.

@Test
public void testRecursiveServiceRemoval() {
    BundleContext bundleContext = CoreTestsActivator.getDefault().getBundleContext();
    ServiceRegistration<?> reg1 = bundleContext.registerService(PrintService.SERVICE_NAME, new StringPrintService(), null);
    final IEclipseContext child = context.createChild();
    final IEclipseContext child2 = context.createChild();
    child.get(PrintService.SERVICE_NAME);
    child2.get(PrintService.SERVICE_NAME);
    ensureUnregistered(reg1);
    final boolean[] done = new boolean[] { false };
    context.runAndTrack(new RunAndTrack() {

        @Override
        public boolean changed(IEclipseContext context) {
            if (context.get(PrintService.SERVICE_NAME) == null) {
                child.dispose();
                done[0] = true;
            }
            return true;
        }
    });
    reg1.unregister();
}
Also used : RunAndTrack(org.eclipse.e4.core.contexts.RunAndTrack) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Aggregations

RunAndTrack (org.eclipse.e4.core.contexts.RunAndTrack)18 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)17 Test (org.junit.Test)15 ContextFunction (org.eclipse.e4.core.contexts.ContextFunction)2 PerformanceTestRunner (org.eclipse.core.tests.harness.PerformanceTestRunner)1 Active (org.eclipse.e4.core.contexts.Active)1 CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)1 BundleContext (org.osgi.framework.BundleContext)1