eclipseemfecoreeclipse-sirius

Generate some child in my ecore model


To simplify my question I've made a little model of my problem.

In this model, I have a Plane in a Simulation. I would like to generate with a little piece of code, some other Plane with the same children classes (MotorType, OtherClass1, OtherClass2) and the same values except the numeric value in MotorType that is incremented with each iteration.

For example, I have a Simulation comprised of a Plane named "plane1", with a MotorType=TypeB with the value 10, and an OtherClass1.

I would like to generate 10 new planes, with OtherClass1 with the same values and the same MotorType, but with the "value" incremented by 10.

How can I generate some new plane child of my simulation that is a copy of an existing plane but with an incrementation of a parameter ?
Is it possible to do this with Sirius by a right click on my plane to copy ?

Example of my model class diagram
Example of a creation of a simulation


Solution

  • You probably want to use EcoreUtil.copy(EObject) on your original Simulation to create your copy.

    Then, using the Java EMF APIs you can navigate inside your copy and alter it however you wish to.

    If you want each Simulation to be in its own file, you will have to create the appropriate EMF Resource and add your newly-created Simulation to its contents before saving it.

    After you have implemented the Java method that does all the above, you can call it from a Sirius diagram using a Java service