org.eclipse.core.commands.Command Java Examples

The following examples show how to use org.eclipse.core.commands.Command. 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: CommandsPropertyTester.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public boolean test(final Object receiver, final String property,
		final Object[] args, final Object expectedValue) {
	if (receiver instanceof IServiceLocator && args.length == 1
			&& args[0] instanceof String) {
		final IServiceLocator locator = (IServiceLocator) receiver;
		if (TOGGLE_PROPERTY_NAME.equals(property)) {
			final String commandId = args[0].toString();
			final ICommandService commandService = (ICommandService) locator
					.getService(ICommandService.class);
			final Command command = commandService.getCommand(commandId);
			final State state = command
					.getState(RegistryToggleState.STATE_ID);
			if (state != null) {
				return state.getValue().equals(expectedValue);
			}
		}
	}
	return false;
}
 
Example #2
Source File: EditLocalDocumentUtil.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * If {@link Preferences#P_TEXT_EDIT_LOCAL} is set, the
 * <code> ch.elexis.core.ui.command.startEditLocalDocument </code> command is called with the
 * provided {@link Brief}, and the provided {@link IViewPart} is hidden.
 * 
 * @param view
 * @param brief
 * @return returns true if edit local is started and view is hidden
 */
public static boolean startEditLocalDocument(IViewPart view, Brief brief){
	if (CoreHub.localCfg.get(Preferences.P_TEXT_EDIT_LOCAL, false) && brief != null) {
		// open for editing
		ICommandService commandService =
			(ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
		Command command =
			commandService.getCommand("ch.elexis.core.ui.command.startEditLocalDocument"); //$NON-NLS-1$
		
		PlatformUI.getWorkbench().getService(IEclipseContext.class)
			.set(command.getId().concat(".selection"), new StructuredSelection(brief));
		try {
			command.executeWithChecks(
				new ExecutionEvent(command, Collections.EMPTY_MAP, view, null));
		} catch (ExecutionException | NotDefinedException | NotEnabledException
				| NotHandledException e) {
			MessageDialog.openError(view.getSite().getShell(), Messages.TextView_errortitle,
				Messages.TextView_errorlocaleditmessage);
		}
		view.getSite().getPage().hideView(view);
		return true;
	}
	return false;
}
 
Example #3
Source File: PCalTranslateAutomaticallyHandler.java    From tlaplus with MIT License 6 votes vote down vote up
@Inject
public void initializeAtStartup(final IWorkbench workbench, final ICommandService commandService) {
	/*
	 * Check the UI state of the IHandler/Command which indicates if the user
	 * enabled automatic PlusCal conversion.
	 */
	final Command command = commandService.getCommand("toolbox.command.module.translate.automatially");
	final State state = command.getState(RegistryToggleState.STATE_ID);
	if (!((Boolean) state.getValue()).booleanValue()) {
		return;
	}
	// This IHander is stateful even across Toolbox restarts. In other words, if the
	// user enables automatic PlusCal translation, it will remain enabled even after
	// a Toolbox restart. This means we have to register this EventHandler at the
	// IEventBroker during Toolbox startup.
	// It is vital that we use the Workbench's IEventBroker instance. If e.g. we
	// would use an IEventBroker from higher up the IEclipseContext hierarchy, the
	// broker would be disposed when a new spec gets opened while the IHandler's state
	// remains enabled.
	workbench.getService(IEventBroker.class).unsubscribe(this);
	Assert.isTrue(workbench.getService(IEventBroker.class).subscribe(TLAEditor.PRE_SAVE_EVENT, this));
}
 
Example #4
Source File: CommandHelp.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Get the displayable key-binding information for the command
 * 
 * @param com - the command
 * @param activep - if true, return only active bindings
 * 
 * @return a String array of binding sequence binding context information
 */
public static String[] getKeyBindingStrings(Command com, boolean activep) {
	String id = com.getId();

	TriggerSequence trigger;
	// Get platform bindings for Command 
	Binding[] bindings = getBindings(com,activep);

	List<String> bindingInfo = new ArrayList<String>();
	ParameterizedCommand c;
	for (Binding bind : bindings) {
		c = bind.getParameterizedCommand();
		if (c != null && c.getId().equals(id)) {
			trigger = bind.getTriggerSequence();
			bindingInfo.add(trigger.toString());
			bindingInfo.add(bind.getContextId());
		}
	}
	return bindingInfo.toArray(new String[0]);
}
 
Example #5
Source File: PasteCoolbarItem.java    From bonita-studio with GNU General Public License v2.0 6 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.PasteButtonLabel);
    if (iconSize < 0) {
        item.setImage(Pics.getImage(PicsConstants.coolbar_paste_48));
        item.setDisabledImage(Pics.getImage(PicsConstants.coolbar_paste_disabled_48));
    } else {
        item.setImage(Pics.getImage(PicsConstants.coolbar_paste_16));
        item.setDisabledImage(Pics.getImage(PicsConstants.coolbar_paste_disabled_16));
    }
    item.setEnabled(false);
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final Command cmd = getCommand();
            try {
                cmd.executeWithChecks(new ExecutionEvent());
            } catch (final Exception ex) {
                BonitaStudioLog.error(ex);
            }
        }
    });
}
 
