Example usage for org.eclipse.jface.contexts IContextIds CONTEXT_ID_WINDOW

List of usage examples for org.eclipse.jface.contexts IContextIds CONTEXT_ID_WINDOW

Introduction

In this page you can find the example usage for org.eclipse.jface.contexts IContextIds CONTEXT_ID_WINDOW.

Prototype

String CONTEXT_ID_WINDOW

To view the source code for org.eclipse.jface.contexts IContextIds CONTEXT_ID_WINDOW.

Click Source Link

Document

The identifier for the context that is active when a shell is registered as a window.

Usage

From source file:fr.inria.linuxtools.tmf.ui.views.uml2sd.SDWidget.java

License:Open Source License

/**
 * Sets view part./*from   ww w.  j  av a2 s . c om*/
 *
 * @param viewSite The view part to set
 */
public void setSite(ViewPart viewSite) {
    fSite = viewSite;
    fSite.getSite().setSelectionProvider(fSelProvider);
    IContextService service = (IContextService) fSite.getSite().getWorkbenchWindow()
            .getService(IContextService.class);
    service.activateContext("fr.inria.linuxtools.tmf.ui.view.uml2sd.context"); //$NON-NLS-1$
    service.activateContext(IContextIds.CONTEXT_ID_WINDOW);
}

From source file:org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget.java

License:Open Source License

public void setSite(ViewPart viewSite) {
    site = viewSite;//from w ww .  j  av  a  2s  .c o m
    site.getSite().setSelectionProvider(selProvider);
    IContextService service = (IContextService) site.getSite().getWorkbenchWindow()
            .getService(IContextService.class);
    service.activateContext("org.eclipse.linuxtools.tmf.ui.view.uml2sd.context"); //$NON-NLS-1$
    service.activateContext(IContextIds.CONTEXT_ID_WINDOW);
}

From source file:org.eclipse.tracecompass.tmf.ui.views.uml2sd.SDWidget.java

License:Open Source License

/**
 * Sets view part.//w ww.ja  va 2 s. c  o m
 *
 * @param viewSite The view part to set
 */
public void setSite(ViewPart viewSite) {
    fSite = viewSite;
    fSite.getSite().setSelectionProvider(fSelProvider);
    Object serviceObject = fSite.getSite().getWorkbenchWindow().getService(IContextService.class);
    IContextService service = (IContextService) serviceObject;
    service.activateContext("org.eclipse.linuxtools.tmf.ui.view.uml2sd.context"); //$NON-NLS-1$
    service.activateContext(IContextIds.CONTEXT_ID_WINDOW);
}

From source file:org.eclipse.ui.internal.keys.BindingPersistence.java

License:Open Source License

/**
 * Reads all of the binding definitions from the preferences.
 * /*from  w w  w  . ja va 2 s .  c  o m*/
 * @param preferences
 *            The memento for the commands preferences key.
 * @param bindingManager
 *            The binding manager to which the bindings should be added;
 *            must not be <code>null</code>.
 * @param commandService
 *            The command service for the workbench; must not be
 *            <code>null</code>.
 */
