Search in sources :

Example 1 with IParameterValues

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));
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IParameter(org.eclipse.core.commands.IParameter) IServiceLocator(org.eclipse.ui.services.IServiceLocator) Parameterization(org.eclipse.core.commands.Parameterization) DebugException(org.eclipse.debug.core.DebugException) ICommandService(org.eclipse.ui.commands.ICommandService) CoreException(org.eclipse.core.runtime.CoreException) DebugException(org.eclipse.debug.core.DebugException) IHandlerService(org.eclipse.ui.handlers.IHandlerService) CoreException(org.eclipse.core.runtime.CoreException) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) Command(org.eclipse.core.commands.Command) IParameterValues(org.eclipse.core.commands.IParameterValues) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand)

Example 2 with IParameterValues

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;
        }
    } });
}
Also used : IParameter(org.eclipse.core.commands.IParameter) Category(org.eclipse.core.commands.Category) ParameterValuesException(org.eclipse.core.commands.ParameterValuesException) Collections(java.util.Collections) IParameterValues(org.eclipse.core.commands.IParameterValues) ECommandService(org.eclipse.e4.core.commands.ECommandService)

Example 3 with IParameterValues

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);
}
Also used : IParameter(org.eclipse.core.commands.IParameter) Category(org.eclipse.core.commands.Category) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) Command(org.eclipse.core.commands.Command) HashMap(java.util.HashMap) IParameterValues(org.eclipse.core.commands.IParameterValues) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) ECommandService(org.eclipse.e4.core.commands.ECommandService) Test(org.junit.Test)

Example 4 with IParameterValues

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);
}
Also used : Context(org.eclipse.core.commands.contexts.Context) KeyBinding(org.eclipse.jface.bindings.keys.KeyBinding) Binding(org.eclipse.jface.bindings.Binding) TriggerSequence(org.eclipse.jface.bindings.TriggerSequence) IParameter(org.eclipse.core.commands.IParameter) Scheme(org.eclipse.jface.bindings.Scheme) Category(org.eclipse.core.commands.Category) HashMap(java.util.HashMap) KeyBinding(org.eclipse.jface.bindings.keys.KeyBinding) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) Command(org.eclipse.core.commands.Command) IParameterValues(org.eclipse.core.commands.IParameterValues) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with IParameterValues

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);
}
Also used : IParameter(org.eclipse.core.commands.IParameter) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) LaunchParameterValues(de.jcup.egradle.eclipse.ide.launch.LaunchParameterValues) ParameterValuesException(org.eclipse.core.commands.ParameterValuesException) IParameterValues(org.eclipse.core.commands.IParameterValues)

Aggregations

IParameter (org.eclipse.core.commands.IParameter)5 IParameterValues (org.eclipse.core.commands.IParameterValues)5 Category (org.eclipse.core.commands.Category)3 Command (org.eclipse.core.commands.Command)3 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)3 HashMap (java.util.HashMap)2 ParameterValuesException (org.eclipse.core.commands.ParameterValuesException)2 ECommandService (org.eclipse.e4.core.commands.ECommandService)2 Test (org.junit.Test)2 LaunchParameterValues (de.jcup.egradle.eclipse.ide.launch.LaunchParameterValues)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 Parameterization (org.eclipse.core.commands.Parameterization)1 NotDefinedException (org.eclipse.core.commands.common.NotDefinedException)1 Context (org.eclipse.core.commands.contexts.Context)1 CoreException (org.eclipse.core.runtime.CoreException)1 Status (org.eclipse.core.runtime.Status)1 DebugException (org.eclipse.debug.core.DebugException)1 Binding (org.eclipse.jface.bindings.Binding)1 Scheme (org.eclipse.jface.bindings.Scheme)1