Search in sources :

Example 1 with IWorkbenchContextSupport

use of org.eclipse.ui.contexts.IWorkbenchContextSupport in project eclipse.platform.ui by eclipse-platform.

the class ExtensionTestCase method testAcceleratorScopes.

/**
 * Tests that the "org.eclipse.ui.acceleratorScopes" extension point can be
 * read in by Eclipse. This extension point is currently deprecated.
 *
 * @throws NotDefinedException
 *             This shouldn't really be possible, as the test should fail
 *             gracefully before this could happen.
 */
@Test
public final void testAcceleratorScopes() throws NotDefinedException {
    final IWorkbenchContextSupport contextSupport = fWorkbench.getContextSupport();
    final IContextManager contextManager = contextSupport.getContextManager();
    final IContext context1 = contextManager.getContext("org.eclipse.ui.tests.acceleratorScopes.test1");
    assertTrue("Context contributed via 'org.eclipse.ui.acceleratorScopes' is not loaded properly.", context1.isDefined());
    assertEquals("Context contributed via 'org.eclipse.ui.acceleratorScopes' does not get its name.", "Test Accelerator Scope 1", context1.getName());
    final IContext context2 = contextManager.getContext("org.eclipse.ui.tests.acceleratorScopes.test2");
    assertTrue("Context contributed via 'org.eclipse.ui.acceleratorScopes' is not loaded properly.", context2.isDefined());
    assertEquals("Context contributed via 'org.eclipse.ui.acceleratorScopes' does not get its name.", "Test Accelerator Scope 2", context2.getName());
    assertEquals("Context contributed via 'org.eclipse.ui.acceleratorScopes' does not get its parent.", "org.eclipse.ui.tests.acceleratorScopes.test1", context2.getParentId());
}
Also used : IContext(org.eclipse.ui.contexts.IContext) IWorkbenchContextSupport(org.eclipse.ui.contexts.IWorkbenchContextSupport) IContextManager(org.eclipse.ui.contexts.IContextManager) Test(org.junit.Test)

Example 2 with IWorkbenchContextSupport

use of org.eclipse.ui.contexts.IWorkbenchContextSupport in project eclipse.platform.ui by eclipse-platform.

the class Bug74990Test method testPartIdSubmission.

/**
 * Tests whether a part-specific context -- submitted via Java code -- is
 * matched properly. This is only using the part id. The test verifies that it
 * is active when the part is active, and not active when the part is not
 * active.
 *
 * @throws PartInitException If something goes wrong creating the part to which
 *                           this handler is tied.
 */
