如何在执行关闭应用程序之前执行IWindowCloseHandler以显示MessageDialog?如何在Eclipse(e4)RCP中实现IWindowCloseHandler?
这里是我的代码:
编辑
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;
}
}
}
伊斯梅尔
如果这是纯粹的e4应用程序,则不能使用PlatformUI。 –
好@格雷格-449,我现在可以更好地理解e4 RCP应用程序。所以,在我最近的编辑中,我使用'EModelService'和'MApplication'来查找我的应用程序的主窗口,并在'processAddictions()'中获得了我的窗口。 LifeCycle类位于'plugin.xml'中。现在,我只需要将窗口传递给'close'方法,但是我不能,我错过了什么去做最后一步? –
正如我已经说过的那样,将'IWindowCloseHandler'放在窗口上下文中,Eclipse将在需要时调用'close'方法。您必须等到应用程序启动事件触发才能将条目放入上下文中。我已更新答案以匹配您的代码 –