From ed821f721dde38bed0624f7f1c35e8631de134fb Mon Sep 17 00:00:00 2001 From: yonson2023 <122909161+yonson2023@users.noreply.github.com> Date: Tue, 17 Jan 2023 11:00:39 -0600 Subject: [PATCH] Fix UI filter box. --- .../desktop/components/list/FilterBox.java | 19 ++++++++++++++++--- .../desktop/main/funds/locked/LockedView.java | 4 ++-- .../main/funds/reserved/ReservedView.java | 6 +++--- .../funds/transactions/TransactionsView.java | 7 ++++--- .../bsqswaps/UnconfirmedBsqSwapsView.java | 4 ++-- .../closedtrades/ClosedTradesView.java | 4 ++-- .../failedtrades/FailedTradesView.java | 4 ++-- .../portfolio/openoffer/OpenOffersView.java | 3 +-- 8 files changed, 32 insertions(+), 19 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/components/list/FilterBox.java b/desktop/src/main/java/bisq/desktop/components/list/FilterBox.java index 91aca5721a7..d23a2f718bb 100644 --- a/desktop/src/main/java/bisq/desktop/components/list/FilterBox.java +++ b/desktop/src/main/java/bisq/desktop/components/list/FilterBox.java @@ -53,20 +53,33 @@ public void initialize(FilteredList filteredList, TableView tableView) { this.filteredList = filteredList; listener = (observable, oldValue, newValue) -> { - tableView.getSelectionModel().clearSelection(); - applyFilteredListPredicate(textField.getText()); + applyFilter(tableView, null); }; } + public void initializeWithCallback(FilteredList filteredList, + TableView tableView, Runnable callback) { + this.filteredList = filteredList; + listener = (observable, oldValue, newValue) -> applyFilter(tableView, callback); + applyFilter(tableView, callback); // first time init + } + public void activate() { textField.textProperty().addListener(listener); - applyFilteredListPredicate(textField.getText()); } public void deactivate() { textField.textProperty().removeListener(listener); } + private void applyFilter(TableView tableView, Runnable callback) { + tableView.getSelectionModel().clearSelection(); + applyFilteredListPredicate(textField.getText()); + if (callback != null) { + callback.run(); + } + } + private void applyFilteredListPredicate(String filterString) { filteredList.setPredicate(item -> item.match(filterString)); } diff --git a/desktop/src/main/java/bisq/desktop/main/funds/locked/LockedView.java b/desktop/src/main/java/bisq/desktop/main/funds/locked/LockedView.java index 0b5cd2e8255..9597e7058a1 100644 --- a/desktop/src/main/java/bisq/desktop/main/funds/locked/LockedView.java +++ b/desktop/src/main/java/bisq/desktop/main/funds/locked/LockedView.java @@ -132,7 +132,6 @@ private LockedView(BtcWalletService btcWalletService, @Override public void initialize() { - filterBox.initialize(filteredList, tableView); dateColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.dateTime"))); tradeIdColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.tradeId"))); detailsColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.details"))); @@ -168,6 +167,8 @@ public void onBalanceChanged(Coin balance, Transaction tx) { HBox.setHgrow(spacer, Priority.ALWAYS); numItems.setId("num-offers"); numItems.setPadding(new Insets(-5, 0, 0, 10)); + filterBox.initializeWithCallback(filteredList, tableView, () -> + numItems.setText(Res.get("shared.numItemsLabel", sortedList.size()))); exportButton.updateText(Res.get("shared.exportCSV")); } @@ -182,7 +183,6 @@ protected void activate() { btcWalletService.addBalanceListener(balanceListener); - numItems.setText(Res.get("shared.numItemsLabel", sortedList.size())); exportButton.setOnAction(event -> { ObservableList> tableColumns = tableView.getColumns(); int reportColumns = tableColumns.size(); diff --git a/desktop/src/main/java/bisq/desktop/main/funds/reserved/ReservedView.java b/desktop/src/main/java/bisq/desktop/main/funds/reserved/ReservedView.java index 446438fe07f..f06c246b54c 100644 --- a/desktop/src/main/java/bisq/desktop/main/funds/reserved/ReservedView.java +++ b/desktop/src/main/java/bisq/desktop/main/funds/reserved/ReservedView.java @@ -132,7 +132,6 @@ private ReservedView(BtcWalletService btcWalletService, @Override public void initialize() { - filterBox.initialize(filteredList, tableView); dateColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.dateTime"))); offerIdColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.offerId"))); detailsColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.details"))); @@ -173,16 +172,17 @@ public void onBalanceChanged(Coin balance, Transaction tx) { @Override protected void activate() { - filterBox.activate(); openOfferManager.getObservableList().addListener(openOfferListChangeListener); tradeManager.getObservableList().addListener(tradeListChangeListener); sortedList.comparatorProperty().bind(tableView.comparatorProperty()); tableView.setItems(sortedList); updateList(); + filterBox.initializeWithCallback(filteredList, tableView, () -> + numItems.setText(Res.get("shared.numItemsLabel", sortedList.size()))); + filterBox.activate(); btcWalletService.addBalanceListener(balanceListener); - numItems.setText(Res.get("shared.numItemsLabel", sortedList.size())); exportButton.setOnAction(event -> { ObservableList> tableColumns = tableView.getColumns(); int reportColumns = tableColumns.size(); diff --git a/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionsView.java b/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionsView.java index 08d7dc71838..8c341c91fb4 100644 --- a/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionsView.java +++ b/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionsView.java @@ -176,7 +176,6 @@ private TransactionsView(BtcWalletService btcWalletService, @Override public void initialize() { - filterBox.initialize(filteredList, tableView); dateColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.dateTime"))); tradeIdColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.tradeId"))); detailsColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.details"))); @@ -231,15 +230,18 @@ public void initialize() { HBox.setHgrow(spacer, Priority.ALWAYS); numItems.setId("num-offers"); numItems.setPadding(new Insets(-5, 0, 0, 10)); + exportButton.updateText(Res.get("shared.exportCSV")); } @Override protected void activate() { - filterBox.activate(); sortedList.comparatorProperty().bind(tableView.comparatorProperty()); tableView.setItems(sortedList); updateList(); + filterBox.initializeWithCallback(filteredList, tableView, () -> + numItems.setText(Res.get("shared.numItemsLabel", sortedList.size()))); + filterBox.activate(); btcWalletService.addChangeEventListener(walletChangeEventListener); @@ -247,7 +249,6 @@ protected void activate() { if (scene != null) scene.addEventHandler(KeyEvent.KEY_RELEASED, keyEventEventHandler); - numItems.setText(Res.get("shared.numItemsLabel", sortedList.size())); exportButton.setOnAction(event -> { final ObservableList> tableColumns = tableView.getColumns(); final int reportColumns = tableColumns.size() - 1; // CSV report excludes the last column (an icon) diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/bsqswaps/UnconfirmedBsqSwapsView.java b/desktop/src/main/java/bisq/desktop/main/portfolio/bsqswaps/UnconfirmedBsqSwapsView.java index 06675a9f404..4cde570ee87 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/bsqswaps/UnconfirmedBsqSwapsView.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/bsqswaps/UnconfirmedBsqSwapsView.java @@ -219,10 +219,10 @@ protected void activate() { tableView.setItems(sortedList); - filterBox.initialize(filteredList, tableView); // here because filteredList is instantiated here + filterBox.initializeWithCallback(filteredList, tableView, () -> + numItems.setText(Res.get("shared.numItemsLabel", sortedList.size()))); filterBox.activate(); - numItems.setText(Res.get("shared.numItemsLabel", sortedList.size())); exportButton.setOnAction(event -> { CSVEntryConverter headerConverter = item -> { String[] columns = new String[ColumnNames.values().length]; diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/closedtrades/ClosedTradesView.java b/desktop/src/main/java/bisq/desktop/main/portfolio/closedtrades/ClosedTradesView.java index e16a1bb613a..c9291ec3a2c 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/closedtrades/ClosedTradesView.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/closedtrades/ClosedTradesView.java @@ -291,10 +291,10 @@ protected void activate() { tableView.setItems(sortedList); - filterBox.initialize(filteredList, tableView); // here because filteredList is instantiated here + filterBox.initializeWithCallback(filteredList, tableView, () -> + numItems.setText(Res.get("shared.numItemsLabel", filteredList.size()))); filterBox.activate(); - numItems.setText(Res.get("shared.numItemsLabel", sortedList.size())); exportButton.setOnAction(event -> { CSVEntryConverter headerConverter = item -> { String[] columns = new String[ColumnNames.values().length]; diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/failedtrades/FailedTradesView.java b/desktop/src/main/java/bisq/desktop/main/portfolio/failedtrades/FailedTradesView.java index 7123744d268..f0aa68ced30 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/failedtrades/FailedTradesView.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/failedtrades/FailedTradesView.java @@ -181,10 +181,10 @@ protected void activate() { sortedList.comparatorProperty().bind(tableView.comparatorProperty()); tableView.setItems(sortedList); - filterBox.initialize(filteredList, tableView); // here because filteredList is instantiated here + filterBox.initializeWithCallback(filteredList, tableView, () -> + numItems.setText(Res.get("shared.numItemsLabel", sortedList.size()))); filterBox.activate(); - numItems.setText(Res.get("shared.numItemsLabel", sortedList.size())); exportButton.setOnAction(event -> { ObservableList> tableColumns = tableView.getColumns(); int reportColumns = tableColumns.size() - 1; // CSV report excludes the last column (an icon) diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/openoffer/OpenOffersView.java b/desktop/src/main/java/bisq/desktop/main/portfolio/openoffer/OpenOffersView.java index 34b10b158a0..a0c497ccc08 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/openoffer/OpenOffersView.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/openoffer/OpenOffersView.java @@ -245,7 +245,7 @@ protected void activate() { sortedList.addListener(sortedListeChangedListener); tableView.setItems(sortedList); - filterBox.initialize(filteredList, tableView); // here because filteredList is instantiated here + filterBox.initializeWithCallback(filteredList, tableView, this::updateNumberOfOffers); filterBox.activate(); updateSelectToggleButtonState(); @@ -261,7 +261,6 @@ protected void activate() { tableView.refresh(); }); - updateNumberOfOffers(); exportButton.setOnAction(event -> { CSVEntryConverter headerConverter = item -> { String[] columns = new String[ColumnNames.values().length];