【问题标题】:Code to disable RCP e4 application close button of the main window禁用主窗口的 RCP e4 应用程序关闭按钮的代码
【发布时间】:2012-10-05 06:56:23
【问题描述】:

有没有一种方法可以禁用主窗口的 RCP e4 应用程序关闭按钮。我尝试获取活动外壳并添加 event.doit = false 。但这行不通。即使我单击是或否,应用程序也会关闭。

【问题讨论】:

  • 它使用 IWindowCloseHandler 对象。必须创建它的一个实例并将其更新到上下文中。这样我们至少可以处理关闭事件

标签: eclipse-rcp rcp


【解决方案1】:

首先创建你的处理程序:

public class WindowCloseHandler implements IWindowCloseHandler{
        @Override
        public boolean close(MWindow window) {
//          System.out.println("in window close handler");
            Object shell = window.getWidget();
            return MessageDialog.openConfirm((Shell) shell, "Confirmation",
                    "Do you want to exit?");
        }
}

第二次将处理程序放在窗口上下文中:我在应用程序中任何部分的 post 构造方法中执行此操作: 公共类 SamplePart {

...

@PostConstruct 公共无效createComposite(复合父, MApplication应用程序, EModelService 服务 ) {

        ... setup the part ...

WindowCloseHandler close_handler = new WindowCloseHandler();
java.util.List<MTrimmedWindow> wins = 
        service.findElements(app, null, null, null);
for(Object win : wins){
    if(win instanceof MTrimmedWindow)
    ((MTrimmedWindow)win).getContext().set(IWindowCloseHandler.class, close_handler);
    else if(win instanceof MWindow)              ((MWindow)win).getContext().set(IWindowCloseHandler.class, close_handler);
}

}

【讨论】:

    猜你喜欢
    • 2015-05-29
    • 2021-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多