Example usage for com.vaadin.shared Range getStart

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

Introduction

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

Prototype

public int getStart() 

Source Link

Document

Returns the inclusive start point of this range.

Usage

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

License:Apache License

@Override
protected void sendDataToClient(boolean initial) {
    if (getDataProvider() == null) {
        return;// ww  w.  ja v a 2 s.  c  om
    }

    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();
}