{
// Open FileDialog
Shell shell = getSite().getShell();
final IEditorInput input = getEditorInput();
IDocumentProvider provider = getDocumentProvider();
final IEditorInput newInput;
FileDialog dialog = new FileDialog( shell, SWT.SAVE );
String path = dialog.open();
if ( path == null )
{
if ( progressMonitor != null )
{
progressMonitor.setCanceled( true );
}
return;
}
// Check whether file exists and if so, confirm overwrite
final File externalFile = new File( path );
if ( externalFile.exists() )
{
MessageDialog overwriteDialog = new MessageDialog( shell,
Messages.getString( "LdifEditor.Overwrite" ), null, Messages.getString( "OverwriteQuestion" ), //$NON-NLS-1$ //$NON-NLS-2$
MessageDialog.WARNING, new String[]
{ IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1 ); // 'No' is the default
if ( overwriteDialog.open() != Window.OK )
{
if ( progressMonitor != null )
{
progressMonitor.setCanceled( true );
return;
}
}
}
IPath iPath = new Path( path );
newInput = new PathEditorInput( iPath );
boolean success = false;
try
{
provider.aboutToChange( newInput );
provider.saveDocument( progressMonitor, newInput, provider.getDocument( input ), true );
success = true;
}
catch ( CoreException x )
{
final IStatus status = x.getStatus();
if ( status == null || status.getSeverity() != IStatus.CANCEL )
{
String title = Messages.getString( "LdifEditor.ErrorInSaveAs" ); //$NON-NLS-1$
String msg = Messages.getString( "LdifEditor.ErrorInSaveAs" ) + x.getMessage(); //$NON-NLS-1$
MessageDialog.openError( shell, title, msg );
}
}
finally
{
provider.changed( newInput );
if ( success )
{
setInput( newInput );
}
}