Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT CellTable with checkbox selection and on row click event

How to call a method when some row is clicked using the checkbox selection model?

I'm setting the checkbox selection model like this:

table.setSelectionModel(selectionModel, 
      DefaultSelectionEventManager.<T> createCheckboxManager(0));
like image 345
Italo Borssatto Avatar asked Apr 12 '11 15:04

Italo Borssatto


2 Answers

I found a solution! Instead of using createCheckboxManager(), use createCustomManager() passing by argument an EventTranslator that extends the CheckboxEventTranslator and do a delegation of the translateSelectionEvent method, intercepting only the events ignored by the super (CheckboxEventTranslator).

The source code:

table.setSelectionModel(selectionModel, 
    DefaultSelectionEventManager.createCustomManager(
        new DefaultSelectionEventManager.CheckboxEventTranslator<T>() {
            @Override
            public SelectAction translateSelectionEvent(CellPreviewEvent<T> event) {
                SelectAction action = super.translateSelectionEvent(event);
                if (action.equals(SelectAction.IGNORE)) {
                    GWT.log("DO WHAT YOU WANT!!!");
                    return SelectAction.IGNORE;
                }
                return action;
            }
        }
    )
);
like image 174
Italo Borssatto Avatar answered Nov 17 '22 19:11

Italo Borssatto


Create a function that you call,

table.setSelectionModel(selectionModel, ClassName.myMethod(0));

static <T> DefaultSelectionEventManager<T> myMethod(int column) {
   //call whatever functions you want
   return DefaultSelectionEventManager.<T> createCheckboxManager(column);
}
like image 1
RankWeis Avatar answered Nov 17 '22 19:11

RankWeis