SelectionListener中的JFace关闭对话框

时间:2017-09-08 09:22:06

标签: java dialog swt jface wizard

如何关闭Dialog中的SelectionListener?目前我的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块内移动呼叫也无济于事。我的命令在Wizard前面打开一个新的Dialog。我可能需要在Dialog打开之前关闭Wizard吗?

1 个答案:

答案 0 :(得分:1)

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

public void widgetSelected(SelectionEvent e) {

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

    close();
}

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

相关问题