If I have an SortedList<PlanItem>
objects sorted by their IntegerProperty rankProperty
, and decide to edit those items (in their source list), how do I know a change has occurred? If I use list.get(2).setRank(3)
, for example, then I need for the SortedList to respond and rearrange itself. I do not intend to go through each one and add a listener to their properties. There might be 30 properties, for instance. I just want to let the ObsList know that a change has occurred.
So far, the only way I know is to treat the PlanItems as immutable and only use set() on the editing index. That way, the SortedList DOES catch the changes. But I want to make my PlanItems mutable. It makes the coding logic much easier (although not very thread safe).
Update: the following triggers wasUpdated() in the ListChangeListener. I only want it triggered once though.
PlanItem a = new PlanItem(), b = new PlanItem();
ObservableList<PlanItem> src = FXCollections.observableArrayList((PlanItem param) -> {
return new Observable[]{param.nameProperty(), param.magnitudeProperty()};
});
src.addAll(a, b);
ObservableList<String> bound = FXCollections.observableArrayList();
CustomBindings.bindLists(bound, src, PlanItem::getName);
System.out.println(src);
System.out.println(bound);
src.get(0).setName("NEW");
src.get(0).setMagnitude(4);
System.out.println("SRC: " + src);
System.out.println("BD: " + bound);
[DEFAULT_NAME [DKJA31], DEFAULT_NAME [9IHCDC]]
[DEFAULT_NAME, DEFAULT_NAME]
UPDATED
UPDATED
SRC: [NEW [DKJA31], DEFAULT_NAME [9IHCDC]]
BD: [DEFAULT_NAME, DEFAULT_NAME]