Wednesday, 22 October 2008

Geoff on GEF pt. I

It's been about 4 years since I last worked with the Graphical Editing Framework, or GEF, in eclipse. I have recently been working on a new application using eclipse RCP to manage tournaments (specifically wargaming events).
Anyway, I have a basic application up and running now and intend to add an additional feature to allow for real-time information to be displayed on a seperate screen (or projector). For this feature I've decided to use GEF once more.
As I said, it has been about 4 years since I last used GEF and I recall that it was a little tricky to get started with. This time around I have decided to document my experience as I develop this new functionality.

To get things started, I paid a visit to the GEF homepage and jumped straight into the tutorial referenced there. The tutorial starts by stating that an updated version was posted in March 2007, not a good sign if the homepage does not point to the more up-to-date documentation.
Skipping quickly over the first section, that explains the MVC architechture, I wrote a couple of EditParts as described, then decided to create a view to display them. Now, the tutorial only deals with creating an editor, not a view. So after some googling I found this post on creating a view for GEF.

One of the methods called is setEditPartFactory(), I know from experience that the Edit Part Factory is a core piece of functionality that creates controllers (EditParts) from your model. I was stunned to find that the Edit PartFactory was not described in the tutorial. I threw one together from memory (see below) to confirm that I could get a view to display.

On launching the app, the view displayed, but there was a null pointer when getting the children of my root object, not really a surprise as I had yet to populate it. Anyway, that was enough for one night. I shall continue to work on it tomorrow.

The content of my EditPartFactory (simply implements EditPartFactory):

public EditPart createEditPart(EditPart context, Object model) {
EditPart part = null;
if(model instanceof TournamentData)
{
part = new FloorplanEditPart();
}
else if(model instanceof Game)
{
part = new GameEditPart();
}

if(part != null)
{
part.setModel(model);
part.setParent(context);
}
return part;
}

No comments: