The context is the location in which this binding is valid. For commands that are visible everywhere—typically the kind of options in the default menu—they can be associated with the org.eclipse.ui.contexts.window
context. If the command should also be invoked from dialogs as well, then the org.eclipse.ui.context.dialogAndWindow
context would be used instead.
plugin.xml
file of the clock.ui
project.contextId
as follows:<extension point="org.eclipse.ui.bindings">
<key commandId="com.packtpub.e4.clock.ui.command.hello"
sequence="M1+9"
//The following commented line needs to be removed
/*contextId="org.eclipse.ui.contexts.window"*/
contextId="org.eclipse.jdt.ui.javaEditorScope"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
</extension>
Unfortunately, it also highlights the fact that just because the keybinding is disabled when in the Java scope, it doesn't disable the underlying command.
If there is no change in behavior, try cleaning the workspace of the test instance at launch, by going to the Run | Run ... menu, and choosing Clear on the workspace. This is sometimes necessary when making changes to the plugin.xml
file, as some extensions are cached and may lead to strange behavior.
Context scopes allow bindings to be valid for certain situations, such as when a Java editor is open. This allows the same keybinding to be used for different situations, such as a Format operation—which may have a different effect in a Java editor than an XML editor, for instance.
Since scopes are hierarchical, they can be specifically targeted for the contexts in which they may be used. The Java editor context is a subcontext of the general text editor, which in turn is a subcontext of the window context, which in turn is a subcontext of the windowAndDialog
context.
The available contexts can be seen by editing the plugin.xml
file in the plug-in editor; in the extensions tab the binding shows an editor window with a form:
Clicking on the Browse… button next to the contextId brings up a dialog, which presents the available contexts:
It's also possible to find out all the contexts programmatically or via the running OSGi instance, by navigating to Window | Show View | Console, and then using New Host OSGi Console in the drop-down menu, and then running the following code snippet:
osgi> pt -v org.eclipse.ui.contexts Extension point: org.eclipse.ui.contexts [from org.eclipse.ui] Extension(s): ------------------- null [from org.eclipse.ant.ui] <context> name = Editing Ant Buildfiles description = Editing Ant Buildfiles Context parentId = org.eclipse.ui.textEditorScope id = org.eclipse.ant.ui.AntEditorScope </context> null [from org.eclipse.compare] <context> name = Comparing in an Editor description = Comparing in an Editor parentId = org.eclipse.ui.contexts.window id = org.eclipse.compare.compareEditorScope </context>