I have a simple EMF model of the following type:
EClass FooGroup {
EString name;
@Properties(containment=true, upper=-1)
List<Node> nodes;
}
EClass BarGroup {
EString name;
@Properties(containment=true, upper=-1)
List<Node> nodes;
}
EClass Node {
EString name;
}
I want to show all names of the nodes in a simple TableViewer
, together with the name of their parent group. Unfortunately, eContainer()
is an operation and not a feature. This means that I can not use the JFace Databinding framework to link this property to the GUI.
How can I solve this problem? Do I create a derived feature? Are there any tricks?
I can't think of a way to use the eContainer in EMF-databinding, but it wouldn't be so hard to add a designated parent-reference to a node, and to update it programmatically whenever the eContainer changes.
Another solution is to add a parent and then change the generated code:
/*
* @generated NOT
*/
public Group getParent() {
if (eContainer() instanceof Group) {
return (Group) eContainer();
}
return null;
}
Then you could use a FeaturePath to get the EMFProperty like this:
IEMFProperty groupNameProperty = EMFProperties.value(
FeaturePath.fromList(
ModelPackage.Literals.NODE__PARENT,
ModelPackage.Literals.GROUP__NAME
)
);