As near as I can tell, the javafx binding using observable values, alot like jgoodies and its not like SWT databinding or WPF binding.
I was creating a cell factory for a TreeView. Just using a label to display the contents and calling toString, alot like the way it works now. However, I could not figure out to create a binding that would bind to a property on my domain object. Is there a way to specify the binding to the Label's text property so that whatever object that the cell's item's value has I can bind to a property that I specify on it e.g. the "name" property. But I could not see how to do that. Also, the only way I could figure out how to update the Label's value was from updateItem. I thought maybe I could even setup the binding in updateItem so that when the TreeItem's value changed at least it would automatically update the label binding, but the API did not seem to support that.
What's the right coding pattern to use when using straight Java coding?
I know in jgoodies I could do this using the PresentationModel approach or master-detail SWT or WPF with just specifying the property on the item's property that I want in WPF.
public static class MyTreeCell extends TreeCell<Object> {
Label label;
public MyTreeCell() {
label = new Label();
setNode(label);
}
@Override
public void updateItem(TreeItem<Object> arg0, boolean arg1) {
if (arg0 != null && arg0.getValue() != null) {
System.out.println("New value: " + arg0.getValue());
label.setText(arg0.getValue().toString());
} else {
System.out.println("New value is null and this println is called alot, why is that?");
}
super.updateItem(arg0, arg1);
}
}