- java.lang.Object
-
- javafx.scene.control.cell.TreeItemPropertyValueFactory<S,T>
-
- All Implemented Interfaces:
Callback<TreeTableColumn.CellDataFeatures<S,T>,ObservableValue<T>>
public class TreeItemPropertyValueFactory<S,T> extends Object implements Callback<TreeTableColumn.CellDataFeatures<S,T>,ObservableValue<T>>
A convenience implementation of the Callback interface, designed specifically for use within theTreeTableColumn
cell value factory
. An example of how to use this class is:TreeTableColumn<Person,String> firstNameCol = new TreeTableColumn<Person,String>("First Name"); firstNameCol.setCellValueFactory(new TreeItemPropertyValueFactory<Person,String>("firstName"));
In this example,
Person
is the class type of theTreeItem
instances used in theTreeTableView
. The classPerson
must be declared public.TreeItemPropertyValueFactory
uses the constructor argument,"firstName"
, to assume thatPerson
has a public methodfirstNameProperty
with no formal parameters and a return type ofObservableValue<String>
.If such a method exists, then it is invoked, and additionally assumed to return an instance of
Property<String>
. The return value is used to populate theTreeTableCell
. In addition, theTreeTableView
adds an observer to the return value, such that any changes fired will be observed by theTreeTableView
, resulting in the cell immediately updating.If no such method exists, then
TreeItemPropertyValueFactory
assumes thatPerson
has a public methodgetFirstName
orisFirstName
with no formal parameters and a return type ofString
. If such a method exists, then it is invoked, and its return value is wrapped in aReadOnlyObjectWrapper
and returned to theTreeTableCell
. In this situation, theTreeTableCell
will not be able to observe changes to the property, unlike in the first approach above.For reference (and as noted in the TreeTableColumn
cell value factory
documentation), the long form of the code above would be the following:TreeTableColumn<Person,String> firstNameCol = new TreeTableColumn<Person,String>("First Name"); firstNameCol.setCellValueFactory(new Callback<CellDataFeatures<Person, String>, ObservableValue<String>>() { public ObservableValue<String> call(CellDataFeatures<Person, String> p) { // p.getValue() returns the TreeItem<Person> instance for a particular // TreeTableView row, and the second getValue() call returns the // Person instance contained within the TreeItem. return p.getValue().getValue().firstNameProperty(); } }); }
Deploying an Application as a Module
If the referenced class is in a named module, then it must be reflectively accessible to the
javafx.base
module. A class is reflectively accessible if the moduleopens
the containing package to at least thejavafx.base
module. Otherwise thecall(TreeTableColumn.CellDataFeatures)
method will log a warning and returnnull
.For example, if the
Person
class is in thecom.foo
package in thefoo.app
module, themodule-info.java
might look like this:module foo.app { opens com.foo to javafx.base; }
Alternatively, a class is reflectively accessible if the module
exports
the containing package unconditionally.- Since:
- JavaFX 8.0
- See Also:
TreeTableColumn
,TreeTableView
,TreeTableCell
,PropertyValueFactory
,MapValueFactory
-
-
Constructor Summary
Constructors Constructor Description TreeItemPropertyValueFactory(String property)
Creates a default PropertyValueFactory to extract the value from a given TableView row item reflectively, using the given property name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ObservableValue<T>
call(TreeTableColumn.CellDataFeatures<S,T> param)
Thecall
method is called when required, and is given a single argument of type P, with a requirement that an object of type R is returned.String
getProperty()
Returns the property name provided in the constructor.
-
-
-
Constructor Detail
-
TreeItemPropertyValueFactory
public TreeItemPropertyValueFactory(String property)
Creates a default PropertyValueFactory to extract the value from a given TableView row item reflectively, using the given property name.- Parameters:
property
- The name of the property with which to attempt to reflectively extract a corresponding value for in a given object.
-
-
Method Detail
-
call
public ObservableValue<T> call(TreeTableColumn.CellDataFeatures<S,T> param)
Thecall
method is called when required, and is given a single argument of type P, with a requirement that an object of type R is returned.
-
getProperty
public final String getProperty()
Returns the property name provided in the constructor.- Returns:
- the property name provided in the constructor
-
-