use of org.eclipse.core.commands.Command in project yamcs-studio by yamcs.
the class OPIShell method sendUpdateCommand.
/**
* Alert whoever is listening that a new OPIShell has been created.
*/
private static void sendUpdateCommand() {
IServiceLocator serviceLocator = PlatformUI.getWorkbench();
ICommandService commandService = (ICommandService) serviceLocator.getService(ICommandService.class);
try {
Command command = commandService.getCommand(OPI_SHELLS_CHANGED_ID);
command.executeWithChecks(new ExecutionEvent());
} catch (ExecutionException | NotHandledException | NotEnabledException | NotDefinedException e) {
log.log(Level.WARNING, "Failed to send OPI shells changed command", e);
}
}
use of org.eclipse.core.commands.Command in project yamcs-studio by yamcs.
the class ScriptUtil method executeEclipseCommand.
/**
* Execute an Eclipse command with optional parameters. Any parameters must be defined along with the command in
* plugin.xml.
*
* @param commandId
* the Eclipse command id
* @param parameters
* a list of further String arguments alternating key, value: * executeEclipseCommand("id", ["pkey",
* "pvalue"])
*/
public static final void executeEclipseCommand(String commandId, String[] parameters) {
IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(IHandlerService.class);
try {
if (parameters.length % 2 != 0) {
throw new IllegalArgumentException("Parameterized commands must have " + "an equal number of keys and values");
}
if (parameters.length == 0) {
handlerService.executeCommand(commandId, null);
} else {
ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(ICommandService.class);
Parameterization[] params = new Parameterization[parameters.length / 2];
Command c = commandService.getCommand(commandId);
for (int i = 0; i < parameters.length / 2; i++) {
String key = parameters[2 * i];
String value = parameters[2 * i + 1];
IParameter p = c.getParameter(key);
Parameterization pp = new Parameterization(p, value);
params[i] = pp;
}
ParameterizedCommand pc = new ParameterizedCommand(c, params);
handlerService.executeCommand(pc, null);
}
} catch (Exception e) {
ErrorHandlerUtil.handleError("Failed to execute eclipse command: " + commandId, e);
}
}
use of org.eclipse.core.commands.Command in project translationstudio8 by heartsome.
the class CommandsPropertyTester method test.
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;
}
use of org.eclipse.core.commands.Command in project translationstudio8 by heartsome.
the class NewHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
String parameter = event.getParameter("wizardParameter");
Command command = null;
ICommandService commandService = (ICommandService) HandlerUtil.getActiveSite(event).getService(ICommandService.class);
if (parameter == null || parameter.equalsIgnoreCase("project")) {
command = commandService.getCommand("net.heartsome.cat.ts.ui.command.newProject");
} else if (parameter.equalsIgnoreCase("folder")) {
command = commandService.getCommand("net.heartsome.cat.ts.ui.command.newFolder");
} else if (parameter.equalsIgnoreCase("tm")) {
command = commandService.getCommand("net.heartsome.cat.database.ui.tm.command.newTM");
} else if (parameter.equalsIgnoreCase("tb")) {
command = commandService.getCommand("net.heartsome.cat.database.ui.tb.command.newTB");
}
if (command == null) {
return null;
}
IEvaluationService evalService = (IEvaluationService) HandlerUtil.getActiveSite(event).getService(IEvaluationService.class);
IEvaluationContext currentState = evalService.getCurrentState();
ExecutionEvent executionEvent = new ExecutionEvent(command, Collections.EMPTY_MAP, this, currentState);
try {
command.executeWithChecks(executionEvent);
} catch (NotDefinedException e) {
LOGGER.error("", e);
} catch (NotEnabledException e) {
LOGGER.error("", e);
} catch (NotHandledException e) {
LOGGER.error("", e);
}
return null;
}
use of org.eclipse.core.commands.Command in project translationstudio8 by heartsome.
the class AbstractShieldCommandStartup method earlyStartup.
public void earlyStartup() {
Set<String> unusedCommand = getUnusedCommandSet();
IWorkbench workbench = PlatformUI.getWorkbench();
ICommandService commandService = (ICommandService) workbench.getService(ICommandService.class);
Command command;
for (String commandId : unusedCommand) {
command = commandService.getCommand(commandId);
command.undefine();
}
}
Aggregations