Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » How to duplicate a GMF diagram (Duplicate a GMF diagram preserving the source layout)
How to duplicate a GMF diagram [message #1142247] Thu, 17 October 2013 13:43 Go to next message
Philippe EUGENE is currently offline Philippe EUGENE
Messages: 26
Registered: January 2011
Junior Member
Hello,

I have an EMF/GMF application.
One feature is: Duplicate a model and it's associated diagram.

Well, it's work fine simply using the code in the DiagramEditorUtil.
public static Resource createDiagram(final MyModel model, URI diagramURI,
URI modelURI, IProgressMonitor progressMonitor)

The newly created diagram use a default layout to display node and connector.

My need is to preserve the original layout of the GMF diagram.
There is lot of auto-generated xmi:id in the GMF model.
All this id are used by connector to set source and target.

Then, i'm a little confused. What is the best way to duplicate a GMF diagram and preserve the original layout ?


Thanks,
--
Philippe
Re: How to duplicate a GMF diagram [message #1143724 is a reply to message #1142247] Fri, 18 October 2013 11:35 Go to previous messageGo to next message
Christian Smietana is currently offline Christian Smietana
Messages: 11
Registered: February 2011
Junior Member
Recently I've come across this class in the api doc (btw., where can I find a reliable version of the GMF API doc e.g. for eclipse 3.7 ? This IBM stuff is the only version of the API doc I've ever found anywhere)

http://publib.boulder.ibm.com/infocenter/rsmhelp/v7r0m0/topic/org.eclipse.gmf.doc/reference/api/runtime/org/eclipse/gmf/runtime/diagram/core/util/ViewRefactorHelper.html

I don't know whether it's what you want, at least it seems to target a similar problem.

Regards
Christian

[Updated on: Fri, 18 October 2013 11:35]

Report message to a moderator

Re: How to duplicate a GMF diagram [message #1149741 is a reply to message #1142247] Tue, 22 October 2013 09:17 Go to previous message
Philippe EUGENE is currently offline Philippe EUGENE
Messages: 26
Registered: January 2011
Junior Member
Hello Christian,
Thanks for the link.
I used an other method to do this. Simply using String replacement, not very nice, but it's work for my need.

/** create the resource Diagram **/
Resource diagram = xxxDiagramEditorUtil.createDiagram(target, diagramURI, modelURI,
new NullProgressMonitor());

/** load the resource of the diagram to duplicate **/
Resource sourceDiagram = // here load the resource;

/** serialize the resource in a String and make the string replacement **/
...
OutputStream outputStream = new ByteArrayOutputStream();
try {
  sourceDiagram.save(outputStream, null);
  String xml = outputStream.toString();
  xml = xml.replaceAll(".myExtension#" + source.getID(),".myExtension#" +   target.getID());
  xml = xml.replaceAll(source.getName(), target.getName());

... 
save the new diagram resource



Previous Topic:create diagram from .ecore file by GMF
Next Topic:type of created diagram in GMF run-time
Goto Forum:
  


Current Time: Fri Oct 31 21:35:23 GMT 2014

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

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