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.
You can use:
if (Dialog.CANCEL.equals(be.getButtonClicked().getItemId())) {
//do action
}