I am trying to understand some code from the following source:
http://code.makery.ch/library/javafx-8-tutorial/part3/
The specific line i am still curious about is the following one:
personTable.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> showPersonDetails(newValue));
I believe that my first understanding of the javadoc was not correct; especially on this part ([...].selectedItemProperty().[...]
):
I was asking myself why we are only adding one listener while we may have several dataobjects but now my understanding is the following and it would be nice to know if it is correct:
What the doc means is that "selectedItem" itself is the property (not the underlying data!)which represents a row that is selected/selection-changed at runtime, so the change method of our Listener is then evoked when the user changes the selected row. Then the synchronization with the underlying datamodel takes place via the change(...)
method of the ChangeListener
Interface, which gets the corresponding dataobjects from the udnerlying datamodel to work on. So from my understanding i would probably raise an exception if i didn't do a correct setItems(...)
on my TableView.
Is this correct so far?
If yes, i have got a follow up question: ReadOnlyObjectProperty
implements both Observable
and ObservableValue
which both have the method addListener
. Is it correct that the Lambda-Expression is resolved correctly by checking the list of parameters of the two methods of the two possible functional interfaces which could be argument to either one of the addListener(...)
methods? That point seemd rather complex to me.