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]);
}
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]);
}
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));
}
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"));
}
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]);
}
Aggregations