@Test
public final void testPartIdSubmission() throws PartInitException {
    // Define a command.
    final String testContextId = "org.eclipse.ui.tests.contexts.Bug74990";
    IWorkbench fWorkbench = PlatformUI.getWorkbench();
    final IWorkbenchContextSupport contextSupport = fWorkbench.getContextSupport();
    final IContext testContext = contextSupport.getContextManager().getContext(testContextId);
    // Create an enabled submission.
    final EnabledSubmission testSubmission = new EnabledSubmission("org.eclipse.ui.tests.api.MockViewPart", null, null, testContextId);
    contextSupport.addEnabledSubmission(testSubmission);
    try {
        // Test to make sure the context is not currently enabled.
        assertTrue("The MockViewPart context should not be enabled", !testContext.isEnabled());
        /*
			 * Open a window with the MockViewPart, and make sure it now enabled.
			 */
        final IWorkbenchPage page = UITestCase.openTestWindow().getActivePage();
        final IViewPart openedView = page.showView("org.eclipse.ui.tests.api.MockViewPart");
        page.activate(openedView);
        while (fWorkbench.getDisplay().readAndDispatch()) {
        }
        assertTrue("The MockViewPart context should be enabled", testContext.isEnabled());
        // Hide the view, and test that is becomes disabled again.
        page.hideView(openedView);
        while (fWorkbench.getDisplay().readAndDispatch()) {
        }
        assertTrue("The MockViewPart context should not be enabled", !testContext.isEnabled());
    } finally {
        contextSupport.removeEnabledSubmission(testSubmission);
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IViewPart(org.eclipse.ui.IViewPart) IContext(org.eclipse.ui.contexts.IContext) EnabledSubmission(org.eclipse.ui.contexts.EnabledSubmission) IWorkbenchContextSupport(org.eclipse.ui.contexts.IWorkbenchContextSupport) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) Test(org.junit.Test)

Example 3 with IWorkbenchContextSupport

use of org.eclipse.ui.contexts.IWorkbenchContextSupport in project eclipse.platform.ui by eclipse-platform.

the class ExtensionTestCase method testContexts.

/**
 * Tests that the currently preferred way of specifiying contexts can be
 * read in properly by Eclipse. This uses all of the non-deprecated
 * attributes.
 *
 * @throws NotDefinedException
 *             This shouldn't really be possible, as the test should fail
 *             gracefully before this could happen.
 */
@Test
public final void testContexts() throws NotDefinedException {
    final IWorkbenchContextSupport contextSupport = fWorkbench.getContextSupport();
    final IContextManager contextManager = contextSupport.getContextManager();
    final IContext context1 = contextManager.getContext("org.eclipse.ui.tests.contexts.context1");
    assertTrue("Context contributed via 'org.eclipse.ui.contexts' is not loaded properly.", context1.isDefined());
    assertEquals("Context contributed via 'org.eclipse.ui.contexts' does not get its name.", "Test Context 1", context1.getName());
    final IContext context2 = contextManager.getContext("org.eclipse.ui.tests.contexts.context2");
    assertTrue("Context contributed via 'org.eclipse.ui.contexts' is not loaded properly.", context2.isDefined());
    assertEquals("Context contributed via 'org.eclipse.ui.contexts' does not get its name.", "Test Context 2", context2.getName());
    assertEquals("Context contributed via 'org.eclipse.ui.contexts' does not get its parent.", "org.eclipse.ui.tests.contexts.context1", context2.getParentId());
}
Also used : IContext(org.eclipse.ui.contexts.IContext) IWorkbenchContextSupport(org.eclipse.ui.contexts.IWorkbenchContextSupport) IContextManager(org.eclipse.ui.contexts.IContextManager) Test(org.junit.Test)

Example 4 with IWorkbenchContextSupport

use of org.eclipse.ui.contexts.IWorkbenchContextSupport in project eclipse.platform.ui by eclipse-platform.

the class ExtensionTestCase method testCommandsScopes.

/**
 * Tests that the "scopes" element in the "org.eclipse.ui.commands"
 * extension point can be read in as a context by Eclipse. This element is
 * currently deprecated.
 *
 * @throws NotDefinedException
 *             This shouldn't really be possible, as the test should fail
 *             gracefully before this could happen.
 */
@Test
public final void testCommandsScopes() throws NotDefinedException {
    final IWorkbenchContextSupport contextSupport = fWorkbench.getContextSupport();
    final IContextManager contextManager = contextSupport.getContextManager();
    final IContext context1 = contextManager.getContext("org.eclipse.ui.tests.commands.scope1");
    assertTrue("Context contributed via 'org.eclipse.ui.commands' is not loaded properly.", context1.isDefined());
    assertEquals("Context contributed via 'org.eclipse.ui.commands' does not get its name.", "Test Scope 1", context1.getName());
    final IContext context2 = contextManager.getContext("org.eclipse.ui.tests.commands.scope2");
    assertTrue("Context contributed via 'org.eclipse.ui.commands' is not loaded properly.", context2.isDefined());
    assertEquals("Context contributed via 'org.eclipse.ui.commands' does not get its name.", "Test Scope 2", context2.getName());
    assertEquals("Context contributed via 'org.eclipse.ui.commands' does not get its parent.", "org.eclipse.ui.tests.commands.scope1", context2.getParentId());
}
Also used : IContext(org.eclipse.ui.contexts.IContext) IWorkbenchContextSupport(org.eclipse.ui.contexts.IWorkbenchContextSupport) IContextManager(org.eclipse.ui.contexts.IContextManager) Test(org.junit.Test)

Aggregations

IContext (org.eclipse.ui.contexts.IContext)4 IWorkbenchContextSupport (org.eclipse.ui.contexts.IWorkbenchContextSupport)4 Test (org.junit.Test)4 IContextManager (org.eclipse.ui.contexts.IContextManager)3 IViewPart (org.eclipse.ui.IViewPart)1 IWorkbench (org.eclipse.ui.IWorkbench)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 EnabledSubmission (org.eclipse.ui.contexts.EnabledSubmission)1