Search in sources :

Example 16 with Category

use of org.eclipse.core.commands.Category in project eclipse.platform.ui by eclipse-platform.

the class BindingTableTests method setUp.

@Before
public void setUp() throws Exception {
    if (loadedBindings == null) {
        IEclipseContext globalContext = TestUtil.getGlobalContext();
        workbenchContext = globalContext.createChild("workbenchContext");
        loadedBindings = new ArrayList<>();
        contextManager = new ContextManager();
        ContextSet.setComparator(new ContextSet.CComp(contextManager));
        for (int i = 0; i < CONTEXTS.length; i += 3) {
            Context context = contextManager.getContext(CONTEXTS[i]);
            context.define(CONTEXTS[i + 1], null, CONTEXTS[i + 2]);
        }
        commandManager = new CommandManager();
        Category category = commandManager.getCategory("bogus");
        category.define("Bogus", null);
        for (int i = 0; i < COMMANDS.length; i += 2) {
            Command cmd = commandManager.getCommand(COMMANDS[i]);
            cmd.define(COMMANDS[i + 1], null, category);
        }
        for (int i = 0; i < BINDINGS.length; i += 3) {
            KeySequence seq = KeySequence.getInstance(BINDINGS[i + 1]);
            Command cmd = commandManager.getCommand(BINDINGS[i]);
            loadedBindings.add(new KeyBinding(seq, new ParameterizedCommand(cmd, null), "org.eclipse.ui.defaultAcceleratorConfiguration", BINDINGS[i + 2], null, null, null, Binding.SYSTEM));
        }
    }
}
Also used : Context(org.eclipse.core.commands.contexts.Context) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Category(org.eclipse.core.commands.Category) ContextSet(org.eclipse.e4.ui.bindings.internal.ContextSet) KeyBinding(org.eclipse.jface.bindings.keys.KeyBinding) CommandManager(org.eclipse.core.commands.CommandManager) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) Command(org.eclipse.core.commands.Command) ContextManager(org.eclipse.core.commands.contexts.ContextManager) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) KeySequence(org.eclipse.jface.bindings.keys.KeySequence) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) Before(org.junit.Before)

Example 17 with Category

use of org.eclipse.core.commands.Category in project eclipse.platform.ui by eclipse-platform.

the class KeyDispatcherTest 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);
    ParameterizedCommand cmd = cs.createCommand(TEST_ID1, null);
    EHandlerService hs = workbenchContext.get(EHandlerService.class);
    handler = new CallHandler();
    hs.activateHandler(TEST_ID1, handler);
    EBindingService bs = workbenchContext.get(EBindingService.class);
    TriggerSequence seq = bs.createSequence("CTRL+A");
    Binding db = createDefaultBinding(bs, seq, cmd);
    bs.activateBinding(db);
    ParameterizedCommand cmd2 = cs.createCommand(TEST_ID2, null);
    twoStrokeHandler = new CallHandler();
    hs.activateHandler(TEST_ID2, twoStrokeHandler);
    TriggerSequence twoKeys = bs.createSequence("CTRL+5 CTRL+A");
    db = createDefaultBinding(bs, twoKeys, cmd2);
    bs.activateBinding(db);
}
Also used : Binding(org.eclipse.jface.bindings.Binding) EHandlerService(org.eclipse.e4.core.commands.EHandlerService) TriggerSequence(org.eclipse.jface.bindings.TriggerSequence) Category(org.eclipse.core.commands.Category) EBindingService(org.eclipse.e4.ui.bindings.EBindingService) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) ECommandService(org.eclipse.e4.core.commands.ECommandService)

Example 18 with Category

use of org.eclipse.core.commands.Category in project eclipse.platform.ui by eclipse-platform.

the class CommandManagerTest method testExecutionListener.

@Test
public final void testExecutionListener() {
    final String commandId = "myCommand";
    final CommandManager commandManager = new CommandManager();
    final Category category = commandManager.getCategory(commandId);
    category.define("name", null);
    final Command command = commandManager.getCommand(commandId);
    command.define("name", null, category, null);
    final ExecutionListener listener = new ExecutionListener();
    commandManager.addExecutionListener(listener);
    Exception exception = null;
    final ExecutionEvent event = new ExecutionEvent();
    try {
        command.execute(event);
    } catch (final ExecutionException | NotHandledException e) {
        exception = e;
    }
    assertSame("Should have received a pre-execute event for the correct command", commandId, listener.preExecuteId);
    assertSame("Should have received a pre-execute event with the correct event", event, listener.preExecuteEvent);
    assertSame("Should have received a not-handled event for the correct command", commandId, listener.notHandledId);
    assertSame("Should have received a not-handled event with the correct exception", exception, listener.notHandledException);
}
Also used : NotHandledException(org.eclipse.core.commands.NotHandledException) CommandManager(org.eclipse.core.commands.CommandManager) Category(org.eclipse.core.commands.Category) Command(org.eclipse.core.commands.Command) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) ExecutionException(org.eclipse.core.commands.ExecutionException) ExecutionException(org.eclipse.core.commands.ExecutionException) NotHandledException(org.eclipse.core.commands.NotHandledException) IExecutionListener(org.eclipse.core.commands.IExecutionListener) Test(org.junit.Test)

