views:

237

answers:

2

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

Since the open method is returning boolean and now we have 3 possible state from Yes, No, or Cancel.

A: 

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

Returns:
    true if the user presses the OK or Yes button, false otherwise
Alexandre Pauzies
That much I know, but that is not the question I asked. I do have a need to use the QUESTION_WITH_CANCEL dialog. If I only need standard yes/no, I would have use the standard confirm dialog.
DJ
+2  A: 

You can't use the static method MessageDialog.open(bunch of parameters), you'll have to create the Dialog and call the 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;
 }
Jerome
I'll give it a try.
DJ
Did it work as expected?
Jerome