【发布时间】:2023-04-02 11:40:01
【问题描述】:
我想创建一个 GUI 表来显示EObject 子类的给定功能列表。为此,我必须获取列标题的功能的显示名称。
如何以最佳方式获取功能显示名称?
一个看起来有点像 hack 的解决方案:
如果我有一个类的实例,那么我可以使用适配器工厂来获取可以执行此操作的IItemPropertySource:
SomeEntity e = ...
String displayName = adaptorFactory.adapt(e, IItemPropertySource.class)
.getPropertyDescriptor(null, feature).getDisplayName(null));
但是当表格为空时,没有方便使用的SomeEntity 对象来获取IItemPropertySource。
我可以通过这种方式使用EFactory 创建一个虚拟对象:
EClass containingClass = feature.getEContainingClass();
SomeEntity dummy = containingClass.getEPackage().getEFactoryInstance()
.create(containingClass));
... 然后使用该对象获取IItemPropertySource。但这似乎有点像黑客。有没有更好的解决方案?
【问题讨论】:
标签: eclipse-emf emf eclipse-emf-ecore