protected void configureEditPartViewer(EditPartViewer viewer) {
    ScalableFreeformRootEditPart rootEditPart = new ScalableFreeformRootEditPart();
    viewer.setRootEditPart(rootEditPart);
    getGraphicalViewer()
        .setContextMenu(
            new ProcessContextMenuProvider(
                getParentEditor().getActionRegistry(), getGraphicalViewer()));

    ((FigureCanvas) viewer.getControl()).setScrollBarVisibility(FigureCanvas.ALWAYS);
  }
  /**
   * Returns the bytes of an encoded image for the specified IFigure in the specified format.
   *
   * @param figure the Figure to create an image for.
   * @param format one of SWT.IMAGE_BMP, SWT.IMAGE_BMP_RLE, SWT.IMAGE_GIF SWT.IMAGE_ICO,
   *     SWT.IMAGE_JPEG, or SWT.IMAGE_PNG
   * @return the bytes of an encoded image for the specified Figure
   */
  private byte[] createImage(final IFigure figure, final int format) {

    final Device device = viewer.getControl().getDisplay();

    final Rectangle r = figure.getBounds();

    final ByteArrayOutputStream result = new ByteArrayOutputStream();

    Image image = null;
    GC gc = null;
    Graphics g = null;
    try {
      image = new Image(device, r.width, r.height);
      gc = new GC(image);
      g = new SWTGraphics(gc);
      g.translate(r.x * -1, r.y * -1);

      figure.paint(g);

      final ImageLoader imageLoader = new ImageLoader();
      imageLoader.data = new ImageData[] {image.getImageData()};
      imageLoader.save(result, format);

    } catch (Exception e) {
      // the image size may not exceed 16M, svg requires less space for graphs than png and jpeg
      e.printStackTrace();
    } finally {
      if (g != null) {
        g.dispose();
      }
      if (gc != null) {
        gc.dispose();
      }
      if (image != null) {
        image.dispose();
      }
    }
    return result.toByteArray();
  }