Example #6
Source File: EmacsPlusCmdHandler.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Execute the command id (with universal-argument, if appropriate)
 * 
 * @param id
 * @param event
 * @return execution result
 */
private Object dispatchId(ITextEditor editor, String id, Map<String,Object> params) {
	Object result = null;
	if (id != null) {
		ICommandService ics = (ICommandService) editor.getSite().getService(ICommandService.class);
		if (ics != null) {
			Command command = ics.getCommand(id);
			if (command != null) {
				try {
					result = executeCommand(id, (Map<String,?>)params, null, getThisEditor());
				} catch (CommandException e) {}
			}
		}
	}
	return result;
}
 
Example #7
Source File: LocalDocumentsDialog.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
private void endLocalEdit(StructuredSelection selection){
	ICommandService commandService =
		(ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
	Command command = commandService.getCommand("ch.elexis.core.ui.command.endLocalDocument"); //$NON-NLS-1$
	
	PlatformUI.getWorkbench().getService(IEclipseContext.class)
		.set(command.getId().concat(".selection"), selection);
	try {
		command
			.executeWithChecks(new ExecutionEvent(command, Collections.EMPTY_MAP, this, null));
		tableViewer.setInput(service.getAll());
	} catch (ExecutionException | NotDefinedException | NotEnabledException
			| NotHandledException e) {
		MessageDialog.openError(getShell(), Messages.LocalDocumentsDialog_errortitle,
			Messages.LocalDocumentsDialog_errorendmessage);
	}
}
 
Example #8
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 #9
Source File: ConfigureCoolbarItem.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void fill(final ToolBar toolbar, final int index, final int iconSize) {
    final ToolItem item = new ToolItem(toolbar, SWT.PUSH);
    item.setToolTipText(Messages.ConfigureButtonLabel);
    item.setData(SWTBotConstants.SWTBOT_WIDGET_ID_KEY, SWTBotConstants.SWTBOT_ID_CONFIGURE_TOOLITEM);
    if (iconSize < 0) {
        item.setImage(Pics.getImage(PicsConstants.coolbar_configure_48));
        item.setDisabledImage(Pics.getImage(PicsConstants.coolbar_configure_disabled_48));
    } else {
        item.setImage(Pics.getImage(PicsConstants.coolbar_configure_16));
        item.setDisabledImage(Pics.getImage(PicsConstants.coolbar_configure_disabled_16));
    }
    item.setEnabled(false);
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final Command cmd = getCommand();
            try {
                cmd.executeWithChecks(new ExecutionEvent());
            } catch (final Exception ex) {
                BonitaStudioLog.error(ex);
            }
        }
    });
}
 
Example #10
Source File: PreferenceCoolbarItem.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void fill(final ToolBar toolbar, final int index, final int iconSize) {
    final ToolItem item = new ToolItem(toolbar, SWT.PUSH | SWT.RIGHT);
    item.setToolTipText(Messages.PreferencesButtonLabel);
    if (iconSize < 0) {
        item.setImage(Pics.getImage(PicsConstants.coolbar_preferences_48));
        item.setDisabledImage(Pics.getImage(PicsConstants.coolbar_preferences_disabled_48));
    } else {
        item.setImage(Pics.getImage(PicsConstants.coolbar_preferences_16));
        item.setDisabledImage(Pics.getImage(PicsConstants.coolbar_preferences_disabled_16));
    }
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final Command cmd = getCommand();
            try {
                cmd.executeWithChecks(new ExecutionEvent());
            } catch (final Exception ex) {
                BonitaStudioLog.error(ex);
            }
        }
    });

}
 
