How to duplicate a GMF diagram [message #1142247] |
Thu, 17 October 2013 09:43  |
Eclipse User |
|
|
|
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 #1149741 is a reply to message #1142247] |
Tue, 22 October 2013 05:17  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.07309 seconds