{
public Object execute(ExecutionEvent event) throws ExecutionException
{
final Shell shell = HandlerUtil.getActiveShell(event);
final IEditorPart editorPart = HandlerUtil.getActiveEditor(event);
if (editorPart != null)
{
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();
}