Code and Stuff

Jan 23, 2012

Graphiti RCP Key bindings and preferences conflicts with Eclipse IDE

When importing org.eclipse.graphiti.ui in your plugin you get the eclipse IDE one as well (org.eclipse.ui.ide). When using Graphiti in an RCP application this is not very nice. Especially because of all the extensions that get defined. In particular the bindings and the preference pages. These can result in conflicts with you own bindings or show undesired pages in the preferences.

Avoiding the IDE Preference Pages

Removing the preference pages node is actually quite simple and can be done with the following snippet. You can add this to the postWindowOpen of your WorkbenchWindowAdvisor.
PreferenceManager pm = PlatformUI.getWorkbench().getPreferenceManager();
pm.remove("org.eclipse.ui.preferencePages.Workbench");

Avoiding the IDE key bindings

Removing the Key bindings is not as easy and is mostly a trick. The basic idea is to create your own key binding scheme and enable it by default. The scheme can be created in the plugin.ini file:
<extension point="org.eclipse.ui.bindings">
   <scheme
      id="my.scheme"
      name="MyScheme">
   </scheme>
</extension>

To enable it you have to add the following line to plugin_configuration.ini:
org.eclipse.ui/KEY_CONFIGURATION_ID=my.scheme
At this point you can create all your keyboard shortcuts. The bindings must use my.scheme as schemeId.
<extension point="org.eclipse.ui.bindings">
   <key
         commandId="my.graphiti.newUntitledDiagram"
         schemeId="my.scheme"
         sequence="M1+N">
   </key>
</extension>

No comments: