类org.eclipse.ui.handlers.IHandlerService源码实例Demo

下面列出了怎么用org.eclipse.ui.handlers.IHandlerService的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: xds-ide   文件: OpenXFindPanelHandler.java
/**
 * {@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;
}
 
源代码2 项目: tlaplus   文件: FilteredItemsSelectionDialog.java
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();
}
 
源代码3 项目: tracecompass   文件: KeyBindingsManager.java
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;
}
 
源代码4 项目: EasyShell   文件: Utils.java
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);
        }
    }
}
 
源代码5 项目: eip-designer   文件: CompareWithRouteAction.java
@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);
   }
}
 
源代码6 项目: eip-designer   文件: PersistToRouteModelAction.java
@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);
   }
}
 
源代码7 项目: eip-designer   文件: CompareWithRouteAction.java
@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);
   }
}
 
源代码8 项目: eip-designer   文件: PersistToRouteModelAction.java
@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);
   }
}
 
/**
 * 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));
}
 
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));
}
 
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);
		}
	}
}
 
源代码12 项目: e4macs   文件: BaseYankHandler.java
/**
 * 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) {
			}
		}
}
 
源代码13 项目: e4macs   文件: EmacsPlusUtils.java
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;
}
 
源代码14 项目: saros   文件: OpenPreferencesAction.java
@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$
  }
}
 
源代码15 项目: bonita-studio   文件: TestFullScenario.java
/**
 * @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);
}
 
源代码16 项目: elexis-3-core   文件: EditEigenleistungUi.java
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);
	}
}
 
源代码17 项目: elexis-3-core   文件: EditEigenartikelUi.java
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);
	}
}
 
源代码18 项目: elexis-3-core   文件: ErstelleRnnCommand.java
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$
	}
}
 
源代码19 项目: elexis-3-core   文件: Handler.java
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$
	}
}
 
源代码20 项目: elexis-3-core   文件: EditLabItemUi.java
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);
	}
}
 
源代码21 项目: wildwebdeveloper   文件: TestHTML.java
@Test
public void testFormat() throws Exception {
	final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("testHTMLFile" + System.currentTimeMillis());
	project.create(null);
	project.open(null);
	final IFile file = project.getFile("blah.html");
	file.create(new ByteArrayInputStream("<html><body><a></a></body></html>".getBytes()), true, null);
	ITextEditor editor = (ITextEditor) IDE
			.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
	editor.setFocus();
	editor.getSelectionProvider().setSelection(new TextSelection(0, 0));
	IHandlerService handlerService = PlatformUI.getWorkbench().getService(IHandlerService.class);
	AtomicReference<Exception> ex = new AtomicReference<>();
	new DisplayHelper() {
		@Override protected boolean condition() {
			try {
				handlerService.executeCommand("org.eclipse.lsp4e.format", null);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
	}.waitForCondition(editor.getSite().getShell().getDisplay(), 3000);
	if (ex.get() != null) {
		throw ex.get();
	}
	new DisplayHelper() {
		@Override protected boolean condition() {
			return editor.getDocumentProvider().getDocument(editor.getEditorInput()).getNumberOfLines() > 1;
		}
	}.waitForCondition(editor.getSite().getShell().getDisplay(), 3000);
}
 
源代码22 项目: n4js   文件: HandlerServiceUtils.java
/**
 * 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();
}
 
源代码23 项目: neoscada   文件: AlarmNotifier.java
private void executeCommand ( final ParameterizedCommand command ) throws PartInitException
{
    final IHandlerService handlerService = (IHandlerService)getWorkbenchWindow ().getService ( IHandlerService.class );
    if ( command.getCommand ().isDefined () )
    {
        try
        {
            handlerService.executeCommand ( command, null );
        }
        catch ( final Exception e )
        {
            throw new RuntimeException ( e );
        }
    }
}
 
源代码24 项目: neoscada   文件: TrendControlImage.java
protected void startHdView ()
{
    try
    {
        final ICommandService commandService = (ICommandService)PlatformUI.getWorkbench ().getService ( ICommandService.class );
        final IHandlerService handlerService = (IHandlerService)PlatformUI.getWorkbench ().getService ( IHandlerService.class );

        final Command command = commandService.getCommand ( "org.eclipse.scada.ui.chart.view.commands.OpenParametersChartView" ); //$NON-NLS-1$

        final Parameterization[] parameterizations = new Parameterization[4];
        parameterizations[0] = new Parameterization ( command.getParameter ( "org.eclipse.scada.ui.chart.connectionId" ), this.connectionId ); //$NON-NLS-1$
        parameterizations[1] = new Parameterization ( command.getParameter ( "org.eclipse.scada.ui.chart.itemId" ), this.itemId ); //$NON-NLS-1$
        if ( this.queryString == null || this.queryString.isEmpty () )
        {
            parameterizations[2] = new Parameterization ( command.getParameter ( "org.eclipse.scada.ui.chart.queryTimespec" ), "2400000:600000" ); //$NON-NLS-1$ //$NON-NLS-2$
        }
        else
        {
            parameterizations[2] = new Parameterization ( command.getParameter ( "org.eclipse.scada.ui.chart.queryTimespec" ), this.queryString ); //$NON-NLS-1$ 
        }
        parameterizations[3] = new Parameterization ( command.getParameter ( "org.eclipse.scada.ui.chart.itemType" ), "hd" ); //$NON-NLS-1$ //$NON-NLS-2$

        final ParameterizedCommand parameterCommand = new ParameterizedCommand ( command, parameterizations );

        handlerService.executeCommand ( parameterCommand, null );
    }
    catch ( final Exception e )
    {
        logger.debug ( "Failed to open view", e );
        StatusManager.getManager ().handle ( new Status ( IStatus.ERROR, Activator.PLUGIN_ID, Messages.TrendControlImage_TrendError, e ), StatusManager.BLOCK );
    }
}
 
源代码25 项目: neoscada   文件: SymbolContext.java
/**
 * Execute an Eclipse command
 *
 * @param commandId
 *            the command to execute
 * @param eventData
 *            the parameter event data (depends on the command)
 */
