Reputation: 83
I want to trigger some code when a object called EventShowable have been modified in an observableList. Here is my code.
mainApp.getCalendars().get(i).getListEvents().addListener(new ListChangeListener<EventShowable>() {
@Override
public void onChanged(ListChangeListener.Change<? extends EventShowable> c) {
while (c.next()) {
if (c.wasUpdated()) {
//this doesn't work.
//perform updated
}
if (c.wasAdded()){
//perform something }
The wasAdded() perform well but not the wasUpdate(). How to get something that works when a EventShowable have been modified ? Thanks
P.S : in the JavaDoc : public boolean wasUpdated() Indicates that the elements between getFrom() (inclusive) to getTo() exclusive has changed. This is the only optional event type and may not be fired by all ObservableLists. https://docs.oracle.com/javase/8/javafx/api/javafx/collections/ListChangeListener.Change.html#wasUpdated--
Upvotes: 2
Views: 765
Reputation: 209398
Create your list using an extractor
.
You haven't really given enough detail to give a complete answer, but if your EventShowable
defines properties such as
public class EventShowable {
public IntegerProperty xProperty() { ... }
public StringProperty yProperty() { ... }
// ...
}
then to create a list that fires update events when x
or y
change you do
ObservableList<EventShowable> listEvents =
FXCollections.observableArrayList(eventShowable ->
new Observable[] { eventShowable.xProperty(), eventShowable.yProperty() });
Upvotes: 2