Я пытаюсь проиллюстрировать (и отредактировать) модель xml с графическим редактором GEF в eclipse. Моя xml-модель может иметь до пяти уровней в иерархии родитель-потомок. Каждый элемент в иерархии - это собственный EditPart (который выглядит как коробка). Детальные элементы будут представлены как «box» EditParts, содержащиеся в поле их родителя, и так далее ...GEF - дочерние элементы EditParts, которые рисуются ниже других фигур Parent?
В каждом из моих EditParts будет фигура draw2d, которая сама по себе будет иметь как минимум две или три (декоративные) draw2d собственные. Декоративные фигуры - это такие, как Header Rectangle, content Rectangles, label и т. Д. Я вижу, что эти декоративные фигуры рисуются над дочерним элементом EditPart EditParts - это означает, что я не вижу ни одного дочернего EditParts.
У меня была работа вокруг этого, где я бы вручную заставить фигуру дочернего EditPart, чтобы быть перемещен в верхней части стека его родителя EditPart о цифрах:
@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();
}
Однако это лишь частично работал. Ребенок EditPart теперь обрабатывался над Parent EditPart, но в отношении Gef это было ниже - некоторые события Gef, такие как drop-слушатели и всплывающая подсказка, будут вести себя так, как если бы дочерний EditPart не существовал.
Edit:
облеченного EditPart в создается следующим образом
@Override
protected IFigure createFigure() {
return new PageFigure(this);
}
Где PageFigure является подклассом чертеж, который строит свои собственные декоративные фигурки ребенка.
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));
}
}
Как создается фигура 'EditPart'? Можете ли вы опубликовать здесь упрощенную версию? – vainolo
См. Выше edit! – icyitscold
Где находятся декоративные фигуры? – vainolo