Java Code Examples for org.eclipse.core.commands.ParameterizedCommand#generateCommand()

The following examples show how to use org.eclipse.core.commands.ParameterizedCommand#generateCommand() . 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: 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 2
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 3
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 4
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 5
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 6
Source File: KeyboardBindingsTask.java    From workspacemechanic with Eclipse Public License 1.0 5 votes vote down vote up
private void modifyBindingsForAddChangeSet(final KbaChangeSet changeSet,
    final KeyBindings bindings, final Scheme scheme) {
  for (KbaBinding toAdd : changeSet.getBindingList()) {
    Command commandToAdd = commandService.getCommand(toAdd.getCid());
    if (!commandToAdd.isDefined()) {
      log.logWarning("Command '" + toAdd.getCid() + "' does not exist. Skipping.");
      continue;
    }
    ParameterizedCommand parameterizedCommandToAdd =
        ParameterizedCommand.generateCommand(commandToAdd, toAdd.getParameters());

    KeySequence triggerSequence;
    try {
      triggerSequence = KeySequence.getInstance(toAdd.getKeySequence());
    } catch (ParseException e) {
      log.logError(e, "Invalid key sequence: %s", toAdd.getKeySequence());
      throw new RuntimeException(e);
    }

    bindings.addIfNotPresent(
        scheme, 
        changeSet.getPlatform(), 
        changeSet.getContextId(), 
        triggerSequence,
        parameterizedCommandToAdd);
  }
}
 
Example 7
Source File: SendBriefAsMailHandler.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException{
	Brief brief = (Brief) ElexisEventDispatcher.getSelected(Brief.class);
	if (brief != null) {
		List<File> attachments = new ArrayList<File>();
		Optional<File> tmpFile = getTempFile(brief);
		if (tmpFile.isPresent()) {
			attachments.add(tmpFile.get());
			ICommandService commandService = (ICommandService) HandlerUtil
				.getActiveWorkbenchWindow(event).getService(ICommandService.class);
			try {
				String attachmentsString = getAttachmentsString(attachments);
				Command sendMailCommand =
					commandService.getCommand("ch.elexis.core.mail.ui.sendMail");
				
				HashMap<String, String> params = new HashMap<String, String>();
				params.put("ch.elexis.core.mail.ui.sendMail.attachments", attachmentsString);
				Patient patient = ElexisEventDispatcher.getSelectedPatient();
				if (patient != null) {
					params.put("ch.elexis.core.mail.ui.sendMail.subject",
						"Patient: " + patient.getLabel());
				}
				
				ParameterizedCommand parametrizedCommmand =
					ParameterizedCommand.generateCommand(sendMailCommand, params);
				PlatformUI.getWorkbench().getService(IHandlerService.class)
					.executeCommand(parametrizedCommmand, null);
			} catch (Exception ex) {
				throw new RuntimeException("ch.elexis.core.mail.ui.sendMail not found", ex);
			}
		}
		removeTempAttachments(attachments);
	}
	return null;
}
 
Example 8
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 9
Source File: DocumentSendAsMailHandler.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException{
	ISelection selection = HandlerUtil.getCurrentSelection(event);
	if (selection instanceof StructuredSelection
		&& !((StructuredSelection) selection).isEmpty()) {
		List<?> iDocuments = ((StructuredSelection) selection).toList();
		
		List<File> attachments = new ArrayList<File>();
		for (Object iDocument : iDocuments) {
			if (iDocument instanceof IDocument) {
				Optional<File> tmpFile = getTempFile((IDocument) iDocument);
				if (tmpFile.isPresent()) {
					attachments.add(tmpFile.get());
				}
			}
		}
		if (!attachments.isEmpty()) {
			ICommandService commandService = (ICommandService) HandlerUtil
				.getActiveWorkbenchWindow(event).getService(ICommandService.class);
			try {
				String attachmentsString = getAttachmentsString(attachments);
				Command sendMailCommand =
					commandService.getCommand("ch.elexis.core.mail.ui.sendMail");
				
				HashMap<String, String> params = new HashMap<String, String>();
				params.put("ch.elexis.core.mail.ui.sendMail.attachments", attachmentsString);
				Patient patient = ElexisEventDispatcher.getSelectedPatient();
				if (patient != null) {
					params.put("ch.elexis.core.mail.ui.sendMail.subject",
						"Patient: " + patient.getLabel());
				}
				
				ParameterizedCommand parametrizedCommmand =
					ParameterizedCommand.generateCommand(sendMailCommand, params);
				PlatformUI.getWorkbench().getService(IHandlerService.class)
					.executeCommand(parametrizedCommmand, null);
			} catch (Exception ex) {
				throw new RuntimeException("ch.elexis.core.mail.ui.sendMail not found", ex);
			}
		}
		removeTempAttachments(attachments);
	}
	return null;
}