Search code examples
gwtdouble-clickcelltable

How to capture doubleClickEvent in GWT CellTable


I'm trying to make a GWT CellTable catch events of type DoubleClickEvent, but while the CellTable correctly receives events of type ClickEvent when a row is clicked in the UI, it not see any DoubleClickEvent when the row is double-clicked.

So, if I click a row in the UI, the handler declared for ClickEvent is correctly triggered, but if I double click the handler declared for DoubleClickEvent is not triggered, instead.

Am I doing something wrong or CellTable itself cannot handle DoubleClickEvent at all? In the latter case, what could be a good way to capture double-clicks in a table?

Below, the code for my CellTable declaration:

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());

I've also tried removing ClickEvent handler declaration and the SelectionModel declaration, to avoid that any of those capture the DoubleClickEvent event and treat it as a ClickEvent but the DoubleClickHandler has not been triggered even in this case.

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());

Solution

  •        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.