use of org.eclipse.e4.core.contexts.Active in project ACS by ACS-Community.
the class PeriodicRefreshHandler method execute.
/**
* Starts a {@link NotifyServiceUpdateJob} with 10 seconds refresh period,
* which will notify the interested parts via the IEventBroker.
* <p>
* An alternative implementation could get parameter <code>@Active MPart part</code> injected
* and notify the part directly, without IEventBroker.
*/
@Execute
public void execute(MHandledItem handledItem) {
// sync menu item state
sharedIsSelected = handledItem.isSelected();
for (MItem menuItem : menuItemsToSync.values()) {
menuItem.setSelected(sharedIsSelected);
}
// start or stop the periodic refresh job
if (sharedIsSelected) {
if (job == null) {
// start periodic refreshes
job = new NotifyServiceUpdateJob(eventModel, sync, statusLineWriter, eventBroker, refreshDelaySeconds * 1000);
job.schedule();
System.out.println("Scheduled refresh job.");
} else {
System.out.println("Error: refresh job is already running!");
}
} else {
if (job != null) {
job.cancel();
job = null;
System.out.println("Cancelled refresh job.");
} else {
System.out.println("Error: refresh job is already cancelled!");
}
}
}
use of org.eclipse.e4.core.contexts.Active in project whole by wholeplatform.
the class AbstractE4DerivedGraphicalPart 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(DerivedLinkableSelectionListener.class, context, configureSelectionLinkable(params));
}
use of org.eclipse.e4.core.contexts.Active in project eclipse.platform.runtime by eclipse.
the class InvokeInRATTest method testStaticInvoke.
@Test
public void testStaticInvoke() {
IEclipseContext context = EclipseContextFactory.create();
final int[] count = new int[1];
context.runAndTrack(new RunAndTrack() {
@Override
public boolean changed(IEclipseContext context) {
TestHandler handler = (TestHandler) context.get("handlerA");
if (handler != null) {
ContextInjectionFactory.invoke(handler, CanExecute.class, context);
count[0]++;
}
// continue to be notified
return true;
}
});
// check that updates are propagated
context.set("active", Integer.valueOf(123));
context.set("selected", "abc");
TestHandler handler = new TestHandler();
context.set("handlerA", handler);
assertEquals(Integer.valueOf(123), handler.active);
assertEquals("abc", handler.selected);
// check handler replacement
count[0] = 0;
TestHandler newHandler = new TestHandler();
context.set("handlerA", newHandler);
assertEquals(1, count[0]);
assertEquals(Integer.valueOf(123), newHandler.active);
assertEquals("abc", newHandler.selected);
// change values in the context; values should not be propagated to handlers
context.set("active", Integer.valueOf(456));
context.set("selected", "xyz");
assertEquals(Integer.valueOf(123), handler.active);
assertEquals("abc", handler.selected);
assertEquals(Integer.valueOf(123), newHandler.active);
assertEquals("abc", newHandler.selected);
}
use of org.eclipse.e4.core.contexts.Active in project eclipse.platform.runtime by eclipse.
the class ContextObjectSupplier method get.
@Override
public void get(IObjectDescriptor[] descriptors, Object[] actualArgs, final IRequestor requestor, boolean initial, boolean track, boolean group) {
final String[] keys = new String[descriptors.length];
final boolean[] active = new boolean[descriptors.length];
for (int i = 0; i < descriptors.length; i++) {
String key = getKey(descriptors[i]);
if ((actualArgs[i] == IInjector.NOT_A_VALUE))
keys[i] = key;
else if (// allow provider to override IEclipseContext
ECLIPSE_CONTEXT_NAME.equals(key))
keys[i] = ECLIPSE_CONTEXT_NAME;
else
keys[i] = null;
if (descriptors[i] == null)
active[i] = false;
else
active[i] = (descriptors[i].hasQualifier(Active.class));
}
if (requestor != null && track) {
// only track if requested
if (initial) {
RunAndTrack trackable = new ContextInjectionListener(context, actualArgs, keys, active, requestor, group);
context.runAndTrack(trackable);
} else {
// we do track if this is done inside a computation, but don't create another runnable
fillArgs(actualArgs, keys, active);
}
} else {
if (descriptors.length > 0) {
pauseRecording();
try {
fillArgs(actualArgs, keys, active);
} finally {
resumeRecording();
}
}
}
}
use of org.eclipse.e4.core.contexts.Active in project eclipse.platform.runtime by eclipse.
the class ActivationTest method testGetActive.
@Test
public void testGetActive() {
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");
// nothing is active - we get value from the node
assertEquals("3", child1.getActive("var"));
child11.activateBranch();
assertEquals("1", child1.getActive("var"));
child12.activateBranch();
assertEquals("2", child1.getActive("var"));
child22.activateBranch();
assertEquals("5", child2.getActive("var"));
}
Aggregations