GMF中,由xxxEditPart获得模型对象的方法的方法

来源:互联网 发布:阿里旺旺mac版如何退出 编辑:程序博客网 时间:2024/06/04 20:05

          其实在前面博客中已提及一部分,在此做个整理:

          法1:

       XXXImpl  xxxImpl = xxxEditPart.resolveSemanticElement();//此方法比较简便,一行代码便可以了

         法2:

         View view = (View) xxxEditPart.getModel();

         XXXImpl xxxImpl = (XXXImpl) view.getElement();

         法3:

         View view = (View) xxxEditPart.getModel();

         EObject obj = ViewUtil.resolveSemanticElement(view);

         XXXImpl file2 = (XXXImpl)obj;

         第一种最简单了,当然有时候我们需要删除图元,要用到图元的View对象,所以了解下怎么得到图元的View对象还是有必要的,另外,由EditPart获得模型对象无法用法1的办法,原因是EditPart没有resolveSemanticElement()这个方法。