0

我有一些流程元素,可以无限地包含其他流程元素。

我直接从调色板管理将新进程添加到其他进程中,它工作正常但是当我拖动一个已经绘制的进程以将其集成为另一个已经绘制的进程的新子进程时,编辑器不让我这样做,我有一个白色十字光标。

在我的模型中,Process 类正在扩展 ContainerElement 类,它处理子元素的添加和删除以及通知内容。

我在想,由于该过程将有一个新的父进程,我必须在更改 ConstraintCommand 中添加它

这是我的代码片段

    public class ProcessFigure extends Figure {
    public ProcessFigure() {
    setLayoutManager(new XYLayout());

    ellipse = new Ellipse();
    ellipse.setFill(false);
    add(ellipse);
    label = new Label();
    add(label);
    ellipse.setLayoutManager(new XYLayout());
   }

    public IFigure getContentPane() {
    return ellipse;
   }
    ...
}

 ------------------------------
 public class ProcessEditPart extends ContainerElementEditPart {
 ...
    public IFigure getContentPane() {
    return ((ProcessFigure)getFigure()).getContentPane();
    }

    @Override
    protected void createEditPolicies() {
    installEditPolicy(EditPolicy.LAYOUT_ROLE, new ContainerElementXYLayoutEditPolicy(
            (XYLayout) getContentPane().getLayoutManager()));
    }
...
}
------------------------

public class ContainerElementXYLayoutEditPolicy extends XYLayoutEditPolicy {
    ...
    public ContainerElementXYLayoutEditPolicy(XYLayout layoutManager) {
    super();
    setXyLayout(layoutManager);
    }

    private Command getProcessCreateCommand(CreateRequest request) {
    ProcessCreateCommand result = new ProcessCreateCommand();
    Rectangle constraint = (Rectangle) getConstraintFor(request);
    result.setLocation(constraint.getLocation());
    result.setProcess((Process)request.getNewObject());
    result.setParent((ContainerElement)getHost().getModel());
    return result;
    }


    protected Command createChangeConstraintCommand (ChangeBoundsRequest request,EditPart child , Object constraint) {
    ProcessChangeConstraintCommand changeConstraintCommand = new ProcessChangeConstraintCommand (); 
    changeConstraintCommand.setProcess((Process)child.getModel());
    changeConstraintCommand.setNewConstraint((Rectangle)constraint);
    return changeConstraintCommand;

    }    
...

}

我认为问题在于 gef 无法确定合适的布局管理器,我尝试了一些更改,但每次都出现强制转换或 stackoverflow 异常,请帮助!

4

1 回答 1

2

当您将元素拖到编辑部件的图形之外时,GEF会触发一个REQ_ORPHAN请求,该请求必须由从中取出元素的编辑部件处理。如果不这样做,我认为您不能将元素放在编辑部分的图形之外。您可以通过覆盖类getOrphanChildrenCommand中的来处理此要求LayoutEditPolicy

我从未使用过此功能,但这是GEF 程序员指南的移动和调整大小中所写的内容

于 2013-04-26T13:40:59.037 回答