org.eclipse.ui.handlers.IHandlerService Java Examples

The following examples show how to use org.eclipse.ui.handlers.IHandlerService. 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: 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 #2
Source File: TestFullScenario.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @throws ExecutionException
 */
public void editAndSave() throws Exception {
    processEditor = getTheOnlyOneEditor();
    processEditor.getEditingDomain().getCommandStack().execute(
            new SetCommand(processEditor.getEditingDomain(),
                    task,
                    ProcessPackage.Literals.ELEMENT__NAME,
                    TESTNAME));

    final IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
    final ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
    final Command saveCommand = commandService.getCommand("org.eclipse.ui.file.save");
    final ExecutionEvent executionEvent = new ExecutionEvent(saveCommand, Collections.EMPTY_MAP, null,
            handlerService.getClass());
    saveCommand.executeWithChecks(executionEvent);
}
 
Example #3
Source File: OpenXFindPanelHandler.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override // IHandler
public Object execute(ExecutionEvent event) throws ExecutionException {

    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    IEditorPart part = window.getActivePage().getActiveEditor();

    XFindPanel panel = XFindPanelManager.getXFindPanel(part, true);
    if (panel != null) {
        panel.showPanel();
    }
    else {
        // failed to create XFindPanel, execute standard command "Find and Replace".   
        IHandlerService handlerService = (IHandlerService)window.getService(IHandlerService.class);
        try {
            handlerService.executeCommand(IWorkbenchCommandConstants.EDIT_FIND_AND_REPLACE, null);
        } catch (Exception ex) {
            LogHelper.logError("Command " + IWorkbenchCommandConstants.EDIT_FIND_AND_REPLACE + " not found");   //$NON-NLS-1$ //$NON-NLS-2$
        }
    }

    return null;
}
 
Example #4
Source File: EmacsPlusUtils.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
private static Object executeCommand(String commandId, Map<String,?> parameters, Event event, ICommandService ics, IHandlerService ihs)
throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException, CommandException {
	Object result = null;
	if (ics != null && ihs != null) {
		Command command = ics.getCommand(commandId);
		if (command != null) {
			try {
				MarkUtils.setIgnoreDispatchId(true);
				ParameterizedCommand pcommand = ParameterizedCommand.generateCommand(command, parameters);
				if (pcommand != null) {
					result = ihs.executeCommand(pcommand, event);
				}
			} finally {
				MarkUtils.setIgnoreDispatchId(false);
			}		
		}
	}
	return result;
}
 
Example #5
Source File: FilteredItemsSelectionDialog.java    From tlaplus with MIT License 6 votes vote down vote up
public boolean close() {
	this.filterJob.cancel();
	this.refreshCacheJob.cancel();
	this.refreshProgressMessageJob.cancel();
	if (showViewHandler != null) {
		IHandlerService service = PlatformUI
				.getWorkbench().getService(IHandlerService.class);
		service.deactivateHandler(showViewHandler);
		showViewHandler.getHandler().dispose();
		showViewHandler = null;
	}
	if (menuManager != null)
		menuManager.dispose();
	if (contextMenuManager != null)
		contextMenuManager.dispose();
	storeDialog(getDialogSettings());
	return super.close();
}
 
Example #6
Source File: BaseYankHandler.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * In the console context, use paste as
 * in some consoles (e.g. org.eclipse.debug.internal.ui.views.console.ProcessConsole), updateText
 * will not simulate keyboard input
 *  
 * @param event the ExecutionEvent
 * @param widget The consoles StyledText widget
 */
protected void paste(ExecutionEvent event, StyledText widget) {
		IWorkbenchPart apart = HandlerUtil.getActivePart(event);
		if (apart != null) {
			try {
				IWorkbenchPartSite site = apart.getSite();
				if (site != null) {
					IHandlerService service = (IHandlerService) site.getService(IHandlerService.class);
					if (service != null) {
						service.executeCommand(IEmacsPlusCommandDefinitionIds.EMP_PASTE, null);
						KillRing.getInstance().setYanked(true);
					}
				}
			} catch (CommandException e) {
			}
		}
}
 
