Search in sources :

Example 21 with Category

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

the class DefineCommandsTest method testCreateWithTwoContexts.

@Test
public void testCreateWithTwoContexts() {
    IEclipseContext localContext = workbenchContext.createChild("Level1");
    ECommandService cs = localContext.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));
    cs = workbenchContext.get(ECommandService.class);
    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));
}
Also used : Category(org.eclipse.core.commands.Category) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) Command(org.eclipse.core.commands.Command) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) ECommandService(org.eclipse.e4.core.commands.ECommandService) Test(org.junit.Test)

Example 22 with Category

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

the class HeadlessApplicationTest method createApplication.

private MApplication createApplication(IEclipseContext appContext, String appURI) throws Exception {
    URI initialWorkbenchDefinitionInstance = URI.createPlatformPluginURI(appURI, true);
    ResourceSet set = new ResourceSetImpl();
    set.getPackageRegistry().put("http://MApplicationPackage/", ApplicationPackageImpl.eINSTANCE);
    Resource resource = set.getResource(initialWorkbenchDefinitionInstance, true);
    MApplication application = (MApplication) resource.getContents().get(0);
    application.setContext(appContext);
    // XXX
    appContext.set(MApplication.class, application);
    appContext.set(EModelService.class, new ModelServiceImpl(appContext));
    ECommandService cs = appContext.get(ECommandService.class);
    Category cat = cs.defineCategory(MApplication.class.getName(), "Application Category", // $NON-NLS-1$
    null);
    List<MCommand> commands = application.getCommands();
    for (MCommand cmd : commands) {
        String id = cmd.getElementId();
        String name = cmd.getCommandName();
        cs.defineCommand(id, name, null, cat, null);
    }
    // take care of generating the contexts.
    List<MWindow> windows = application.getChildren();
    for (MWindow window : windows) {
        E4Workbench.initializeContext(appContext, window);
    }
    processPartContributions(application.getContext(), resource);
    renderer = createPresentationEngine(getEngineURI());
    return application;
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) Category(org.eclipse.core.commands.Category) MCommand(org.eclipse.e4.ui.model.application.commands.MCommand) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI) MWindow(org.eclipse.e4.ui.model.application.ui.basic.MWindow) ModelServiceImpl(org.eclipse.e4.ui.internal.workbench.ModelServiceImpl) MApplication(org.eclipse.e4.ui.model.application.MApplication) ECommandService(org.eclipse.e4.core.commands.ECommandService)

Example 23 with Category

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

the class HandlerTest method defineCommands.

private void defineCommands(IEclipseContext appContext) {
    ECommandService cmdService = (ECommandService) appContext.get(ECommandService.class.getName());
    Category category = cmdService.defineCategory("cat." + HELP_COMMAND_ID, "Help Category", null);
    cmdService.defineCommand(HELP_COMMAND_ID, "Help Command", null, category, null);
    cmdService.defineCommand(HELP_COMMAND1_ID, "Help 1 Command", null, category, null);
}
Also used : Category(org.eclipse.core.commands.Category) ECommandService(org.eclipse.e4.core.commands.ECommandService)

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