Top Description Fields Constructors Methods
com.dlsc.gemsfx.paging

public Class LoadingService<T>

extends Service<PagingLoadResponse<T>>
Class Inheritance
Type Parameters
<T>
the type of items to be shown by the UI
Imports
javafx.beans.property.IntegerProperty, .LongProperty, .ObjectProperty, .SimpleIntegerProperty, .SimpleLongProperty, .SimpleObjectProperty, javafx.concurrent.Service, .Task, javafx.util.Callback

A service that performs the actual loading of items for a paging control such as the PagingListView or the PagingGridTableView. The service delays the actual loading by a couple of milliseconds so that it can be restarted (cancel and start) when the user changes the page index quickly. This avoids redundant updates and heavy query operations. The service binds all of its properties to the paging control that uses it.
See Also
pageProperty(), pageSizeProperty(), loaderProperty(), loadDelayInMillisProperty()

Field Summary

Modifier and TypeField and Description
private final LongProperty
private final ObjectProperty<Callback<PagingLoadRequest, PagingLoadResponse<T>>>
private final IntegerProperty
private final IntegerProperty
public static int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected Task<PagingLoadResponse<T>>
createTask()

Implements abstract javafx.concurrent.Service.createTask.

Invoked after the Service is started on the JavaFX Application Thread.

public final long
public final Callback<PagingLoadRequest, PagingLoadResponse<T>>
public final int
public final int
public final LongProperty

Returns:

the delay before data will actually be loaded
loadDelayInMillisProperty
()

The delay in milliseconds before the loading service will actually try to retrieve the data from (for example) a backend.

public final ObjectProperty<Callback<PagingLoadRequest, PagingLoadResponse<T>>>
public final IntegerProperty

Returns:

the number of the currently showing page
pageProperty
()

The index of the currently showing page.

public final IntegerProperty

Returns:

the number of items per page
pageSizeProperty
()

The number of items shown per page of the control that is being controlled by the pagination control.

public final void
setLoadDelayInMillis(long loadDelayInMillis)

Inherited from javafx.concurrent.Service:
addEventFilteraddEventHandlerbuildEventDispatchChaincancelcancelledexceptionPropertyexecuteTaskexecutorPropertyfailedfireEventgetExceptiongetExecutorgetMessagegetOnCancelledgetOnFailedgetOnReadygetOnRunninggetOnScheduledgetOnSucceededgetProgressgetStategetTitlegetTotalWorkgetValuegetWorkDoneisRunningmessagePropertyonCancelledPropertyonFailedPropertyonReadyPropertyonRunningPropertyonScheduledPropertyonSucceededPropertyprogressPropertyreadyremoveEventFilterremoveEventHandlerresetrestartrunningrunningPropertyscheduledsetEventHandlersetExecutorsetOnCancelledsetOnFailedsetOnReadysetOnRunningsetOnScheduledsetOnSucceededstartstatePropertysucceededtitlePropertytotalWorkPropertyvaluePropertyworkDoneProperty

Field Detail

loadDelayInMillisback to summary
private final LongProperty loadDelayInMillis
loaderback to summary
private final ObjectProperty<Callback<PagingLoadRequest, PagingLoadResponse<T>>> loader
pageback to summary
private final IntegerProperty page
pageSizeback to summary
private final IntegerProperty pageSize
UNDEFINEDback to summary
public static int UNDEFINED

Constructor Detail

LoadingServiceback to summary
public LoadingService()

Method Detail

createTaskback to summary
protected Task<PagingLoadResponse<T>> createTask()

Implements abstract javafx.concurrent.Service.createTask.

Doc from javafx.concurrent.Service.createTask.

Invoked after the Service is started on the JavaFX Application Thread. Implementations should save off any state into final variables prior to creating the Task, since accessing properties defined on the Service within the background thread code of the Task will result in exceptions. For example:


    protected Task createTask() {
        final String url = myService.getUrl();
        return new Task<String>() {
            protected String call() {
                URL u = new URL("http://www.oracle.com");
                BufferedReader in = new BufferedReader(
                        new InputStreamReader(u.openStream()));
                String result = in.readLine();
                in.close();
                return result;
            }
        }
    }

If the Task is a pre-defined class (as opposed to being an anonymous class), and if it followed the recommended best-practice, then there is no need to save off state prior to constructing the Task since its state is completely provided in its constructor.

protected Task createTask() {
        // This is safe because getUrl is called on the FX Application
        // Thread and the FirstLineReaderTasks stores it as an
        // immutable property
        return new FirstLineReaderTask(myService.getUrl());
    }
Annotations
@Override
getLoadDelayInMillisback to summary
public final long getLoadDelayInMillis()
getLoaderback to summary
public final Callback<PagingLoadRequest, PagingLoadResponse<T>> getLoader()
getPageback to summary
public final int getPage()
getPageSizeback to summary
public final int getPageSize()
loadDelayInMillisPropertyback to summary
public final LongProperty loadDelayInMillisProperty()

The delay in milliseconds before the loading service will actually try to retrieve the data from (for example) a backend. This delay is around a few hundred milliseconds by default. Delaying the loading has the advantage that sudden property changes will not trigger multiple backend queries but will get batched together in a single reload operation.

Returns:LongProperty

the delay before data will actually be loaded

loaderPropertyback to summary
public final ObjectProperty<Callback<PagingLoadRequest, PagingLoadResponse<T>>> loaderProperty()
pagePropertyback to summary
public final IntegerProperty pageProperty()

The index of the currently showing page.

Returns:IntegerProperty

the number of the currently showing page

pageSizePropertyback to summary
public final IntegerProperty pageSizeProperty()

The number of items shown per page of the control that is being controlled by the pagination control.

Returns:IntegerProperty

the number of items per page

setLoadDelayInMillisback to summary
public final void setLoadDelayInMillis(long loadDelayInMillis)