Example usage for org.eclipse.jface.bindings.keys KeySequence toString

List of usage examples for org.eclipse.jface.bindings.keys KeySequence toString

Introduction

In this page you can find the example usage for org.eclipse.jface.bindings.keys KeySequence toString.

Prototype

@Override
public final String toString() 

Source Link

Document

Returns the formal string representation for this key sequence.

Usage

From source file:de.xirp.io.command.CommandKeyManager.java

License:Open Source License

/**
 * Calls {@link KeySequence#toString()} to get a re-parsable
 * string of the given key sequence./*  www  .  j av  a 2  s. c  om*/
 * 
 * @see de.xirp.io.command.AbstractCommandPersistManager#saveObject(java.lang.Object)
 */
@Override
protected String saveObject(KeySequence k) {
    return k.toString();
}

From source file:de.xirp.ui.widgets.dialogs.preferences.HotkeysFolder.java

License:Open Source License

/**
 * Tests if the given key is already used for an other command.
 * //from   w  w  w . j  a  v  a  2 s. c  o m
 * @param command
 *            the actual command to check.
 * @param seq
 *            the key to check.
 * @return <code>true</code> if the given key is free to be used
 *         by the given command.
 */
private boolean isFree(CommandDefinition command, KeySequence seq) {
    if (seq.toString().equalsIgnoreCase(FORMAL_EMPTY_KEY)) {
        return true;
    }
    KeySequence old = keyMappings.get(command);
    if (old != null && old.equals(seq)) {
        return true;
    } else {
        return !keyMappings.values().contains(seq);
    }
}

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.  j ava  2s  .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 KeySequence readKeySequence(IConfigurationElement configurationElement, List warningsToLog,
        String commandId, String keySequenceText) {

    KeySequence keySequence = null;
    if (keySequenceText.equals(configurationElement.getAttribute(ATT_STRING))) {
        // The key sequence is in the old-style format.
        try {/*  w ww .j  a va 2s.c o  m*/
            keySequence = convert2_1Sequence(parse2_1Sequence(keySequenceText));
        } catch (final IllegalArgumentException e) {
            addWarning(warningsToLog, "Could not parse key sequence", //$NON-NLS-1$
                    configurationElement, commandId, "keySequence", //$NON-NLS-1$
                    keySequenceText);
            return null;
        }
    } else {
        // The key sequence is in the new-style format.
        try {
            keySequence = KeySequence.getInstance(keySequenceText);
        } catch (final ParseException e) {
            addWarning(warningsToLog, "Could not parse key sequence", //$NON-NLS-1$
                    configurationElement, commandId, "keySequence", //$NON-NLS-1$
                    keySequenceText);
            return null;
        }
        if (keySequence.isEmpty() || !keySequence.isComplete()) {
            addWarning(warningsToLog, "Key bindings should not have an empty or incomplete key sequence", //$NON-NLS-1$
                    configurationElement, commandId, "keySequence", //$NON-NLS-1$
                    keySequence.toString());
            return null;
        }

    }
    return keySequence;
}