/* * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * * * * * * * * * * * * * */ package javafx.scene.control.cell; import javafx.beans.NamedArg; import javafx.beans.property.Property; import javafx.beans.property.ReadOnlyObjectWrapper; import javafx.beans.value.ObservableValue; import javafx.scene.control.TreeItem; import javafx.scene.control.TreeTableColumn; import javafx.scene.control.TreeTableColumn.CellDataFeatures; import javafx.util.Callback; import com.sun.javafx.property.PropertyReference; import com.sun.javafx.scene.control.Logging; import sun.util.logging.PlatformLogger; import sun.util.logging.PlatformLogger.Level; /** * A convenience implementation of the Callback interface, designed specifically * for use within the {@link TreeTableColumn} * {@link TreeTableColumn#cellValueFactoryProperty() 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, the "firstName" string is used as a reference to an assumed
* firstNameProperty()
method in the Person
class type
* (which is the class type of the TreeTableView). Additionally, this method must
* return a {@link Property} instance. If a method meeting these requirements
* is found, then the {@link javafx.scene.control.TreeTableCell} is populated with this ObservableValueIf no method matching this pattern exists, there is fall-through support
* for attempting to call get<property>() or is<property>() (that is,
* getFirstName()
or isFirstName()
in the example
* above). If a method matching this pattern exists, the value returned from this method
* is wrapped in a {@link ReadOnlyObjectWrapper} and returned to the TreeTableCell.
* However, in this situation, this means that the TreeTableCell will not be able
* to observe the ObservableValue for changes (as is the case in the first
* approach above).
*
*
For reference (and as noted in the TreeTableColumn * {@link TreeTableColumn#cellValueFactory 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 instance for a particular
* // TreeTableView row, and the second getValue() call returns the
* // Person instance contained within the TreeItem.
* return p.getValue().getValue().firstNameProperty();
* }
* });
* }
*
*
* @see TreeTableColumn
* @see javafx.scene.control.TreeTableView
* @see javafx.scene.control.TreeTableCell
* @see PropertyValueFactory
* @see MapValueFactory
* @since JavaFX 8.0
*/
public class TreeItemPropertyValueFactory