【问题标题】:JFace close dialog in SelectionListenerSelectionListener 中的 JFace 关闭对话框
【发布时间】:2018-02-17 04:11:07
【问题描述】:

如何关闭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

【问题讨论】:

  • @greg-449 编辑了问题。 here是我的第二个问题
  • 该命令有什么作用?您是否希望对话框在命令结束之前关闭(它不会)?
  • 该命令调用处理程序,而该处理程序又只打开向导。我确实希望单击按钮后对话框会立即关闭,但仍应执行该命令

标签: java dialog swt jface wizard


【解决方案1】:

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

public void widgetSelected(SelectionEvent e) {

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

    close();
}

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多