Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » JFace App - how to handle close event?
JFace App - how to handle close event? [message #449464] Tue, 25 January 2005 00:43 Go to next message
Bill Ewing is currently offline Bill EwingFriend
Messages: 49
Registered: July 2009
Member
The following snippet shows how to have a message box query the user
before exiting an SWT app. It allows the user to decide whether to exit
or not. It is quite straightforward.

http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet99.java?rev=HEAD&a mp;content-type=text/vnd.viewcvs-markup

But, has anyone ever done this in a JFace app?

We have tried many ways and failed. It seems like JFace was so intent on
hiding details in the name of abstraction and elegance that we now cannot
access those details.

Our next step would be to download the source and seriously hack
ApplicationWindow to get this to work.

All comments and suggestions appreciated!
Re: JFace App - how to handle close event? [message #449469 is a reply to message #449464] Tue, 25 January 2005 06:00 Go to previous message
Konstantin Scheglov is currently offline Konstantin ScheglovFriend
Messages: 555
Registered: July 2009
Senior Member
Bill Ewing:

In short: Window.canHandleShellCloseEvent()
See full example below.
Do you still want to handle shell events in Designer? ;-)


import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.StatusLineManager;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
/**
* @author scheglov_ke
*/
public class ConfirmCloseTest extends ApplicationWindow {
public ConfirmCloseTest() {
super(null);
createActions();
addToolBar(SWT.FLAT | SWT.WRAP);
addMenuBar();
addStatusLine();
}
protected Control createContents(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
container.setLayout(new GridLayout());
return container;
}
private void createActions() {
}
protected MenuManager createMenuManager() {
MenuManager result = new MenuManager("menu");
return result;
}
protected ToolBarManager createToolBarManager(int style) {
ToolBarManager toolBarManager = new ToolBarManager(style);
return toolBarManager;
}
protected StatusLineManager createStatusLineManager() {
StatusLineManager statusLineManager = new StatusLineManager();
statusLineManager.setMessage(null, "");
return statusLineManager;
}
public static void main(String args[]) {
try {
ConfirmCloseTest window = new ConfirmCloseTest();
window.setBlockOnOpen(true);
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
newShell.setText("New Application");
}
protected Point getInitialSize() {
return new Point(425, 350);
}
protected boolean canHandleShellCloseEvent() {
if (!MessageDialog.openQuestion(getShell(), "Confirm", "Do you really
want close window?")) {
return false;
}
return super.canHandleShellCloseEvent();
}
}



> The following snippet shows how to have a message box query the user
> before exiting an SWT app. It allows the user to decide whether to exit
> or not. It is quite straightforward.
>
> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet99.java?rev=HEAD&a mp;content-type=text/vnd.viewcvs-markup
>
>
> But, has anyone ever done this in a JFace app?
>
> We have tried many ways and failed. It seems like JFace was so intent
> on hiding details in the name of abstraction and elegance that we now
> cannot access those details.
> Our next step would be to download the source and seriously hack
> ApplicationWindow to get this to work.
> All comments and suggestions appreciated!
>
>


--
SY, Konstantin.
Advanced Eclipse SWT Designer (http://www.swt-designer.com)


Konstantin Scheglov,
Google, Inc.
Previous Topic:CoolItem Unable to take entire space horizontally
Next Topic:Table Columns with mutiple lines of data
Goto Forum:
  


Current Time: Fri Mar 29 07:12:18 GMT 2024

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

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

Back to the top