Example usage for com.vaadin.shared Range isEmpty

List of usage examples for com.vaadin.shared Range isEmpty

Introduction

In this page you can find the example usage for com.vaadin.shared Range isEmpty.

Prototype

public boolean isEmpty() 

Source Link

Document

Checks whether the range has no elements between the start and end.

Usage

From source file:org.vaadin.viritin.grid.SizelessDataCommunicator.java

License:Apache License

@Override
protected void sendDataToClient(boolean initial) {
    if (getDataProvider() == null) {
        return;//from   ww  w . j  ava 2  s .  c  o  m
    }

    if (initial || reset) {
        rpc.reset(0);
    }

    Range requestedRows = getPushRows();
    if (!requestedRows.isEmpty()) {
        int offset = requestedRows.getStart();
        // Always fetch some extra rows.
        int limit = requestedRows.length() + getMinPushSize();
        List<T> rowsToPush = fetchItemsWithRange(offset, limit);
        int lastIndex = offset + rowsToPush.size();
        if (lastIndex > knownSize) {
            int rowsToAdd = lastIndex - knownSize;
            rpc.insertRows(knownSize, rowsToAdd + (rowsToPush.size() == limit ? 1 : 0));
            knownSize = lastIndex;
        } else if (rowsToPush.size() < requestedRows.length()) {
            // Size decreased
            int rowsToRemove = Math.max(requestedRows.length() - rowsToPush.size(), knownSize - lastIndex);
            knownSize = lastIndex;
            rpc.removeRows(knownSize, rowsToRemove);
        }
        pushData(offset, rowsToPush);
    }

    if (!getUpdatedData().isEmpty()) {
        JsonArray dataArray = Json.createArray();
        int i = 0;
        for (T data : getUpdatedData()) {
            dataArray.set(i++, getDataObject(data));
        }
        rpc.updateData(dataArray);
    }

    setPushRows(Range.withLength(0, 0));
    getUpdatedData().clear();
}