June 1, 2007 in Software Development by Mark Levison

I’m struggling to build an GEF application in Eclipse. Unfortunately the documentation for GEF consists of half a dozen tutorials that were written between 2003-4. These tutorials are excellent as far as they go but don’t really shed light in alot of areas. So this is Anti-FAQ – its a batch of questions that should (but don’t currently have answers). I will update this posting with new questions and answers over time.

GEF Tutorials/Documentation

Current list. My favorites so far: A Shape Diagram Editor by Bo Majewski. The source code for this tutorial is included in the GEF Examples download (link is 3.2.2).

What’s missing no tutorial/sample covers a standalone RCP/GEF application. In particular there is no information on how to integrate into the RCP commands and menu structure.

API Questions

Retarget Actions

  1. What is a retarget action? It appears to be a wrapper around the existing SWT actions. Retarget actions Javadocs only tell you that it "tracks the active part in the workbench". Not why this would be useful. 
  2. Why do we need an action that is different from IAction? 
  3. Does retarget action play nicely with 3.3 new handler code? 
  4. Which actions need retarget actions and which don’t? For example the Copy has one and Print doesn’t. Why?

Integration with a plain RCP application

  1. Why use ActionContributor vs. adding Actions in the ActionBarAdvisor?

ActionBarContributor

  1. If you’re using the ActionBarContributor how do you contribute to a menu that already exists – perhaps file? In a specific place in that menu? 
  2. When adding actions via an ActionBarContributor should you add the actions  to a ‘global handler’:
        • pageSite.getActionBars().setGlobalActionHandler() as per the logic editor sample **or** editor handler
        • getEditorSite().getService(IHandlerService.class).
    activateHandler() as per the shapes example?

Drawing

  1. When drawing your own figure what method should you override? paint() or paintClientArea() or paintFigure(). Finally one where I have answer (even though none of the methods provide any hints in the docs). From the Logic Designer sample code, I noticed that one that gets paintFigure() gets overridden. 
  2. Need to turn on antialaising? Just do graphics.setAntialias(SWT.ON); If its inside paintFigure you don’t need to turn it off since paint() does a graphics.restoreState(); immediately after calling paintFigure(); 
  3. Need a linear diagonal gradient fill so that you graphical objects can mimic the correct Windows XP look and feel?image 

    Want to mimic the style of the rectangle to your left? Try this code:

    protected void paintFigure(Graphics graphics) {	Display display = Display.getCurrent();	Rectangle boundingRect = getBounds();
    
    	Point topLeft = boundingRect.getTopLeft();	Point bottomRight = boundingRect.getBottomRight();
    
    	Pattern pattern = new Pattern(display, topLeft.x, topLeft.y,		bottomRight.x, bottomRight.y,		ColorConstants.lightBlue, ColorConstants.darkBlue);	graphics.setBackgroundPattern(pattern);	graphics.fillRectangle(boundingRect);	graphics.setBackgroundPattern(null);	pattern.dispose();}
     
  4. Which naturally leads us to discover that in Eclipse 3.2, GEF 3.2.2 setBackgroundPattern() is not implemented for Scaled or Printer graphics – so you will get an exception if you try to use it.

Labels underneath Figures?

See:  Narrow Figures – Wide Labels – More GEF discoveries

Misc

Developing Eclipse RCP apps? Want access to Display etc will running your Unit Tests?

If you enjoyed this post, subscribe now to get free updates.