Example #7
Source File: OpenPreferencesAction.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void run() {
  IHandlerService service =
      PlatformUI.getWorkbench()
          .getActiveWorkbenchWindow()
          .getActivePage()
          .getActivePart()
          .getSite()
          .getService(IHandlerService.class);
  try {
    service.executeCommand(
        "saros.ui.commands.OpenSarosPreferences", //$NON-NLS-1$
        null);
  } catch (Exception e) {
    log.error("Could not execute command", e); // $NON-NLS-1$
  }
}
 
Example #8
Source File: KeyBindingsManager.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
private void dispose() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        //During Eclipse shutdown the active workbench window is null
        return;
    }
    Object serviceObject = window.getService(IHandlerService.class);
    IHandlerService service = (IHandlerService) serviceObject;
    for (IHandlerActivation activation : fHandlerActivations) {
        service.deactivateHandler(activation);
    }
    fHandlerActivations.clear();

    fGoToMessageForKeyBinding = null;
    fFindForKeyBinding = null;
    fMoveUpForKeyBinding = null;
    fMoveDownForKeyBinding = null;
    fMoveLeftForKeyBinding = null;
    fMoveRightForKeyBinding = null;
    fShowNodeStartForKeyBinding = null;
    fShowNodeEndForKeyBinding = null;
}
 
Example #9
Source File: EditEigenleistungUi.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
public static void executeWithParams(PersistentObject parameter){
	try {
		// get the command
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		ICommandService cmdService = (ICommandService) window.getService(ICommandService.class);
		Command cmd = cmdService.getCommand(EditEigenleistungUi.COMMANDID);
		// create the parameter
		HashMap<String, Object> param = new HashMap<String, Object>();
		param.put(EditEigenleistungUi.PARAMETERID, parameter);
		// build the parameterized command
		ParameterizedCommand pc = ParameterizedCommand.generateCommand(cmd, param);
		// execute the command
		IHandlerService handlerService =
			(IHandlerService) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
				.getService(IHandlerService.class);
		handlerService.executeCommand(pc, null);
	} catch (Exception ex) {
		throw new RuntimeException(EditEigenleistungUi.COMMANDID, ex);
	}
}
 
Example #10
Source File: EditEigenartikelUi.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
public static void executeWithParams(PersistentObject parameter){
	try {
		// get the command
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		ICommandService cmdService = (ICommandService) window.getService(ICommandService.class);
		Command cmd = cmdService.getCommand(EditEigenartikelUi.COMMANDID);
		// create the parameter
		HashMap<String, Object> param = new HashMap<String, Object>();
		param.put(EditEigenartikelUi.PARAMETERID, parameter);
		// build the parameterized command
		ParameterizedCommand pc = ParameterizedCommand.generateCommand(cmd, param);
		// execute the command
		IHandlerService handlerService =
			(IHandlerService) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
				.getService(IHandlerService.class);
		handlerService.executeCommand(pc, null);
	} catch (Exception ex) {
		throw new RuntimeException(EditEigenleistungUi.COMMANDID, ex);
	}
}
 
Example #11
Source File: EditLabItemUi.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
public static void executeWithParams(PersistentObject parameter){
	try {
		// get the command
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		ICommandService cmdService = (ICommandService) window.getService(ICommandService.class);
		Command cmd = cmdService.getCommand(COMMANDID);
		// create the parameter
		HashMap<String, Object> param = new HashMap<String, Object>();
		param.put(PARAMETERID, parameter);
		// build the parameterized command
		ParameterizedCommand pc = ParameterizedCommand.generateCommand(cmd, param);
		// execute the command
		IHandlerService handlerService =
			(IHandlerService) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
				.getService(IHandlerService.class);
		handlerService.executeCommand(pc, null);
	} catch (Exception ex) {
		throw new RuntimeException(COMMANDID, ex);
	}
}
 