Example 19 with Category

use of org.eclipse.core.commands.Category in project eclipse.platform.ui by eclipse-platform.

the class ProgressContantsTest method testCommandPropertyEnablement.

@Test
public void testCommandPropertyEnablement() throws Exception {
    openProgressView();
    DummyJob okJob = new DummyJob("OK Job", Status.OK_STATUS);
    okJob.shouldFinish = false;
    IWorkbench workbench = PlatformUI.getWorkbench();
    ECommandService commandService = workbench.getService(ECommandService.class);
    String commandId = "org.eclipse.ui.tests.progressEnableViewCommand";
    // Must use ECommandService#defineCommand to have the proper legacy
    // handler hookup beforehand, such as for handler changes
    Category category = commandService.defineCategory("org.eclipse.ui.tests.progress.category", "test", "test");
    Command command = commandService.defineCommand(commandId, "test", "test", category, new IParameter[0]);
    ParameterizedCommand parameterizedCommand = new ParameterizedCommand(command, null);
    okJob.setProperty(IProgressConstants2.COMMAND_PROPERTY, parameterizedCommand);
    okJob.setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE);
    okJob.schedule();
    processEventsUntil(() -> findProgressInfoItem(okJob) != null, 3000);
    ProgressInfoItem item = findProgressInfoItem(okJob);
    assertNotNull(item);
    assertFalse(item.isTriggerEnabled());
    IHandlerService service = workbench.getService(IHandlerService.class);
    CommandHandler handler = new CommandHandler();
    IHandlerActivation activation = service.activateHandler(commandId, handler);
    assertTrue(item.isTriggerEnabled());
    service.deactivateHandler(activation);
    assertFalse(item.isTriggerEnabled());
    okJob.cancel();
    okJob.join();
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) ProgressInfoItem(org.eclipse.ui.internal.progress.ProgressInfoItem) Category(org.eclipse.core.commands.Category) IHandlerService(org.eclipse.ui.handlers.IHandlerService) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) Command(org.eclipse.core.commands.Command) IHandlerActivation(org.eclipse.ui.handlers.IHandlerActivation) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) ECommandService(org.eclipse.e4.core.commands.ECommandService) Test(org.junit.Test)

Example 20 with Category

use of org.eclipse.core.commands.Category in project eclipse.platform.ui by eclipse-platform.

the class DefineCommandsTest method testCreateCommands.

@Test
public void testCreateCommands() {
    ECommandService cs = workbenchContext.get(ECommandService.class);
    assertNotNull(cs);
    assertNotNull(cs.defineCategory(TEST_CAT1, "CAT1", null));
    Category category = cs.getCategory(TEST_CAT1);
    assertNotNull("need category", category);
    assertNotNull("command1", cs.defineCommand(TEST_ID1, "ID1", null, category, null));
    assertNotNull("command2", cs.defineCommand(TEST_ID2, "ID2", null, category, null));
    Command cmd1 = cs.getCommand(TEST_ID1);
    assertNotNull("get command1", cmd1);
    try {
        assertEquals("ID1", cmd1.getName());
    } catch (NotDefinedException e) {
        fail(e.getMessage());
    }
    assertNotNull("get command2", cs.getCommand(TEST_ID2));
    assertNotNull("parameterized command", cs.createCommand(TEST_ID1, null));
}
Also used : Category(org.eclipse.core.commands.Category) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) Command(org.eclipse.core.commands.Command) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) ECommandService(org.eclipse.e4.core.commands.ECommandService) Test(org.junit.Test)

Aggregations

Category (org.eclipse.core.commands.Category)23 Command (org.eclipse.core.commands.Command)14 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)13 ECommandService (org.eclipse.e4.core.commands.ECommandService)10 Test (org.junit.Test)7 NotDefinedException (org.eclipse.core.commands.common.NotDefinedException)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 IParameter (org.eclipse.core.commands.IParameter)5 Context (org.eclipse.core.commands.contexts.Context)4 HashSet (java.util.HashSet)3 IParameterValues (org.eclipse.core.commands.IParameterValues)3 ParameterType (org.eclipse.core.commands.ParameterType)3 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)3 Binding (org.eclipse.jface.bindings.Binding)3 TriggerSequence (org.eclipse.jface.bindings.TriggerSequence)3 CommandManager (org.eclipse.core.commands.CommandManager)2 ExecutionException (org.eclipse.core.commands.ExecutionException)2 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)2 IStatus (org.eclipse.core.runtime.IStatus)2