Java Code Examples for org.eclipse.ui.handlers.IHandlerService#activateHandler()

The following examples show how to use org.eclipse.ui.handlers.IHandlerService#activateHandler() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractInfoView.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Fills the actions bars.
 * <p>
 * Subclasses may extend.
 *
 * @param actionBars the action bars
 */
protected void fillActionBars(IActionBars actionBars) {
	IToolBarManager toolBar= actionBars.getToolBarManager();
	fillToolBar(toolBar);

	IAction action;

	action= getCopyToClipboardAction();
	if (action != null)
		actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), action);

	action= getSelectAllAction();
	if (action != null)
		actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), action);

	IHandlerService handlerService= (IHandlerService) getSite().getService(IHandlerService.class);
	handlerService.activateHandler(IWorkbenchCommandConstants.NAVIGATE_TOGGLE_LINK_WITH_EDITOR, new ActionHandler(fToggleLinkAction));
}
 
Example 2
Source File: PackageExplorerActionGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void setGlobalActionHandlers(IActionBars actionBars) {
	// Navigate Go Into and Go To actions.
	actionBars.setGlobalActionHandler(IWorkbenchActionConstants.GO_INTO, fZoomInAction);
	actionBars.setGlobalActionHandler(ActionFactory.BACK.getId(), fBackAction);
	actionBars.setGlobalActionHandler(ActionFactory.FORWARD.getId(), fForwardAction);
	actionBars.setGlobalActionHandler(IWorkbenchActionConstants.UP, fUpAction);
	actionBars.setGlobalActionHandler(IWorkbenchActionConstants.GO_TO_RESOURCE, fGotoResourceAction);
	actionBars.setGlobalActionHandler(JdtActionConstants.GOTO_TYPE, fGotoTypeAction);
	actionBars.setGlobalActionHandler(JdtActionConstants.GOTO_PACKAGE, fGotoPackageAction);
	actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), fSelectAllAction);

	fRefactorActionGroup.retargetFileMenuActions(actionBars);

	IHandlerService handlerService= (IHandlerService) fPart.getViewSite().getService(IHandlerService.class);
	handlerService.activateHandler(IWorkbenchCommandConstants.NAVIGATE_TOGGLE_LINK_WITH_EDITOR, new ActionHandler(fToggleLinkingAction));
	handlerService.activateHandler(CollapseAllHandler.COMMAND_ID, new ActionHandler(fCollapseAllAction));
}
 
Example 3
Source File: CorrectionCommandInstaller.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public void registerCommands(CompilationUnitEditor editor) {
	IWorkbench workbench= PlatformUI.getWorkbench();
	ICommandService commandService= (ICommandService) workbench.getAdapter(ICommandService.class);
	IHandlerService handlerService= (IHandlerService) workbench.getAdapter(IHandlerService.class);
	if (commandService == null || handlerService == null) {
		return;
	}

	if (fCorrectionHandlerActivations != null) {
		JavaPlugin.logErrorMessage("correction handler activations not released"); //$NON-NLS-1$
	}
	fCorrectionHandlerActivations= new ArrayList<IHandlerActivation>();

	Collection<String> definedCommandIds= commandService.getDefinedCommandIds();
	for (Iterator<String> iter= definedCommandIds.iterator(); iter.hasNext();) {
		String id= iter.next();
		if (id.startsWith(ICommandAccess.COMMAND_ID_PREFIX)) {
			boolean isAssist= id.endsWith(ICommandAccess.ASSIST_SUFFIX);
			CorrectionCommandHandler handler= new CorrectionCommandHandler(editor, id, isAssist);
			IHandlerActivation activation= handlerService.activateHandler(id, handler, new LegacyHandlerSubmissionExpression(null, null, editor.getSite()));
			fCorrectionHandlerActivations.add(activation);
		}
	}
}
 