Example #12
Source File: Utils.java    From EasyShell with Eclipse Public License 2.0 6 votes vote down vote up
private static void executeCommand(IWorkbench workbench, String commandName, Map<String, Object> params) {
    if (workbench == null) {
        workbench = PlatformUI.getWorkbench();
    }
    // get command
    ICommandService commandService = (ICommandService)workbench.getService(ICommandService.class);
    Command command = commandService != null ? commandService.getCommand(commandName) : null;
    // get handler service
    //IBindingService bindingService = (IBindingService)workbench.getService(IBindingService.class);
    //TriggerSequence[] triggerSequenceArray = bindingService.getActiveBindingsFor("de.anbos.eclipse.easyshell.plugin.commands.open");
    IHandlerService handlerService = (IHandlerService)workbench.getService(IHandlerService.class);
    if (command != null && handlerService != null) {
        ParameterizedCommand paramCommand = ParameterizedCommand.generateCommand(command, params);
        try {
            handlerService.executeCommand(paramCommand, null);
        } catch (Exception e) {
            Activator.logError(Activator.getResourceString("easyshell.message.error.handlerservice.execution"), paramCommand.toString(), e, true);
        }
    }
}
 
Example #13
Source File: ErstelleRnnCommand.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
public static Object ExecuteWithParams(IViewSite origin, Tree<?> tSelection){
	IHandlerService handlerService = (IHandlerService) origin.getService(IHandlerService.class);
	ICommandService cmdService = (ICommandService) origin.getService(ICommandService.class);
	try {
		Command command = cmdService.getCommand(ID);
		Parameterization px =
			new Parameterization(command.getParameter("ch.elexis.RechnungErstellen.parameter"), //$NON-NLS-1$
				new TreeToStringConverter().convertToString(tSelection));
		ParameterizedCommand parmCommand =
			new ParameterizedCommand(command, new Parameterization[] {
				px
			});
		
		return handlerService.executeCommand(parmCommand, null);
		
	} catch (Exception ex) {
		throw new RuntimeException("add.command not found"); //$NON-NLS-1$
	}
}
 
Example #14
Source File: CompareWithRouteAction.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
@Override
public void run(IAction action) {
   System.err.println("In run(IACtion)");
   if (serviceLocator == null) {
      serviceLocator = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
   } 
   
   // Create an ExecutionEvent using Eclipse machinery.
   ICommandService srv = (ICommandService) serviceLocator.getService(ICommandService.class);
   IHandlerService hsrv = (IHandlerService) serviceLocator.getService(IHandlerService.class);
   ExecutionEvent event = hsrv.createExecutionEvent(srv.getCommand(ActionCommands.COMPARE_WITH_ROUTE_ACTION), null);
   // Fill it my current active selection.
   if (event.getApplicationContext() instanceof IEvaluationContext) {
      ((IEvaluationContext) event.getApplicationContext()).addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, mySelection);
   }
   
   try {
      handler.execute(event);
   } catch (ExecutionException e) {
      Activator.handleError(e.getMessage(), e, true);
   }
}
 
Example #15
Source File: PersistToRouteModelAction.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
@Override
public void run(IAction action) {
   if (serviceLocator == null) {
      serviceLocator = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
   } 
   
   // Create an ExecutionEvent using Eclipse machinery.
   ICommandService srv = (ICommandService) serviceLocator.getService(ICommandService.class);
   IHandlerService hsrv = (IHandlerService) serviceLocator.getService(IHandlerService.class);
   ExecutionEvent event = hsrv.createExecutionEvent(srv.getCommand(ActionCommands.PERSIST_TO_ROUTE_MODEL_ACTION), null);
   // Fill it my current active selection.
   if (event.getApplicationContext() instanceof IEvaluationContext) {
      ((IEvaluationContext) event.getApplicationContext()).addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, mySelection);
   }
   
   try {
      handler.execute(event);
   } catch (ExecutionException e) {
      Activator.handleError(e.getMessage(), e, true);
   }
}
 
Example #16
Source File: CompareWithRouteAction.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
@Override
public void run(IAction action) {
   System.err.println("In run(IACtion)");
   if (serviceLocator == null) {
      serviceLocator = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
   } 
   
   // Create an ExecutionEvent using Eclipse machinery.
   ICommandService srv = (ICommandService) serviceLocator.getService(ICommandService.class);
   IHandlerService hsrv = (IHandlerService) serviceLocator.getService(IHandlerService.class);
   ExecutionEvent event = hsrv.createExecutionEvent(srv.getCommand(ActionCommands.COMPARE_WITH_ROUTE_ACTION), null);
   // Fill it my current active selection.
   if (event.getApplicationContext() instanceof IEvaluationContext) {
      ((IEvaluationContext) event.getApplicationContext()).addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, mySelection);
   }
   
   try {
      handler.execute(event);
   } catch (ExecutionException e) {
      Activator.handleError(e.getMessage(), e, true);
   }
}
 
