|
17 | 17 |
|
18 | 18 |
|
19 | 19 | import javafx.beans.value.ObservableValue; |
| 20 | +import javafx.collections.ObservableList; |
20 | 21 | import javafx.event.ActionEvent; |
21 | 22 | import javafx.event.Event; |
22 | 23 | import javafx.event.EventType; |
|
27 | 28 | import javafx.stage.Window; |
28 | 29 | import javafx.stage.WindowEvent; |
29 | 30 | import rx.Observable; |
| 31 | +import rx.functions.Func1; |
30 | 32 | import rx.javafx.sources.*; |
31 | 33 |
|
32 | 34 |
|
@@ -117,4 +119,73 @@ public static Observable<ActionEvent> fromActionEvents(final ContextMenu context |
117 | 119 | public static Observable<ActionEvent> fromActionEvents(final MenuItem menuItem) { |
118 | 120 | return ActionEventSource.fromActionEvents(menuItem); |
119 | 121 | } |
| 122 | + |
| 123 | + /** |
| 124 | + * Creates an observable that emits an ObservableList every time it is modified |
| 125 | + * |
| 126 | + * @param source The target ObservableList of the ListChange events |
| 127 | + * @return An Observable emitting the ObservableList each time it changes |
| 128 | + */ |
| 129 | + public static <T> Observable<ObservableList<T>> fromObservableList(final ObservableList<T> source) { |
| 130 | + return ObservableListSource.fromObservableList(source); |
| 131 | + } |
| 132 | + /** |
| 133 | + * Creates an observable that emits all additions to an ObservableList |
| 134 | + * |
| 135 | + * @param source The target ObservableList for the item add events |
| 136 | + * @return An Observable emitting items added to the ObservableList |
| 137 | + */ |
| 138 | + public static <T> Observable<T> fromObservableListAdds(final ObservableList<T> source) { |
| 139 | + return ObservableListSource.fromObservableListAdds(source); |
| 140 | + } |
| 141 | + /** |
| 142 | + * Creates an observable that emits all removal items from an ObservableList |
| 143 | + * |
| 144 | + * @param source The target ObservableList for the item removal events |
| 145 | + * @return An Observable emitting items removed from the ObservableList |
| 146 | + */ |
| 147 | + public static <T> Observable<T> fromObservableListRemovals(final ObservableList<T> source) { |
| 148 | + return ObservableListSource.fromObservableListRemovals(source); |
| 149 | + } |
| 150 | + /** |
| 151 | + * Creates an observable that emits all updated items from an ObservableList. |
| 152 | + * If you declare an ObservableList that listens to one or more properties of each element, |
| 153 | + * you can emit the changed items every time these properties are modified |
| 154 | + * <pre>ObservableList<Person> sourceList = FXCollections.observableArrayList(user -> new javafx.beans.Observable[]{user.age} );</pre> |
| 155 | + * @param source The target ObservableList for the item update events |
| 156 | + * |
| 157 | + * @return An Observable emitting items updated in the ObservableList |
| 158 | + */ |
| 159 | + public static <T> Observable<T> fromObservableListUpdates(final ObservableList<T> source) { |
| 160 | + return ObservableListSource.fromObservableListUpdates(source); |
| 161 | + } |
| 162 | + |
| 163 | + /** |
| 164 | + * Emits all added, removed, and updated items from an ObservableList |
| 165 | + * @param source |
| 166 | + * @return An Observable emitting changed items with an ADDED, REMOVED, or UPDATED flags |
| 167 | + */ |
| 168 | + public static <T> Observable<ListChange<T>> fromObservableListChanges(final ObservableList<T> source) { |
| 169 | + return ObservableListSource.fromObservableListChanges(source); |
| 170 | + } |
| 171 | + /** |
| 172 | + * Emits distinctly added and removed items from an ObservableList. |
| 173 | + * If dupe items with identical hashcode/equals evaluations are added to an ObservableList, only the first one will fire an ADDED item. |
| 174 | + * When the last dupe is removed, only then will it fire a REMOVED item. |
| 175 | + * @param source |
| 176 | + * @return An Observable emitting changed items with an ADDED, REMOVED, or UPDATED flags |
| 177 | + */ |
| 178 | + public static <T> Observable<ListChange<T>> fromObservableListDistinctChanges(final ObservableList<T> source) { |
| 179 | + return ObservableListSource.fromObservableListDistinctChanges(source); |
| 180 | + } |
| 181 | + /** |
| 182 | + * Emits distinctly added and removed mappings of each item from an ObservableList. |
| 183 | + * If dupe mapped items with identical hashcode/equals evaluations are added to an ObservableList, only the first one will fire an ADDED item. |
| 184 | + * When the last dupe is removed, only then will it fire a REMOVED item. |
| 185 | + * @param source |
| 186 | + * @return An Observable emitting changed mapped items with an ADDED, REMOVED, or UPDATED flags |
| 187 | + */ |
| 188 | + public static <T,R> Observable<ListChange<R>> fromObservableListDistinctMappings(final ObservableList<T> source, Func1<T,R> mapper) { |
| 189 | + return ObservableListSource.fromObservableListDistinctMappings(source,mapper); |
| 190 | + } |
120 | 191 | } |
0 commit comments