Example usage for org.eclipse.jface.bindings Binding getLocale

List of usage examples for org.eclipse.jface.bindings Binding getLocale

Introduction

In this page you can find the example usage for org.eclipse.jface.bindings Binding getLocale.

Prototype

public final String getLocale() 

Source Link

Document

Returns the locale in which this binding applies.

Usage

From source file:com.google.dart.tools.ui.internal.preferences.DartKeyBindingPersistence.java

License:Open Source License

private void updateKeyBinding(Map<String, String> map) throws CoreException {
    try {/* w  w  w  . ja  v  a 2  s .c o m*/
        String platform = map.get(XML_ATTRIBUTE_PLATFORM);
        String commandName = map.get(XML_ATTRIBUTE_COMMANDID);
        String stdKeys = map.get(XML_ATTRIBUTE_KEYS);
        Binding binding = findBinding(commandName, platform);
        if (binding == null) {
            return;
        }
        Command command = binding.getParameterizedCommand().getCommand();
        ParameterizedCommand cmd = new ParameterizedCommand(command, null);
        String schemeId = binding.getSchemeId();
        String contextId = binding.getContextId();
        String locale = binding.getLocale();
        String wm = null;
        int type = Binding.USER;
        KeySequence stdSeq = KeySequence.getInstance(stdKeys);
        Binding newBind = new KeyBinding(stdSeq, cmd, schemeId, contextId, locale, platform, wm, type);
        bindingManager.removeBindings(stdSeq, schemeId, contextId, null, null, null, type);
        bindingManager.addBinding(newBind);
    } catch (NotDefinedException ex) {
        throw createException(ex, ex.getMessage());
    } catch (ParseException ex) {
        throw createException(ex, ex.getMessage());
    }
}

From source file:org.eclipse.e4.ui.keybinding.tests.Bug36537Test.java

License:Open Source License

/**
 * Tests that there are no redundant key bindings defined in the
 * application.//from   w  w w. j a  v  a2s  .c  om
 */
public void testForRedundantKeySequenceBindings() {
    final IWorkbenchWindow window = openTestWindow();
    final IWorkbench workbench = window.getWorkbench();
    final IBindingService bindingService = (IBindingService) workbench.getAdapter(IBindingService.class);
    final Binding[] bindings = bindingService.getBindings();
    final int bindingCount = bindings.length;
    Map keySequenceBindingsByKeySequence = new HashMap();

    for (int i = 0; i < bindingCount; i++) {
        // Retrieve the key binding.
        final Binding binding = bindings[i];

        // Find the point the bindings with matching key sequences.
        TriggerSequence triggerSequence = binding.getTriggerSequence();
        List matches = (List) keySequenceBindingsByKeySequence.get(triggerSequence);
        if (matches == null) {
            matches = new ArrayList();
            keySequenceBindingsByKeySequence.put(triggerSequence, matches);
        }

        // Check that we don't have any redundancy or other wackiness.
        Iterator matchItr = matches.iterator();
        while (matchItr.hasNext()) {
            final Binding matchedBinding = (Binding) matchItr.next();
            ParameterizedCommand commandA = binding.getParameterizedCommand();
            ParameterizedCommand commandB = matchedBinding.getParameterizedCommand();
            String contextA = binding.getContextId();
            String contextB = matchedBinding.getContextId();
            String keyConfA = binding.getSchemeId();
            String keyConfB = matchedBinding.getSchemeId();
            String localeA = binding.getLocale();
            String localeB = matchedBinding.getLocale();
            String platformA = binding.getPlatform();
            String platformB = matchedBinding.getPlatform();

            boolean same = true;
            int nullMatches = 0;
            same &= (commandA == null) ? (commandB == null) : (commandA.equals(commandB));
            same &= (contextA == null) || (contextB == null) || (contextA.equals(contextB));
            if (((contextA == null) || (contextB == null)) && (contextA != contextB)) {
                nullMatches++;
            }
            same &= (keyConfA == null) || (keyConfB == null) || (keyConfA.equals(keyConfB));
            if (((keyConfA == null) || (keyConfB == null)) && (keyConfA != keyConfB)) {
                nullMatches++;
            }
            same &= (localeA == null) || (localeB == null) || (localeA.equals(localeB));
            if (((localeA == null) || (localeB == null)) && (localeA != localeB)) {
                nullMatches++;
            }
            same &= (platformA == null) || (platformB == null) || (platformA.equals(platformB));
            if (((platformA == null) || (platformB == null)) && (platformA != platformB)) {
                nullMatches++;
            }

            assertFalse("Redundant key bindings: " + binding + ", " + matchedBinding, //$NON-NLS-1$//$NON-NLS-2$
                    same && (nullMatches < 1));
        }

        // Add the key binding.
        matches.add(binding);
    }
}

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

