package scenegraphdemo; import javafx.beans.binding.Bindings; import javafx.beans.property.ObjectProperty; import javafx.scene.Node; import javafx.scene.control.Cell; import javafx.scene.control.Label; import javafx.scene.text.Text; /** * A data template that produces the UI by transforming (through binding) the * domain object into a hierarchy of nodes. The default data template transforms * the property factory's bean into a string with toString(). The data template * should be associated with the cell with the applyTo method. This * sets up data binding with the node and editing * property in order to drive node creation in this class. New content should be * created on each loadContent method call. * * @author Mr. Java * */ public class DataTemplate extends Template { Class targetType; public Class getTargetType() { return targetType; } public DataTemplate(Class targetType) { this.targetType = targetType; } public void applyTo(Cell cell) { applyTo(cell, "item"); } public void applyTo(Cell cell, String... path) { BeanPropertyFactory factory = new BeanPropertyFactory( Bindings.select(cell, path)); Node node = loadContent(factory); cell.setNode(node); } protected Node loadContent(BeanPropertyFactory factory) { Label label = new Label(); label.textProperty().bind(factory.beanStringProperty()); return label; } }