private static final void readBindingsFromPreferences(final IMemento preferences,
        final BindingManager bindingManager, final CommandManager commandService) {
    List warningsToLog = new ArrayList(1);

    if (preferences != null) {
        final IMemento[] preferenceMementos = preferences.getChildren(TAG_KEY_BINDING);
        int preferenceMementoCount = preferenceMementos.length;
        for (int i = preferenceMementoCount - 1; i >= 0; i--) {
            final IMemento memento = preferenceMementos[i];

            // Read out the command id.
            String commandId = readOptional(memento, ATT_COMMAND_ID);
            if (commandId == null) {
                commandId = readOptional(memento, ATT_COMMAND);
            }
            String viewParameter = null;
            final Command command;
            if (commandId != null) {
                command = commandService.getCommand(commandId);
            } else {
                command = null;
            }

            // Read out the scheme id.
            String schemeId = readOptional(memento, ATT_KEY_CONFIGURATION_ID);
            if (schemeId == null) {
                schemeId = readRequired(memento, ATT_CONFIGURATION, warningsToLog,
                        "Key bindings need a scheme or key configuration"); //$NON-NLS-1$
                if (schemeId == null) {
                    continue;
                }
            }

            // Read out the context id.
            String contextId = readOptional(memento, ATT_CONTEXT_ID);
            if (contextId == null) {
                contextId = readOptional(memento, ATT_SCOPE);
            }
            if (LEGACY_DEFAULT_SCOPE.equals(contextId)) {
                contextId = null;
            }
            if (contextId == null) {
                contextId = IContextIds.CONTEXT_ID_WINDOW;
            }

            // Read out the key sequence.
            String keySequenceText = readOptional(memento, ATT_KEY_SEQUENCE);
            KeySequence keySequence = null;
            if (keySequenceText == null) {
                keySequenceText = readRequired(memento, ATT_STRING, warningsToLog,
                        "Key bindings need a key sequence or string"); //$NON-NLS-1$
                if (keySequenceText == null) {
                    continue;
                }

                // The key sequence is in the old-style format.
                keySequence = convert2_1Sequence(parse2_1Sequence(keySequenceText));

            } else {
                // The key sequence is in the new-style format.
                try {
                    keySequence = KeySequence.getInstance(keySequenceText);
                } catch (final ParseException e) {
                    addWarning(warningsToLog, "Could not parse", null, //$NON-NLS-1$
                            commandId, "keySequence", keySequenceText); //$NON-NLS-1$
                    continue;
                }
                if (keySequence.isEmpty() || !keySequence.isComplete()) {
                    addWarning(warningsToLog, "Key bindings cannot use an empty or incomplete key sequence", //$NON-NLS-1$
                            null, commandId, "keySequence", keySequence //$NON-NLS-1$
                                    .toString());
                    continue;
                }

            }

            // Read out the locale and platform.
            final String locale = readOptional(memento, ATT_LOCALE);
            final String platform = readOptional(memento, ATT_PLATFORM);

            // Read out the parameters
            final ParameterizedCommand parameterizedCommand;
            if (command == null) {
                parameterizedCommand = null;
            } else if (viewParameter != null) {
                HashMap parms = new HashMap();
                parms.put(ShowViewMenu.VIEW_ID_PARM, viewParameter);
                parameterizedCommand = ParameterizedCommand.generateCommand(command, parms);
            } else {
                parameterizedCommand = readParameters(memento, warningsToLog, command);
            }

            final Binding binding = new KeyBinding(keySequence, parameterizedCommand, schemeId, contextId,
                    locale, platform, null, Binding.USER);
            bindingManager.addBinding(binding);
        }
    }

    // If there were any warnings, then log them now.
    logWarnings(warningsToLog, "Warnings while parsing the key bindings from the preference store"); //$NON-NLS-1$
}

From source file:org.eclipse.ui.internal.keys.BindingPersistence.java

License:Open Source License

private static String readContextId(final IConfigurationElement configurationElement) {
    String contextId = configurationElement.getAttribute(ATT_CONTEXT_ID);
    if (LEGACY_DEFAULT_SCOPE.equals(contextId)) {
        contextId = null;//from   w w  w  .  ja v  a 2s.  co  m
    } else if ((contextId == null) || (contextId.length() == 0)) {
        contextId = configurationElement.getAttribute(ATT_SCOPE);
        if (LEGACY_DEFAULT_SCOPE.equals(contextId)) {
            contextId = null;
        }
    }
    if ((contextId == null) || (contextId.length() == 0)) {
        contextId = IContextIds.CONTEXT_ID_WINDOW;
    }
    return contextId;
}

