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

The following examples show how to use org.eclipse.ui.handlers.IHandlerService#executeCommand() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
Source File: EmacsPlusUtils.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
private static Object executeCommand(String commandId, Event event, IHandlerService service)
throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException, CommandException {
	Object result = null;
	if (service != null) {
		try {
			MarkUtils.setIgnoreDispatchId(true);
			result =  service.executeCommand(commandId, event);
		} finally {
			MarkUtils.setIgnoreDispatchId(false);
		}		
	}
	return result;
}
 
Example 13
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 14
Source File: AlarmNotifier.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
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 );
        }
    }
}
 
Example 15
Source File: SWTBotUtils.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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());
    }
}
 
Example 16
Source File: ImportAction.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void run() {
	if (Database.get() == null) {
		MsgBox.info("No opened database",
				"You need to open the database for the import first.");
		return;
	}
	try {
		IHandlerService service = PlatformUI
				.getWorkbench().getService(IHandlerService.class);
		service.executeCommand(ActionFactory.IMPORT.getCommandId(), null);
	} catch (Exception e) {
		log.error("Failed to open import wizard", e);
	}
}
 
Example 17
Source File: DoubleClickShowDetailsHandler.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@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 );
    }
}
 
Example 18
Source File: TrendControlImage.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
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 );
    }
}
 
Example 19
Source File: PreferencesActionDelegate.java    From LogViewer with Eclipse Public License 2.0 4 votes vote down vote up
public void run(LogViewer view, Shell shell) {
	
	/* 
	 * first try: create dialog with preference page
	 * 
	IPreferencePage page = new RulePreferencePage();
	PreferenceManager mgr = new PreferenceManager();
	IPreferenceNode node = new PreferenceNode("1", page);
	mgr.addToRoot(node);
	PreferenceDialog dialog = new PreferenceDialog(shell, mgr);
	dialog.create();
	dialog.setMessage(page.getTitle());
	dialog.open();
	*/

	/*
	 * second try: use command framework 
	 */

	// get services
	IWorkbenchWindow window = view.getSite().getWorkbenchWindow();
	ICommandService cS = (ICommandService)window.getService(ICommandService.class);
	IHandlerService hS = (IHandlerService)window.getService(IHandlerService.class);
	
	// get command for preference pages
	Command cmd        = cS.getCommand("org.eclipse.ui.window.preferences");

	// add parameter preferencePageId
	Map<String,Object> params = new HashMap<String,Object>();
	params.put("preferencePageId", "de.anbos.eclipse.logviewer.plugin.LogViewer.page1.3");

	// create command with parameters
	ParameterizedCommand pC = ParameterizedCommand.generateCommand(cmd, params);
	
	// execute parametrized command
	try {
		hS.executeCommand(pC, null);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 20
Source File: TraceControlTestFacility.java    From tracecompass with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Executes an Eclipse command with command ID
 * @param commandId
 * @throws ExecutionException
 * @throws NotDefinedException
 * @throws NotEnabledException
 * @throws NotHandledException
 */
public void executeCommand(String commandId) throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException {
    Object handlerServiceObject = fControlView.getSite().getService(IHandlerService.class);
    IHandlerService handlerService = (IHandlerService) handlerServiceObject;
    handlerService.executeCommand(COMMAND_CATEGORY_PREFIX + commandId, null);
    waitForJobs();
}