Example usage for com.google.gwt.view.client MultiSelectionModel isSelected

List of usage examples for com.google.gwt.view.client MultiSelectionModel isSelected

Introduction

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

Prototype

public boolean isSelected(T object) 

Source Link

Usage

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

License:Open Source License

/**
 * Update the selection model based on a user selection event.
 * /*from  ww  w  .j a  v a 2  s.  co  m*/
 * @param selectionModel the selection model to update
 * @param row the selected row index relative to the page start
 * @param rowValue the selected row value
 * @param action the {@link SelectAction} to apply
 * @param selectRange true to select the range from the last selected row
 * @param clearOthers true to clear the current selection
 */
public void doMultiSelection(MultiSelectionModel<? super T> selectionModel, HasData<T> display, int row,
        T rowValue, SelectAction action, boolean selectRange, boolean clearOthers) {
    // Determine if we will add or remove selection.
    boolean addToSelection = true;
    if (action != null) {
        switch (action) {
        case IGNORE:
            // Ignore selection.
            return;
        case SELECT:
            addToSelection = true;
            break;
        case DESELECT:
            addToSelection = false;
            break;
        case TOGGLE:
            addToSelection = !selectionModel.isSelected(rowValue);
            break;
        }
    }

    // Determine which rows will be newly selected.
    int pageStart = display.getVisibleRange().getStart();
    if (selectRange && pageStart == lastPageStart && lastSelectedIndex > -1 && shiftAnchor > -1
            && display == lastDisplay) {
        /*
         * Get the new shift bounds based on the existing shift anchor and the
         * selected row.
         */
        int start = Math.min(shiftAnchor, row); // Inclusive.
        int end = Math.max(shiftAnchor, row); // Inclusive.

        if (lastSelectedIndex < start) {
            // Revert previous selection if the user reselects a smaller range.
            setRangeSelection(selectionModel, display, new Range(lastSelectedIndex, start - lastSelectedIndex),
                    !shiftAdditive, false);
        } else if (lastSelectedIndex > end) {
            // Revert previous selection if the user reselects a smaller range.
            setRangeSelection(selectionModel, display, new Range(end + 1, lastSelectedIndex - end),
                    !shiftAdditive, false);
        } else {
            // Remember if we are adding or removing rows.
            shiftAdditive = addToSelection;
        }

        // Update the last selected row, but do not move the shift anchor.
        lastSelectedIndex = row;

        // Select the range.
        setRangeSelection(selectionModel, display, new Range(start, end - start + 1), shiftAdditive,
                clearOthers);
    } else {
        /*
         * If we are not selecting a range, save the last row and set the shift
         * anchor.
         */
        lastDisplay = display;
        lastPageStart = pageStart;
        lastSelectedIndex = row;
        shiftAnchor = row;
        selectOne(selectionModel, rowValue, addToSelection, clearOthers);
    }
}

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.
 * //from  w  ww . ja  v  a2  s  . 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);
        }
    }
}

From source file:org.zanata.webtrans.client.presenter.SearchResultsPresenter.java

License:Open Source License

/**
 * Build selection change handler to uncheck 'Select All' in document list
 * if any child is unchecked//from www .j  ava  2s.c om
 *
 * @param docId
 * @param selectionModel
 * @param dataProvider
 * @return
 */
private Handler buildSelectionChangeDeselectHandler(final Long docId,
        final MultiSelectionModel<TransUnitReplaceInfo> selectionModel,
        final ListDataProvider<TransUnitReplaceInfo> dataProvider) {
    return event -> {
        boolean isAllSelected = true;
        for (TransUnitReplaceInfo data : dataProvider.getList()) {
            if (!selectionModel.isSelected(data)) {
                isAllSelected = false;
                break;
            }
        }

        if (selectAllDocList.containsKey(docId)) {
            selectAllDocList.get(docId).setValue(isAllSelected);
        }

        isAllSelected = true;
        for (HasValue<Boolean> docSelectAll : selectAllDocList.values()) {
            if (!docSelectAll.getValue().booleanValue()) {
                isAllSelected = false;
                break;
            }
        }
        display.getSelectAllChk().setValue(isAllSelected);
    };
}

From source file:org.zanata.webtrans.client.presenter.SearchResultsPresenter.java

License:Open Source License

private void executePostSucess(UpdateTransUnitResult result) {
    for (TransUnitUpdateInfo info : result.getUpdateInfoList()) {
        TransUnitReplaceInfo replaceInfo = allReplaceInfos.get(info.getTransUnit().getId());
        setReplaceState(replaceInfo, ReplacementState.NotReplaced);
        if (replaceInfo.getPreview() == null) {
            replaceInfo.setPreviewState(PreviewState.NotFetched);
        } else {//from   ww  w .  j  a v  a 2 s. com
            MultiSelectionModel<TransUnitReplaceInfo> selectionModel = documentSelectionModels
                    .get(replaceInfo.getDocId());
            if (selectionModel != null && selectionModel.isSelected(replaceInfo)) {
                replaceInfo.setPreviewState(PreviewState.Show);
            } else {
                replaceInfo.setPreviewState(PreviewState.Hide);
            }
        }
        refreshInfoDisplay(replaceInfo);
    }
    refreshReplaceAllButton();
}