Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » Copy Objects with ecoreutil.copy
Copy Objects with ecoreutil.copy [message #508971] Wed, 20 January 2010 18:05 Go to next message
Eclipse UserFriend
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] Wed, 20 January 2010 23:33 Go to previous messageGo to next message
Eclipse UserFriend
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 05:53 Go to previous messageGo to next message
Eclipse UserFriend
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 10:09 Go to previous message
Eclipse UserFriend
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 11:29] by Moderator

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


Current Time: Mon Jul 07 12:06:14 EDT 2025

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

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

Back to the top