Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 360455

Summary: API for cloning a model
Product: z_Archived Reporter: Nepomuk Seiler <nepomuk.seiler>
Component: SapphireAssignee: Konstantin Komissarchik <konstantin>
Status: CLOSED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: konstantin, shenxue.zhou
Version: unspecifiedKeywords: plan
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Nepomuk Seiler CLA 2011-10-10 11:47:41 EDT
Build Identifier: 

As discussed in this thread http://www.eclipse.org/forums/index.php/t/245046/ a API for cloning an existing model would be helpfull. 

Reproducible: Always
Comment 1 Konstantin Komissarchik CLA 2011-10-11 12:10:02 EDT
Enhancement implemented. See IModelElement.copy( [IModelElement] ) method. Unit tests in TestModelingMisc0012. Please verify.

Usage examples (from 0.4 enhancements guide):

In this example, the copy method is used to duplicate the entities held in a list property.

ModelElementList<Entity> entities = model.getEntities();

for( int i = 0, n = entities.size; i < n; i++ )
{
    final Entity original = entities.get( i );
    final Entity duplicate = entities.addNewElement();
    duplicate.copy( original );
}

Here, an entire model is copied to a memory resource. Perhaps the original model instance was loaded from disk via an XML resource.

Model original = ...
Model duplicate = Model.TYPE.instantiate();
duplicate.copy( original );
Comment 2 Shenxue Zhou CLA 2011-11-28 13:56:05 EST
I've used IModelElement.copy() method. Closing.
Comment 3 Konstantin Komissarchik CLA 2011-11-28 14:31:23 EST
Since you are a committer, you can mark the bug as closed when verifying, without going through the verified status.