org.eclipse.graphiti.ui.features
Class DefaultSaveImageFeature

java.lang.Object
  extended by org.eclipse.graphiti.features.impl.AbstractFeature
      extended by org.eclipse.graphiti.features.impl.AbstractSaveImageFeature
          extended by org.eclipse.graphiti.ui.features.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 Summary
DefaultSaveImageFeature(IFeatureProvider fp)
          Creates a new DefaultSaveImageFeature.
 
Method Summary
protected  String addFileExtension(String extension, String filename)
          Adds the given file extension to the given filename.
protected  Map<String,Boolean> getDiagramExporters()
          Returns all available Graphiti diagram exporters that are registered at the according Graphiti extension point.
protected  String getFilename(GraphicalViewer viewer, ISaveAsImageConfiguration saveAsImageConfiguration)
          Must return the filename under which the image will be saved.
protected  GraphicalViewer getGraphicalViewer(ISaveImageContext context)
          Must return a GraphicalViewer that contains the diagram to be saved as an image.
protected  ISaveAsImageConfiguration getSaveAsImageConfiguration(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..
protected  IRunnableWithProgress getSaveAsImageOperation(ISaveAsImageConfiguration saveAsImageConfiguration, String filename)
          Called to create the operation that is actually used for executing the save as image functionality.
protected  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.
protected  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.
 void save(ISaveImageContext context)
          Performs the save as image operation.
 
Methods inherited from class org.eclipse.graphiti.features.impl.AbstractSaveImageFeature
canExecute, canSave, execute, getName, hasDoneChanges, postSave, preSave
 
Methods inherited from class org.eclipse.graphiti.features.impl.AbstractFeature
addGraphicalRepresentation, canUndo, getAllBusinessObjectsForPictogramElement, getBusinessObjectForPictogramElement, getDescription, getDiagram, getDiagramBehavior, getDiagramEditor, getFeatureProvider, getProgressCallback, getUserDecision, isAvailable, layoutPictogramElement, link, link, manageColor, manageColor, manageDefaultFont, manageFont, manageFont, setProgressCallback, toString, updatePictogramElement
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.eclipse.graphiti.features.ISaveImageFeature
canSave, postSave, preSave
 
Methods inherited from interface org.eclipse.graphiti.features.IFeature
canExecute, canUndo, execute, hasDoneChanges, isAvailable
 
Methods inherited from interface org.eclipse.graphiti.IName
getName
 
Methods inherited from interface org.eclipse.graphiti.IDescription
getDescription
 
Methods inherited from interface org.eclipse.graphiti.features.IFeatureProviderHolder
getFeatureProvider
 

Constructor Detail

DefaultSaveImageFeature

public DefaultSaveImageFeature(IFeatureProvider fp)
Creates a new DefaultSaveImageFeature.

Parameters:
fp - The feature provider providing this feature
Method Detail

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 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 AbstractFeature.getDiagramEditor().

Parameters:
context - Context information for saving.
Returns:
the viewer holding the diagram to save.

getSaveAsImageConfiguration

protected ISaveAsImageConfiguration getSaveAsImageConfiguration(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(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 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 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 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.


Copyright (c) SAP AG 2005, 2012.