Programmatically navigate and export Diagram to PNG file [message #1008623] |
Wed, 13 February 2013 10:54 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
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 16:03 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
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!
|
|
|
|
|
|
Re: Programmatically navigate and export Diagram to PNG file [message #1011087 is a reply to message #1008623] |
Mon, 18 February 2013 20:36 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Hi Gabriele,
if you loaded the resource you can iterate over its contents and filter for instances of Diagram. For each Diagram, you can use the DiagramRenderUtil to render an SWT Image.
Image image = DiagramRenderUtil.renderToSWTImage(diagram);
Then you can save the image to your file system.
Best regards,
Andreas
|
|
|
Re: Programmatically navigate and export Diagram to PNG file [message #1011346 is a reply to message #1011087] |
Tue, 19 February 2013 11:20 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
@Ralph Thank you, I'm reading that post.
@Andreas Thank you, but these are some exception I get running that code
LogFilter.isLoggable threw a non-fatal unchecked exception as follows:
java.lang.NullPointerException
at org.eclipse.core.internal.runtime.Log.isLoggable(Log.java:101)
at org.eclipse.equinox.log.internal.ExtendedLogReaderServiceFactory.safeIsLoggable(ExtendedLogReaderServiceFactory.java:59)
at org.eclipse.equinox.log.internal.ExtendedLogReaderServiceFactory.logPrivileged(ExtendedLogReaderServiceFactory.java:164)
at org.eclipse.equinox.log.internal.ExtendedLogReaderServiceFactory.log(ExtendedLogReaderServiceFactory.java:150)
at org.eclipse.equinox.log.internal.ExtendedLogServiceFactory.log(ExtendedLogServiceFactory.java:65)
at org.eclipse.equinox.log.internal.ExtendedLogServiceImpl.log(ExtendedLogServiceImpl.java:87)
at org.eclipse.equinox.log.internal.LoggerImpl.log(LoggerImpl.java:54)
at org.eclipse.core.internal.runtime.Log.log(Log.java:60)
at org.eclipse.ui.statushandlers.WorkbenchErrorHandler.handle(WorkbenchErrorHandler.java:80)
at org.eclipse.ui.internal.ide.IDEWorkbenchErrorHandler.handle(IDEWorkbenchErrorHandler.java:108)
at org.eclipse.ui.internal.WorkbenchErrorHandlerProxy.handle(WorkbenchErrorHandlerProxy.java:36)
at org.eclipse.ui.statushandlers.StatusManager.handle(StatusManager.java:189)
at org.eclipse.ui.statushandlers.StatusManager.handle(StatusManager.java:231)
at org.eclipse.ui.statushandlers.StatusManager.handle(StatusManager.java:242)
at org.eclipse.ui.application.WorkbenchAdvisor.eventLoopException(WorkbenchAdvisor.java:326)
at org.eclipse.ui.internal.ExceptionHandler.handleException(ExceptionHandler.java:65)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:829)
at org.eclipse.jface.window.Window.open(Window.java:801)
at org.eclipse.jface.dialogs.MessageDialog.open(MessageDialog.java:334)
at org.eclipse.jface.dialogs.MessageDialog.open(MessageDialog.java:364)
at org.eclipse.jface.dialogs.MessageDialog.openInformation(MessageDialog.java:446)
This openInformation is called inside my code.
It' strange because I've a big try-catch(Exception) around all my function, while this seems to not be catched.
Another fatal exception on renderToSWTImage
java.lang.NullPointerException
at org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker.initializeDiagramEventBroker(DiagramEventBroker.java:243)
at org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker.startListening(DiagramEventBroker.java:230)
at org.eclipse.gmf.runtime.diagram.ui.OffscreenEditPartFactory.createDiagramEditPart(OffscreenEditPartFactory.java:126)
at org.eclipse.gmf.runtime.diagram.ui.OffscreenEditPartFactory.createDiagramEditPart(OffscreenEditPartFactory.java:77)
at org.eclipse.gmf.runtime.diagram.ui.render.util.DiagramRenderUtil.renderToSWTImage(DiagramRenderUtil.java:79)
Thrown by renderToSWTImage; I pass a Diagram to this function, retrieved as resource.getContents().get(0) from correctly read ecorediag file.
Thank you!
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04884 seconds