GMF中,自动画连接线

       忘记将自动画连接线的代码贴出来了,特此补一补:

       private void drawLink(ModuleEditPart sourceModuleEditPart, ModuleEditPart targetModuleEditPart) {

    IElementType type = ModuleElementTypes.Link_3001; // 连接线类型

    CreateConnectionViewAndElementRequest createConnectionRequest 

                           = new CreateConnectionViewAndElementRequest(

                      type, ((IHintedType) type).getSemanticHint(),

                      PreferencesHint.USE_DEFAULTS);

    org.eclipse.gef.commands.Command createConnection

                           = CreateConnectionViewAndElementRequest

                   .getCreateCommand(createConnectionRequest,

                        sourceModuleEditPart, targetModuleEditPart);

    moduleDiagramEditPart.getDiagramEditDomain()

          .getDiagramCommandStack().execute(createConnection);

    }

           画连接线和画节点的不同之处在于画连接线的时候要指定源和目标节点。

posted @ 2012-06-08 11:32  supermmao  阅读(332)  评论(0编辑  收藏  举报