Eclipse-Papyrus在droplocation创建节点

时间:2016-12-19 14:01:11

标签: eclipse drag-and-drop location papyrus

我想将列表中的一些项目拖放到模型查看器中。 我已经可以这样做,但节点总是在查看器的左上角创建,我不知道如何在删除的位置创建节点。

这是创建节点的函数(x和y是droplocation的坐标)

private View addNode(Node node, View deploymentView) {

    // use the view service to create the types. This is a bit cleaner than
    // using the sequence-diagram view provider directlys
    final String nodeType = UMLVisualIDRegistry
            .getType(org.eclipse.papyrus.uml.diagram.deployment.edit.parts.NodeEditPart.VISUAL_ID);
    org.eclipse.gmf.runtime.notation.Node nodeView = ViewService.createNode(deploymentView.getDiagram(), node,
            nodeType, UMLDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
    Bounds location = NotationFactory.eINSTANCE.createBounds();

    System.out.println("Dropped at x: "+ (int)this.x + " y: "+ (int)this.y);
    location.setX((int)this.x);
    location.setY((int)this.y);
    return nodeView;
}

1 个答案:

答案 0 :(得分:0)

好的,难以修复它......

private View addNode(Node node, View deploymentView) {


    // use the view service to create the types. This is a bit cleaner than
    // using the sequence-diagram view provider directlys
    final String nodeType = UMLVisualIDRegistry
            .getType(org.eclipse.papyrus.uml.diagram.deployment.edit.parts.NodeEditPart.VISUAL_ID);
    org.eclipse.gmf.runtime.notation.Node nodeView = ViewService.createNode(deploymentView.getDiagram(), node,
            nodeType, UMLDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);


    System.out.println("Dropped at x: "+ (int)this.x + " y: "+ (int)this.y);

    //for(int i=0;i<nodeView.getDiagram().getChildren().size();i++)System.out.println(nodeView.getDiagram().getChildren().get(i).toString());

    nodeView.setLayoutConstraint(NotationFactory.eINSTANCE
            .createLocation());
    Location location = (Location) nodeView.getLayoutConstraint();
    location.setX((int)this.x);
    location.setY((int)this.y);
    return nodeView;
}