Example #11
Source File: StatsShapeOptionHandler.java    From depan with Apache License 2.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
  ViewEditor viewer = getViewEditor(event);

  Command command = event.getCommand();
  String optionId = command.getId();

  // For now, simply flip this one state.
  String value = viewer.getOption(optionId);
  if (Strings.isNullOrEmpty(value)) {
    value = StatsViewExtension.SHAPE_DEGREE_MODE_ID.getLabel();
  } else {
    value = null;
  }

  viewer.setOption(optionId, value);
  return null;
}
 
Example #12
Source File: StatsRatioOptionHandler.java    From depan with Apache License 2.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
  ViewEditor viewer = getViewEditor(event);

  Command command = event.getCommand();
  String optionId = command.getId();

  // For now, simply flip this one state.
  String value = viewer.getOption(optionId);
  if (Strings.isNullOrEmpty(value)) {
    value = StatsViewExtension.RATIO_DEGREE_MODE_ID.getLabel();
  } else {
    value = null;
  }

  viewer.setOption(optionId, value);
  return null;
}
 
Example #13
Source File: StatsSizeOptionHandler.java    From depan with Apache License 2.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
  ViewEditor viewer = getViewEditor(event);

  Command command = event.getCommand();
  String optionId = command.getId();

  // For now, simply flip this one state.
  String value = viewer.getOption(optionId);
  if (Strings.isNullOrEmpty(value)) {
    value = StatsViewExtension.SIZE_DEGREE_MODE_ID.getLabel();
  } else {
    value = null;
  }

  viewer.setOption(optionId, value);
  return null;
}
 
Example #14
Source File: OpenPortalCoolbarItem.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void fill(final ToolBar toolbar, final int index, final int iconSize) {
    final ToolItem item = new ToolItem(toolbar, SWT.PUSH);
    item.setToolTipText(Messages.OpenUserXPButtonLabel);
    if (iconSize < 0) {
        item.setImage(Pics.getImage(PicsConstants.coolbar_portal_48));
        item.setDisabledImage(Pics.getImage(PicsConstants.coolbar_portal_disabled_48));
    } else {
        item.setImage(Pics.getImage(PicsConstants.coolbar_portal_16));
        item.setDisabledImage(Pics.getImage(PicsConstants.coolbar_portal_16));
    }
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final Command cmd = getCommand();
            try {
                cmd.executeWithChecks(new ExecutionEvent());
            } catch (final Exception ex) {
                BonitaStudioLog.error(ex);
            }
        }
    });

}
 
