Tracing 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.

6 Responses to “Tracing Keybindings in Eclipse RCP”

  1. ekke says:

    Thanks, elias!

    I wasn’t aware of these tracing options. very helpful.

  2. Lars Vogel says:

    Thanks Elias,

    that is very useful. I used your information to describe this from the perspective of the Eclipse IDE, you find this here:

    http://www.vogella.de/articles/EclipseCodeAccess/article.html#keybindings

    I hope it is ok that I used your information.

  3. Elias says:

    Hi Lars,

    No problem with citing this in your article. Thanks for the backlink. :-)

  4. eD says:

    How about this issue, i execute a key binding and the action works( i can see it in the console and on screen). I do a few things inside my application, then try and do the exact same key binding and it shows it in the console, but no action is executed?

  5. Elias says:

    @eD: hard to answer without looking at your code. My best guess: assuming you use commands and handlers – I would put breakpoints at the locations below and step through the code once you hit the key shortcut. The actual line numbers may differ if you are not on Eclipse 3.6.

    WorkbenchKeyboard [line: 435] – executeCommand(Binding, Event)
    Command [line: 457] – executeWithChecks(ExecutionEvent)

    I should also mention that we offer hourly developer support, where I and other Eclipse experts look at your code via screensharing and help out.

  6. Adil says:

    Hey….

    Thanks for showing this tip.

    I am in the process of debugging why my rcp custom editor does not pick “Ctrl+1″ quick fix key binding.
    The quick fix works from the right click menu but not by using the keyboard sequence. We lost this functionality as part of our upgrade from 3.3 to 3.6

    Thank you,
    Adil

6 responses so far

Written by . Published in Categories: Planet Eclipse

Author:
Published:
Jul 8th, 2009
Follow:

Twitter GitHub