Key bindings
The association between a command and the key combinations that should
invoke the command is called a key binding Plug-ins can define key
bindings along with commands in the
org.eclipse.ui.bindings
extension point. From our InfoView example:
<extension
point="org.eclipse.ui.bindings">
<key
commandId="org.eclipse.ui.examples.contributions.view.edit"
contextId="org.eclipse.ui.examples.contributions.view.context"
sequence="M1+O"
schemeId="org.eclipse.ui.examples.contributions.scheme">
</key>
</extension>
The sequence attribute for a key binding defines the key
combination that is used to invoke a command. As long as our InfoView
context is active, we will try and execute the InfoView edit command when the
user chooses CTRL+O and the scheme is set to
org.eclipse.ui.examples.contributions.scheme. The mapping of M1 to CTRL
is described in the extension point description for
org.eclipse.ui.bindings.
The contextId indicates what active context this key binding will
be active in. More information on defining contexts declaratively and
activating them programmatically can be found in
Contexts. In this case, this key binding will be active
when the org.eclipse.ui.examples.contributions.view.context context
is active.
In our InfoView we have code called from the end of createPartControl(Composite):
private static final String VIEW_CONTEXT_ID = "org.eclipse.ui.examples.contributions.view.context"; //$NON-NLS-1$
...
/**
* Activate a context that this view uses. It will be tied to this view
* activation events and will be removed when the view is disposed.
*/
private void activateContext() {
IContextService contextService = (IContextService) getSite()
.getService(IContextService.class);
contextService.activateContext(VIEW_CONTEXT_ID);
}
As mentioned in
org.eclipse.ui.handlers this context will be active
only when the InfoView part is active. It will also be deactivated when
the InfoView part is disposed.