|
WorkbenchWindowAdvisor?のサブクラスでpreWindowShellClose?を以下のようにOverrideする。 public boolean preWindowShellClose() {
// 複数上がってる場合はダイアログ出さないで閉じちゃう。
if (getWorkbench().getWorkbenchWindowCount() > 1) {
return true;
}
// the user has asked to close the last window, while will cause the
// workbench to close in due course - prompt the user for confirmation
IPreferenceStore store = ApplicationsPlugin.getDefault()
.getPreferenceStore();
// この設定値("EXIT_PROMPT_ON_CLOSE_LAST_WINDOW")をみて、ダイアログを出すかを決定する。
boolean promptOnExit = store
.getBoolean("EXIT_PROMPT_ON_CLOSE_LAST_WINDOW");
// storeの設定がtrueだったら
if (promptOnExit) {
String message;
String productName = null;
IProduct product = Platform.getProduct();
if (product != null) {
productName = product.getName();
}
if (productName == null) {
message = "Exit application?";
} else {
message = NLS.bind("Exit {0}?", productName);
}
MessageDialogWithToggle dlg = MessageDialogWithToggle
.openOkCancelConfirm(getWindowConfigurer().getWindow()
.getShell(), "終了の確認", message, "常にプロンプトなしで終了",
false, null, null);
if (dlg.getReturnCode() != IDialogConstants.OK_ID) {
return false;
}
if (dlg.getToggleState()) {
// チェックボックスを付けた(はずした?)とき、falseで保存する。
store.setValue("EXIT_PROMPT_ON_CLOSE_LAST_WINDOW", false);
ApplicationsPlugin.getDefault().savePluginPreferences();
}
}
return true;
}
上で、チェックボックスなしのダイアログを使う †上のやり方は、Eclipse3.1のIDEをパクリました。「常にプロンプトなしで終了」チェックボックスを出さないダイアログは以下でよいと思います。 return MessageDialog.openConfirm(getWindowConfigurer().getWindow() .getShell(), "終了の確認", message); ちなみに、http://www.eclipsecon.org/2005/tutorials.php によるとRCPのStartupからShutdownまでに呼ばれるメソッド*1は以下のようになっています。 この記事は 現在のアクセス:8185 |