it seems I have encountered a problem with ListProperties. ObservableLists implement the marker interface SortableList that allows them to be sorted efficiently, firing only a single event. ListProperties do not implement this interface (how could they...?). Instead they use the default implementation of the List interface, firing a lot of changes.
The only solution I can see would be to call sort() on the underlying List directly. But this collides with the scheme of returning the Property itself:
public ObservableList getSomeList()
{
return someListProperty();
}
which ensures that ListChangeListener remain registered when the underlying List is exchanged.
I would be happy to get some input, maybe I missed something?
I guess the
SortableListyou refer to is the one used inFXCollections.sort.ListPropertycould implement theSortableListinterface.It may indeed be a good idea, since this would allow you to choose the way the wrapped list is sorted, if e.g.
FXCollections.sortis used on the property. You could useFXCollections.sorton the contained list in this case.How could they? Like this:
The only problem is, that
SortableListis inside thecom.sun.javafx.collectionspackage (see It is a bad practice to use Sun's proprietary Java classes?).About your collision with the property scheme: there is none, if you define the property the intended way, see Using JavaFX Properties and Binding section Understanding Properties
The property would be implemented like this:
The
ListPropertyhas to ensure theListChangeListeners registered to it receive the change events from the wrapped list.Maybe you got confused with readonly list properties used in fxml, but a
ListPropertyis not readonly.You could still use this property in a fxml file, but you'd need to use a value of type
ObservableList: