Java源码示例:com.vaadin.shared.Range
示例1
@Override
public void onDataAvailable(DataAvailableEvent event) {
int current = cell.getRowIndex();
int min = Math.min(current, previous);
int max = Math.max(current, previous);
if (!ctrlOrMeta) {
model.deselectAll();
}
Range dataAvailable = event.getAvailableRows();
Range selected = Range.between(min, max + 1);
Range[] partition = selected.partitionWith(dataAvailable);
for (int i = partition[1].getStart(); i < partition[1].getEnd(); ++i) {
model.select(grid.getDataSource().getRow(i));
}
if (handler != null) {
handler.removeHandler();
}
}
示例2
@Override
public void onDataAvailable(DataAvailableEvent event) {
// Perform shift selection
int current = cell.getRowIndex();
int min = Math.min(current, previous);
int max = Math.max(current, previous);
// TODO: Fix batching.
if (!ctrlOrMeta) {
model.deselectAll();
}
Range dataAvailable = event.getAvailableRows();
Range selected = Range.between(min, max + 1);
Range[] partition = selected.partitionWith(dataAvailable);
for (int i = partition[1].getStart(); i < partition[1].getEnd(); ++i) {
model.select(grid.getDataSource().getRow(i));
}
// TODO: Batch end
rpc.selectRange(partition[0].getStart(), partition[0].length());
rpc.selectRange(partition[2].getStart(), partition[2].length());
if (handler != null) {
handler.removeHandler();
}
WidgetUtil.setTextSelectionEnabled(grid.getElement(), true);
}
示例3
@Override
protected void sendDataToClient(boolean initial) {
if (getDataProvider() == null) {
return;
}
if (initial) {
rpc.reset(0);
if (reset) {
reset = false;
}
}
if (reset) {
pageCache.clear();
rpc.reset(getDataProviderSize());
reset = false;
}
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();
}
示例4
@Override
protected void sendDataToClient(boolean initial) {
if (getDataProvider() == null) {
return;
}
if (initial) {
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();
}