GXT 2.2-MessageBox按钮常数 [英] GXT 2.2 - MessageBox button constants

查看:104
本文介绍了GXT 2.2-MessageBox按钮常数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个有关如何检测在MessageBox/Dialog中单击哪个按钮的问题. 仅GXT 2.1或2.2. 请不要使用GXT 3进行回答.

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");
    }
  });

  • 但是.由于尚未定义box,box.getDialog()将为NPE,
  • 并且编译器通过破坏未初始化的框"来抢占这一点,
  • 并且不能初始化,因为box必须是最终的
  • 框必须是最终的,因为它在anon Listener类中使用.
    • 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.
    • 相反,我必须使用按钮文本来比较按钮.这不是i18n友好的.不好的做法.

      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");
          }
      

      在GXT 2.2中,这是推荐的方法吗?还是有一种更好的方法来检测按钮是否被按下,对i18n友好?

      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.

      推荐答案

      您可以使用:

      if (Dialog.CANCEL.equals(be.getButtonClicked().getItemId())) {
      
          //do action 
      
      }
      

      这篇关于GXT 2.2-MessageBox按钮常数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