java - SelectionListener 中的 JFace 关闭对话框

标签 java dialog swt jface wizard

如何关闭 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 block 内也无济于事。我的命令在 Dialog 前面打开一个新的 Wizard。我是否必须在向导打开之前关闭对话框

最佳答案

如果您希望对话框在其运行的命令完成之前关闭,您将需要异步运行该命令。为此,请使用 Display.asyncExec 。使用类似的东西:

public void widgetSelected(SelectionEvent e) {

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

    close();
}

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

关于java - SelectionListener 中的 JFace 关闭对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46112992/

相关文章:

java - 使用 Spring oAuth2.0 进行身份验证

Java错误?扫描仪无法直接读取GB2312文件

javascript - 如何在 jQuery Mobile 中显示对话框

c++ - 创建对话框时没有类或命名空间

java - TableViewer 的编辑支持字符串输入

java - C# 无法访问的代码(依赖于属性的数组复制器)

java - 如何重用 JavaFX GUI?我可以动态更改 Controller 吗?

android - Dialog 中 TextView 的可见性

java - 如何在 swt java 中创建一个定时器

java - SWT:复合图像;获取 IllegalArgumentException