final ICommandService commandService) {
final Collection bindings = new ArrayList(configurationElementCount);
final List warningsToLog = new ArrayList(1);
for (int i = 0; i < configurationElementCount; i++) {
final IConfigurationElement configurationElement = configurationElements[i];
/*
* Read out the command id. Doing this before determining if the key
* binding is actually valid is a bit wasteful. However, it is
* helpful to have the command identifier when logging syntax
* errors.
*/
String commandId = configurationElement
.getAttribute(ATT_COMMAND_ID);
if ((commandId == null) || (commandId.length() == 0)) {
commandId = configurationElement.getAttribute(ATT_COMMAND);
}
if ((commandId != null) && (commandId.length() == 0)) {
commandId = null;
}
final Command command;
if (commandId != null) {
command = commandService.getCommand(commandId);
if (!command.isDefined()) {
// Reference to an undefined command. This is invalid.
addWarning(warningsToLog,
"Cannot bind to an undefined command", //$NON-NLS-1$
configurationElement, commandId);
continue;
}
} else {
command = null;
}
// Read out the scheme id.
String schemeId = configurationElement.getAttribute(ATT_SCHEME_ID);
if ((schemeId == null) || (schemeId.length() == 0)) {
schemeId = configurationElement
.getAttribute(ATT_KEY_CONFIGURATION_ID);
if ((schemeId == null) || (schemeId.length() == 0)) {
schemeId = configurationElement
.getAttribute(ATT_CONFIGURATION);
if ((schemeId == null) || (schemeId.length() == 0)) {
// The scheme id should never be null. This is invalid.
addWarning(warningsToLog, "Key bindings need a scheme", //$NON-NLS-1$
configurationElement, commandId);
continue;
}
}
}
// Read out the context id.
String contextId = configurationElement
.getAttribute(ATT_CONTEXT_ID);
if (LEGACY_DEFAULT_SCOPE.equals(contextId)) {
contextId = null;
} 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;
}
// Read out the key sequence.
KeySequence keySequence = null;
String keySequenceText = configurationElement
.getAttribute(ATT_SEQUENCE);
if ((keySequenceText == null) || (keySequenceText.length() == 0)) {
keySequenceText = configurationElement
.getAttribute(ATT_KEY_SEQUENCE);
}
if ((keySequenceText == null) || (keySequenceText.length() == 0)) {
keySequenceText = configurationElement.getAttribute(ATT_STRING);
if ((keySequenceText == null)
|| (keySequenceText.length() == 0)) {
// The key sequence should never be null. This is pointless
addWarning(
warningsToLog,
"Defining a key binding with no key sequence has no effect", //$NON-NLS-1$
configurationElement, commandId);
continue;
}
// The key sequence is in the old-style format.
try {
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);
continue;
}
} 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);
continue;
}
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());
continue;
}
}
// Read out the locale and platform.
String locale = configurationElement.getAttribute(ATT_LOCALE);
if ((locale != null) && (locale.length() == 0)) {
locale = null;
}
String platform = configurationElement.getAttribute(ATT_PLATFORM);
if ((platform != null) && (platform.length() == 0)) {
platform = null;
}
// Read out the parameters, if any.