Adding Rulers to Eclipse GEF Editors

In order to add rulers to an existing GEF editor:

  • You’ll need two new objects in your model to store ruler info: one for the ruler and one for the guides.
  • You’ll need a RulerProvider
  • You’ll have to modify your GEF editor:
    • Override the createGraphicalViewer to inject a RulerComposite as the top level component.
    • Override getGraphicalControl to return the RulerComposite
    • Configure the ruler properties on the graphical viewer

The “logic” GEF example includes rulers and is a good place to start. Under the hood what the RulerComposite does is add two new graphical viewers to your editor, one for the north and one for the west rulers. GEF rulers can only mark pixels, inches, or centimeters. If you want anything else, you’ll have to override the RulerComposite and several other classes. I’ll get to that in a future entry too.

I know this isn’t a lot of info, but hopefully it’s enough to get someone started.