/* * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ 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.TreeTableCell; import javafx.scene.control.TreeTableColumn; import javafx.scene.control.TreeTableColumn.CellDataFeatures; import javafx.scene.control.TreeTableView; 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, {@code Person} is the class type of the {@link TreeItem}
* instances used in the {@link TreeTableView}.
* {@code TreeItemPropertyValueFactory} uses the constructor argument,
* {@code "firstName"}, to assume that {@code Person} has a method
* {@code firstNameProperty} with no formal parameters and a return type of
* {@code ObservableValue
* If such a method exists, then it is invoked, and additionally assumed
* to return an instance of {@code Property
* If no such method exists, then {@code TreeItemPropertyValueFactory} * assumes that {@code Person} has a method {@code getFirstName} or * {@code isFirstName} with no formal parameters and a return type of * {@code String}. If such a method exists, then it is invoked, and its return * value is wrapped in a {@link ReadOnlyObjectWrapper} * and returned to the {@code TreeTableCell}. In this situation, * the {@code TreeTableCell} will not be able to observe changes to the property, * unlike in the first approach above. *
** The class {@code Person} must be declared public. If that class is in a named * module, then the module must {@link Module#isOpen(String,Module) open} * the containing package to at least the {@code javafx.base} module * (or {@link Module#isExported(String) export} the containing package * unconditionally). * Otherwise the {@link #call call(TreeTableColumn.CellDataFeatures)} method * will log a warning and return {@code null}. *
* *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");
* {@literal
* firstNameCol.setCellValueFactory(new Callback, ObservableValue>() {
* public ObservableValue call(CellDataFeatures 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 TreeTableView
* @see TreeTableCell
* @see PropertyValueFactory
* @see MapValueFactory
* @since JavaFX 8.0
*/
public class TreeItemPropertyValueFactory