1

I would like to create an image of an Eclipse GEF diagram on the server side without having to load the entire editor environment.

The diagram is designed using eclipse bpmn2-modeler which is based on eclipse graphiti which is based on GEF.

The idea would be:

  1. load BPMN model
  2. generate diagram information
  3. export diagram as image

This snippet should do step 1, load the BPMN model:

    URI modelUri = URI.createFileURI("D:/temp/data.bpmn");
    ResourceSet resourceSet = new Bpmn2ModelerResourceSetImpl();
    resourceSet.setURIConverter(new ProxyURIConverterImplExtension(modelUri));
    Bpmn2ResourceImpl resource = (Bpmn2ResourceImpl) resourceSet.createResource(modelUri, Bpmn2ModelerResourceImpl.BPMN2_CONTENT_TYPE_ID);
    ModelHandler modelHandler = ModelHandlerLocator.createModelHandler(modelUri, resource);
  1. to generate the diagram information I found org.eclipse.bpmn2.modeler.core.di.DIImport.
    The problem here is that the constructor requires a org.eclipse.graphiti.ui.editor.DiagramEditor and on the server I don't have one, no running UI environment.
    Is there some other util or handler that can generate the diagram for me?

  2. I took a look at the org.eclipse.graphiti.ui.features.DefaultSaveImageFeature and org.eclipse.graphiti.ui.internal.util.ui.print.AbstractFigureSelectionDialog (initScaledImage()).
    But I need to first get passed the step 2 issue, before digging deeper into this.

Maybe I'm on the wrong way and there is a much easier approach?

flavio.donze
  • 7,432
  • 9
  • 58
  • 91

2 Answers2

1

You can have a look at how GMF generates diagram image without the editor. However that generation is still UI dependent because you'd be needing SWT and the Display thread (you can start the Display thread in headless Eclipse mode).

The idea is to use EditPart factory to create editparts for model elements and then paint the root figure on the Canvas hosted by the Shell created offscreen. The graphics context of the GC is SWT image. There are ways to generate the image of the diagram without using Eclipse UI based on AWT or generate the SVG. However, keep it in mind that layout of the figures is SWT dependent when it comes to text labels, so you'd need SWT and the Display thread either way. Colors, fonts and other attributes of figures are SWT objects too.

The class in GMF to look at would be org.eclipse.gmf.runtime.diagram.ui.OffscreenEditPartFactory

aboyko
  • 1,337
  • 1
  • 9
  • 11
  • Yes I figured that I need to create the editparts but I hoped to find a factory in graphiti that does it for me (since not using GMF). I created a topic in the eclipse forum https://www.eclipse.org/forums/index.php/t/965255/. – flavio.donze Jan 26 '15 at 15:08
1

Graphiti recently received an enhancement which allows you to export the diagram w/o bringing up the editor. You'd still need the eclipse UI environment though. I have an example here that uses the helper method listed below.

org.eclipse.graphiti.ui.internal.services.impl.ImageService.convertDiagramToBytes(Diagram, int)
untitled
  • 11
  • 1