Programmatically navigate and export Diagram to PNG file [message #1008623] |
Wed, 13 February 2013 05:54  |
Eclipse User |
|
|
|
Hi all,
I'm working with ecorediag file and I have files with more than one Diagram per file.
I need to export each diagram programmatically to PNG file (like manually doing "right button -> file -> save as image file..." per diagram).
First question.
How is it possible to access to each diagram in java?
A diagram's java class is "org.eclipse.gmf.runtime.notation.Diagram" but how can I obtain them from ecorediag file?
I've found EcoreDiagramEditor class, having a getDiagram() method but it returns only one Diagram.
If this is the correct method, how can I navigate to get the others?
I've tried getNavigationManager().next() to an EcoreDiagramEditor object after opening a IWokbenchPage, but it doesn't change diagram.
Second question.
Having a Diagram object, how can I export it to a PNG file?
Thank you!
|
|
|
|
|
|
Re: Programmatically navigate and export Diagram to PNG file [message #1009737 is a reply to message #1009704] |
Fri, 15 February 2013 11:03   |
Eclipse User |
|
|
|
I've ecorediag file having more than one diagram inside it, similar to
<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.2/notation">
<notation:Diagram xmi:id="_TnwF0HeGEeKGu7kx0XPfRQ" type="EcoreTools" name="first.ecorediag" measurementUnit="Pixel">
<children xmi:type="notation:Node" xmi:id="_ToOm8HeGEeKGu7kx0XPfRQ" type="1001">
...
<edges xmi:type="notation:Edge" xmi:id="_To-N0neGEeKGu7kx0XPfRQ" type="3002" source="_ToOm8HeGEeKGu7kx0XPfRQ" target="_TowLbneGEeKGu7kx0XPfRQ">
...
</edges>
</notation:Diagram>
<notation:Diagram xmi:id="_VuV-4HeGEeKGu7kx0XPfRQ" type="EcoreTools" name="test.ecorediag" measurementUnit="Pixel">
<children xmi:type="notation:Node" xmi:id="_WQXG0HeGEeKGu7kx0XPfRQ" type="1001">
...
</children>
<edges xmi:type="notation:Edge" xmi:id="_W85csHeGEeKGu7kx0XPfRQ" type="3003" source="_W8raQHeGEeKGu7kx0XPfRQ" target="_WQXG0HeGEeKGu7kx0XPfRQ">
..
</edges>
</notation:Diagram>
</xmi:XMI>
As you can see, there are two diagram "first.ecorediag" and "test.ecorediag", I can see them from Outline view of ecorediag editor.
I wish save them separately, so I need one of them at time to load and, after that, use CopyToImageDialog class.
I've tried IDE.openEditor(
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
new URIEditorInput(URI.createFileURI(ecoreDiagramFilepath),
EcoreDiagramEditor.ID);
with this code I can open ecorediag file showing "first.ecorediag" but I can't open "test.ecorediag" .
Another test I've done was about use NavigationManager, returned by EcoreDiagramEditor, to call its next() method, but after opening the editor on first.ecorediag, this method does anything.
I could call NavigationManager.set() but I need a Diagram object, that I don't know how I can obtain from ecorediag file.
EcoreDiagramOutlinePage, to loead other selected diagram, does ((EcoreDiagramEditor) getEditor()).setDiagram((Diagram) selectedObject);
Again I don't know how to obtain an object from ecorediag file.
Thank you!
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04365 seconds