Tracing Keybindings in Eclipse RCP

July 8, 2009 | 2 min Read

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

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.