Search in sources :

Example 6 with Active

use of org.eclipse.e4.core.contexts.Active 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 7 with Active

use of org.eclipse.e4.core.contexts.Active 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)

Example 8 with Active

use of org.eclipse.e4.core.contexts.Active in project whole by wholeplatform.

the class E4OutlineTreePart method createSelectionLinkable.

protected ILinkableSelectionListener createSelectionLinkable(IEntityPartViewer viewer) {
    IEclipseContext params = EclipseContextFactory.create();
    // we need to pass the viewer because it has not been set in the active context
    params.set(IEntityPartViewer.class, viewer);
    return ContextInjectionFactory.make(OutlineDerivedLinkableSelectionListener.class, context, configureSelectionLinkable(params));
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext)

Example 9 with Active

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

the class ActivationTest method testGetActiveBug384425.

@Test
public void testGetActiveBug384425() {
    IEclipseContext root = EclipseContextFactory.create("root");
    IEclipseContext child1 = root.createChild("child1");
    IEclipseContext child11 = child1.createChild("child11");
    IEclipseContext child2 = root.createChild("child2");
    // nothing is active - we get value from the node
    assertNull(root.getActive("var"));
    assertNull(child1.getActive("var"));
    assertNull(child2.getActive("var"));
    child11.activateBranch();
    child11.set("var", "1");
    assertEquals("1", root.getActive("var"));
    assertEquals("1", child1.getActive("var"));
    assertNull(child2.getActive("var"));
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 10 with Active

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

the class ActivationTest method testGetActiveRATNumberOfCalls.

@Test
public void testGetActiveRATNumberOfCalls() {
    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", "1");
    child1.set("var", "3");
    child21.set("var", "4");
    child22.set("var", "4");
    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("1", result[0]);
    assertEquals(2, called[0]);
    child12.activateBranch();
    assertEquals("1", result[0]);
    assertEquals(3, called[0]);
    child22.activateBranch();
    assertEquals("1", result[0]);
    assertEquals(3, called[0]);
    child21.activateBranch();
    assertEquals("1", 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)

Aggregations

IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)11 Test (org.junit.Test)7 RunAndTrack (org.eclipse.e4.core.contexts.RunAndTrack)6 CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)2 Type (java.lang.reflect.Type)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Active (org.eclipse.e4.core.contexts.Active)1 InjectionException (org.eclipse.e4.core.di.InjectionException)1 Execute (org.eclipse.e4.core.di.annotations.Execute)1 MItem (org.eclipse.e4.ui.model.application.ui.menu.MItem)1 Bundle (org.osgi.framework.Bundle)1 BundleContext (org.osgi.framework.BundleContext)1 Event (org.osgi.service.event.Event)1 EventAdmin (org.osgi.service.event.EventAdmin)1