简体   繁体   English

GWT CellTable高亮显示行

[英]GWT CellTable highlighted row

So I have a cell table with click event selection model working fine. 所以我有一个单元格表,其单击事件选择模型运行良好。 I later found out you can press UP and DOWN arrows to get the highlighted row to change, but the awful thing is you have to press Space for it to actually call the SelectionChangeEvent. 后来我发现您可以按UP和DOWN箭头来更改突出显示的行,但是可怕的是您必须按Space才能真正调用SelectionChangeEvent。 I am trying to cheat my way a little, by catching the UP and DOWN events and firing the SPACE event. 我试图通过捕捉UP和DOWN事件并触发SPACE事件来欺骗自己的方式。 Sadly it doesn't work :( Here is my code any help would be appreciated! 遗憾的是,它不起作用:(这是我的代码,我们将不胜感激!

        table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
        table.sinkEvents(Event.KEYUP);
        table.sinkEvents(Event.KEYDOWN);
        table.sinkEvents(32);
        table.addHandler(new KeyUpHandler(){
            @Override
            public void onKeyUp(KeyUpEvent event)
            {
                System.out.println(event.getNativeKeyCode());
                if(event.getNativeEvent().getKeyCode() == 40)
                {
                    // down is pressed
                    int i = rows.getFilterList().indexOf(selectionModel.getLastSelectedObject())+1;
                    if(i >= 0 && i < rows.getFilterList().size())
                    {
//                      selectionModel.setSelected(selectionModel.getLastSelectedObject(), false);
//                      selectionModel.setSelected(rows.getFilterList().get(i), true);
//                      SelectionChangeEvent.fire(selectionModel);
                        System.out.println("firing native event space");
                        DomEvent.fireNativeEvent(Document.get().createKeyUpEvent(false, false, false, false, 32), table);
                    }
                }
                else if(event.getNativeEvent().getKeyCode() == 38)
                {
                    // up is pressed
                    int i = rows.getFilterList().indexOf(selectionModel.getLastSelectedObject())-1;
                    if(i >= 0 && i < rows.getFilterList().size())
                    {
//                      selectionModel.setSelected(selectionModel.getLastSelectedObject(), false);
//                      selectionModel.setSelected(rows.getFilterList().get(i), true);
//                      SelectionChangeEvent.fire(selectionModel);
                        System.out.println("firing native event space");
                        DomEvent.fireNativeEvent(Document.get().createKeyUpEvent(false, false, false, false, 32), table);
                    }
                }
            }

        }, KeyUpEvent.getType());

32 is assumingly the NativeEvent for space, my console prints something like: 假设32是用于空间的NativeEvent,我的控制台将打印以下内容:

40
firing native event space
32

so assumingly the event type 32 is being called for the object table. 因此,假设正在为对象表调用事件类型32。

I check if the object is selected, because on the right hand side of the screen I have additional information being pulled out from a list, since the cell table doesn't show all the information. 我检查是否选择了对象,因为在单元格表中没有显示所有信息,因此在屏幕的右侧我还从列表中拉出了其他信息。 I want it so when I press UP and DOWN the RHS information changes and I dont have to press SPACE to prompt the info change 我想要它,所以当我按UP和DOWN时,RHS信息会更改,而不必按空格键来提示信息更改

Ideally you would poke into the selection internals. 理想情况下,您应该戳入选择内部。 Specifically the DefaultKeyboardSelectionHandler is the default implementation of keyboard navigation and the DefaultSelectionEventManager is the default implementation of selection actions using spacebar/clicks (they are both CellPreviewEvent.Handler s). 具体来说, DefaultKeyboardSelectionHandler是键盘导航的默认实现,而DefaultSelectionEventManager是使用空格键/单击(它们都是CellPreviewEvent.Handler )的选择动作的默认实现。

Anyway, you can force the keyboard selection to be bound to the underlying SelectionModel by using setKeyboardSelectionPolicy(KeyboardSelectionPolicy.BOUND_TO_SELECTION) . 无论如何,您可以使用setKeyboardSelectionPolicy(KeyboardSelectionPolicy.BOUND_TO_SELECTION)强制将键盘选择绑定到基础的SelectionModel It should be fine for your use case. 对于您的用例来说应该没问题。 Much like what is done for the CellList showcase sample (the selection API is the same across cell widgets). 就像对CellList展示示例所做的操作一样(跨单元小部件的选择API相同)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM