• Post Reply Bookmark Topic Watch Topic
  • New Topic

A question about closing a shell in SWT

 
Peng Fan
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, everyone!
I am writing a desktop application using SWT, but I got a seemingly-trival problem, that's I don't know how to prevent unintentional closing the application window by clicking the close box of the window. I want to fulfill such goal: when a user click on the close box of the window, a message box with a ok button and a cancel button on it will pop up to warn the the user, if the user click the ok, the application window will be closed , otherwise the window will remain opening. thx a lot!
 
J Arshad
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

One solution is to use JFace's ApplicationWindow & override ApplicationWindow.close() method. This method is called when the user closes the window. You can then do something like:

public boolean close() {

String title = "Confirm";
String message = "Are you sure you want to close this window?";

if (org.eclipse.jface.dialogs.MessageDialog.openQuestion(Display.getCurrent().getActiveShell(), title, message)) {
super.close();
}

Hope it helps!
 
Peng Fan
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi: J Arshad,thank you for your suggestion.
But, what a pity, actually I am currently write a web-based warehouse management system and most of it have been completed. If I adopted your solution, most my system's structure would be altered. I don't know whether you or any other guy could figure out a better solution! Thanks again for all your generous help!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!