自定义GMF编辑器属性视图的Cell Editor

以一个自定义的对话框的Cell Editor的例子进行说明:
1)自定义***CellEditor 继承 DialogCellEditor,并覆盖openDialogBox()方法,返回要打开的对话框
2)自定义***PortPropertyDescriptor继承PropertyDescriptor,覆盖方法createEDataTypeCellEditor,返回步骤1定义的***CellEditor,如:
            protected CellEditor createEDataTypeCellEditor(EDataType e, Composite c) {
                EAttribute feature = (EAttribute) itemPropertyDescriptor
                  .getFeature(object);
                 if(ConnectionPackage.Literals. ***.equals(f eature)){
                     return new ***CellEditor(e, c, object, feature);
                  }
                 return super.createEDataTypeCellEditor(e,cc);
            }
3)自定义***PropertySource继承 PropertySource,并覆盖createPropertyDescriptor()方法,返回步骤2定义的***PortPropertyDescriptor:
     protected IPropertyDescriptor createPropertyDescriptor(IItemPropertyDescriptor des) {
     if (itemPropertyDescriptor != null) {
                         Object feature = des.getFeature(object);
if (ConnectionPackage.Literals.***.equals(feature) {
                    return new ***PropertyDescriptor(object, des);
}
     }
     return new PropertyDescriptor(object, des);
             }
4)找到***.diagram工程中***sheet包下的***PropertySection.java, 修改getPropertySource方法,返回步骤3定义的***PropertySourc:其中***ItemProvider为生成的***.edit工程中对应的提供器
    public IPropertySource getPropertySource(Object object) {
    if (object instanceof IPropertySource) {
    return (IPropertySource) object;
     }
     AdapterFactory af = getAdapterFactory(object);
     if (af != null){
                             IItemPropertySource ips = (IItemPropertySource) af.adapt(object,IItemPropertySource.class);
     if (ips != null) {
        if(ips instanceof ***ItemProvider){
            return new ***PropertySource(object, ips);
         }else {
                                   return new PropertySource(object, ips);
                                 }
     }
      }
    if (object instanceof IAdaptable) {
   return (IPropertySource) ((IAdaptable) object).getAdapter(IPropertySource.class);
     }
    return null;
              }

你可能感兴趣的:(C++,c,F#,C#)