if (original != null)
dialog.setOriginalFile(original);
dialog.create();
IDocumentProvider provider = getDocumentProvider();
if (provider == null) {
// editor has programatically been closed while the dialog was open
return;
}
if (provider.isDeleted(input) && original != null) {
String message = "The original file, '" + original.getName() + "' has been deleted";
dialog.setErrorMessage(null);
dialog.setMessage(message, IMessageProvider.WARNING);
}
if (dialog.open() == Dialog.CANCEL) {
if (progressMonitor != null)
progressMonitor.setCanceled(true);
editor.setSaveAsStatus(MultiPageEditor.SAVE_AS_CANCELLED);
return;
}
IPath filePath = dialog.getResult();
if (filePath == null) {
if (progressMonitor != null)
progressMonitor.setCanceled(true);
editor.setSaveAsStatus(MultiPageEditor.SAVE_AS_CANCELLED);
return;
}
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IFile file = workspace.getRoot().getFile(filePath);
final IEditorInput newInput = new FileEditorInput(file);
WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
public void execute(final IProgressMonitor monitor) throws CoreException {
getDocumentProvider().saveDocument(monitor, newInput,
getDocumentProvider().getDocument(getEditorInput()), true);
}
};
boolean success = false;
try {
provider.aboutToChange(newInput);
new ProgressMonitorDialog(shell).run(false, true, op);
success = true;
} catch (InterruptedException x) {
} catch (InvocationTargetException x) {
Throwable targetException = x.getTargetException();
String title = "Error saving"; // TextEditorMessages.getString("Editor.error.save.title");
// //$NON-NLS-1$
String msg = "Error occurred during save operation"; // MessageFormat.format(TextEditorMessages.getString("Editor.error.save.message"),
// new Object[] {
// targetException.getMessage()});
// //$NON-NLS-1$
if (targetException instanceof CoreException) {
CoreException coreException = (CoreException) targetException;
IStatus status = coreException.getStatus();
if (status != null) {
switch (status.getSeverity()) {
case IStatus.INFO:
MessageDialog.openInformation(shell, title, msg);
break;
case IStatus.WARNING:
MessageDialog.openWarning(shell, title, msg);
break;
default:
MessageDialog.openError(shell, title, msg);
}
} else {
MessageDialog.openError(shell, title, msg);
}
}
} finally {
provider.changed(newInput);
if (success) {
setInput(newInput);
editor.setSaveAsStatus(MultiPageEditor.SAVE_AS_CONFIRMED);
} else {
editor.setSaveAsStatus(MultiPageEditor.SAVE_AS_CANCELLED);