Example 4
Source File: GenerateActionGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void installQuickAccessAction() {
	fHandlerService= (IHandlerService)fSite.getService(IHandlerService.class);
	if (fHandlerService != null) {
		IHandler handler= new JDTQuickMenuCreator(fEditor) {
			@Override
			protected void fillMenu(IMenuManager menu) {
				fillQuickMenu(menu);
			}
		}.createHandler();
		fQuickAccessHandlerActivation= fHandlerService.activateHandler(QUICK_MENU_ID, handler);
	}
}
 
Example 5
Source File: RefactorActionGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void installQuickAccessAction() {
	fHandlerService= (IHandlerService)fSite.getService(IHandlerService.class);
	if (fHandlerService != null) {
		IHandler handler= new JDTQuickMenuCreator(fEditor) {
			@Override
			protected void fillMenu(IMenuManager menu) {
				fillQuickMenu(menu);
			}
		}.createHandler();
		fQuickAccessHandlerActivation= fHandlerService.activateHandler(QUICK_MENU_ID, handler);
	}
}
 
Example 6
Source File: OccurrencesSearchResultPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void createControl(Composite parent) {
	super.createControl(parent);

	IActionBars bars= getSite().getActionBars();
	IMenuManager menu= bars.getMenuManager();
	menu.add(fToggleLinkingAction);

	IHandlerService handlerService= (IHandlerService) getSite().getService(IHandlerService.class);
	handlerService.activateHandler(IWorkbenchCommandConstants.NAVIGATE_TOGGLE_LINK_WITH_EDITOR, new ActionHandler(fToggleLinkingAction));
}
 
Example 7
Source File: ERDiagramEditor.java    From ermasterr with Apache License 2.0 4 votes vote down vote up
private void addKeyHandler(final IAction action) {
    final IHandlerService service = getSite().getService(IHandlerService.class);
    service.activateHandler(action.getActionDefinitionId(), new ActionHandler(action));
}
 
Example 8
Source File: MainDiagramEditor.java    From erflute with Apache License 2.0 4 votes vote down vote up
private void addKeyHandler(IAction action) {
    final IHandlerService service = (IHandlerService) getSite().getService(IHandlerService.class);
    service.activateHandler(action.getActionDefinitionId(), new ActionHandler(action));
}
 
Example 9
Source File: JavaBrowsingPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
protected void activateHandlers(IHandlerService handlerService) {
	handlerService.activateHandler(IWorkbenchCommandConstants.NAVIGATE_TOGGLE_LINK_WITH_EDITOR, new ActionHandler(fToggleLinkingAction));
}
 
Example 10
Source File: ProjectsView.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected void activateHandlers(IHandlerService handlerService) {
	super.activateHandlers(handlerService);
	handlerService.activateHandler(CollapseAllHandler.COMMAND_ID, new ActionHandler(fCollapseAllAction));
}
 
Example 11
Source File: ERDiagramEditor.java    From ermaster-b with Apache License 2.0 4 votes vote down vote up
private void addKeyHandler(IAction action) {
	IHandlerService service = (IHandlerService) this.getSite().getService(
			IHandlerService.class);
	service.activateHandler(action.getActionDefinitionId(),
			new ActionHandler(action));
}
 
Example 12
Source File: GlobalActions.java    From elexis-3-core with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Creates an ActionHandler for the given IAction and registers it to the Site's HandlerService,
 * i. e. binds the action to the command so that key bindings get activated. You need to set the
 * action's actionDefinitionId to the command id.
 * 
 * @param action
 *            the action to activate. The action's actionDefinitionId must have been set to the
 *            command's id (using <code>setActionDefinitionId()</code>)
 * @param part
 *            the view this action should be registered for
 */
public static void registerActionHandler(final ViewPart part, final IAction action){
	String commandId = action.getActionDefinitionId();
	if (!StringTool.isNothing(commandId)) {
		IHandlerService handlerService = part.getSite().getService(IHandlerService.class);
		IHandler handler = new ActionHandler(action);
		handlerService.activateHandler(commandId, handler);
	}
}