1

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));
    }
}
icyitscold
  • 1,151
  • 1
  • 9
  • 19
  • How is the `EditPart`'s figure created? Can you post a simplified version of it here? – vainolo Sep 26 '13 at 19:09
  • Where are the decorative figures? – vainolo Sep 26 '13 at 22:44
  • Within PageFigure - see contentRectangle, headerRectangle, and headerLabel. Edit: I should say that those figures don't have any EditParts associated with them because they do not represent any elements/data in the model – icyitscold Sep 26 '13 at 22:55

1 Answers1

2

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/.

vainolo
  • 6,907
  • 4
  • 24
  • 47
  • Thanks! I figured this is what was going on - but didn't know about content pane figures. I'll try this out now and accept the answer if everything works out! – icyitscold Sep 26 '13 at 23:36
  • I'm accepting the answer because it showed me the correct way to implement container EditParts. A lot of the quirks I was experiencing have been resolved. However, I'm still seeing the main issue (Child edit parts are drawn on top but GEF events are passing through them). I'd imagine that I'm going to have to do a lot of debugging to fix this. – icyitscold Sep 27 '13 at 02:55
  • As an FYI, I finally fixed this - my last issue (GEF drag events passing through my child edit part) was fixed adding a new CONTAINER_ROLE editpolicy to my container edit parts. I discovered this by more closely reviewing the code located on your blog! Thanks again – icyitscold Sep 28 '13 at 23:29