Skip to content

Commit

Permalink
Added ObservableLists.isEmpty() utility method (returns observable bo…
Browse files Browse the repository at this point in the history
…olean)
  • Loading branch information
salmonb committed May 2, 2024
1 parent 23b5550 commit 41eb000
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import dev.webfx.platform.util.Objects;
import dev.webfx.platform.util.collection.Collections;
import dev.webfx.platform.util.function.Converter;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ObservableBooleanValue;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;

Expand Down Expand Up @@ -64,4 +66,11 @@ public static <T> void runNowAndOnListChange(ListChangeListener<T> listener, Obs
public static <T> void runOnListChange(ListChangeListener<T> listener, ObservableList<T> list) {
list.addListener(listener);
}

public static <T> ObservableBooleanValue isEmpty(ObservableList<T> list) {
SimpleBooleanProperty isEmpty = new SimpleBooleanProperty(list.isEmpty());
runOnListChange(c -> isEmpty.setValue(list.isEmpty()), list);
return isEmpty;
}

}

0 comments on commit 41eb000

Please sign in to comment.