From source file:org.eclipse.ui.internal.keys.KeysPreferencePage.java

License:Open Source License

/**
 * Changes the selected context name in the context combo box. The context
 * selected is either the one matching the identifier provided (if
 * possible), or the default context identifier. If no matching name can be
 * found in the combo, then the first item is selected.
 * // w  w  w. j  av a 2  s.c  o m
 * @param contextId
 *            The context identifier for the context to be selected in the
 *            combo box; may be <code>null</code>.
 */
private final void setContextId(final String contextId) {
    // Clear the current selection.
    comboContext.clearSelection();
    comboContext.deselectAll();

    // Figure out which name to look for.
    String contextName = (String) contextUniqueNamesById.get(contextId);
    if (contextName == null) {
        contextName = (String) contextUniqueNamesById.get(IContextIds.CONTEXT_ID_WINDOW);
    }
    if (contextName == null) {
        contextName = Util.ZERO_LENGTH_STRING;
    }

    // Scan the list for the selection we're looking for.
    final String[] items = comboContext.getItems();
    boolean found = false;
    for (int i = 0; i < items.length; i++) {
        if (contextName.equals(items[i])) {
            comboContext.select(i);
            found = true;
            break;
        }
    }

    // If we didn't find an item, then set the first item as selected.
    if ((!found) && (items.length > 0)) {
        comboContext.select(0);
    }
}

From source file:org.eclipse.ui.tests.contexts.Bug84763Test.java

License:Open Source License

/**
 * <p>// w ww  .  j  ava  2  s.c  o m
 * Testst whether the binding manager will overwrite information in the
 * context manager. In particular, whether the list of previous enabled
 * context identifiers will be changed.
 * </p>
 * 
 * @throws NotDefinedException
 *             If the scheme we try to activate is not defined.
 * @throws ParseException
 *             If "CTRL+F" cannot be parsed for some reason.
 */
public void testWindowChildWhenDialog() throws NotDefinedException, ParseException {
    // Define the contexts to use.
    final Context dialogAndWindowsContext = contextManager.getContext(IContextIds.CONTEXT_ID_DIALOG_AND_WINDOW);
    dialogAndWindowsContext.define("In Dialogs and Windows", null, null);
    final Context dialogContext = contextManager.getContext(IContextIds.CONTEXT_ID_DIALOG);
    dialogContext.define("In Dialogs", null, IContextIds.CONTEXT_ID_DIALOG_AND_WINDOW);
    final Context windowContext = contextManager.getContext(IContextIds.CONTEXT_ID_WINDOW);
    windowContext.define("In Windows", null, IContextIds.CONTEXT_ID_DIALOG_AND_WINDOW);
    final Context windowChildContext = contextManager.getContext("sibling");
    windowChildContext.define("Sibling", null, IContextIds.CONTEXT_ID_WINDOW);

    // Force a binding computation.
    final Scheme scheme = bindingManager.getScheme("na");
    scheme.define("name", null, null);
    bindingManager.setActiveScheme(scheme);
    final CommandManager commandManager = new CommandManager();
    final Command command = commandManager.getCommand("commandId");
    final ParameterizedCommand parameterizedCommand = new ParameterizedCommand(command, null);
    bindingManager.addBinding(new KeyBinding(KeySequence.getInstance("CTRL+F"), parameterizedCommand,
            scheme.getId(), windowChildContext.getId(), null, null, null, Binding.SYSTEM));
    bindingManager.getActiveBindingsFor((ParameterizedCommand) null);

    // Activate the dialog context and the sibling.
    final Set activeContextIds = new HashSet();
    activeContextIds.add(IContextIds.CONTEXT_ID_DIALOG);
    activeContextIds.add(IContextIds.CONTEXT_ID_DIALOG_AND_WINDOW);
    activeContextIds.add(windowChildContext.getId());
    contextManager.setActiveContextIds(activeContextIds);

    // Force a binding computation.
    bindingManager.getActiveBindingsFor((ParameterizedCommand) null);

    // Active the window context.
    activeContextIds.remove(IContextIds.CONTEXT_ID_DIALOG);
    activeContextIds.add(IContextIds.CONTEXT_ID_WINDOW);
    contextManager.setActiveContextIds(activeContextIds);

    // Force a binding computation.
    bindingManager.getActiveBindingsFor((ParameterizedCommand) null);

    /*
     * Check to see what the listener got as the list of previously active
     * context identifiers.
     */
    assertEquals("There should have been 3 context ids active previously", 3, previousContextIds.size());
    assertTrue("The previous contexts should include the dialog context",
            previousContextIds.contains(IContextIds.CONTEXT_ID_DIALOG));
    assertTrue("The previous contexts should include the dialog context",
            previousContextIds.contains(IContextIds.CONTEXT_ID_DIALOG_AND_WINDOW));
    assertTrue("The previous contexts should include the dialog context",
            previousContextIds.contains(windowChildContext.getId()));
    System.out.println("testSiblingContext");
}

