How to use MessageDialog.open () with QUESTION_WITH_CANCEL?

I am wondering how to use the new QUESTION_WITH_CANCEL dialog when opening with MessageDialog.open(int kind, Shell parent, String title, String message,int style) .

Since the public method returns a boolean, and now we have 3 possible states from Yes , No, or Cancel .

+6
eclipse eclipse-rcp
source share
2 answers

You cannot use the static method MessageDialog.open(bunch of parameters) , you will need to create a dialog and call non-static open() yourself to check its return value.

  MessageDialog dg = new MessageDialog( window.getShell(), "My title", null, "My question", MessageDialog.QUESTION_WITH_CANCEL, new String[]{ IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL}, 0 ); switch(dg.open()) { case 0: //yes System.out.println("yes"); break; case 1: //no System.out.println("no"); break; case 2: //cancel System.out.println("cancel"); break; } 
+13
source share

Looking at JavaDoc , I believe that No and Cancel have the same effect: false

 Returns: true if the user presses the OK or Yes button, false otherwise 
0
source share

All Articles