Example usage for com.google.gwt.view.client CellPreviewEvent getDisplay

List of usage examples for com.google.gwt.view.client CellPreviewEvent getDisplay

Introduction

In this page you can find the example usage for com.google.gwt.view.client CellPreviewEvent getDisplay.

Prototype

public HasData<T> getDisplay() 

Source Link

Document

Get the HasData source of the event.

Usage

From source file:com.agnie.gwt.common.client.rpc.MultiSelectEventTranslator.java

License:Open Source License

@Override
public SelectAction translateSelectionEvent(CellPreviewEvent<T> event) {
    NativeEvent nativeEvent = event.getNativeEvent();
    if ("click".equals(nativeEvent.getType())) {

        // Determine if we clicked on a checkbox.
        Element target = nativeEvent.getEventTarget().cast();
        if ("input".equals(target.getTagName().toLowerCase())) {
            final InputElement input = target.cast();
            if ("checkbox".equals(input.getType().toLowerCase())) {
                // Synchronize the checkbox with the current selection state.
                input.setChecked(event.getDisplay().getSelectionModel().isSelected(event.getValue()));
                return SelectAction.TOGGLE;
            }//w w  w.  ja v a  2  s  .co m
        } else if (cmd != null) {
            cmd.setSelected(event.getValue());
            Scheduler.get().scheduleDeferred(cmd);
        }
    }
    return SelectAction.IGNORE;
}

From source file:org.gss_project.gss.web.client.GSSSelectionEventManager.java

License:Open Source License

public void onCellPreview(CellPreviewEvent<T> event) {
    // Early exit if selection is already handled or we are editing.
    if (event.isCellEditing() || event.isSelectionHandled()) {
        return;//from  w ww.ja  va 2  s .  c  om
    }

    // Early exit if we do not have a SelectionModel.
    HasData<T> display = event.getDisplay();
    SelectionModel<? super T> selectionModel = display.getSelectionModel();
    if (selectionModel == null) {
        return;
    }

    // Check for user defined actions.
    SelectAction action = (translator == null) ? SelectAction.DEFAULT
            : translator.translateSelectionEvent(event);

    // Handle the event based on the SelectionModel type.
    if (selectionModel instanceof MultiSelectionModel) {
        // Add shift key support for MultiSelectionModel.
        handleMultiSelectionEvent(event, action, (MultiSelectionModel<? super T>) selectionModel);
    } else {
        // Use the standard handler.
        handleSelectionEvent(event, action, selectionModel);
    }
}

From source file:org.gss_project.gss.web.client.GSSSelectionEventManager.java

License:Open Source License

/**
 * Handle an event that could cause a value to be selected for a
 * {@link MultiSelectionModel}. This overloaded method adds support for both
 * the control and shift keys. If the shift key is held down, all rows between
 * the previous selected row and the current row are selected.
 * // ww  w.  ja v a 2s .com
 * @param event the {@link CellPreviewEvent} that triggered selection
 * @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();
    boolean rightclick = "mousedown".equals(type) && nativeEvent.getButton() == NativeEvent.BUTTON_RIGHT;
    if (rightclick) {
        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;
        }
        //if the row is selected then do nothing
        if (selectionModel.isSelected(event.getValue())) {
            return;
        }
        doMultiSelection(selectionModel, event.getDisplay(), event.getIndex(), event.getValue(), action, shift,
                clearOthers);
    } else if ("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);
        if (ctrlOrMeta) {
            event.setCanceled(true);
        }
    } else if ("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;
            }
            doMultiSelection(selectionModel, event.getDisplay(), event.getIndex(), event.getValue(), action,
                    shift, clearOthers);
        }
    }
}