1

Eclipse で GEF を使用したグラフィカル エディターを使用して xml モデルを説明 (および編集) しようとしています。私の xml モデルは、その親子階層に最大 5 つのレベルを持つことができます。階層内の各要素は、独自の EditPart (ボックスのように見えます) です。子要素は、親のボックス内に含まれる「ボックス」EditParts として表されます。

私の EditParts のそれぞれには draw2d Figure があり、それ自体に少なくとも 2 つまたは 3 つの (装飾的な) draw2d Figure があります。装飾的な図は、ヘッダーの四角形、コンテンツの四角形、ラベルなどです。これらの装飾的な図は、EditPart の子 EditPart の上に描画されています。つまり、子の EditPart が表示されません。

私はこれを回避するために、手動で子 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 は現在、親 EditPart の上にレンダリングされていましたが、Gef に関する限り、それは下にありました。ドロップ リスナーやツールチップなどの一部の Gef イベントは、子 EditPart が存在しないかのように動作します。

編集:

EditPart の図は、次のように作成されます。

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

PageFigure は Figure のサブクラスであり、独自の装飾的な子フィギュアを構築します。

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

1 に答える 1