簡體   English   中英

SWT-繼承父對話框外殼?

[英]SWT - Inheriting parent dialog shell?

我真的需要了解父/子對話框的工作方式。

我的用戶使用稱為Teamcenter的OTB應用程序。 我正在編寫從Teamcenter應用程序中的菜單選擇中調用的附加應用程序。

當他們單擊菜單項時,將執行處理程序類並為我的應用程序創建基礎對話框。

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.我是否應該獲得工作區外殼,並在基本對話框中傳遞它? 但是即使打開我的應用程序,用戶仍然需要能夠使用Teamcenter應用程序選擇要發送到我的應用程序的數據

問題3.從基本對話框中打開對話框時,是否應該始終將基本對話框外殼傳遞給那些對話框?

問題4.在完成用戶操作后,是否應該使用標准方法關閉對話框?

您需要將父外殼傳遞給對話框,以便在關閉父外殼時,子外殼也將被關閉。

您應該將對話框設置為MODELESS(使用SWT.MODELSS作為樣式。注意:它是Hint),以便它不會阻塞您的父shell。

這是示例代碼:

 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;
    }

  }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM