Eclipse Yoxos Services Downloads Blogs About
Home > Blogs >

Posts Tagged ‘bindings’

on Jul 8th, 2009Tracing Keybindings in Eclipse RCP

When adding keybindings to an existing Eclipse RCP application, it is extremelly helpful to get realtime information about which keybinding registered and to what command handlers it is mapped to. Why is that?  Because sometimes the operating system or another widget will consume the keyboard event before it gets to the command framework. Other times there are several handlers bound to the same key causing a conflict.

Enabling Tracing for Keybindigs

Fortunatelly, this information is easy to get, if you enable the right tracing options:

org.eclipse.ui/debug = true
org.eclipse.ui/trace/keyBindings = true
org.eclipse.ui/trace/keyBindings.verbose = true

trace keybindings Tracing Keybindings in Eclipse RCP

After that each keystroke will produce some output on the console:

KEYS --- WorkbenchKeyboard.press(potentialKeyStrokes = [CTRL+PAGE_UP, CTRL+])
KEYS --- WorkbenchKeyboard.executeCommand(commandId = 'org.eclipse.riena.navigation.ui.previousSubApplication', parameters = {})

In the above you can see that Ctrl+PageUp is mapped to the ‘previousSubApplication’ command.

Some times there is a conflict – i.e. one keybinding is mapped to two or more ‘active’ command handlers. This looks like this:

BINDINGS --- A conflict occurred for CTRL+SHIFT+W
BINDINGS ---     [Binding(CTRL+SHIFT+W,
	ParameterizedCommand(Command(org.eclipse.ui.file.closeAll,Close All,
		Close all editors,
		Category(org.eclipse.ui.category.file,File,null,true),
		org.eclipse.ui.internal.CloseAllHandler,
		,,true),null),
	org.eclipse.ui.defaultAcceleratorConfiguration,
	org.eclipse.ui.contexts.window,,,system), Binding(CTRL+SHIFT+W,
	ParameterizedCommand(Command(org.eclipse.riena.navigation.ui.closeModuleGroup,Close module group,
		,
		Category(org.eclipse.riena.navigation.ui.swt,Riena Navigation Commands,null,true),
		org.eclipse.riena.internal.navigation.ui.swt.handlers.CloseModuleGroup@39880a,
		,,true),null),
	org.eclipse.ui.defaultAcceleratorConfiguration,
	org.eclipse.ui.contexts.window,,,system)]

What happened here is that Ctrl+Shift+W was already bound to the CloseAllHandler via the ‘file.closeAll’ command. I was not aware of this initially, because it is defined in the org.eclipse.ui plugin. So I accidentally bound another command and handler to Ctrl+Shift+W. With the output I quickly realized what was going on. I ditched my own command and instead made ‘CloseModuleGroup’ a handler for the ‘file.closeAll’ command.

on Jul 18th, 2008Tip: Suppressing Keybindings

I was helping a colleague today with a key binding issue that I think is fairly common. To illustrate the problem, let’s look at what happens when you press CMD+N in the RCP mail sample:

Oh no, why did I get the new project wizard!?

What!? New Project Wizard? That’s not what I wanted! In this case, I actually wanted a ‘New Message’ to pop up instead of that new wizard. I don’t want any of my end-users ever seeing this dialog! What’s the problem here? Well, in simple terms, Eclipse is using its own default key configuration scheme if you don’t set one. So by default, you may get strange results like above or even conflicts with existing key bindings.

What’s the solution?

Well, there are a few ways to go about this but I think the simplest one for most people is to simply create your own key configuration scheme and instruct Eclipse to use it. To do this, you first need to create your own scheme:

<extension point="org.eclipse.ui.bindings">
<scheme
id="mail.scheme"
name="My Mail Scheme">
</scheme>
</extension>

After that, make sure your bindings are instructed to use this scheme:

<extension
point="org.eclipse.ui.bindings">
<key
commandId="mail.open"
schemeId="mail.scheme"
sequence="M1+N">
</key>
<key
commandId="mail.openMessage"
schemeId="mail.scheme"
sequence="M1+3">
</key>
<key
commandId="org.eclipse.ui.file.exit"
schemeId="mail.scheme"
sequence="M1+X">
</key>
</extension>

Finally, you need to create a plugin_customization.ini if you don’t have one already for your application and put this in there:

org.eclipse.ui/KEY_CONFIGURATION_ID=mail.scheme

That’s it. Once you do that, you should have key binding bliss:

Alright, that\'s what I want!

Thanks for listening and let me know if this helps. Here is the sample project for reference.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes
© EclipseSource 2008 - 2009