Search in sources :

Example 1 with Update

use of com.vaadin.flow.data.provider.ArrayUpdater.Update in project flow by vaadin.

the class DataCommunicator method performUpdate.

private void performUpdate(Set<String> oldActive, Range effectiveRequested, final Range previousActive, Activation activation) {
    // In case received less items than what was expected, adjust size
    if (activation.isSizeRecheckNeeded()) {
        if (definedSize) {
            assumedSize = getDataProviderSize();
        } else {
            // the end has been reached
            assumedSize = requestedRange.getStart() + activation.getActiveKeys().size();
            skipCountIncreaseUntilReset = true;
            /*
                 * If the fetch query returned 0 items, it means that the user
                 * has scrolled past the end of the exact item count or the
                 * items have been changed in the backend (for example, applying
                 * the filter). Instead of returning 0 items to the client and
                 * letting it incrementally request for the previous pages,
                 * we'll cancel this flush and tweak the requested range and
                 * flush again.
                 */
            if (assumedSize != 0 && activation.getActiveKeys().isEmpty()) {
                int delta = requestedRange.length();
                // Request the items from a bit behind the current range
                // at the next call to backend, and check that the
                // requested
                // range doesn't intersect the 0 point.
                requestedRange = requestedRange.offsetBy(-delta).restrictTo(Range.withLength(0, assumedSize));
                // to avoid recursiveness
                requestFlush(true);
                return;
            }
        }
        effectiveRequested = requestedRange.restrictTo(Range.withLength(0, assumedSize));
    }
    activeKeyOrder = activation.getActiveKeys();
    activeStart = effectiveRequested.getStart();
    // Phase 2: Collect changes to send
    Update update = arrayUpdater.startUpdate(assumedSize);
    boolean updated = collectChangesToSend(previousActive, effectiveRequested, update);
    resendEntireRange = false;
    assumeEmptyClient = false;
    sizeReset = false;
    // Phase 3: passivate anything that isn't longer active
    passivateInactiveKeys(oldActive, update, updated);
    // Phase 4: unregister passivated and updated items
    unregisterPassivatedKeys();
    fireItemCountEvent(assumedSize);
}
Also used : Update(com.vaadin.flow.data.provider.ArrayUpdater.Update)

Aggregations

Update (com.vaadin.flow.data.provider.ArrayUpdater.Update)1