Example #17
Source File: PersistToRouteModelAction.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
@Override
public void run(IAction action) {
   if (serviceLocator == null) {
      serviceLocator = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
   } 
   
   // Create an ExecutionEvent using Eclipse machinery.
   ICommandService srv = (ICommandService) serviceLocator.getService(ICommandService.class);
   IHandlerService hsrv = (IHandlerService) serviceLocator.getService(IHandlerService.class);
   ExecutionEvent event = hsrv.createExecutionEvent(srv.getCommand(ActionCommands.PERSIST_TO_ROUTE_MODEL_ACTION), null);
   // Fill it my current active selection.
   if (event.getApplicationContext() instanceof IEvaluationContext) {
      ((IEvaluationContext) event.getApplicationContext()).addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, mySelection);
   }
   
   try {
      handler.execute(event);
   } catch (ExecutionException e) {
      Activator.handleError(e.getMessage(), e, true);
   }
}
 
Example #18
Source File: Handler.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
private static Object execute(IViewSite origin, String commandID, Map<String, Object> params){
	if (origin == null) {
		log.error("origin is null");
		return null;
	}
	IHandlerService handlerService = (IHandlerService) origin.getService(IHandlerService.class);
	ICommandService cmdService = (ICommandService) origin.getService(ICommandService.class);
	try {
		Command command = cmdService.getCommand(commandID);
		String name = StringTool.unique("CommandHandler"); //$NON-NLS-1$
		paramMap.put(name, params);
		Parameterization px = new Parameterization(new DefaultParameter(), name);
		ParameterizedCommand parmCommand =
			new ParameterizedCommand(command, new Parameterization[] {
				px
		});
		
		return handlerService.executeCommand(parmCommand, null);
		
	} catch (Exception ex) {
		throw new RuntimeException("add.command not found"); //$NON-NLS-1$
	}
}
 
Example #19
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 #20
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 #21
Source File: ConsoleCopyCutHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see com.mulgasoft.emacsplus.commands.ConsoleCmdHandler#consoleDispatch(TextConsoleViewer, IConsoleView, ExecutionEvent)
 */
@Override
public Object consoleDispatch(TextConsoleViewer viewer, IConsoleView activePart, ExecutionEvent event) {
	Object result = null;
	IDocument doc = viewer.getDocument();
	try {
		IWorkbenchPartSite site = activePart.getSite();
		if (site != null) {
			IHandlerService service = (IHandlerService) site.getService(IHandlerService.class);
			if (doc != null && service != null) {
				doc.addDocumentListener(KillRing.getInstance());
				String cmdId = getId(event, viewer);
				if (cmdId != null) {
					result = service.executeCommand(cmdId, null);
				}
			}
		}
	} catch (CommandException e) {
		// Shouldn't happen as the Command id will be null or valid
		e.printStackTrace();
	} finally {
		if (doc != null) {
			doc.removeDocumentListener(KillRing.getInstance());
		}
		// clear kill command flag
		KillRing.getInstance().setKill(null, false);
	}
	
	MarkUtils.clearConsoleMark(viewer);
	return result;
}
 
