自定义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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
GMF图的GS文件是Graphical Definition Model文件,用于定义GMF图的外观和行为。以下是一个简单的GMF图的GS文件示例: ``` <?xml version="1.0" encoding="UTF-8"?> <gmfgen:GenDiagram xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:gmfgen="http://www.eclipse.org/gmf/2006/GenModel" diagram="MyDiagram" diagramUpdaterClass="com.example.MyDiagramUpdater" diagramEditorUtilClass="com.example.MyDiagramEditorUtil" editPartFactoryClass="com.example.MyEditPartFactory" notationViewFactoryClass="com.example.MyNotationViewFactory" preferencePageProviderClass="com.example.MyPreferencePageProvider" rootEditPartClass="com.example.MyRootEditPart" validationProviderClass="com.example.MyValidationProvider"> <rules> <rule suffix="MyRule" class="com.example.MyRule" /> </rules> <nodeLabels> <label name="label1" text="%name" /> </nodeLabels> <linkLabels> <label name="label2" text="%name" /> </linkLabels> <compartments> <compartment name="compartment1" label="Compartment 1" /> </compartments> </gmfgen:GenDiagram> ``` 其中,`GenDiagram`元素定义了GMF图的基本信息,包括所使用的类、工具等。`rules`元素定义了GMF图的规则,`nodeLabels`和`linkLabels`元素定义了节点和连接线标签的显示方式,`compartments`元素定义了容器的外观和行为。在GS文件中还可以定义其他元素,例如视图编辑器属性等。 请注意,GS文件是基于Eclipse GMF框架的,因此需要在Eclipse中安装GMF插件才能使用。在Eclipse中打开GS文件,可以使用GMF Graphical Editor编辑器编辑和预览GMF图的外观效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值