Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
Vaadin is a web application framework for Rich Internet Applications (RIA).
Vaadin enables easy development and maintenance of fast and
secure rich web
applications with a stunning look and feel and a wide browser support.
It features a server-side architecture with the majority of the logic
running
on the server. Ajax technology is used at the browser-side to ensure a
rich
and interactive user experience.
/*
* Copyright 2000-2014 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.client.data;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.google.gwt.core.client.Duration;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.vaadin.client.Profiler;
import com.vaadin.shared.ui.grid.Range;
/**
* Base implementation for data sources that fetch data from a remote system.
* This class takes care of caching data and communicating with the data source
* user. An implementation of this class should override
* {@link #requestRows(int, int, RequestRowsCallback)} to trigger asynchronously
* loading of data and then pass the loaded data into the provided callback.
*
* @since 7.4
* @author Vaadin Ltd
* @param
* the row type
*/
public abstract class AbstractRemoteDataSource implements DataSource {
/**
* Callback used by
* {@link AbstractRemoteDataSource#requestRows(int, int, RequestRowsCallback)}
* to pass data to the underlying implementation when data has been fetched.
*/
public static class RequestRowsCallback {
private final Range requestedRange;
private final double requestStart;
private final AbstractRemoteDataSource source;
/**
* Creates a new callback
*
* @param source
* the data source for which the request is made
* @param requestedRange
* the requested row range
*/
protected RequestRowsCallback(AbstractRemoteDataSource source,
Range requestedRange) {
this.source = source;
this.requestedRange = requestedRange;
requestStart = Duration.currentTimeMillis();
}
/**
* Called by the
* {@link AbstractRemoteDataSource#requestRows(int, int, RequestRowsCallback)}
* implementation when data has been received.
*
* @param rowData
* a list of row objects starting at the requested offset
* @param totalSize
* the total number of rows available at the remote end
*/
public void onResponse(List rowData, int totalSize) {
if (source.size != totalSize) {
source.resetDataAndSize(totalSize);
}
source.setRowData(requestedRange.getStart(), rowData);
}
/**
* Gets the range of rows that was requested.
*
* @return the requsted row range
*/
public Range getRequestedRange() {
return requestedRange;
}
}
protected class RowHandleImpl extends RowHandle {
private T row;
private final Object key;
public RowHandleImpl(final T row, final Object key) {
this.row = row;
this.key = key;
}
/**
* A method for the data source to update the row data.
*
* @param row
* the updated row object
*/
public void setRow(final T row) {
this.row = row;
assert getRowKey(row).equals(key) : "The old key does not "
+ "equal the new key for the given row (old: " + key
+ ", new :" + getRowKey(row) + ")";
}
@Override
public T getRow() throws IllegalStateException {
if (isPinned()) {
return row;
} else {
throw new IllegalStateException("The row handle for key " + key
+ " was not pinned");
}
}
public boolean isPinned() {
return pinnedRows.containsKey(key);
}
@Override
public void pin() {
pinHandle(this);
}
@Override
public void unpin() throws IllegalStateException {
unpinHandle(this);
}
@Override
protected boolean equalsExplicit(final Object obj) {
if (obj instanceof AbstractRemoteDataSource.RowHandleImpl) {
/*
* Java prefers AbstractRemoteDataSource>.RowHandleImpl. I
* like the @SuppressWarnings more (keeps the line length in
* check.)
*/
@SuppressWarnings("unchecked")
final RowHandleImpl rhi = (RowHandleImpl) obj;
return key.equals(rhi.key);
} else {
return false;
}
}
@Override
protected int hashCodeExplicit() {
return key.hashCode();
}
@Override
public void updateRow() {
int index = indexOf(row);
if (index >= 0) {
dataChangeHandler.dataUpdated(index, 1);
}
}
}
private RequestRowsCallback currentRequestCallback;
private boolean coverageCheckPending = false;
private Range requestedAvailability = Range.between(0, 0);
private Range cached = Range.between(0, 0);
private final HashMap indexToRowMap = new HashMap();
private final HashMap