Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Prompting User for Unsaved data(ISaveablePart2?)
Prompting User for Unsaved data [message #1015265] Wed, 27 February 2013 22:53 Go to next message
Ronald So is currently offline Ronald SoFriend
Messages: 198
Registered: April 2011
Senior Member
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 #1015461 is a reply to message #1015265] Thu, 28 February 2013 16:09 Go to previous messageGo to next message
Ronald So is currently offline Ronald SoFriend
Messages: 198
Registered: April 2011
Senior Member
A small update. I have attached a IPartListener to my view, and call "getSite().getPage().saveAllEditors(true);" during "partDeactivated" seems to do the trick to call "promptToSaveOnClose()" method. However, I got a "Prevented recursive attempt to activate part <part_name_1> while still in the middle of activating part <part_name_2>.

Also, I still can't find a way to stop user from navigating to a different view/perspective if he/she chooses to "stay" in the view. For instance, if user enters some data and accidentally click on a different view, "promptToSaveOnClose()" gets called and asks if user wants to proceed to where he/she wants to go. User says no and wants to stay in the same view. How should I stop the workbench to activate the new view and keep the user to stay in the current view?

Thanks a lot,
Ronald
Re: Prompting User for Unsaved data [message #1015674 is a reply to message #1015461] Fri, 01 March 2013 16:24 Go to previous message
Ronald So is currently offline Ronald SoFriend
Messages: 198
Registered: April 2011
Senior Member
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
Previous Topic:How import a GEF based editor into a my webApp with RAP?
Next Topic:How to have single sourcing ?
Goto Forum:
  


Current Time: Fri Apr 19 01:39:27 GMT 2024

Powered by FUDForum. Page generated in 0.01663 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top