From d4dae4b6b1f773198b16299f10028603bbd96db5 Mon Sep 17 00:00:00 2001 From: jmacxx <47253594+jmacxx@users.noreply.github.com> Date: Mon, 16 Mar 2020 08:58:46 -0500 Subject: [PATCH] Sort order of offers appropriately by min/max range This change fixes an issue with sorting the offer list when the amount is shown as a range. In OfferBookView::activate() we add a listener for the sortTypeProperty on amountColumn and volumeColumn. When the sortType is changed we set the comparator to be the approprate property of the Offer; either getAmount/getMinAmount; getVolume/getMinVolume. Fixes #3818 --- .../main/offer/offerbook/OfferBookView.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java index f11a1e7f285..f91c593dd0e 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java @@ -241,8 +241,8 @@ public void initialize() { Comparator.nullsFirst(Comparator.naturalOrder()) )); priceColumn.setComparator(Comparator.comparing(o -> o.getOffer().getPrice(), Comparator.nullsFirst(Comparator.naturalOrder()))); - amountColumn.setComparator(Comparator.comparing(o -> o.getOffer().getAmount())); - volumeColumn.setComparator(Comparator.comparing(o -> o.getOffer().getVolume(), Comparator.nullsFirst(Comparator.naturalOrder()))); + amountColumn.setComparator(Comparator.comparing(o -> o.getOffer().getMinAmount())); + volumeColumn.setComparator(Comparator.comparing(o -> o.getOffer().getMinVolume(), Comparator.nullsFirst(Comparator.naturalOrder()))); paymentMethodColumn.setComparator(Comparator.comparing(o -> o.getOffer().getPaymentMethod())); avatarColumn.setComparator(Comparator.comparing(o -> o.getOffer().getOwnerNodeAddress().getFullAddress())); @@ -293,6 +293,21 @@ protected void activate() { model.priceSortTypeProperty.addListener((observable, oldValue, newValue) -> priceColumn.setSortType(newValue)); priceColumn.setSortType(model.priceSortTypeProperty.get()); + amountColumn.sortTypeProperty().addListener((observable, oldValue, newValue) -> { + if (newValue == TableColumn.SortType.DESCENDING) { + amountColumn.setComparator(Comparator.comparing(o -> o.getOffer().getAmount(), Comparator.nullsFirst(Comparator.naturalOrder()))); + } else { + amountColumn.setComparator(Comparator.comparing(o -> o.getOffer().getMinAmount(), Comparator.nullsFirst(Comparator.naturalOrder()))); + } + }); + volumeColumn.sortTypeProperty().addListener((observable, oldValue, newValue) -> { + if (newValue == TableColumn.SortType.DESCENDING) { + volumeColumn.setComparator(Comparator.comparing(o -> o.getOffer().getVolume(), Comparator.nullsFirst(Comparator.naturalOrder()))); + } else { + volumeColumn.setComparator(Comparator.comparing(o -> o.getOffer().getMinVolume(), Comparator.nullsFirst(Comparator.naturalOrder()))); + } + }); + paymentMethodComboBox.setConverter(new PaymentMethodStringConverter(paymentMethodComboBox)); paymentMethodComboBox.getEditor().getStyleClass().add("combo-box-editor-bold");