From source file:org.eclipse.ui.tests.dynamicplugins.BindingsExtensionDynamicTest.java

License:Open Source License

/**
 * Tests whether the items defined in the extension point can be added and
 * removed dynamically. It tests that the data doesn't exist, and then loads
 * the extension. It tests that the data then exists, and unloads the
 * extension. It tests that the data then doesn't exist.
 * /*  w  w  w .  j  a v  a  2  s  . co m*/
 * @throws ParseException
 *             If "M1+W" can't be parsed by the extension point.
 */
public void testBindings() throws ParseException {
    final IBindingService bindingService = (IBindingService) getWorkbench().getAdapter(IBindingService.class);
    final TriggerSequence triggerSequence = KeySequence.getInstance("M1+W");
    Binding[] bindings;
    Scheme scheme;
    boolean found;

    found = false;
    bindings = bindingService.getBindings();
    if (bindings != null) {
        for (int i = 0; i < bindings.length; i++) {
            final Binding binding = bindings[i];
            if ("monkey".equals(binding.getSchemeId())
                    && IContextIds.CONTEXT_ID_WINDOW.equals(binding.getContextId())
                    && "org.eclipse.ui.views.showView".equals(binding.getParameterizedCommand().getId())
                    && binding.getParameterizedCommand().getParameterMap()
                            .containsKey(IWorkbenchCommandConstants.VIEWS_SHOW_VIEW_PARM_ID)
                    && binding.getPlatform() == null && binding.getLocale() == null
                    && binding.getType() == Binding.SYSTEM
                    && triggerSequence.equals(binding.getTriggerSequence())) {
                found = true;

            }
        }
    }
    assertTrue(!found);
    scheme = bindingService.getScheme("monkey");
    try {
        scheme.getName();
        fail();
    } catch (final NotDefinedException e) {
        assertTrue(true);
    }

    getBundle();

    found = false;
    bindings = bindingService.getBindings();
    if (bindings != null) {
        for (int i = 0; i < bindings.length; i++) {
            final Binding binding = bindings[i];
            if ("monkey".equals(binding.getSchemeId())
                    && IContextIds.CONTEXT_ID_WINDOW.equals(binding.getContextId())
                    && "org.eclipse.ui.views.showView".equals(binding.getParameterizedCommand().getId())
                    && binding.getParameterizedCommand().getParameterMap()
                            .containsKey(IWorkbenchCommandConstants.VIEWS_SHOW_VIEW_PARM_ID)
                    && binding.getPlatform() == null && binding.getLocale() == null
                    && binding.getType() == Binding.SYSTEM
                    && triggerSequence.equals(binding.getTriggerSequence())) {
                found = true;

            }
        }
    }
    assertTrue(found);
    scheme = bindingService.getScheme("monkey");
    try {
        assertTrue("Monkey".equals(scheme.getName()));
    } catch (final NotDefinedException e) {
        fail();
    }

    removeBundle();

    found = false;
    bindings = bindingService.getBindings();
    if (bindings != null) {
        for (int i = 0; i < bindings.length; i++) {
            final Binding binding = bindings[i];
            if ("monkey".equals(binding.getSchemeId())
                    && IContextIds.CONTEXT_ID_WINDOW.equals(binding.getContextId())
                    && "org.eclipse.ui.views.showView".equals(binding.getParameterizedCommand().getId())
                    && binding.getParameterizedCommand().getParameterMap()
                            .containsKey(IWorkbenchCommandConstants.VIEWS_SHOW_VIEW_PARM_ID)
                    && binding.getPlatform() == null && binding.getLocale() == null
                    && binding.getType() == Binding.SYSTEM
                    && triggerSequence.equals(binding.getTriggerSequence())) {
                found = true;

            }
        }
    }
    assertTrue(!found);
    scheme = bindingService.getScheme("monkey");
    try {
        scheme.getName();
        fail();
    } catch (final NotDefinedException e) {
        assertTrue(true);
    }
}