Example #22
Source File: HandlerServiceUtils.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Optionally returns with the current state of the workbench only and if only the
 * {@link PlatformUI#isWorkbenchRunning() workbench is running}.
 *
 * @return the current state of the running workbench. Returns with an {@link Optional#absent() absent} if the
 *         workbench is not running or the {@link IHandlerService} is not available.
 */
public static Optional<IEvaluationContext> getCurrentWorkbenchState() {
	if (!isWorkbenchRunning()) {
		return absent();
	}
	final Object service = getWorkbench().getService(IHandlerService.class);
	return service instanceof IHandlerService ? fromNullable(((IHandlerService) service).getCurrentState())
			: absent();
}
 
Example #23
Source File: TriggerQuickAccessAction.java    From codeexamples-eclipse with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run(IAction action) {
	IHandlerService handlerService = window.getService(IHandlerService.class);
	try {
		handlerService.executeCommand("org.eclipse.ui.window.quickAccess", null); // //$NON-NLS-1$
	} catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) {
		e.printStackTrace();
	}
}
 
Example #24
Source File: SaveCoolbarItem.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void fill(final ToolBar toolbar, final int index, final int iconSize) {
    item = new ToolItem(toolbar, SWT.PUSH);
    item.setToolTipText(Messages.SaveProcessButtonLabel);
    item.setData(SWTBotConstants.SWTBOT_WIDGET_ID_KEY, SWTBotConstants.SWTBOT_ID_SAVE_EDITOR);
    if (iconSize < 0) {
        item.setImage(Pics.getImage(PicsConstants.coolbar_save_48));
        item.setDisabledImage(Pics.getImage(PicsConstants.coolbar_save_disabled_48));
    } else {
        item.setImage(Pics.getImage(PicsConstants.coolbar_save_16));
        item.setDisabledImage(Pics.getImage(PicsConstants.coolbar_save_disabled_16));
    }
    item.setEnabled(false);
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
                    .getActiveEditor();
            if (editor != null) {
                if (editor instanceof DiagramEditor) {
                    final IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench()
                            .getService(IHandlerService.class);
                    final Command command = getCommand();
                    final ExecutionEvent executionEvent = new ExecutionEvent(command, Collections.EMPTY_MAP, null,
                            handlerService.getClass());
                    try {
                        command.executeWithChecks(executionEvent);
                    } catch (final Exception e1) {
                        BonitaStudioLog.error(e1);
                    }

                } else {
                    editor.doSave(null);
                }
            }
        }
    });
}
 
Example #25
Source File: WithMinibuffer.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param editor
 * @param binding
 * @throws ExecutionException
 * @throws NotDefinedException
 * @throws NotEnabledException
 * @throws NotHandledException
 */
private void callBinding(final ITextEditor editor,
		final Binding binding) {
	try {
		IHandlerService service = (IHandlerService) editor.getSite().getService(IHandlerService.class);
		ParameterizedCommand pcommand = binding.getParameterizedCommand();
		service.executeCommand(pcommand, null);
	} catch (Exception e) {
		// Shouldn't happen, but fail quietly
	} 
}
 
Example #26
Source File: CorrectionCommandInstaller.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void deregisterCommands() {
	IHandlerService handlerService= (IHandlerService) PlatformUI.getWorkbench().getAdapter(IHandlerService.class);
	if (handlerService != null && fCorrectionHandlerActivations != null) {
		handlerService.deactivateHandlers(fCorrectionHandlerActivations);
		fCorrectionHandlerActivations= null;
	}
}
 
Example #27
Source File: KeyBindingHelper.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param fActivateEditorBinding
 */
public static void executeCommand(String commandId) {
    IHandlerService handlerService = PlatformUI.getWorkbench().getService(IHandlerService.class);
    try {
        handlerService.executeCommand(commandId, null);
    } catch (Exception e) {
        Log.log(e);
    }

}
 
Example #28
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 #29
Source File: TaskOverview.java    From codeexamples-eclipse with Eclipse Public License 1.0 5 votes vote down vote up
private void hookDoubleClickCommand() {
	viewer.addDoubleClickListener(new IDoubleClickListener() {
		@Override
		public void doubleClick(DoubleClickEvent event) {
			IHandlerService handlerService = getSite().getService(IHandlerService.class);
			try {
				handlerService.executeCommand("com.vogella.rcp.editor.example.openEditor", null);
			} catch (Exception ex) {
				throw new RuntimeException(ex.getMessage());
			}
		}
	});
}
 
Example #30
Source File: ChangeXMPPAccountAction.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
private void openPreferences() {
  IHandlerService service =
      PlatformUI.getWorkbench()
          .getActiveWorkbenchWindow()
          .getActivePage()
          .getActivePart()
          .getSite()
          .getService(IHandlerService.class);
  try {
    service.executeCommand("saros.ui.commands.OpenSarosPreferences", null);
  } catch (Exception e) {
    log.debug("Could execute command", e);
  }
}