Example #15
Source File: LocalDocumentsDialog.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
private void abortLocalEdit(StructuredSelection selection){
	ICommandService commandService =
		(ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
	Command command = commandService.getCommand("ch.elexis.core.ui.command.abortLocalDocument"); //$NON-NLS-1$
	
	PlatformUI.getWorkbench().getService(IEclipseContext.class)
		.set(command.getId().concat(".selection"), selection);
	try {
		command.executeWithChecks(new ExecutionEvent(command, Collections.EMPTY_MAP, this, null));
		tableViewer.setInput(service.getAll());
	} catch (ExecutionException | NotDefinedException | NotEnabledException
			| NotHandledException e) {
		MessageDialog.openError(getShell(), Messages.LocalDocumentsDialog_errortitle,
			Messages.LocalDocumentsDialog_errorabortmessage);
	}
}
 
Example #16
Source File: CommandUtils.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public static Parameterization createParameter( Command command,
		String parameterId, Object value ) throws NotDefinedException,
		ExecutionException, ParameterValueConversionException
{
	ParameterType parameterType = command.getParameterType( parameterId );
	if ( parameterType == null )
	{
		throw new ExecutionException( "Command does not have a parameter type for the given parameter" ); //$NON-NLS-1$
	}

	IParameter param = command.getParameter( parameterId );
	AbstractParameterValueConverter valueConverter = parameterType.getValueConverter( );
	if ( valueConverter == null )
	{
		throw new ExecutionException( "Command does not have a value converter" ); //$NON-NLS-1$
	}

	String valueString = valueConverter.convertToString( value );
	Parameterization parm = new Parameterization( param, valueString );
	return parm;
}
 
Example #17
Source File: CommandsPropertyTester.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public boolean test(final Object receiver, final String property,
		final Object[] args, final Object expectedValue) {
	if (receiver instanceof IServiceLocator && args.length == 1
			&& args[0] instanceof String) {
		final IServiceLocator locator = (IServiceLocator) receiver;
		if (TOGGLE_PROPERTY_NAME.equals(property)) {
			final String commandId = args[0].toString();
			final ICommandService commandService = (ICommandService) locator
					.getService(ICommandService.class);
			final Command command = commandService.getCommand(commandId);
			final State state = command
					.getState(RegistryToggleState.STATE_ID);
			if (state != null) {
				return state.getValue().equals(expectedValue);
			}
		}
	}
	return false;
}
 
Example #18
Source File: MarkUtils.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
private static void removeExecutionListeners(ITextEditor editor) {
	ICommandService ics = (ICommandService) editor.getSite().getService(ICommandService.class);
	if (ics != null) {
		if (execExecListener != null) {
			ics.removeExecutionListener(execExecListener);
		}
		if (copyCmdExecListener != null) {
			Command com = ics.getCommand(EMP_COPY);
			if (com != null) {
				com.removeExecutionListener(copyCmdExecListener);
			}
		}
	}
	copyCmdExecListener = null;
	execExecListener = null;
}
 
Example #19
Source File: CommandAproposHandler.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
private void printCommand(String name, Command command, EmacsPlusConsole console) {
	console.printBold(name + SWT.TAB);
	String bindingStrings = CommandHelp.getKeyBindingString(command, true);
	if (bindingStrings != null) {
		console.printContext(A_MSG + bindingStrings + Z_MSG);
	}
	try {
		String desc = command.getDescription();
		if (desc != null) {
			desc = desc.replaceAll(CR, CR + blanks + SWT.TAB);
			console.print(desc + CR);
		} else {
			console.print(CR);
		}
	} catch (NotDefinedException e) {
	}
}
 
Example #20
Source File: EditorToolbar.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
private void hookToCommands(final ToolItem lastEdit, final ToolItem nextEdit) {
	WorkbenchHelper.runInUI("Hooking to commands", 0, m -> {
		final Command nextCommand = getCommand(NAVIGATE_FORWARD_HISTORY);
		nextEdit.setEnabled(nextCommand.isEnabled());
		final ICommandListener nextListener = e -> nextEdit.setEnabled(searching || nextCommand.isEnabled());
		nextCommand.addCommandListener(nextListener);
		final Command lastCommand = getCommand(NAVIGATE_BACKWARD_HISTORY);
		final ICommandListener lastListener = e -> lastEdit.setEnabled(searching || lastCommand.isEnabled());
		lastEdit.setEnabled(lastCommand.isEnabled());
		lastCommand.addCommandListener(lastListener);
		// Attaching dispose listeners to the toolItems so that they remove the
		// command listeners properly
		lastEdit.addDisposeListener(e -> lastCommand.removeCommandListener(lastListener));
		nextEdit.addDisposeListener(e -> nextCommand.removeCommandListener(nextListener));
	});

}
 
Example #21
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 #22
Source File: HelpCoolbarItem.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void fill(final ToolBar toolbar, final int index, final int iconSize) {
    final ToolItem item = new ToolItem(toolbar, SWT.PUSH | SWT.RIGHT);
    item.setToolTipText(Messages.HelpButtonLabel);
    if (iconSize < 0) {
        item.setImage(Pics.getImage(PicsConstants.coolbar_help_48));
        item.setDisabledImage(Pics.getImage(PicsConstants.coolbar_help_disabled_48));
    } else {
        item.setImage(Pics.getImage(PicsConstants.coolbar_help_16));
        item.setDisabledImage(Pics.getImage(PicsConstants.coolbar_help_disabled_16));
    }
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final Command cmd = getCommand();
            try {
                cmd.executeWithChecks(new ExecutionEvent());
            } catch (final Exception ex) {
                BonitaStudioLog.error(ex);
            }
        }
    });
}
 
Example #23
Source File: KbdMacroLoadHandler.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Bind the loaded macro to its previous key binding, removing any conflicts
 * 
 * @param editor
 * @param command - the new kbd macro command
 * @param sequence - key sequence for binding
 * @param previous - conflicting binding
 */
