use of org.eclipse.ui.ActiveShellExpression 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.ActiveShellExpression in project eclipse-integration-commons by spring-projects.
the class QuickSearchDialog method createViewMenu.
private void createViewMenu(Composite parent) {
toolBar = new ToolBar(parent, SWT.FLAT);
toolItem = new ToolItem(toolBar, SWT.PUSH, 0);
GridData data = new GridData();
data.horizontalAlignment = GridData.END;
toolBar.setLayoutData(data);
toolBar.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
showViewMenu();
}
});
toolItem.setImage(WorkbenchImages.getImage(IWorkbenchGraphicConstants.IMG_LCL_VIEW_MENU));
toolItem.setToolTipText(WorkbenchMessages.FilteredItemsSelectionDialog_menu);
toolItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
showViewMenu();
}
});
menuManager = new MenuManager();
fillViewMenu(menuManager);
IHandlerService service = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
IHandler handler = new AbstractHandler() {
public Object execute(ExecutionEvent event) {
showViewMenu();
return null;
}
};
showViewHandler = service.activateHandler(IWorkbenchCommandConstants.WINDOW_SHOW_VIEW_MENU, handler, new ActiveShellExpression(getShell()));
}
use of org.eclipse.ui.ActiveShellExpression 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();
}
}
}
});
}
use of org.eclipse.ui.ActiveShellExpression 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));
}
}
});
}
Aggregations