Class DefaultSaveImageFeature

All Implemented Interfaces:
IFeature, IFeatureProviderHolder, ISaveImageFeature, IDescription, IName

public class DefaultSaveImageFeature extends AbstractSaveImageFeature implements ISaveImageFeature
The default feature implementation for saving a diagram as an image. This feature is used to trigger saving from inside an open and initialized DiagramEditor. It relies on an existing GraphicalViewer showing the diagram to save.
Since:
0.10 Has been moved from plug-in org.eclipse.graphiti package org.eclipse.graphiti.features
  • Constructor Details

  • Method Details

    • save

      public void save(ISaveImageContext context)
      Performs the save as image operation. The default implementation delegates to #getGraphicalViewer(IPrintContext) to retrieve the GraphicalViewer that already displays the diagram, queries for ISaveAsImageConfiguration to use by calling getSaveAsImageConfiguration(GraphicalViewer), queries for the filename by delegating to getFilename(GraphicalViewer, ISaveAsImageConfiguration) and finally uses getSaveAsImageOperation(ISaveAsImageConfiguration, String) to create an operation to perform the save as image operation. All those methods may be overridden to change the default behavior, so normally one would not need to override this method unless the complete sequence needs to changed or the save as image is performed in a completely different scenario.
      Specified by:
      save in interface ISaveImageFeature
      Parameters:
      context - Context information for saving as an image.
    • getGraphicalViewer

      protected org.eclipse.gef.GraphicalViewer getGraphicalViewer(ISaveImageContext context)
      Must return a GraphicalViewer that contains the diagram to be saved as an image. The default implementation returns the viewer of the DiagramEditor that started this save as image feature; this is the one associated to the feature provider of the currently opened diagram, see #getDiagramEditor().
      Parameters:
      context - Context information for saving.
      Returns:
      the viewer holding the diagram to save.
    • getSaveAsImageConfiguration

      protected ISaveAsImageConfiguration getSaveAsImageConfiguration(org.eclipse.gef.GraphicalViewer viewer)
      Called to create a configuration object for the save as image operation that defines what to save and in which format, zoom level etc.. The default implementation returns the standard Graphiti dialog used for save as image that allows the user to define the standard Graphiti settings.
      Parameters:
      viewer - The GraphicalViewer displaying the diagram to print
      Returns:
      A newly created dialog that implements the ISaveAsImageConfiguration interface used in the save as image job.
    • getFilename

      protected String getFilename(org.eclipse.gef.GraphicalViewer viewer, ISaveAsImageConfiguration saveAsImageConfiguration)
      Must return the filename under which the image will be saved. The filename can (and shall be) without an extension as this will be added by a separate (outside) call to addFileExtension(String, String). The default implementation brings up a standard Eclipse file selection dialog in save mode. The dialog is configured to select between the allowed extensions for images (standard one plus the ones the registered Graphiti image exporters allow).
      Parameters:
      viewer - The GraphicalViewer displaying the diagram to print
      saveAsImageDialog - The save as image configurations as defined by getSaveAsImageConfiguration(GraphicalViewer).
      Returns:
      A string containg the absolute path of the selected file, or null if the dialog was cancelled or an error occurred.
    • addFileExtension

      protected String addFileExtension(String extension, String filename)
      Adds the given file extension to the given filename.
      Parameters:
      extension - A string holding the extension.
      filename - A string holding the filename.
      Returns:
      A string holding the filename plus the extension.
    • getSaveAsImageOperation

      protected org.eclipse.jface.operation.IRunnableWithProgress getSaveAsImageOperation(ISaveAsImageConfiguration saveAsImageConfiguration, String filename)
      Called to create the operation that is actually used for executing the save as image functionality. The default implementation returns the Graphiti default save as image operation that should be sufficient for almost all use cases.

      This method delegates to getSaveAsImageOperationForStandardExporter(ISaveAsImageConfiguration, String) to perform the save as image for the standard formats like GIF, JPG, BMP etc. and to getSaveAsImageOperationForNonStandardExporter(ISaveAsImageConfiguration, String) for the non standard exporters (registered via the Graphiti export image extension point) like SVG.

      Parameters:
      saveAsImageConfiguration - The ISaveAsImageConfiguration instance that was used to configure this save as image operation. In the default implementation this is the dialog to use for selecting the image format, zoom level etc.
      filename - The filename to use for saving the image
      Returns:
      The operation that will be used to actually perform the save as image.
    • getSaveAsImageOperationForNonStandardExporter

      protected org.eclipse.jface.operation.IRunnableWithProgress getSaveAsImageOperationForNonStandardExporter(ISaveAsImageConfiguration saveAsImageConfiguration, String filename)
      Called to create the operation that is actually used for executing the save as image functionality for standard formats. The default implementation returns the Graphiti default save as image operation that should be sufficient for almost all use cases.
      Parameters:
      saveAsImageConfiguration - The ISaveAsImageConfiguration instance that was used to configure this save as image operation. In the default implementation this is the dialog to use for selecting the image format, zoom level etc.
      filename - The filename to use for saving the image
      Returns:
      The operation that will be used to actually perform the save as image.
    • getSaveAsImageOperationForStandardExporter

      protected org.eclipse.jface.operation.IRunnableWithProgress getSaveAsImageOperationForStandardExporter(ISaveAsImageConfiguration saveAsImageConfiguration, String filename)
      Called to create the operation that is actually used for executing the save as image functionality for non-standard formats. The default implementation returns the Graphiti default save as image operation that should be sufficient for almost all use cases.
      Parameters:
      saveAsImageConfiguration - The ISaveAsImageConfiguration instance that was used to configure this save as image operation. In the default implementation this is the dialog to use for selecting the image format, zoom level etc.
      filename - The filename to use for saving the image
      Returns:
      The operation that will be used to actually perform the save as image.
    • getDiagramExporters

      protected Map<String,Boolean> getDiagramExporters()
      Returns all available Graphiti diagram exporters that are registered at the according Graphiti extension point. Note that the standard exporters like GIF, JPG, BMP are not part of the returned ones.
      Returns:
      A Map holding all exporters.