License:Open Source License

/**
 * Writes the binding to the memento. This creates a new child element on
 * the memento, and places the properties of the binding as its attributes.
 * /*ww  w  .  j  av a2  s .co  m*/
 * @param parent
 *            The parent memento for the binding element; must not be
 *            <code>null</code>.
 * @param binding
 *            The binding to write; must not be <code>null</code>.
 */
private static final void writeBindingToPreferences(final IMemento parent, final Binding binding) {
    final IMemento element = parent.createChild(TAG_KEY_BINDING);
    element.putString(ATT_CONTEXT_ID, binding.getContextId());
    final ParameterizedCommand parameterizedCommand = binding.getParameterizedCommand();
    final String commandId = (parameterizedCommand == null) ? null : parameterizedCommand.getId();
    element.putString(ATT_COMMAND_ID, commandId);
    element.putString(ATT_KEY_CONFIGURATION_ID, binding.getSchemeId());
    element.putString(ATT_KEY_SEQUENCE, binding.getTriggerSequence().toString());
    element.putString(ATT_LOCALE, binding.getLocale());
    element.putString(ATT_PLATFORM, binding.getPlatform());
    if (parameterizedCommand != null) {
        final Map parameterizations = parameterizedCommand.getParameterMap();
        final Iterator parameterizationItr = parameterizations.entrySet().iterator();
        while (parameterizationItr.hasNext()) {
            final Map.Entry entry = (Map.Entry) parameterizationItr.next();
            final String id = (String) entry.getKey();
            final String value = (String) entry.getValue();
            final IMemento parameterElement = element.createChild(TAG_PARAMETER);
            parameterElement.putString(ATT_ID, id);
            parameterElement.putString(ATT_VALUE, value);
        }
    }
}

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

License:Open Source License

static private boolean isSameBinding(MKeyBinding existingBinding, MCommand cmd, Binding binding) {
    // see org.eclipse.jface.bindings.Binding#equals(final Object object)
    if (!cmd.equals(existingBinding.getCommand()))
        return false;
    String existingKeySequence = existingBinding.getKeySequence();
    if (existingKeySequence == null)
        return false;
    try {/*from  w w  w . jav a 2  s . c  o  m*/
        final KeySequence existingSequence = KeySequence.getInstance(existingKeySequence);
        if (!existingSequence.equals(binding.getTriggerSequence()))
            return false;
    } catch (ParseException e) {
        return false;
    }

    // tags to look for:
    final List<String> modelTags = existingBinding.getTags();

    String schemeId = binding.getSchemeId();
    if (schemeId != null && !schemeId.equals(BindingPersistence.getDefaultSchemeId())) {
        if (!modelTags.contains(EBindingService.SCHEME_ID_ATTR_TAG + ":" + schemeId)) //$NON-NLS-1$
            return false;
    }
    String locale = binding.getLocale();
    if (locale != null) {
        if (!modelTags.contains(EBindingService.LOCALE_ATTR_TAG + ":" + locale)) //$NON-NLS-1$
            return false;
    }
    String platform = binding.getPlatform();
    if (platform != null) {
        if (!modelTags.contains(EBindingService.PLATFORM_ATTR_TAG + ":" + platform)) //$NON-NLS-1$
            return false;
    }
    if (binding.getType() == Binding.USER) {
        if (!modelTags.contains(EBindingService.TYPE_ATTR_TAG + ":user")) //$NON-NLS-1$
            return false;
    }
    return true;
}

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

License:Open Source License

