Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UI filter box. #6525

Merged
merged 1 commit into from Jan 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions desktop/src/main/java/bisq/desktop/components/list/FilterBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,33 @@ public void initialize(FilteredList<? extends FilterableListItem> filteredList,
TableView<? extends FilterableListItem> tableView) {
this.filteredList = filteredList;
listener = (observable, oldValue, newValue) -> {
tableView.getSelectionModel().clearSelection();
applyFilteredListPredicate(textField.getText());
applyFilter(tableView, null);
};
}

public void initializeWithCallback(FilteredList<? extends FilterableListItem> filteredList,
TableView<? extends FilterableListItem> 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<? extends FilterableListItem> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
Expand Down Expand Up @@ -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"));
}

Expand All @@ -182,7 +183,6 @@ protected void activate() {

btcWalletService.addBalanceListener(balanceListener);

numItems.setText(Res.get("shared.numItemsLabel", sortedList.size()));
exportButton.setOnAction(event -> {
ObservableList<TableColumn<LockedListItem, ?>> tableColumns = tableView.getColumns();
int reportColumns = tableColumns.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
Expand Down Expand Up @@ -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, () ->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yonson2023 Why is that not inside initialize()?

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<TableColumn<ReservedListItem, ?>> tableColumns = tableView.getColumns();
int reportColumns = tableColumns.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
Expand Down Expand Up @@ -231,23 +230,25 @@ 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);

scene = root.getScene();
if (scene != null)
scene.addEventHandler(KeyEvent.KEY_RELEASED, keyEventEventHandler);

numItems.setText(Res.get("shared.numItemsLabel", sortedList.size()));
exportButton.setOnAction(event -> {
final ObservableList<TableColumn<TransactionsListItem, ?>> tableColumns = tableView.getColumns();
final int reportColumns = tableColumns.size() - 1; // CSV report excludes the last column (an icon)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<UnconfirmedBsqSwapsListItem> headerConverter = item -> {
String[] columns = new String[ColumnNames.values().length];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ClosedTradesListItem> headerConverter = item -> {
String[] columns = new String[ColumnNames.values().length];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TableColumn<FailedTradesListItem, ?>> tableColumns = tableView.getColumns();
int reportColumns = tableColumns.size() - 1; // CSV report excludes the last column (an icon)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -261,7 +261,6 @@ protected void activate() {
tableView.refresh();
});

updateNumberOfOffers();
exportButton.setOnAction(event -> {
CSVEntryConverter<OpenOfferListItem> headerConverter = item -> {
String[] columns = new String[ColumnNames.values().length];
Expand Down