Fortunately eclipse can provides an easy solution. Your editor just has to implement the ISaveablePart2 interface. This interface requires the implementation of a single method promptToSaveOnClose. This method is only called when the part is closed or when the RCP application is shutting down. The implementation of this method now just needs to show a custom dialog and the user can decide what to do with unsaved data. Easy, isn’t it? Let’s have look at a short example.
Assume that you have an editor there the isDirty method returns true (so eclipse would show the save-message).
In the diagram you can see the short application flow. First a message is shown and the user can decide what to do. If the user selects NO, NO is also the result of the promptToSaveOnClose. If NO is returned nothing is saved and the editor is closed. On CANCEL nothing should happen and just CANCEL is returned. On YES the content of the editor is validated. If the validation fails CANCEL is returned, otherwise the result is YES.
This method can also return DEFAULT. In that case the standard eclipse dialog is shown.That’s all if the user wants to close the editor and save the content this is only allowed if editor content as valid.