Blessed Geek
Blessed Geek

Reputation: 21614

GXT 2.2 - MessageBox button constants

This is a question on how to detect which button was clicked in the MessageBox/Dialog. GXT 2.1 or 2.2 only. Please do not answer using GXT 3.

Ideally, this is how I could do a confirm dialog.

final MessageBox box = MessageBox.confirm(
  "Confirm kill avatar",
  "Please remove " + getAvatar().getName(),
  new Listener<MessageBoxEvent>()
  {
    @Override
    public void handleEvent(MessageBoxEvent be)
    {
      Button clicked = be.getButtonClicked();
      if (clicked == box.getDialog().getButtonById("yes"))
        deleteAvatar();
      else
       Info.display("Action cancelled");
    }
  });

Instead, I have to compare buttons using the button text. Which is not i18n friendly. Very bad practice.

    @Override
    public void handleEvent(MessageBoxEvent be)
    {
      Button clicked = be.getButtonClicked();
      if (clicked.getText().equals("Yes")))
        deleteAvatar();
      else
       Info.display("Action cancelled");
    }

In GXT 2.2, is this the recommended way? Or is there a better way to detect button being pressed, i18n-friendly?

I SHOULD compare buttons NOT the text of the buttons.

Upvotes: 2

Views: 1786

Answers (2)

tm nvm
tm nvm

Reputation: 56

You can use:

if (Dialog.CANCEL.equals(be.getButtonClicked().getItemId())) {

    //do action 

}

Upvotes: 4

Blessed Geek
Blessed Geek

Reputation: 21614

Never mind.

I should simply construct my own confirm/alert/etc from Dialog and provide my own submit/cancel buttons with the appropriate listeners.

Messagebox is but a sandbox/example on how to do simple gxt dialogs.

Upvotes: 0

Related Questions