[英]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.