在gmf中属性页的支持是由PropertyProvider完成的。自动生成的PropertyProvider只有三个方法:

public boolean provides(IOperation operation)
{
……
}

public ICompositePropertySource
……
}


protected EObject getSemanticElement(Object object)
{
……
}
第一个方法主要是判断这个provider是否可以处理某个operation.
第二个方法返回一个PropertySource,和传统的eclipse PropertySource相似
第三个方法返回View对应的semantic model
要想定置自己的属性编辑器可以重载GenericEMFPropertiesProvider里面的
protected ICompositePropertySource createPropertySource(Object object,

IItemPropertySource itemPropertySource)
{
……
}
方法,这个方法返回一个你自己重载的EMFCompositePropertySource对象,在你的EMFCompositePropertySource对象中你需要重载方法:
protected IPropertyDescriptor newPropertyDescriptor(

IItemPropertyDescriptor itemPropertyDescriptor)
{
……
}
这个方法中返回一个自己订制的EMFCompositeSourcePropertyDescriptor对象,在你的对象中,你需要重载其中的:

protected CellEditor doCreateEditor(Composite composite)
{
……
}
方法。在EMFCompositeSourcePropertyDescriptor类中有方法getFeature()可以获得这个PropertyDescriptor对应的属性值,可以通过判断这个属性值的类型来返回你自己的celleditor。

public boolean provides(IOperation operation)
{
……
}
public ICompositePropertySource
……
}

protected EObject getSemanticElement(Object object)
{
……
}
第二个方法返回一个PropertySource,和传统的eclipse PropertySource相似
第三个方法返回View对应的semantic model
要想定置自己的属性编辑器可以重载GenericEMFPropertiesProvider里面的
protected ICompositePropertySource createPropertySource(Object object,
IItemPropertySource itemPropertySource)
{
……
}
protected IPropertyDescriptor newPropertyDescriptor(
IItemPropertyDescriptor itemPropertyDescriptor)
{
……
}
protected CellEditor doCreateEditor(Composite composite)
{
……
}
本文介绍了如何在GMF中通过重写PropertyProvider的方法来自定义属性页。主要涉及如何创建自定义的EMFCompositePropertySource及EMFCompositeSourcePropertyDescriptor,并实现特定的CellEditor。
2289

被折叠的 条评论
为什么被折叠?



