繁体   English   中英

SelectionListener中的JFace关闭对话框

[英]JFace close dialog in SelectionListener

如何在SelectionListener关闭Dialog 目前,我的SelectionListener如下所示:

public void widgetSelected(SelectionEvent e) {
    ICommandService commandService = (ICommandService) PlatformUI.getWorkbench()
            .getService(ICommandService.class);
    IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench()
            .getService(IHandlerService.class);

    Command command = commandService
            .getCommand("com.mainfirst.backoffice.gui.accounting.command.createBookingReversal");

    Map<String, String> params = new HashMap<String, String>();
    params.put("com.mainfirst.backoffice.gui.accounting.reversalCodeParameter",
            String.valueOf(model.getVal().getCode()));

    ParameterizedCommand paraCommand = ParameterizedCommand.generateCommand(command, params);

    try {
        handlerService.executeCommand(paraCommand, null);
    } catch (Exception ex) {
        Status status = new Status(IStatus.ERROR, AccountingActivator.PLUGIN_ID,
                "Error opening reversal wizard", ex);
        StatusManager.getManager().handle(status, StatusManager.SHOW);
        throw new RuntimeException(ex);
    }
    close();
}

如您所见,我确实调用close(); ,但Dialog最后仍保持打开状态。 将呼叫移至finally块内也无济于事。 我的命令在Dialog前面打开一个新的Wizard Wizard打开之前,我是否必须关闭Dialog

如果希望对话框在命令运行完成之前关闭,则需要异步运行命令。 为此使用Display.asyncExec 使用类似:

public void widgetSelected(SelectionEvent e) {

    Display.getDefault().asyncExec(() ->
       {
          ... code to call command
       });

    close();
}

(假设Java 8,对于Java 7或更早版本使用Runnable )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM