如何在RCP应用程序中单击时使MessageDialog的自定义按钮不关闭对话框?

时间:2012-03-28 15:13:18

标签: java eclipse-rcp jface

我有一个RCP应用程序,其中up​​en delete,MessageDialog用于确认删除操作。您可以在下面的代码中看到的其中一个按钮是“预览”按钮,如果单击该按钮,将弹出另一个对话框以显示有关预期操作结果的更多信息。这个“预览”按钮默认以某种方式关闭我的主MessageDialog。我该怎么办才能使它不关闭主对话框?

MessageDialog dialog =
         new MessageDialog(null, "Dangerous Activity", null,
                    "Are you sure you want to delete?", MessageDialog.CONFIRM,
                    new String[]{"Preview>", "Delete", "Cancel"}, 0);

     int dialogResult = dialog.open();
     // if preview button is selected
      if (dialogResult == 0) {
           // open another dialog for a second more informative warning
           // but DO NOT CLOSE THE CURRENT MAIN ONE..HOW TO?

            }

我感谢任何帮助!

谢谢,

1 个答案:

答案 0 :(得分:3)

尝试覆盖MessageDialog上的buttonPressed方法:

MessageDialog dialog =
     new MessageDialog(null, "Dangerous Activity", null,
                "Are you sure you want to delete?", MessageDialog.CONFIRM,
                new String[]{"Preview>", "Delete", "Cancel"}, 0)
{
protected void buttonPressed(int buttonId) {
    setReturnCode(buttonId);
    // close(); Call close for Delete or Cancel?
}};