use of org.eclipse.ui.handlers.IHandlerActivation in project bndtools by bndtools.
the class BndEditor method setupActions.
private void setupActions() {
String fileName = getFileAndProject(getEditorInput()).getFirst();
if (fileName.endsWith(LaunchConstants.EXT_BNDRUN)) {
final IHandlerService handlerSvc = (IHandlerService) getEditorSite().getService(IHandlerService.class);
final AbstractHandler handler = new AbstractHandler() {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
resolveRunBundles(new NullProgressMonitor(), false);
return null;
}
};
final IHandlerActivation activation = handlerSvc.activateHandler("bndtools.runEditor.resolve", handler);
this.resolveJobListener = new JobChangeAdapter() {
@Override
public void running(IJobChangeEvent event) {
if (event.getJob() instanceof ResolveJob)
Display.getDefault().asyncExec(() -> handlerSvc.deactivateHandler(activation));
}
@Override
public void done(IJobChangeEvent event) {
if (event.getJob() instanceof ResolveJob)
Display.getDefault().asyncExec(() -> handlerSvc.activateHandler(activation));
}
};
Job.getJobManager().addJobChangeListener(resolveJobListener);
}
}
use of org.eclipse.ui.handlers.IHandlerActivation in project xtext-eclipse by eclipse.
the class CodetemplatesEmbeddedEditorActions method createFocusAndDisposeListeners.
@Override
protected void createFocusAndDisposeListeners() {
final List<IHandlerActivation> handlerActivations = Lists.newArrayListWithExpectedSize(3);
final IHandlerService handlerService = workbench.getAdapter(IHandlerService.class);
final IContextService contextService = workbench.getAdapter(IContextService.class);
Shell shell = viewer.getTextWidget().getShell();
final ActiveShellExpression expression = new ActiveShellExpression(shell);
AtomicReference<IContextActivation> contextActivationHolder = new AtomicReference<>();
shell.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
handlerService.deactivateHandlers(handlerActivations);
}
});
viewer.getTextWidget().addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
IContextActivation contextActivation = contextActivationHolder.get();
if (contextActivation != null) {
contextService.deactivateContext(contextActivation);
}
handlerService.deactivateHandlers(handlerActivations);
handlerActivations.clear();
}
@Override
public void focusGained(FocusEvent e) {
final IContextActivation contextActivation = contextService.activateContext(EMBEDDED_TEXT_EDITOR_SCOPE, expression);
contextActivationHolder.set(contextActivation);
for (final IAction action : allActions.values()) {
handlerActivations.add(handlerService.activateHandler(action.getActionDefinitionId(), new ActionHandler(action), expression, true));
}
}
});
}
use of org.eclipse.ui.handlers.IHandlerActivation in project tmdm-studio-se by Talend.
the class XMLSourceViewer method activateHandlers.
/**
* Activate all handlers
*/
protected void activateHandlers() {
// if handler service is null, return
if (handlerService == null) {
return;
}
// activate handlers if it is not active
Iterator<String> i = handlers.keySet().iterator();
while (i.hasNext()) {
String id = i.next();
IHandler handler = handlers.get(id);
IHandlerActivation activation = handlerActivations.get(handler);
if (activation == null) {
activation = handlerService.activateHandler(id, handler);
handlerActivations.put(handler, activation);
}
}
}
use of org.eclipse.ui.handlers.IHandlerActivation in project xtext-eclipse by eclipse.
the class EmbeddedEditorActions method createFocusAndDisposeListeners.
protected void createFocusAndDisposeListeners() {
final List<IHandlerActivation> handlerActivations = Lists.newArrayListWithExpectedSize(3);
final IHandlerService handlerService = workbench.getAdapter(IHandlerService.class);
final IContextService contextService = workbench.getAdapter(IContextService.class);
Shell shell = viewer.getTextWidget().getShell();
final ActiveShellExpression expression = new ActiveShellExpression(shell);
final IContextActivation contextActivation = contextService.activateContext(EMBEDDED_TEXT_EDITOR_SCOPE, expression);
shell.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
handlerService.deactivateHandlers(handlerActivations);
contextService.deactivateContext(contextActivation);
}
});
viewer.getTextWidget().addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
handlerService.deactivateHandlers(handlerActivations);
handlerActivations.clear();
}
@Override
public void focusGained(FocusEvent e) {
for (final IAction action : allActions.values()) {
handlerActivations.add(handlerService.activateHandler(action.getActionDefinitionId(), new ActionHandler(action), expression, true));
}
}
});
}
use of org.eclipse.ui.handlers.IHandlerActivation in project egit by eclipse.
the class ActionUtils method setGlobalActions.
/**
* Hooks up the {@link Control} such that the given {@link IAction}s are
* registered with the given {@link IHandlerService} while the control has
* the focus. Ensures that actions are properly de-registered when the
* control is disposed.
*
* @param control
* to hook up
* @param actions
* to be registered while the control has the focus
* @param service
* to register the actions with
*/
public static void setGlobalActions(Control control, Collection<? extends IAction> actions, IHandlerService service) {
Collection<IHandlerActivation> handlerActivations = new ArrayList<>();
control.addDisposeListener(event -> {
if (!handlerActivations.isEmpty()) {
service.deactivateHandlers(handlerActivations);
handlerActivations.clear();
}
});
final ActiveShellExpression expression = new ActiveShellExpression(control.getShell());
control.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
if (!handlerActivations.isEmpty()) {
service.deactivateHandlers(handlerActivations);
handlerActivations.clear();
}
}
@Override
public void focusGained(FocusEvent e) {
if (!handlerActivations.isEmpty()) {
// Looks like sometimes we get two focusGained events.
return;
}
for (final IAction action : actions) {
handlerActivations.add(service.activateHandler(action.getActionDefinitionId(), new ActionHandler(action), expression, false));
if (action instanceof IUpdate) {
((IUpdate) action).update();
}
}
}
});
}
Aggregations