{
IEditorInput editorInput = editorPart.getEditorInput();
if (!(editorInput instanceof IFileEditorInput))
{
throw new ExecutionException("Editor input must be a file");
}
IFileEditorInput fileInput = (IFileEditorInput) editorInput;
try
{
// Save the editor content (if dirty)
IRunnableWithProgress saveOperation = new IRunnableWithProgress()
{
public void run(IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException
{
if (editorPart.isDirty())
{
if (MessageDialog.openQuestion(
shell,
"Save File",
"The file contents must be saved before the command can be executed. Do you wish to save now?"))
{
editorPart.doSave(monitor);
}
else
{
throw new InterruptedException();
}
}
}
};
new ProgressMonitorDialog(shell).run(false, true, saveOperation);
// Execute on the file
IFile file = fileInput.getFile();
getResourceCommandHandler().execute(new IResource[] { file }, event);
}
catch (InvocationTargetException e)
{
throw new ExecutionException("Error saving file", e.getTargetException());
}
catch (InterruptedException e)
{
// Exit the command silently
}