T - the type of data this provider will deliverpublic class ObjectDataProvider<T> extends java.lang.Object implements DataProvider<T>, WriteBackProvider<T>
DataProvider that allows
the retrieval and parsing of data that is represented as a single Java instance.
In case a list of entities are expected to be retrieved, a ListDataProvider
should be used. Instances of this class are typically used to populate Observable
objects.
This class requires a DataReader that either can be passed
with the constructor or using the setDataReader(io.datafx.io.DataReader)
method.
No external data will be retrieved until the retrieve() method is called.
Developers that prefer the builder approach can choose to use the
ObjectDataProviderBuilder class to create an
instance of ObjectDataProvider.
Example:
XmlConverter xmlConverter = new XmlConverter(MyEntity.class);
RestSource restSource = new RestSource(HOST, xmlConverter);
restSource.setPath("somepath");
ObjectDataProvider<MyEntity> sodp = new ObjectDataProvider(restSource);
sodp.setResultObjectProperty(model.myActiveEntity());
| Constructor and Description |
|---|
ObjectDataProvider()
Create an ObjectDataProvider.
|
ObjectDataProvider(DataReader<T> reader)
Create an ObjectDataProvider that will use the passed
reader for
retrieving the data |
ObjectDataProvider(DataReader<T> reader,
java.util.concurrent.Executor executor)
Create an ObjectDataProvider that will use the passed
reader for
retrieving the data and the executor for executing the request |
| Modifier and Type | Method and Description |
|---|---|
protected javafx.concurrent.Task<T> |
createReceiverTask(DataReader<T> reader) |
protected javafx.concurrent.Service<T> |
createService(javafx.beans.property.ObjectProperty<T> value) |
javafx.beans.property.ObjectProperty<T> |
getData()
A ObservableValue that wraps the provided Data.
|
javafx.concurrent.Worker<T> |
retrieve()
Starts to retrieve the data in a background thread and returns the Worker for
monitoring.
|
void |
setDataReader(DataReader<T> reader)
Set the DataReader that contains the data that will be provided by this
ObjectDataProvider
|
void |
setExecutor(java.util.concurrent.Executor executor)
Explicitly set the
Executor that should be
used for retrieving the data. |
void |
setResultObjectProperty(javafx.beans.property.ObjectProperty<T> result)
Convenience (backward compatible) method.
|
void |
setResultProperty(javafx.beans.property.Property<T> result)
Sets the ObjectProperty that contains the result of the data retrieval.
|
void |
setWriteBackHandler(WriteBackHandler<T> handler)
Set the
WriteBackHandler for this provider to the specified
handler. |
public ObjectDataProvider()
retrieve() method, a
DataReader instance should be set using
setDataReader(io.datafx.io.DataReader).public ObjectDataProvider(DataReader<T> reader)
reader for
retrieving the datareader - the source of the data.public ObjectDataProvider(DataReader<T> reader, java.util.concurrent.Executor executor)
reader for
retrieving the data and the executor for executing the requestreader - the source of the data.executor - the Executor that will be used for doing the call to the
data source. In case this parameter is null, a new Thread will be used.public void setDataReader(DataReader<T> reader)
reader - the source of the data.public void setExecutor(java.util.concurrent.Executor executor)
Executor that should be
used for retrieving the data.executor - the Executor instance that should be used when retrieving the datapublic void setResultProperty(javafx.beans.property.Property<T> result)
retrieve method has been called // TODO: enforce thissetResultProperty in interface DataProvider<T>result - the Property that should be filled with the retrieved valuepublic void setResultObjectProperty(javafx.beans.property.ObjectProperty<T> result)
setResultProperty(javafx.beans.property.Property).result - the Property that should be filled with the retrieved valuepublic javafx.concurrent.Worker<T> retrieve()
DataProviderWorker.valueProperty() propertyretrieve in interface DataProvider<T>protected javafx.concurrent.Task<T> createReceiverTask(DataReader<T> reader)
protected javafx.concurrent.Service<T> createService(javafx.beans.property.ObjectProperty<T> value)
public javafx.beans.property.ObjectProperty<T> getData()
DataProviderInvalidationListener or a
ChangeListener to the result of this
method will make sure that you will be notified once data is available.getData in interface DataProvider<T>ObservableValue that contains or will
contain the data obtained by this DataProvider.public void setWriteBackHandler(WriteBackHandler<T> handler)
WriteBackProviderWriteBackHandler for this provider to the specified
handler. When the provider decides to write data back to the original
datasource (that is, when data has been changed locally), the
WriteBackHandler.createDataSource(java.lang.Object) method will
be called. This method returns a WritableDataReader
that will be used to send the data to the origin, by calling the
WritableDataReader.writeBack() method.setWriteBackHandler in interface WriteBackProvider<T>handler - the handler that will be used when the provider decides to
write data back to the original source.