* @param action the action to handle
* @param selectionModel the {@link SelectionModel} to update
*/
protected void handleMultiSelectionEvent(CellPreviewEvent<T> event,
SelectAction action, MultiSelectionModel<? super T> selectionModel) {
NativeEvent nativeEvent = event.getNativeEvent();
String type = nativeEvent.getType();
if (BrowserEvents.CLICK.equals(type)) {
/*
* Update selection on click. Selection is toggled only if the user
* presses the ctrl key. If the user does not press the control key,
* selection is additive.
*/
boolean shift = nativeEvent.getShiftKey();
boolean ctrlOrMeta = nativeEvent.getCtrlKey() || nativeEvent.getMetaKey();
boolean clearOthers = (translator == null) ? !ctrlOrMeta
: translator.clearCurrentSelection(event);
if (action == null || action == SelectAction.DEFAULT) {
action = ctrlOrMeta ? SelectAction.TOGGLE : SelectAction.SELECT;
}
doMultiSelection(selectionModel, event.getDisplay(), event.getIndex(),
event.getValue(), action, shift, clearOthers);
} else if (BrowserEvents.KEYUP.equals(type)) {
int keyCode = nativeEvent.getKeyCode();
if (keyCode == 32) {
/*
* Update selection when the space bar is pressed. The spacebar always
* toggles selection, regardless of whether the control key is pressed.
*/
boolean shift = nativeEvent.getShiftKey();
boolean clearOthers = (translator == null) ? false
: translator.clearCurrentSelection(event);
if (action == null || action == SelectAction.DEFAULT) {
action = SelectAction.TOGGLE;
}