Prompting User for Unsaved data [message #1015265] |
Wed, 27 February 2013 17:53  |
Eclipse User |
|
|
|
I have a view that contains a lot of text fields. To prevent users from losing unsaved data when user navigates away from the current view, I need a mechanism to prompt the user if he/she really wants to navigate away from the current view. If user answers yes, unsaved data will be purged. Otherwise, user stays in the same view.
I know a ViewPart can implement ISaveablePart2 interface to set the "dirty" bit. I have no problem getting the asterisk next to my view name by firing a property change called PROP_DIRTY when I programmatically set the dirty bit to true when user starts entering data. However, I can't get the framework to call "promptToSaveOnClose()" method even when isDirty() returns true. Can anyone shed some light on that?
In addition, if I have the aforementioned problem solved, how can I get the behavior I am looking for? Consider this scenario. When user is editing in the current view, he/she clicks to a different perspective. A warning message is shown "You have unsaved data. Are you sure you want to leave this page?". User clicks Yes, a new view is shown and data is discarded. What if user clicks No and want to stay in the same view? How do I accomplish that?
Thanks,
Ronald
|
|
|
|
Re: Prompting User for Unsaved data [message #1015674 is a reply to message #1015461] |
Fri, 01 March 2013 11:24  |
Eclipse User |
|
|
|
Another update. I add some logic and tag along with what ISaveablePart2 interface gave me and I am able to achieve the desired behavior. It does not come clean without a Java exception as mentioned in my last comment. I called:
getSite.getPage().saveAllEditors(true);
in order to change the "confirm" flag of WorkbenchPage to true but it causes:
"Prevented recursive attempt to activate part <part_name_1> while still in the middle of activating part <part_name_2>."
I looked closer to the IWorkbenchPart API and realized that there is a call to save just one EditorPart:
getSite().getPage().saveEditor(IEditorPart part, boolean confirm)
How do I get a handle of the "IEditorPart"? My view extends ViewPart that implements ISaveablePart2. ViewPart extends WorkbenchPart that implements IViewPart, which IViewPart extends IWorkbenchPart. IWorkbenchPart is a superinterface of IEditorPart. I can't seem to see a way to get a handle of the IEditorPart from my ViewPart.
Any suggestions / hints are welcome. I just don't like to see that stack trace even though I got my desired behavior.
Thanks a lot,
Ronald
|
|
|
Powered by
FUDForum. Page generated in 0.05045 seconds