use of org.eclipse.core.commands.IParameterValues in project egradle by de-jcup.
the class EGradleLaunchDelegate method launch.
@Override
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
IServiceLocator serviceLocator = (IServiceLocator) PlatformUI.getWorkbench();
IHandlerService handlerService = (IHandlerService) serviceLocator.getService(IHandlerService.class);
ICommandService commandService = (ICommandService) serviceLocator.getService(ICommandService.class);
Command command = commandService.getCommand(LaunchGradleCommandHandler.COMMAND_ID);
try {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
try {
IParameter parameter = command.getParameter(LaunchGradleCommandHandler.PARAMETER_LAUNCHCONFIG);
IParameterValues values = parameter.getValues();
if (values instanceof LaunchParameterValues) {
LaunchParameterValues launchParameterValues = (LaunchParameterValues) values;
/* Bugfix #79 - reset always launch data */
launchParameterValues.resetLaunchData();
launchParameterValues.setLaunch(launch);
appendAdditionalLaunchParameters(launchParameterValues);
Parameterization[] params = new Parameterization[] { new Parameterization(parameter, "true") };
ParameterizedCommand parametrizedCommand = new ParameterizedCommand(command, params);
/*
* execute launch command with parameters - will show progress etc. as well
*/
handlerService.executeCommand(parametrizedCommand, null);
} else {
IDEUtil.logWarning(getClass().getSimpleName() + ":parameter values without being a launch parameter value was used !??! :" + values);
}
} catch (Exception e) {
throw new IllegalStateException("EGradle launch command execution failed", e);
} finally {
/*
* the following workaround does really work, but it is the correct place
*/
if (!launch.isTerminated()) {
try {
launch.terminate();
} catch (DebugException e) {
IDEUtil.logError("Was not able to terminate launch", e);
}
}
}
}
});
} catch (Exception e) {
throw new CoreException(new Status(Status.ERROR, IDEActivator.PLUGIN_ID, "Not handled!", e));
}
}
use of org.eclipse.core.commands.IParameterValues in project eclipse.platform.ui by eclipse-platform.
the class HandlerTest method defineCommands.
private void defineCommands(IEclipseContext context) {
ECommandService cs = workbenchContext.get(ECommandService.class);
Category category = cs.defineCategory(TEST_CAT1, "CAT1", null);
cs.defineCommand(TEST_ID1, "ID1", null, category, null);
cs.defineCommand(TEST_ID2, "ID2", null, category, null);
cs.defineCommand(TEST_ID3, "ID3", null, category, new IParameter[] { new IParameter() {
@Override
public boolean isOptional() {
return true;
}
@Override
public IParameterValues getValues() throws ParameterValuesException {
return Collections::emptyMap;
}
@Override
public String getName() {
return ACTIVE_INFO_ID;
}
@Override
public String getId() {
return ACTIVE_INFO_ID;
}
} });
}
use of org.eclipse.core.commands.IParameterValues in project eclipse.platform.ui by eclipse-platform.
the class DefineCommandsTest method testParamizedCommandsSimple.
@Test
public void testParamizedCommandsSimple() {
ECommandService cs = workbenchContext.get(ECommandService.class);
IParameter[] parms = new IParameter[1];
parms[0] = new IParameter() {
@Override
public String getId() {
return "viewId";
}
@Override
public String getName() {
return "View Id";
}
@Override
public IParameterValues getValues() {
return null;
}
@Override
public boolean isOptional() {
return false;
}
};
// command needs to be defined
Category defineCategory = cs.defineCategory(TEST_CAT1, "CAT1", null);
Command command = cs.defineCommand(TEST_ID1_WITH_PARAMETERS, "TEST_ID1_WITH_PARAMETERS", null, defineCategory, parms);
Map<String, Object> parameters = new HashMap<>();
parameters.put("viewId", "Testing");
// afterwards it is possible to create a ParameterizedCommand
ParameterizedCommand createdParamizedCommand = cs.createCommand(TEST_ID1_WITH_PARAMETERS, parameters);
assertNotNull(command);
assertNotNull(createdParamizedCommand);
Command cmd1 = cs.getCommand(TEST_ID1_WITH_PARAMETERS);
assertNotNull("get command1", cmd1);
}
use of org.eclipse.core.commands.IParameterValues in project eclipse.platform.ui by eclipse-platform.
the class BindingManagerTest method testGetBestActiveBindingFor.
/**
* Tests whether the method works with a null argument. Tests that it works
* in a simple case.
*
* @throws NotDefinedException
* If the scheme we try to activate is not defined.
*/
@Test
public void testGetBestActiveBindingFor() throws Exception {
// Test with a null argument.
final TriggerSequence[] activeBindingsForNull = bindingManager.getActiveBindingsFor((ParameterizedCommand) null);
assertNotNull("The active bindings for a command should never be null", activeBindingsForNull);
assertTrue("The active binding for a null command should always be empty", activeBindingsForNull.length == 0);
// Test a simple case.
final Context context = contextManager.getContext("na");
context.define("name", "description", null);
final Scheme scheme = bindingManager.getScheme("na");
scheme.define("name", "description", null);
bindingManager.setActiveScheme(scheme);
final Set<String> activeContextIds = new HashSet<>();
activeContextIds.add("na");
contextManager.setActiveContextIds(activeContextIds);
final String commandId = "commandId";
final String categoryId = "cat";
Category cat = commandManager.getCategory(categoryId);
cat.define("cat", "cat");
Command cmd = commandManager.getCommand(commandId);
IParameter[] parms = new IParameter[1];
parms[0] = new IParameter() {
@Override
public String getId() {
return "viewId";
}
@Override
public String getName() {
return "View Id";
}
@Override
public IParameterValues getValues() {
return null;
}
@Override
public boolean isOptional() {
return false;
}
};
cmd.define("na", "NA", cat, parms);
Map<String, String> map = new HashMap<>();
map.put("viewId", "outline");
ParameterizedCommand outline = ParameterizedCommand.generateCommand(cmd, map);
map = new HashMap<>();
map.put("viewId", "console");
ParameterizedCommand console = ParameterizedCommand.generateCommand(cmd, map);
assertFalse(outline.equals(console));
final Binding b2 = new KeyBinding(KeySequence.getInstance("M1+M2+V"), outline, "na", "na", null, null, null, Binding.SYSTEM);
bindingManager.addBinding(b2);
final Binding binding = new KeyBinding(KeySequence.getInstance("M1+V"), outline, "na", "na", null, null, null, Binding.SYSTEM);
bindingManager.addBinding(binding);
final Binding b3 = new KeyBinding(KeySequence.getInstance("M1+M2+C"), console, "na", "na", null, null, null, Binding.SYSTEM);
bindingManager.addBinding(b3);
// - above is all done as part of startup
final TriggerSequence[] bindings = bindingManager.getActiveBindingsFor(binding.getParameterizedCommand());
assertEquals(2, bindings.length);
final TriggerSequence bestBinding = bindingManager.getBestActiveBindingFor(outline);
assertEquals(binding.getTriggerSequence(), bestBinding);
final TriggerSequence bestBinding2 = bindingManager.getBestActiveBindingFor(console);
assertEquals(b3.getTriggerSequence(), bestBinding2);
}
use of org.eclipse.core.commands.IParameterValues in project egradle by de-jcup.
the class LaunchGradleCommandHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
try {
IParameter configparameter = event.getCommand().getParameter(PARAMETER_LAUNCHCONFIG);
IParameterValues values = configparameter.getValues();
if (values instanceof LaunchParameterValues) {
LaunchParameterValues launchParameterValues = (LaunchParameterValues) values;
taskAttributeOverride = launchParameterValues.getOverriddenTasks();
launch = launchParameterValues.getLaunch();
postJob = launchParameterValues.getPostJob();
} else {
IDEUtil.logWarning(getClass().getSimpleName() + ":parameter values without being a launch parameter value was used !??! :" + values);
}
} catch (NotDefinedException | ParameterValuesException e) {
throw new IllegalStateException("Cannot fetch command parameter!", e);
}
return super.execute(event);
}
Aggregations