Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Copy Objects with ecoreutil.copy
Copy Objects with ecoreutil.copy [message #508971] Wed, 20 January 2010 23:05 Go to next message
Christian  is currently offline Christian Friend
Messages: 4
Registered: September 2009
Junior Member
Hey everyone.
I really need some help and hope you guys can point me into the right direction here.

I have a gmf editor with a model where an object A contains several other small objects.
Is it possible to write a copy tool which automatically copies the smaller objects contained in A into a new object B?

For example: I select A, press copy and a new object B appears with the same content as A.

I think I could use ecoreutil.copy but I am not exactly sure how to proceed now. (i.e. what to put in the java tool class)

Any help is greatly appreciated! Smile
Thanks!
Hi, Christian [message #508996 is a reply to message #508971] Thu, 21 January 2010 04:33 Go to previous messageGo to next message
SonglinPiao  is currently offline SonglinPiao Friend
Messages: 11
Registered: December 2009
Junior Member
In my way, I think there are two possible ways to implement that function.
Did you find that there is already copy function in the default gmf-generated program? You can extend this function , so that when you select one node and click copy then you can select all the sub nodes too. The other way is that you can add another context menu by yourself. For example , if we named it "copy all" , then what you just do is to implement in the source code.
By the I have question , how could you implement that you can put the subnodes inside a parent node ? Thanks !!
Re: Hi, Christian [message #509077 is a reply to message #508996] Thu, 21 January 2010 10:53 Go to previous messageGo to next message
Christian  is currently offline Christian Friend
Messages: 4
Registered: September 2009
Junior Member
Hey!
I hope this is what you mean:
First part: I specified an aggregation in the ecore model (A contains several B Objects)
Second part" Then in the gmfmap model you can specify Child references. So for example, you have a Top Node Rererence for A with a node mapping inside it. This Node Mapping has several Child References as children which define the nodes you can put inside a in the editor. (as "containment feature" you select the aggregation from your ecore model)

Im still working on implementing that copy thing. If anyone has a similar example or code that does something similar or maybe even uses ecoreutil.copy it would be nice if I could learn from it since I'm fairly new to all this. Thanks
Re: Copy Objects with ecoreutil.copy [message #509486 is a reply to message #508971] Fri, 22 January 2010 15:09 Go to previous message
Christian  is currently offline Christian Friend
Messages: 4
Registered: September 2009
Junior Member
Hi everyone, its me again.

I hope Im able to ask a more concrete question now:

So I tried to copy an element with this code (executed via popup menu extension point)

		EObject	selectedEObject = ((View) selectedElement.getModel()).getElement();
		EObject newEObject = EcoreUtil.copy(selectedEObject);

		IElementType type = ElementTypeRegistry.getInstance().getElementType(selectedEObject);	
		DiagramEditPart mapEditPart = (DiagramEditPart) selectedElement.getParent();
	
		
		CreateViewRequest.ViewDescriptor viewDescriptor1 = new CreateViewRequest.ViewDescriptor(
							new EObjectAdapter(newEObject),
							Node.class, 
							((IHintedType) type).getSemanticHint(), 
							mapEditPart.getDiagramPreferencesHint());


		CreateViewRequest createViewRequest = new CreateViewRequest(viewDescriptor1);


		Command cmd = mapEditPart.getCommand(createViewRequest);

		cc.add(cmd);



My Problem: The element appears in the diagram but is not part of the underlying emf model. Can anyone tell me how to make the new copy of that element part of the emf model as well? Because after saving and reopening it it's gone Sad

Thank you!

[Updated on: Fri, 22 January 2010 16:29]

Report message to a moderator

Previous Topic:[XPand/GMF] templates import statements
Next Topic:two kinds of models in GMF
Goto Forum:
  


Current Time: Thu Apr 22 12:25:14 GMT 2021

Powered by FUDForum. Page generated in 0.01369 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top