From source file:org.eclipse.ui.tests.dynamicplugins.CommandsExtensionDynamicTest.java

License:Open Source License

/**
 * Tests whether the items defined in the extension point can be added and
 * removed dynamically. It tests that the data doesn't exist, and then loads
 * the extension. It tests that the data then exists, and unloads the
 * extension. It tests that the data then doesn't exist.
 * //from   ww  w  . j  a  v  a2  s .  c o  m
 * @throws ParseException
 *             If "M1+W" can't be parsed by the extension point.
 */
public final void testCommands() throws ParseException {
    final IBindingService bindingService = (IBindingService) getWorkbench().getAdapter(IBindingService.class);
    final ICommandService commandService = (ICommandService) getWorkbench().getAdapter(ICommandService.class);
    final IContextService contextService = (IContextService) getWorkbench().getAdapter(IContextService.class);
    final TriggerSequence triggerSequence = KeySequence.getInstance("M1+W");
    NamedHandleObject namedHandleObject;
    Binding[] bindings;
    Command command;
    boolean found;

    assertTrue(!"monkey".equals(bindingService.getActiveScheme().getId()));
    found = false;
    bindings = bindingService.getBindings();
    if (bindings != null) {
        for (int i = 0; i < bindings.length; i++) {
            final Binding binding = bindings[i];
            if ("monkey".equals(binding.getSchemeId())
                    && IContextIds.CONTEXT_ID_WINDOW.equals(binding.getContextId())
                    && "monkey".equals(binding.getParameterizedCommand().getId())
                    && binding.getPlatform() == null && binding.getLocale() == null
                    && binding.getType() == Binding.SYSTEM
                    && triggerSequence.equals(binding.getTriggerSequence())) {
                found = true;

            }
        }
    }
    assertTrue(!found);
    namedHandleObject = bindingService.getScheme("monkey");
    try {
        namedHandleObject.getName();
        fail();
    } catch (final NotDefinedException e) {
        assertTrue(true);
    }
    namedHandleObject = commandService.getCategory("monkey");
    try {
        namedHandleObject.getName();
        fail();
    } catch (final NotDefinedException e) {
        assertTrue(true);
    }
    command = commandService.getCommand("monkey");
    try {
        command.execute(new ExecutionEvent());
        fail();
    } catch (final ExecutionException e) {
        fail();
    } catch (final NotHandledException e) {
        assertTrue(true);
    }
    try {
        command.getName();
        fail();
    } catch (final NotDefinedException e) {
        assertTrue(true);
    }
    namedHandleObject = contextService.getContext("context");
    try {
        namedHandleObject.getName();
        fail();
    } catch (final NotDefinedException e) {
        assertTrue(true);
    }
    namedHandleObject = contextService.getContext("scope");
    try {
        namedHandleObject.getName();
        fail();
    } catch (final NotDefinedException e) {
        assertTrue(true);
    }

    getBundle();

    assertTrue("monkey".equals(bindingService.getActiveScheme().getId()));
    found = false;
    bindings = bindingService.getBindings();
    if (bindings != null) {
        for (int i = 0; i < bindings.length; i++) {
            final Binding binding = bindings[i];
            if ("monkey".equals(binding.getSchemeId())
                    && IContextIds.CONTEXT_ID_WINDOW.equals(binding.getContextId())
                    && "monkey".equals(binding.getParameterizedCommand().getId())
                    && binding.getPlatform() == null && binding.getLocale() == null
                    && binding.getType() == Binding.SYSTEM
                    && triggerSequence.equals(binding.getTriggerSequence())) {
                found = true;

            }
        }
    }
    assertTrue(found);
    namedHandleObject = bindingService.getScheme("monkey");
    try {
        assertTrue("Monkey".equals(namedHandleObject.getName()));
    } catch (final NotDefinedException e) {
        fail();
    }
    command = commandService.getCommand("monkey");
    try {
        command.execute(new ExecutionEvent());
    } catch (final ExecutionException e) {
        fail();
    } catch (final NotHandledException e) {
        fail();
    }
    try {
        assertEquals("Monkey", command.getName());
    } catch (final NotDefinedException e) {
        fail();
    }
    namedHandleObject = commandService.getCommand("monkey");
    try {
        assertTrue("Monkey".equals(namedHandleObject.getName()));
    } catch (final NotDefinedException e) {
        fail();
    }
    namedHandleObject = contextService.getContext("context");
    try {
        assertTrue("Monkey".equals(namedHandleObject.getName()));
    } catch (final NotDefinedException e) {
        fail();
    }
    namedHandleObject = contextService.getContext("scope");
    try {
        assertTrue("Monkey".equals(namedHandleObject.getName()));
    } catch (final NotDefinedException e) {
        fail();
    }

    removeBundle();

    assertTrue(!"monkey".equals(bindingService.getActiveScheme().getId()));
    found = false;
    bindings = bindingService.getBindings();
    if (bindings != null) {
        for (int i = 0; i < bindings.length; i++) {
            final Binding binding = bindings[i];
            if ("monkey".equals(binding.getSchemeId())
                    && IContextIds.CONTEXT_ID_WINDOW.equals(binding.getContextId())
                    && "monkey".equals(binding.getParameterizedCommand().getId())
                    && binding.getPlatform() == null && binding.getLocale() == null
                    && binding.getType() == Binding.SYSTEM
                    && triggerSequence.equals(binding.getTriggerSequence())) {
                found = true;

            }
        }
    }
    assertTrue(!found);
    namedHandleObject = bindingService.getScheme("monkey");
    try {
        namedHandleObject.getName();
        fail();
    } catch (final NotDefinedException e) {
        assertTrue(true);
    }
    namedHandleObject = commandService.getCategory("monkey");
    try {
        namedHandleObject.getName();
        fail();
    } catch (final NotDefinedException e) {
        assertTrue(true);
    }
    command = commandService.getCommand("monkey");
    try {
        command.execute(new ExecutionEvent());
        fail();
    } catch (final ExecutionException e) {
        fail();
    } catch (final NotHandledException e) {
        assertTrue(true);
    }
    try {
        command.getName();
        fail();
    } catch (final NotDefinedException e) {
        assertTrue(true);
    }
    namedHandleObject = contextService.getContext("context");
    try {
        namedHandleObject.getName();
        fail();
    } catch (final NotDefinedException e) {
        assertTrue(true);
    }
    namedHandleObject = contextService.getContext("scope");
    try {
        namedHandleObject.getName();
        fail();
    } catch (final NotDefinedException e) {
        assertTrue(true);
    }
}