0

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]
Toni_Entranced
  • 969
  • 2
  • 12
  • 29
  • Remember http://stackoverflow.com/questions/23822550/listview-is-not-reflecting-changes/23828608#23828608 ? – James_D Sep 07 '14 at 13:56
  • Ah yes, I remember! Does this mean that I have to provide an extractor and manually map EVERY property each time? I feel like I could provide the PlanItem with its own BooleanProperty changed, and have that triggered somehow whenever any of the other setters are called. But that would mean it would get triggered multiple times. If I change 5 properties, I only want it to fire the update once. Also, I noticed that wasUpdated() was actually triggered in my custom list binding. – Toni_Entranced Sep 07 '14 at 20:57
  • don't understand the logic: if a change in a property requires an update in the list, so be it - if not, don't addd that property. Why would you want to be notified "only once"? And once per-what? – kleopatra Sep 09 '14 at 09:24
  • Let's say I'm in another window and am currently modifying an item from an ObservableList. This editor window lets you preview its properties and lets you enter in new ones. As you hit save, that item gets a multitude of setXYZ() calls. Naturally, this would fire the wasUpdated() flag as many times as those setters are called. That seems a bit wasteful on resources, because you'd be calling set() repeatedly. I just want it called once after all the setters have been called. – Toni_Entranced Sep 09 '14 at 09:32

0 Answers0