APIdia Launch Partner
Top Description Fields Constructors Methods
javafx.scene.control.cell

public Class TreeItemPropertyValueFactory<S, T>

extends Object
implements Callback<TreeTableColumn.CellDataFeatures<S, T>, ObservableValue<T>>
Class Inheritance
All Implemented Interfaces
javafx.util.Callback
Type Parameters
<S>
the TableView type
<T>
the TreeTableColumn type
Imports
javafx.beans.NamedArg, javafx.beans.property.ReadOnlyObjectWrapper, javafx.beans.value.ObservableValue, javafx.scene.control.TreeItem, .TreeTableCell, .TreeTableColumn, .TreeTableColumn.CellDataFeatures, .TreeTableView, javafx.util.Callback, com.sun.javafx.property.PropertyReference, com.sun.javafx.scene.control.Logging, com.sun.javafx.logging.PlatformLogger, .PlatformLogger.Level

A convenience implementation of the Callback interface, designed specifically for use within the TreeTableColumn 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 the TreeItem instances used in the TreeTableView. The class Person must be declared public. TreeItemPropertyValueFactory uses the constructor argument, "firstName", to assume that Person has a public method firstNameProperty with no formal parameters and a return type of ObservableValue<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 the TreeTableCell. In addition, the TreeTableView adds an observer to the return value, such that any changes fired will be observed by the TreeTableView, resulting in the cell immediately updating.

If no such method exists, then TreeItemPropertyValueFactory assumes that Person has a public method getFirstName or isFirstName with no formal parameters and a return type of String. If such a method exists, then it is invoked, and its return value is wrapped in a ReadOnlyObjectWrapper and returned to the TreeTableCell. In this situation, the TreeTableCell 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 module opens the containing package to at least the javafx.base module. Otherwise the call(TreeTableColumn.CellDataFeatures) method will log a warning and return null.

For example, if the Person class is in the com.foo package in the foo.app module, the module-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

Field Summary

Modifier and TypeField and Description
private Class<?>
private String
private final String
private PropertyReference<T>

Constructor Summary

AccessConstructor and Description
public
TreeItemPropertyValueFactory(String
The name of the property with which to attempt to reflectively extract a corresponding value for in a given object.
property
)

Creates a default PropertyValueFactory to extract the value from a given TableView row item reflectively, using the given property name.

Method Summary

Modifier and TypeMethod and Description
public ObservableValue<T>
call(TreeTableColumn.CellDataFeatures<S, T> param)

Implements javafx.util.Callback.call.

The call 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.

private ObservableValue<T>
public final String

Returns:

the property name provided in the constructor
getProperty
()

Returns the property name provided in the constructor.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

columnClassback to summary
private Class<?> columnClass
previousPropertyback to summary
private String previousProperty
propertyback to summary
private final String property
propertyRefback to summary
private PropertyReference<T> propertyRef

Constructor Detail

TreeItemPropertyValueFactoryback to summary
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:String

The name of the property with which to attempt to reflectively extract a corresponding value for in a given object.

Method Detail

callback to summary
public ObservableValue<T> call(TreeTableColumn.CellDataFeatures<S, T> param)

Implements javafx.util.Callback.call.

Doc from javafx.util.Callback.call.

The call 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.

Annotations
@Override
getCellDataReflectivelyback to summary
private ObservableValue<T> getCellDataReflectively(S rowData)
getPropertyback to summary
public final String getProperty()

Returns the property name provided in the constructor.

Returns:String

the property name provided in the constructor