GXT 2.2 - MessageBox button constants

ぐ巨炮叔叔 提交于 2019-12-11 01:35:42

问题


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");
    }
  });
  • However. since box has not been defined, box.getDialog() would be NPE,
  • and compiler preempts that by croaking "box not initialised",
  • and cannot initialise because box has to be final,
  • box has to be final because it is used in the anon Listener class.

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.


回答1:


You can use:

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

    //do action 

}



回答2:


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.



来源:https://stackoverflow.com/questions/9910188/gxt-2-2-messagebox-button-constants

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!