The IWindowCloseHandler
must be registered in the Eclipse context (IEclipseContext
) for the MWindow
which you want to control.
MWindow window = get the window
window.getContext().set(IWindowCloseHandler.class, handler);
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:
public class LifeCycle
{
@ProcessAdditions
public void processAdditions(IEventBroker eventBroker, MApplication app, EModelService modelService)
{
MWindow window =(MWindow)modelService.find("uploadcenter.source.trimmedwindow.0", app);
eventBroker.subscribe(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE,
new AppStartupCompleteEventHandler(window));
}
private static class AppStartupCompleteEventHandler implements EventHandler
{
private MWindow theWindow;
AppStartupCompleteEventHandler(MWindow window)
{
theWindow = window;
}
@Override
public void handleEvent(final Event event)
{
theWindow.getContext().set(IWindowCloseHandler.class, handler);
}
}
}