I'd like to create a GUI table to display a given list of features of an EObject sub-class. To do this I have to get the display names of the features for the column header.
How do I get the feature display names in the best way?
One solution that seems a bit like a hack:
If I have an instance of the class then I can use the adaptor factory to get a IItemPropertySource that can do this:
SomeEntity e = ...
String displayName = adaptorFactory.adapt(e, IItemPropertySource.class)
.getPropertyDescriptor(null, feature).getDisplayName(null));
But when the table is empty there is no SomeEntity object handy to use to get the IItemPropertySource.
I can create a dummy object using the EFactory in this way:
EClass containingClass = feature.getEContainingClass();
SomeEntity dummy = containingClass.getEPackage().getEFactoryInstance()
.create(containingClass));
... and then use that object the get the IItemPropertySource. But this seem a bit like a hack. Is there no better solution?
If you know the class at compile time, you can create the
ItemProviderAdapteryourself:If you do not know the class at compile time, but only have an
EClassinstance at runtime, things are more complicated, because the necessary methods are protected. You have to "make" them public first.I would add respective methods to the generated
MyPackageSwitchandMyPackageAdapterFactoryclasses (in myPackage.util).In
MyPackageAdapterFactory:In
MyPackageSwitch:Now you can create an
ItemProviderAdapterfor anEClasstheEClasslike this:EMF was obviously not made for this. Keep in mind that this all is only working if you do not have any custom provider implementations that uses the
EObjectvalues.