Question

I'm trying to illustrate (and edit) an xml model with a GEF powered graphical editor in eclipse. My xml model can have up to five levels in its parent-child hierarchy. Each element in the heirarchy is its own EditPart (which looks like a box). Child elements will be represented as "box" EditParts contained within their parent's box, and so on...

Each one of my EditParts will have a draw2d Figure which, itself, will have at least two or three more (decorative) draw2d figures of its own. The decorative figures are things like Header Rectangle's, content Rectangles, label's etc. I'm seeing these decorative figures being drawn above the EditPart's child EditParts - meaning that I can't see any child EditParts.

I had a work around for this where I would manually force the child EditPart's figure to be moved to the top of its parent's EditPart's stack of figures:

@Override
protected void refreshVisuals() {

    super.refreshVisuals();

    IFigure figure = getFigure();

    if(figure instanceof BaseElementFigure){
        //Refresh the figure...
        ((BaseElementFigure) figure).refresh(this);
    }
    if (figure.getParent() != null) {
        //This moves the figure to the top of its parent's stack so it is not drawn behind the parent's other (decorative) figures
        figure.getParent().add(figure);

        ((GraphicalEditPart) getParent()).setLayoutConstraint(this, figure, getBounds());
    }

    refreshChildrenVisuals();
}

However, this only partially worked. The child EditPart was now being rendered above the Parent EditPart, but as far as Gef was concerned, it was beneath - some Gef events like drop listeners and tooltip would behave as if the child EditPart didn't exist.

Edit:

An EditPart's figure is created by as follows

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

Where PageFigure is a subclass of Figure which constructs it's own decorative child figures.

public class PageFigure extends Figure {

    protected Label headerLabel;
    protected RectangleFigure contentRectangle;
    protected RectangleFigure headerRectangle;

    private UiElementEditPart context;


    public PageFigure(UiElementEditPart context) {
        this.context = context;
        setLayoutManager(new XYLayout());

        this.contentRectangle = new RectangleFigure();
        contentRectangle.setFill(false);
        contentRectangle.setOpaque(false);

        this.headerRectangle = new RectangleFigure();
        headerRectangle.setFill(false);
        headerRectangle.setOpaque(false);

        this.headerLabel = new Label();
        headerLabel.setForegroundColor(ColorConstants.black);
        headerLabel.setBackgroundColor(ColorConstants.lightGray);
        headerLabel.setOpaque(true);
        headerLabel.setLabelAlignment(Label.LEFT);
        headerLabel.setBorder(new MarginBorder(0, 5, 0, 0));

        headerRectangle.add(headerLabel);

        add(contentRectangle);
        add(headerRectangle);

        //Initializing the bounds for these figures (including this one)
        setBounds(context.getBounds());

        contentRectangle.setBounds(new Rectangle(this.getBounds().x, this.getBounds().y + 20, this.getBounds().width, this.getBounds().height - 20));


        Rectangle headerBounds = new Rectangle(this.getBounds().x, this.getBounds().y, this.getBounds().width, 20);
        headerRectangle.setBounds(headerBounds);

        headerLabel.setBounds(new Rectangle(headerBounds.x + 30, headerBounds.y, headerBounds.width - 30, 20));
    }
}
Was it helpful?

Solution

What is happening is that GEF is adding the child EditPart figures to the PageFigure, and the order of drawing in GEF starting from the last figure added and on top the figures added before, like a stack. This is why the figures of your child EditParts are below the child figures of the parent EditPart.

What you can do is add a content pane figure that will contain the child figures, and make it the first figure that is added to the EditPart's figure. Then override the figure's contentPane, so that all child figures are added on this figure.

If this doesn't help, check the tutorial on this subject some time ago. I may have forgotten some of the details: http://www.vainolo.com/2011/09/01/creating-an-opm-gef-editor-%E2%80%93-part-17-how-to-define-container-edit-parts/.

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