public void executeCommand ( final String commandId, final Map<String, String> eventData )
{
    try
    {
        final ICommandService commandService = (ICommandService)PlatformUI.getWorkbench ().getService ( ICommandService.class );
        final IHandlerService handlerService = (IHandlerService)PlatformUI.getWorkbench ().getService ( IHandlerService.class );

        final Command command = commandService.getCommand ( commandId );

        final Parameterization[] parameterizations = new Parameterization[eventData.size ()];

        int i = 0;
        for ( final Map.Entry<String, String> entry : eventData.entrySet () )
        {
            parameterizations[i] = new Parameterization ( command.getParameter ( entry.getKey () ), entry.getValue () );
            i++;
        }
        final ParameterizedCommand parameterCommand = new ParameterizedCommand ( command, parameterizations );

        handlerService.executeCommand ( parameterCommand, null );
    }
    catch ( final Exception e )
    {
        logger.warn ( "Failed to execute command", e );
        StatusManager.getManager ().handle ( StatusHelper.convertStatus ( Activator.PLUGIN_ID, e ), StatusManager.BLOCK );
    }
}
 
源代码26 项目: neoscada   文件: DoubleClickShowDetailsHandler.java
@Override
public void doubleClick ( final DoubleClickEvent event )
{
    try
    {
        final IHandlerService handlerService = (IHandlerService)PlatformUI.getWorkbench ().getService ( IHandlerService.class );
        handlerService.executeCommand ( COMMAND_ID, null );
    }
    catch ( final Exception e )
    {
        logger.warn ( "Failed to execute command", e );
        StatusManager.getManager ().handle ( StatusHelper.convertStatus ( Activator.PLUGIN_ID, e ), StatusManager.BLOCK );
    }
}
 
源代码27 项目: xtext-eclipse   文件: ValidateActionHandlerTest.java
@Test public void testExpensiveMarkerCreation() throws Exception {
	IFile iFile = createFile("foo/bar.testlanguage", "stuff foo");
	XtextEditor xtextEditor = openEditor(iFile);
	IHandlerService handlerService = xtextEditor.getSite().getService(IHandlerService.class);
	handlerService.executeCommand("org.eclipse.xtext.ui.tests.TestLanguage.validate", null);
	closeEditors();
	Job[] find = Job.getJobManager().find(ValidationJob.XTEXT_VALIDATION_FAMILY);
	for (Job job : find) {
		job.join();
	}
	IResource file = xtextEditor.getResource();
	IMarker[] markers = file.findMarkers(MarkerTypes.EXPENSIVE_VALIDATION, true, IResource.DEPTH_ZERO);
	assertEquals(1, markers.length);

}
 
源代码28 项目: xtext-xtend   文件: ShowHierarchyTest.java
private TestingTypeHierarchyHandler invokeTestingHandler(XtextEditor xtextEditor, String commandID) throws Exception {
	IHandlerService handlerService = xtextEditor.getSite().getService(IHandlerService.class);
	final ICommandService commandService = xtextEditor.getSite()
			.getService(ICommandService.class);
	Command command = commandService.getCommand("org.eclipse.xtext.xbase.ui.hierarchy.OpenTypeHierarchy");
	TestingTypeHierarchyHandler testingHandler = new TestingTypeHierarchyHandler();
	getInjector().injectMembers(testingHandler);
	IHandler originalHandler = command.getHandler();
	command.setHandler(testingHandler);
	final ExecutionEvent event = new ExecutionEvent(command,
			Collections.EMPTY_MAP, null, handlerService.getCurrentState());
	command.executeWithChecks(event);
	command.setHandler(originalHandler);
	return testingHandler;
}
 
源代码29 项目: tracecompass   文件: SWTBotUtils.java
/**
 * Maximize a part. Calling this a second time will "un-maximize" a part.
 *
 * @param part
 *            the workbench part
 */
public static void maximize(@NonNull IWorkbenchPart part) {
    assertNotNull(part);
    IWorkbenchPartSite site = part.getSite();
    assertNotNull(site);
    // The annotation is to make the compiler not complain.
    @Nullable Object handlerServiceObject = site.getService(IHandlerService.class);
    assertTrue(handlerServiceObject instanceof IHandlerService);
    IHandlerService handlerService = (IHandlerService) handlerServiceObject;
    try {
        handlerService.executeCommand(IWorkbenchCommandConstants.WINDOW_MAXIMIZE_ACTIVE_VIEW_OR_EDITOR, null);
    } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) {
        fail(e.getMessage());
    }
}
 
源代码30 项目: tracecompass   文件: AbstractTimeGraphView.java
@Override
public void partDeactivated(IWorkbenchPart part) {
    if ((part == AbstractTimeGraphView.this) && (fFindHandlerActivation != null)) {
        final Object service = PlatformUI.getWorkbench().getService(IHandlerService.class);
        ((IHandlerService) service).deactivateHandler(fFindHandlerActivation);
        fFindHandlerActivation = null;
    }
}
 
 类所在包
 同包方法