문제

I have a JFace dialog and this is how I'm opening:

SampleDialog dialog = new SampleDialog(shell);
if(Window.OK == dialog.open())
{
  // do something
  if(condition)
  {
    MessageBox dialog = new MessageBox(shell, SWT.ICON_QUESTION | SWT.OK| SWT.CANCEL);
    dialog.setText("Sample");
    dialog.setMessage("Some problem in processing");
  }
  else
  {
     // do something
  }
}

If the control goes to the if block , I dont want the dialog to be closed. How to achieve this?

도움이 되었습니까?

해결책 2

Overriding the JFace Dialogs close() method is another way of addressing it:

@Override
public boolean close()
{
    if( condition )
    {
        if( this.getReturnCode() == OK )
        {
            MessageBox dialog = new MessageBox(shell, SWT.ICON_QUESTION | SWT.OK|                   SWT.CANCEL);
            dialog.setText("Sample");
            dialog.setMessage("Some problem in processing");

            return false;
        }
    }
    return super.close();
}

다른 팁

You should do your check and message box display by overriding the okPressed method in the dialog.

public class SampleDialog extends Dialog
{

  @Override
  protected void okPressed()
  {
    if (condition)
     {
        // TODO show your message box
     }
    else
     {
       // Allow the dialog to close
       super.okPressed();
     } 
  }

}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top