private void bindMacro(ITextEditor editor, Command command, KeySequence sequence, Binding previous) {
	if (command != null && sequence != null) {
		
		IBindingService service = (editor != null) ? (IBindingService) editor.getSite().getService(IBindingService.class) :
			(IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class);
		if (service instanceof  BindingService) {
			BindingService bindingMgr = (BindingService) service;
			if (previous != null) {
				bindingMgr.removeBinding(previous);
			}
			ParameterizedCommand p = new ParameterizedCommand(command, null);
			Binding binding = new KeyBinding(sequence, p,
					KBD_SCHEMEID, KBD_CONTEXTID, null, null, null, Binding.USER);
			bindingMgr.addBinding(binding);
			// check for conflicts independent of the current Eclipse context
			checkConflicts(bindingMgr,sequence,binding);
		}
	}				
}
 
Example #24
Source File: CommandDescribeHandler.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see com.mulgasoft.emacsplus.minibuffer.IMinibufferExecutable#executeResult(ITextEditor, java.lang.Object)
 */
public boolean doExecuteResult(ITextEditor editor, Object minibufferResult) {

	if (minibufferResult != null) {
		EmacsPlusConsole console = EmacsPlusConsole.getInstance();
		console.clear();
		console.activate();

		ICommandResult commandR = (ICommandResult) minibufferResult;
		String name = commandR.getName();
		Command cmd = commandR.getCommand();
		console.printBold(name + CR);
		printCmdDetails(cmd, console);
	}
	return true;
}
 
Example #25
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 #26
Source File: ContributionAction.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
public Object executeCommand(){
	try {
		ICommandService commandService =
			(ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
		
		Command cmd = commandService.getCommand(commandId);
		if (selection != null) {
			PlatformUI.getWorkbench().getService(IEclipseContext.class)
				.set(commandId.concat(".selection"), new StructuredSelection(selection));
		}
		ExecutionEvent ee = new ExecutionEvent(cmd, Collections.EMPTY_MAP, null, null);
		return cmd.executeWithChecks(ee);
	} catch (Exception e) {
		LoggerFactory.getLogger(getClass())
			.error("cannot execute command with id: " + commandId, e);
	}
	return null;
}
 
Example #27
Source File: CommandUtils.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public static Object executeCommand( String commandId, Map paramMap )
		throws NotDefinedException, ExecutionException,
		ParameterValueConversionException, NotEnabledException,
		NotHandledException
{
	Command cmd = CommandUtils.getCommand( commandId );
	List paramList = new ArrayList( );
	if ( paramMap != null )
	{
		for ( Iterator iter = paramMap.entrySet( ).iterator( ); iter.hasNext( ); )
		{
			Map.Entry entry = (Entry) iter.next( );
			String paramId = entry.getKey( ).toString( );
			Object value = entry.getValue( );
			if ( value != null )
			{
				paramList.add( createParameter( cmd, paramId, value ) );
			}
		}
	}
	if ( paramList.size( ) > 0 )
	{
		ParameterizedCommand paramCommand = new ParameterizedCommand( cmd,
				(Parameterization[]) paramList.toArray( new Parameterization[paramList.size( )] ) );

		return getHandlerService( ).executeCommand( paramCommand, null );
	}
	else
	{
		return getHandlerService( ).executeCommand( commandId, null );
	}
}
 
Example #28
Source File: MedicationViewHelper.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
public static ViewerSortOrder getSelectedComparator(){
	ICommandService service =
		(ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
	Command command = service.getCommand(ApplyCustomSortingHandler.CMD_ID);
	State state = command.getState(ApplyCustomSortingHandler.STATE_ID);
	
	if ((Boolean) state.getValue()) {
		return ViewerSortOrder.getSortOrderPerValue(ViewerSortOrder.MANUAL.val);
	} else {
		return ViewerSortOrder.getSortOrderPerValue(ViewerSortOrder.DEFAULT.val);
	}
}
 
Example #29
Source File: CommandUtils.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public static void disposeParameter( String parameterId, Command command )
		throws NotDefinedException
{
	ParameterType parameterType = command.getParameterType( parameterId );
	Object valueConverter = parameterType.getValueConverter( );
	if ( valueConverter instanceof IDisposable )
		( (IDisposable) valueConverter ).dispose( );
}
 
Example #30
Source File: KbdMacroDefineHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Name and define the Command associated with the kbd macro
 * 
 * @param name - the short name
 * @param editor
 * @param category - the category to use in the Command definition
 * @return
 */
Command nameKbdMacro(String name, ITextEditor editor, String category) {
	Command command = null;
	if (name != null && name.length() > 0) {
		// Register the named macro with KbdMacroSupport
		String id = KbdMacroSupport.getInstance().nameKbdMacro(name);
		command = defineKbdMacro(editor, id, name, category); 
	}
	return command;
}