How to create a Has-A reference (containment) in ECORE that is available at runtime?

463 views Asked by At

Hey, I am new to EMF/ECORE. I want to model a Has-A reference (Containment), but the containment should be available at runtime. So:

I have different classes that have a volume. so the volume is modeled in a class:

MyVolume
 - depth: EDouble
 - height: EDouble
 - width: EDouble
 - volume()

MyClass
 - name: EString
 - volume: MyVolume

If a create an Editor with the .genmodel, I can add to Class a Volume. but I want that volumne is a part of Class, so that the user can use the Class Volume as an attribute like name without creating it first. And depth, height and width should be displayed the same way as the attribute name in the properties view of the Editor.

Which property in model should be set or is there another way to archive the goal?

Thanks in advance

Steffen

I figured out a "solution":

  • I created the class MyVolume, and then
  • a datatype MyVolume that use My.impl.MyAttributeImpl as Instance Class Name.
  • Then created in MyClass an attribute volume: MyVolume (Datatype).
  • So I can acccess depth in the source code like this fixture.getVolume().getDepth();
  • But only volume is show in the properties views in the Editor.

Any more ideas?

Steffen

2

There are 2 answers

1
Volker Stolz On

Why not simple make MyClass extend MyVolume, instead of having an attribute? I don't think this kind of union that you want is supported in any other way.

0
Cédric Brun On

You could also override the item provider to automatically create an instance of MyVolume when you create a "MyClass".

The EMF Book has tons of examples like that, here is the general presentation of the EMF.Edit framework, have a look on the "overriding commands" part.