public void doSave(IProgressMonitor monitor) {
// we remove the selection in order to generate valid graph picture
getGraphicalViewer().deselectAll();
getGraphicalViewer().flush();
SWTGraphics g = null;
GC gc = null;
Image image = null;
LayerManager lm = (LayerManager) getGraphicalViewer().getEditPartRegistry().get(LayerManager.ID);
IFigure figure = lm.getLayer(LayerConstants.PRINTABLE_LAYERS);
try {
Rectangle r = figure.getBounds();
editor.getDefinition().setDimension(new Dimension(r.width, r.height));
image = new Image(Display.getDefault(), r.width, r.height);
gc = new GC(image);
g = new SWTGraphics(gc);
g.translate(r.x * -1, r.y * -1);
figure.paint(g);
ImageLoader imageLoader = new ImageLoader();
imageLoader.data = new ImageData[] { ImageHelper.downSample(image) };
imageLoader.save(getImageSavePath(), SWT.IMAGE_JPEG);
} catch (Exception e) {
DesignerLogger.logError(e);
} finally {
if (g != null) {
g.dispose();
}
if (gc != null) {
gc.dispose();
}
if (image != null) {