Question

In a GEF editor, I have the following EditPart:

public class MyLabelEditPart extends AbstractGraphicalEditPart {

@Override
protected IFigure createFigure() {
    return new Label();
}

@Override
protected void refreshVisuals() {
    MyModel model = (MyModel) getModel();
    Label figure = (Label) getFigure();
    EditPart parent = getParent();

    Font font = new Font(Display.getCurrent(), "sansserif", 11, SWT.BOLD);
    figure.setFont(font);
    figure.setForegroundColor(ColorConstants.darkGray);
    figure.setText(model.getValueString());
    parent.refresh();
}

All works fine with most models, but - you will have spotted the error already - I never dispose of the font. So, with a large-ish model of 10k+ tokens, this throws an org.eclipse.swt.SWTError: No more handles. At least I think (hope) this is what causes the error.

Now I cannot figure out how to dispose the font, as the figure for the EditPart is a Draw2D Label, not an SWT Widget. How can I make sure the dreaded error can be circumvented?

Was it helpful?

Solution

Apart from Baz' solution to make the font a static field, a good solution is to use a JFace FontRegistry, as detailed in this strangeoptics blog post.

OTHER TIPS

If you want to keep and reuse all your resources ( images, fonts, colors..etc) at one point rather than using registries, follow this windows builder class

http://code.google.com/p/goclipse/source/browse/trunk/goclipse-n/src/org/eclipse/wb/swt/SWTResourceManager.java?r=445

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top