@Override
protected Object run( final Presentation context )
{
DiagramPresentation diagramPresentation = (DiagramPresentation)context;
SapphireDiagramEditor diagramEditor = diagramPresentation.getConfigurationManager().getDiagramEditor();
if( diagramEditor != null )
{
final FileDialog dialog = new FileDialog( diagramEditor.getSite().getShell(), SWT.SAVE );
final IEditorInput editorInput = diagramEditor.getPart().adapt( IEditorInput.class );
final StringBuilder initialFileName = new StringBuilder();
if( editorInput == null )
{
initialFileName.append( defaultFileName.text() );
}
else
{
if( editorInput instanceof IFileEditorInput )
{
dialog.setFilterPath( ( (IFileEditorInput) editorInput ).getFile().getParent().getLocation().toOSString() );
}
final String editorInputName = editorInput.getName();
final int editorInputLastDot = editorInputName.lastIndexOf( '.' );
if( editorInputLastDot == -1 )
{
initialFileName.append( editorInputName );
}
else
{
initialFileName.append( editorInputName.substring( 0, editorInputLastDot ) );
}
}
initialFileName.append( ".png" );
dialog.setFileName( initialFileName.toString() );
dialog.setFilterExtensions( new String[] { "*.png" } );
dialog.setText( saveAsImageMessage.text() );
dialog.setOverwrite( true );
String filePath = dialog.open();
if( filePath == null )
{
return null;
}
GraphicalViewer graphicalViewer = (GraphicalViewer) diagramEditor.getAdapter( GraphicalViewer.class );
ScalableFreeformRootEditPart rootEditPart
= (ScalableFreeformRootEditPart) graphicalViewer.getRootEditPart();
IFigure figure = rootEditPart.getLayer( LayerConstants.PRINTABLE_LAYERS );