[英]SWT - Opening / Disposing Shells - General Practice
I am looking for general practices for Disposing Shells. 我正在寻找处置壳的常规方法。
Main Application Menu Click Executes the following sequence 主应用程序菜单单击执行以下顺序
DialogHandler Class = (Executes My Application Base GUI Class) DialogHandler Class =(执行我的应用程序基础GUI类)
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
if (dlg == null){
try {
AbstractAIFApplication app = AIFDesktop.getActiveDesktop().getCurrentApplication();
session = (TCSession) app.getSession();
TCUserService userService = session.getUserService();
AplotVersion.negotiateVersion(userService);
AplotQueryCapabilities.initialize(userService);
shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell();
dlg = new AplotBaseDialog(shell, session);
}
catch (Exception ex) {
MessageBox.post(HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell(), ex, true);
}
}
dlg.open();
return null;
}// end execute()
Question. 题。 Being I am opening the Dialog in DialogHandler, do I have to dispose of it in that class?
当我在DialogHandler中打开Dialog时,是否必须在该类中处理它?
while(!shell.isDisposed()){
if(!display.readAndDispatch())
display.sleep();
}
display.dispose();
My GUI Base Class AplotBaseDialog = (Extends TitleAreaDialog) 我的GUI基类AplotBaseDialog =(扩展了TitleAreaDialog)
The constructor is receiving the Shell from DialogHandler Class. 构造函数正在从DialogHandler类接收Shell。
Question: Do I put the While(!shell.isDisposed()) code in this class? 问题:是否将While(!shell.isDisposed())代码放在此类中?
I am also opening a couple of dialogs from buttons in the AplotBaseDialog class. 我还将通过AplotBaseDialog类中的按钮打开几个对话框。
private void showPDFCreateDialog() {
pdfDialog = new AplotCreatePDFDialog(this, getShell(), session);
pdfDialog.open();
pdfDialog.getShell().setSize(700, 400);
}
Question: Do I have to include the dispose code in each of these dialog classes or does having a dispose() in the close button code good enough? 问题:我是否必须在每个对话框类中都包含dispose代码,或者在关闭按钮代码中包含dispose()足够好吗?
Question: Is this the proper way to create and open the dialog? 问题:这是创建和打开对话框的正确方法吗?
Question: Right now, I do not set the Display anywhere in my application code. 问题:现在,我没有在应用程序代码中的任何地方设置“显示”。
Display display = Display.getDefault();
I am just passing a Shell from the Parent Dialog to the Child Dialog and use asyncExec when needed. 我只是将Shell从父对话框传递给子对话框,并在需要时使用asyncExec。
Display.getDefault().asyncExec(new Runnable() {
public void run() {
}
}
Question: Do I need to have to have while(!shell.isDisposed()) somewhere in my application code? 问题:我是否需要在我的应用程序代码中的某处放置while(!shell.isDisposed())?
JFace Dialog
does the below functionality for you. JFace
Dialog
为您执行以下功能。 You dont need to do anything unless you want build your own dialog instead extending JFace Dialog
您无需执行任何操作,除非您想要构建自己的对话框而不是扩展JFace
Dialog
//this is for keep reading events from event table
while(!shell.isDisposed()){
if(!display.readAndDispatch())
display.sleep();
}
display.dispose();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.