This content has been marked as final. Show 2 replies
It's not exactly the same, but ObservableLists can report changes to properties in the elements of the list if you specify an "extractor" for them. The mechanism they use is that you create an ObservableList<T> and specify a Callback<T, Observable) which returns an array of properties to be observed for each item in the list. You could try to emulate this for ObjectProperty<T>.1 person found this helpful
See the javadocs at http://docs.oracle.com/javafx/2/api/javafx/collections/FXCollections.html#observableList(java.util.List, javafx.util.Callback) which contains a (very) brief description. [Note the part in parentheses is part of the link, the forum formatting will likely remove these so you may need to copy and paste into the browser to get the link to the correct anchor in the page.]
There are some subtleties in implementing this. Obviously you register listeners with the properties the extractor returns, but if set(...) is called on the "outer" object property, you need to remove those listeners and register them with the new value.
You can do something similar to what I do in this code:1 person found this helpful
where canSave is a BooleanProperty in the Editor class contained in the editor property.
saveItem.disableProperty().bind(Bindings.selectBoolean(editorProperty(), "canSave").not()); // NOI18N.
And then set a listener on the BooleanBinding that is returned by selectBoolean().
Edited by: bouye on Jan 25, 2013 1:03 PM