How can I implement IWindowCloseHandler in order to display a MessageDialog before closing the application ?
Here is my code :
EDIT
public class LifeCycle {
@PostContextCreate
public void postContextCreate()
{
// TODO start up code here
System.out.println("open");
}
@ProcessAdditions
void processAdditions(MApplication app, EModelService modelService)
{
WindowCloseHandler closeHandler=new WindowCloseHandler();
MWindow window = (MWindow)modelService.find("uploadcenter.source.trimmedwindow.0", app);
window.getContext().set(IWindowCloseHandler.class, closeHandler);
}
private static class WindowCloseHandler implements IWindowCloseHandler{
@Override
public boolean close(MWindow window) {
// TODO Auto-generated method stub
Shell shell = new Shell();
if (MessageDialog.openConfirm(shell, "Confirmation",
"Do you want to exit?")) {
return true;
}
return false;
}
}
}
Ismail
A variation on @greg-449's answer using dependency injection and annotation. Register this class as an addon in your Application.e4xmi.
The
IWindowCloseHandler
must be registered in the Eclipse context (IEclipseContext
) for theMWindow
which you want to control.If you want to set this up in the
LifeCycle
class there is a bit of work to do because the life cycle methods are called too early in the application start up to be able to set the value in the context directly. It is necessary to wait for the app startup complete event: