Vaadin 表中的全选快捷键 (Ctrl-A)? [英] Select-all shortcut (Ctrl-A) in Vaadin Table?

查看:51
本文介绍了Vaadin 表中的全选快捷键 (Ctrl-A)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 UI Builder 代码中有以下代码段:

I have the following snippet in my UI Builder code:

table.addShortcutListener(new ShortcutListener("Select all", null, KeyCode.A, ModifierKey.CTRL) {

  @Override
  public void handleAction(Object sender, Object target) {
    AbstractSelect t = (AbstractSelect) target;
    if (t.isMultiSelect()) {
      t.setValue(t.getItemIds());
    }
  }
});
return table;

这允许按 Ctrl+A 选择表中的所有项目.这通常在我第一次加载视图时起作用,直到我使其中一个表不可见(setVisible(false)).使表格再次可见后,它不再起作用(甚至在重新加载页面时也不起作用),每当我按 Ctrl+A 时,我都会得到以下控制台输出:

This allows to press Ctrl+A to select all items in a table. This usually works the first time I load a view until I make one of the tables invisible (setVisible(false)). After making the tables visible again, it no longer works (not even on reloading the page) and I get the following console output whenever I press Ctrl+A:

WARNING: Ignoring action for disabled connector c.b.a.web.ui.builder.table.TranslatedHeaderTable
Nov 03, 2014 11:15:00 AM com.vaadin.event.ConnectorActionManager handleAction

我的代码有什么问题?我将如何实现我的目标?

What is wrong with my code? How would I achieve my goal?

推荐答案

Action.Notifier 接口的 Table 实现似乎存在一些问题.在此 Vaadin 论坛帖子中,Vaadin 开发人员建议添加 ShortcutListener 不是指向表格本身,而是指向包含表格的面板.

It seems there are some problems with the Table implementation of the Action.Notifier interface. In this Vaadin Forum Post, the Vaadin Devs suggest to add the ShortcutListener not to the Table itself but to a Panel that the Table is enclosed within.

我的新实现:

private void addCtrlAHandler(final AbstractSelect table) {
    Panel panelEnclosingTable = table.findAncestor(Panel.class);
    Preconditions.checkArgument(panelEnclosingTable != null, "Table is not enclosed in a panel; cannot add shortcut handlers");

    panelEnclosingTable.addShortcutListener(new ShortcutListener("Select all", null, KeyCode.A, ModifierKey.CTRL) {

        @Override
        public void handleAction(Object sender, Object target) {
            if (table.isMultiSelect()) {
                table.setValue(table.getItemIds());
            }
        }
    });
}

通过这种解决方法,我得到了预期的行为.

With this workaround, I get the expected behavior.

这篇关于Vaadin 表中的全选快捷键 (Ctrl-A)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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