Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 370888

Summary: API Access to export and print
Product: [Modeling] Graphiti Reporter: Josef Pohl <josef.m.pohl>
Component: CoreAssignee: Michael Wenz <michael.wenz>
Status: VERIFIED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: graf, michael.wenz, peh, r.zozmann, rui.domingues
Version: 0.7.0Flags: michael.wenz: kepler+
Target Milestone: ---   
Hardware: All   
OS: All   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=352120
Whiteboard: Kepler M6 Theme_round_offs

Description Josef Pohl CLA 2012-02-07 16:33:30 EST
Build Identifier: Version: 3.7.1 Build id: 20110916-0149

This is to request an API extension in Graphiti to gain access to the printing and export diagram functionality.  

There is currently no public API to functionality such as Graphiti's PrintFigureDialog or any of the diagram export utilities built into the editor. 

The rationale behind this is to be able to generate printable product that is
1. based on scalable graphics (ie exported svg then to pdf or printer) 
2. can have a printable region 
   (e.g. print current view, print selected region)

There may be other use cases but these were apparent to me.


Reproducible: Didn't try
Comment 1 Michael Wenz CLA 2012-02-08 04:17:57 EST
The functionalitity should be available without the need to have an active diagram editor.
This request will due to capacity limitations unfortunatly not fit into the Juno timeframe, unless there are contributions in this area.
Comment 2 Ralf Zozmann CLA 2012-11-16 05:28:25 EST
We use a Eclipse based tool for our model based requirement and
development process. As part of that we create documentation for models
and diagrams in a generic way (supporting several DSL's and diagram
providers like GMF and Graphiti).
To do that we have the need to export a diagram content as image in a
programatic way from a plugin in Eclipse. This documentation generation
is also available in a headless Eclipse (without UI).

Vote +1
Comment 3 Andreas Graf CLA 2012-11-16 06:10:45 EST
I think this is a very useful feature that we would need as well.

Vote +1.
Comment 4 Michael Wenz CLA 2012-11-16 08:25:57 EST
Increased priority, let's see what we can do for Kepler
Comment 5 Rui Domingues CLA 2012-11-19 05:28:30 EST
+1. It's important for me too.
tks
Comment 6 Michael Wenz CLA 2012-11-29 10:38:14 EST
Marked for Kepler
Comment 7 Michael Wenz CLA 2012-12-07 10:25:37 EST
I started to work on this topic with the printing. The work is still in progress, nevertheless I would like to provide the current status and an outlook on what might be expected here:

I moved the IPrintFeature/DefaultPrintFeature/PrintContext to an API package so clients may use them. During that I also refactored some of the functionality so that clients can influence hopefully all aspects of the printing process. This is available already on my local machine and still needs some fine tuning in order to be checked in. But I hope to get that ready soon.

But at least currently it is only possible to use the printing functionality from within an open editor (or at least having one at hand), because what is being printed is defined with help of an open and initialized GraphicalViewer (GEF instance).

More technically: currently we need to use the graphical viewer from the editor to provide what diagram to print. To avoid the editor we need to somehow have another correctly initialized instance of it available; this might in the future e.g. be a graphical viewer hosted inside an Eclipse view (see enhancement request  
https://bugs.eclipse.org/bugs/show_bug.cgi?id=352120) or another viewer provided by clients. The new printing API would enable clients to provide such a viewer but that is not trivial.
Comment 8 Michael Wenz CLA 2012-12-20 11:28:50 EST
I pushed a first version of what I changed to Gerrit just to preserve it and maybe to get some checking if this goes into the right direction:
https://git.eclipse.org/r/#/c/9329/
Comment 9 Michael Wenz CLA 2013-02-08 10:36:41 EST
I have pushed the enhancement to Gerrit for review, please have a look if it fulfills the requirements:
https://git.eclipse.org/r/9329

It addresses the issue of the print and save as image features not being part of the API. They are now and may be overridden and changed by clients. However, they always need an open diagram to execute; this currently means an open diagram editor. In the future there might be better alternatives to get to an open diagram, see the current development happening for diagrams in views (https://bugs.eclipse.org/bugs/show_bug.cgi?id=352120).
One issue that we cannot address is that SWT is and will be needed for printing and exporting to a file. Our implementation and the underlying GEF heavily rely on SWT being active.
Comment 10 Michael Wenz CLA 2013-03-19 04:44:08 EDT
The change has been merged to master for Kepler M6
Comment 11 Michael Wenz CLA 2013-03-19 04:48:05 EDT
There is now a new API that allows clients to adapt the print and save as image functionality according to their needs. In combination with the new diagram in views possibilities clients can retrieve a GraphicalViewer not only from editors, but also from views and popups which allows for more flexibility in the usage of this feature.
A non-UI layer dependent usage of print and save as image is currently not possible as GEF itself is relying on the UI being present.