static public MKeyBinding createORupdateMKeyBinding(MApplication application, MBindingTable table,
        Binding binding) {
    boolean addToTable = false;

    ParameterizedCommand parmCmd = binding.getParameterizedCommand();

    String id = parmCmd.getId();/*  w w w .j  a v a2s  . c om*/
    MCommand cmd = null;
    for (MCommand appCommand : application.getCommands()) {
        if (id.equals(appCommand.getElementId())) {
            cmd = appCommand;
            break;
        }
    }
    if (cmd == null) {
        return null;
    }

    MKeyBinding keyBinding = null;
    for (MKeyBinding existingBinding : table.getBindings()) {
        Binding b = (Binding) existingBinding.getTransientData().get(EBindingService.MODEL_TO_BINDING_KEY);
        if (binding.equals(b)) {
            keyBinding = existingBinding;
            break;
        }
        if (isSameBinding(existingBinding, cmd, binding)) {
            keyBinding = existingBinding;
            break;
        }
    }

    if (keyBinding == null) {
        addToTable = true;
        keyBinding = CommandsFactoryImpl.eINSTANCE.createKeyBinding();
        keyBinding.setCommand(cmd);
        keyBinding.setKeySequence(binding.getTriggerSequence().toString());

        for (Object obj : parmCmd.getParameterMap().entrySet()) {
            @SuppressWarnings({ "unchecked" })
            Map.Entry<String, String> entry = (Map.Entry<String, String>) obj;

            String paramID = entry.getKey();
            if (paramID == null)
                continue;
            List<MParameter> bindingParams = keyBinding.getParameters();
            MParameter p = null;
            for (MParameter param : bindingParams) {
                if (paramID.equals(param.getElementId())) {
                    p = param;
                    break;
                }
            }
            if (p == null) {
                p = CommandsFactoryImpl.eINSTANCE.createParameter();
                p.setElementId(entry.getKey());
                keyBinding.getParameters().add(p);
            }
            p.setName(entry.getKey());
            p.setValue(entry.getValue());
        }

        List<String> tags = keyBinding.getTags();
        // just add the 'schemeId' tag if the binding is for anything other
        // than
        // the default scheme
        if (binding.getSchemeId() != null
                && !binding.getSchemeId().equals(BindingPersistence.getDefaultSchemeId())) {
            tags.add(EBindingService.SCHEME_ID_ATTR_TAG + ":" + binding.getSchemeId()); //$NON-NLS-1$
        }
        if (binding.getLocale() != null) {
            tags.add(EBindingService.LOCALE_ATTR_TAG + ":" + binding.getLocale()); //$NON-NLS-1$
        }
        if (binding.getPlatform() != null) {
            tags.add(EBindingService.PLATFORM_ATTR_TAG + ":" + binding.getPlatform()); //$NON-NLS-1$
        }
        // just add the 'type' tag if it's a user binding
        if (binding.getType() == Binding.USER) {
            tags.add(EBindingService.TYPE_ATTR_TAG + ":user"); //$NON-NLS-1$
        }
    }

    keyBinding.getTransientData().put(EBindingService.MODEL_TO_BINDING_KEY, binding);
    if (addToTable) {
        table.getBindings().add(keyBinding);
    }
    return keyBinding;
}

From source file:org.eclipse.ui.internal.keys.model.BindingModel.java

License:Open Source License

final static boolean deletes(final Binding del, final Binding binding) {
    boolean deletes = true;
    deletes &= Util.equals(del.getContextId(), binding.getContextId());
    deletes &= Util.equals(del.getTriggerSequence(), binding.getTriggerSequence());
    if (del.getLocale() != null) {
        deletes &= Util.equals(del.getLocale(), binding.getLocale());
    }//from   w  w w  .  ja  va  2  s. com
    if (del.getPlatform() != null) {
        deletes &= Util.equals(del.getPlatform(), binding.getPlatform());
    }
    deletes &= (binding.getType() == Binding.SYSTEM);
    deletes &= Util.equals(del.getParameterizedCommand(), null);

    return deletes;
}

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  ww  .  j a v  a2  s  . c  om
 * @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   w ww .  j av  a 2s.  com
 * @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);
    }
}