Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Prompting before closing Stopped working(Something weird in the Shell closing listener)
Prompting before closing Stopped working [message #1017116] Sat, 09 March 2013 13:47 Go to next message
AppleJus Mising name is currently offline AppleJus Mising name
Messages: 46
Registered: July 2010
Member
Hi there,

Thank you for your kind help. I am experiencing a small and bizarre issue regarding prompting a user if he wants to close a shell or not, before it actually closes.

I am using a shell "SWT.Close" listener, in which I am using a "MessageDialog.openQuestion()" function with an if condition and a "event.doit = true"
if the user choose "YES" and a "event.doit = false" otherwise...
This code should prompt the user to choose whether to close the shell or not upon pressing the X button of the shell. What is happening now is that the shell is closing BEFORE the dialog shows... Regardless of the answer chosen the shell has already closed...

The same code used to work in much earlier versions of eclipse as I remember. Now I am using Eclipse 4.2 Juno (Version: 4.2.0 - Build id: I20120608-1400)

I tried to look how to solve this on my own, but I really ran out of ideas.
Can anyone help?

Thank you!
Re: Prompting before closing Stopped working [message #1017211 is a reply to message #1017116] Mon, 11 March 2013 07:41 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk Fauth
Messages: 1354
Registered: July 2012
Senior Member
Hi,

well if it worked in a earlier version of Eclipse, which version do you mean? Already Eclipse 4 or Eclipse 3?

The next question is, when do you attach the Shell close listener? And moreover, are you attaching it to a Shell you created additionally to your main window or is it a close listener that should listen to closing your Eclipse application?

If you are trying to attach a listener that listens for closing your main window and therefore the whole application, you need to attach it in another way as in Eclipse 3 because of the creation time of your window. Maybe this thread is helpful then: http://www.eclipse.org/forums/index.php/t/452376/

Greez,
Dirk
Re: Prompting before closing Stopped working [message #1017257 is a reply to message #1017211] Mon, 11 March 2013 10:50 Go to previous messageGo to next message
AppleJus Mising name is currently offline AppleJus Mising name
Messages: 46
Registered: July 2010
Member
Thank you for your help and link. Actually it turns out that this issue does not happen on Eclipse 4.1 (Version: 4.1.0
Build id: I20110501-0200). I am trying indeed to close the main Shell (the application), and I fiddled around placing the code in
different places and after different constructs and listeners and the problem remains. Either I have not explored all possibilities of placing
the code, or the problem really lies in Eclipse 4.2 (and possibly higher versions?)

Since prompting the user about something before closing the shell is a pretty common feature, I think this issue should be fixed... if only I knew how!

Thanks
Re: Prompting before closing Stopped working [message #1017259 is a reply to message #1017257] Mon, 11 March 2013 11:02 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk Fauth
Messages: 1354
Registered: July 2012
Senior Member
Looking here you will find an example on how to add the needed listener via command:
http://www.vogella.com/articles/EclipseRCP/article.html#context_who

I adapted that code so it is executed when the main view of my application is created. So I don't need to execute a special command.

The link I posted above points out that with 4.3 there will be a new event that is fired after application startup. UIEvents.UILifecycle.APP_STARTUP_COMPLETE
This allows to create a listener that listens for the application startup (e.g. in the lifecycle hook) that will append the IWindowCloseListener AFTER startup.
Note that adding the listener IN the lifecycle hook will not work as the UI components are not created at that point of time.

Using 4.2 you will need some workaround like the approach I'm using with the code in the main part, or the approach Lars Vogel shows in his tutorial.

Hope that helps,
Dirk
Re: Prompting before closing Stopped working [message #1017360 is a reply to message #1017259] Mon, 11 March 2013 16:57 Go to previous message
AppleJus Mising name is currently offline AppleJus Mising name
Messages: 46
Registered: July 2010
Member
Thanks Dirk, this seems well like the proper way of doing things!
Previous Topic:Injection and SWT
Next Topic:Strange behaviour with contributed Handler
Goto Forum:
  


Current Time: Fri Oct 31 20:09:15 GMT 2014

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

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