2

私は Eclipse プラグインを作成しています。何らかのアクションに応答して、(別のジョブ内で) 一連の操作を開始することに興味があります。これらの操作の 1 つは、ユーザーにファイル名を提供するように要求することです。これは、JFace JDialog で実行しようとしています。

ただし、モードレスな方法でこれを行う方法は明確ではありません。たとえば、ディスプレイとシェルはどこで入手できますか? 開発者がダイアログで内容を編集できる間、UI が引き続き動作するようにするにはどうすればよいですか?

4

2 に答える 2

4

Eclipse自体がどのようにそれを行うかを見ることができるかもしれません:

FindAndReplaceDialog.java

 /**
  * Creates a new dialog with the given shell as parent.
  * @param parentShell the parent shell
  */
 public FindReplaceDialog(Shell parentShell) {
     super(parentShell);

     fParentShell= null;

     [...]

     readConfiguration();

     setShellStyle(SWT.CLOSE | SWT.MODELESS | SWT.BORDER | SWT.TITLE | SWT.RESIZE);
     setBlockOnOpen(false);
 }

 /**
  * Returns this dialog's parent shell.
  * @return the dialog's parent shell
  */
 public Shell getParentShell() {
     return super.getParentShell();
 }

/**
 * Sets the parent shell of this dialog to be the given shell.
 *
 * @param shell the new parent shell
 */
public void setParentShell(Shell shell) {
    if (shell != fParentShell) {

        if (fParentShell != null)
            fParentShell.removeShellListener(fActivationListener);

        fParentShell= shell;
        fParentShell.addShellListener(fActivationListener);
    }

    fActiveShell= shell;
}

ダイアログのフォーカスに応じて、親シェルを管理します。

 /**
  * Updates the find replace dialog on activation changes.
  */
 class ActivationListener extends ShellAdapter {
     /*
      * @see ShellListener#shellActivated(ShellEvent)
      */
     public void shellActivated(ShellEvent e) {
         fActiveShell= (Shell)e.widget;
         updateButtonState();

         if (fGiveFocusToFindField && getShell() == fActiveShell && 
               okToUse(fFindField))
             fFindField.setFocus();

     }

     /*
      * @see ShellListener#shellDeactivated(ShellEvent)
      */
     public void shellDeactivated(ShellEvent e) {
         fGiveFocusToFindField= false;

         storeSettings();

         [...]

         fActiveShell= null;
         updateButtonState();
     }
 }

は、の状態の変化を処理するメソッドを提供するインターフェイスShellAdapterによって記述されたメソッドのデフォルトの実装を提供します。ShellListenerShell

于 2009-03-06T06:39:50.387 に答える
0

重要なことは、スタイル値に SWT.MODELESS を含める必要があることです。

スタイルは、SWT で注目すべき最も重要な要素の 1 つです。スタイルの値によってのみ多くの制御と初期化を行うことができるからです。

于 2009-03-06T06:55:51.173 に答える