Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT CellTable Custom Selection Model

I need a 'custom selection model' for GWT CellTable. One of the columns in CellTable is a Checkbox column.

Basic rquirements (both work in solution below):
- Row click (not on checkbox), selects that row and un-selects all other rows.
- Checkbox selection should select/un-select that row only.

Following is the code I am using, but its very very slow. Any guidance would be appreciated.

final SelectionModel<T> selectionModel = new MultiSelectionModel<T>();
dataTable.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)) {
                            selectionModel.clear();
                            return SelectAction.TOGGLE;
                        }
                        return action;
                    }
                }
            )
        );

Following is the code snipped for CheckColumn callback.

Column<T, Boolean> checkColumn = new Column<T, Boolean>(
    new CheckboxCell(true, false))
        {
            @Override
            public Boolean getValue(T t)
            {
                // Get the value from the selection model.
                return selectionModel.isSelected(t);
            }
        };
like image 708
AM01 Avatar asked Sep 18 '26 05:09

AM01


1 Answers

I have put in a KeyProvider for the CellTable and its not slow anymore. :)

ProvidesKey<T> keyProvider = new ProvidesKey<T>() {
    public Object getKey(T t) {
        return tip == null? null : tip.getId();
    }
};
dataTable = new CellTable<T>(PAGE_SIZE, keyProvider);
like image 163
AM01 Avatar answered Sep 20 '26 18:09

AM01



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!