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));
}
}