aqubi+shin1

Recent site activity

ダイアログ表示

ダイアログを表示するタイミングのスレッド

ダイアログを表示したいタイミングがDisplayのスレッドでない場合(例えば、コンパイル処理中とか)、DisplayのThreadにて動作させてあげる必要がある。
それを考慮すると以下の感じ。
        Display display = DebugUIPlugin.getStandardDisplay();
        if (display.getThread().equals(Thread.currentThread())) {
            Shell shell = DebugUIPlugin.getShell();
            MessageDialog.openError(shell, "ERROR", message);
        } else {
            Runnable r = new Runnable() {
                public void run() {
                    Shell shell = DebugUIPlugin.getShell();
                   MessageDialog.openError(shell, "ERROR", message);
                }
            };
            DebugUIPlugin.getStandardDisplay().syncExec(r);
        }

ダイアログの種類

org.eclipse.jface.dialogs.MessageDialog

ダイアログはorg.eclipse.jface.dialogs.MessageDialogが使えます。
このクラスには
  • public static void openError(Shell parent, String title, String message)
  • public static void openInformation(Shell parent, String title, String message)
  • public static boolean openQuestion(Shell parent, String title, String message)
  • public static void openWarning(Shell parent, String title, String message)
以下のようなダイアログが表示できます。


org.eclipse.swt.widgets.MessageBoxの方を使うと、以下のような感じになります。
アイコンは、多分起動しているアプリのものになるのかな。

org.eclipse.jface.dialogs.ErrorDialog

エラーダイアログであればErrorDialogも使えます。ErrorDialogの場合はorg.eclipse.core.runtime.ILogでも使うorg.eclipse.core.runtime.IStatusを引数に取る事ができます。
  • public static int openError(Shell parent, String dialogTitle, String message, IStatus status)
  • public static int openError(Shell parentShell, String title, String message, IStatus status, int displayMask)