3

我正在尝试让 GWTCellTable捕获类型的事件DoubleClickEvent,但是当在 UI 中单击一行时CellTable正确接收类型的事件,当双击该行时ClickEvent它看不到任何事件。DoubleClickEvent

因此,如果我单击 UI 中的一行,则声明的处理程序ClickEvent会正确触发,但如果我双击声明的处理程序,DoubleClickEvent不会触发。

我是做错了什么还是CellTable自己根本无法处理DoubleClickEvent?在后一种情况下,捕捉表格中双击的好方法是什么?

下面是我的 CellTable 声明的代码:

CellTable<ServiceTypeUI> contentTable = new CellTable<ServiceTypeUI>(10, style);
contentTable.setSelectionModel(new SingleSelectionModel<ServiceTypeUI>());
contentTable.addHandler(new DoubleClickHandler() { // HANDLER NOT CORRECTLY TRIGGERED
   @Override
   @SuppressWarnings("unchecked")
   public void onDoubleClick(DoubleClickEvent event) {
       presenter.doubleClickHandler(event);
   }

}, DoubleClickEvent.getType());
contentTable.addHandler(new ClickHandler() { // HANDLER CORRECTLY TRIGGERED
   @Override
   @SuppressWarnings("unchecked")
   public void onClick(ClickEvent event) {
       presenter.clickHandler(event);
   }

}, ClickEvent.getType());

我还尝试删除ClickEvent处理程序声明和SelectionModel声明,以避免其中任何一个捕获DoubleClickEvent事件并将其视为,ClickEvent但即使在这种情况下也没有触发 DoubleClickHandler。

CellTable<ServiceTypeUI> contentTable = new CellTable<ServiceTypeUI>(10, style);
contentTable.addHandler(new DoubleClickHandler() { // HANDLER NOT CORRECTLY TRIGGERED
   @Override
   @SuppressWarnings("unchecked")
   public void onDoubleClick(DoubleClickEvent event) {
       presenter.doubleClickHandler(event);
   }

}, DoubleClickEvent.getType());
4

1 回答 1

10
       SingleSelectionModel<T> selectionModel
     = new SingleSelectionModel<T>();

   cellTable.setSelectionModel(selectionModel);
   cellTable.addDomHandler(new DoubleClickHandler() {

        @Override
        public void onDoubleClick(final DoubleClickEvent event) {
            T selected = selectionModel
                    .getSelectedObject();
            if (selected != null) {
                //DO YOUR STUFF

                                  }

        }
    }, 
    DoubleClickEvent.getType());

You have to replace the T with the your "ServiceTypeUI" . The value selected will be the object which was been chosen from the user.

于 2012-10-22T12:46:23.133 回答