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