首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SWT -继承父对话框shell?

SWT -继承父对话框shell?
EN

Stack Overflow用户
提问于 2012-10-25 21:37:29
回答 1查看 3.5K关注 0票数 0

我真的需要了解父/子对话框是如何工作的。

我的用户使用一个名为Teamcenter的OTB应用程序。我正在编写一个附加应用程序,该应用程序可从Teamcenter应用程序的菜单选择中调用。

当他们单击菜单项时,将执行一个处理程序类,并为我的应用程序创建基本对话框。

代码语言:javascript
复制
public class AplotDialogHandler extends AbstractHandler {
  private static AplotBaseDialog dlg = null;

  public AplotDialogHandler() {

  }// end Constructor

  //////////////////////////////////////////////////////////////////////////
  //                            execute()                                 //
  //////////////////////////////////////////////////////////////////////////
  @Override 
  public Object execute(final ExecutionEvent event) throws ExecutionException {
     if (dlg == null) {
        try {
           AbstractAIFApplication app = AIFDesktop.getActiveDesktop().getCurrentApplication();
        TCSession session = (TCSession) app.getSession();
        TCUserService userService = session.getUserService();

        AplotVersion.negotiateVersion(userService);
        AplotQueryCapabilities.initialize(userService);

        dlg = new AplotBaseDialog(null, session);
     }
     catch (Exception ex) {
        MessageBox.post(HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell(), ex, true);
     }
  }

  dlg.create();
  dlg.getShell().setSize(700, 400);
  dlg.open();

  return null;
 }// end execute()
}// end EdiDialogHandler()

问题1.我的应用程序似乎没有绑定到Teamcenter应用程序。这意味着我可以关闭Teamcenter,而我的应用程序保持打开状态。

问题2.我是否应该获取工作区shell并在基本对话框中传递它?但是,即使我的应用程序处于打开状态,用户仍然需要能够使用Teamcenter应用程序来选择要发送到我的应用程序的数据

问题3.当从我的基础对话框打开对话框时,我是否应该总是将基础对话框shell传递给那些对话框?

问题4.当用户完成操作时,有没有一种标准的关闭对话框的方法?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-10-26 00:14:33

您需要将父shell传递给对话框,以便在关闭父Shell时,子shell也将关闭。

你应该使你的对话框无模式(使用SWT.MODELSS作为样式。注意:这是一个提示),这样它就不会阻止您的父shell。

以下是示例代码:

代码语言:javascript
复制
 public static void main(String[] args) {

    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new GridLayout(1, false));
    shell.setSize(200, 200);
    Button b = new Button(shell, SWT.NONE);
    b.setText("Click");
    b.addSelectionListener(new SelectionListener() {

      @Override
      public void widgetSelected(SelectionEvent e) {


         CDialog dialog = new CDialog(shell);

         dialog.open();
      }

      @Override
      public void widgetDefaultSelected(SelectionEvent e) {

        // TODO Auto-generated method stub

      }
    });

    shell.open();



    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }
    display.dispose();
  }  


  private static class CDialog extends Dialog
  {

    /**
     * @param parentShell
     */
    protected CDialog(Shell parentShell) {

      super(parentShell);
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
     */
    @Override
    protected Control createDialogArea(Composite parent) {

      Composite comp =  (Composite) super.createDialogArea(parent);

      Label lbl = new Label(comp, SWT.NONE);
      lbl.setText("Test modeless dialog");

      return comp;
    }
    /* (non-Javadoc)
     * @see org.eclipse.jface.window.Window#getShellStyle()
     */
    @Override
    protected int getShellStyle() {
      return SWT.DIALOG_TRIM|SWT.MODELESS;
    }

  }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13069865

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档