Use FXCollections instead of not existing ObservableListWrapper

This commit is contained in:
Christoph Atteneder 2018-09-07 14:04:56 +02:00
parent 8ed7f4218f
commit 13266b26da
No known key found for this signature in database
GPG Key ID: CD5DC1C529CDFD3B
4 changed files with 17 additions and 11 deletions

View File

@ -204,7 +204,7 @@ public class OfferBookChartView extends ActivatableViewAndModel<VBox, OfferBookC
}
});
model.currencyListItems.addListener(currencyListItemsListener);
model.currencyListItems.getObservableList().addListener(currencyListItemsListener);
model.getOfferBookListItems().addListener(changeListener);
tradeCurrencySubscriber = EasyBind.subscribe(model.selectedTradeCurrencyProperty,
@ -295,7 +295,7 @@ public class OfferBookChartView extends ActivatableViewAndModel<VBox, OfferBookC
protected void deactivate() {
model.getOfferBookListItems().removeListener(changeListener);
tabPaneSelectionModel.selectedIndexProperty().removeListener(selectedTabIndexListener);
model.currencyListItems.removeListener(currencyListItemsListener);
model.currencyListItems.getObservableList().removeListener(currencyListItemsListener);
tradeCurrencySubscriber.unsubscribe();
currencyComboBox.setOnAction(null);
buyOfferTableView.getSelectionModel().selectedItemProperty().removeListener(buyTableRowSelectionListener);

View File

@ -234,11 +234,11 @@ class OfferBookChartViewModel extends ActivatableViewModel {
}
public ObservableList<CurrencyListItem> getCurrencyListItems() {
return currencyListItems;
return currencyListItems.getObservableList();
}
public Optional<CurrencyListItem> getSelectedCurrencyListItem() {
return currencyListItems.stream().filter(e -> e.tradeCurrency.equals(selectedTradeCurrencyProperty.get())).findAny();
return currencyListItems.getObservableList().stream().filter(e -> e.tradeCurrency.equals(selectedTradeCurrencyProperty.get())).findAny();
}
public int getMaxNumberOfPriceZeroDecimalsToColorize(Offer offer) {

View File

@ -220,11 +220,11 @@ class TradesChartsViewModel extends ActivatableViewModel {
}
public ObservableList<CurrencyListItem> getCurrencyListItems() {
return currencyListItems;
return currencyListItems.getObservableList();
}
public Optional<CurrencyListItem> getSelectedCurrencyListItem() {
return currencyListItems.stream().filter(e -> e.tradeCurrency.equals(selectedTradeCurrencyProperty.get())).findAny();
return currencyListItems.getObservableList().stream().filter(e -> e.tradeCurrency.equals(selectedTradeCurrencyProperty.get())).findAny();
}
///////////////////////////////////////////////////////////////////////////////////////////

View File

@ -22,7 +22,8 @@ import bisq.core.user.Preferences;
import com.google.common.collect.Lists;
import com.sun.javafx.collections.ObservableListWrapper;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import java.util.ArrayList;
import java.util.Comparator;
@ -36,25 +37,30 @@ import java.util.function.BiFunction;
import javax.annotation.Nullable;
public class CurrencyList extends ObservableListWrapper<CurrencyListItem> {
public class CurrencyList {
private final CurrencyPredicates predicates;
private final Preferences preferences;
private final List<CurrencyListItem> delegate;
public CurrencyList(Preferences preferences) {
this(new ArrayList<>(), preferences, new CurrencyPredicates());
}
CurrencyList(List<CurrencyListItem> delegate, Preferences preferences, CurrencyPredicates predicates) {
super(delegate);
public CurrencyList(List<CurrencyListItem> delegate, Preferences preferences, CurrencyPredicates predicates) {
this.delegate = delegate;
this.predicates = predicates;
this.preferences = preferences;
}
public ObservableList<CurrencyListItem> getObservableList() {
return FXCollections.observableList(delegate);
}
public void updateWithCurrencies(List<TradeCurrency> currencies, @Nullable CurrencyListItem first) {
List<CurrencyListItem> result = Lists.newLinkedList();
Optional.ofNullable(first).ifPresent(result::add);
result.addAll(getPartitionedSortedItems(currencies));
setAll(result);
delegate.addAll(result);
}
private List<CurrencyListItem> getPartitionedSortedItems(List<TradeCurrency> currencies) {