Skip to content

Commit

Permalink
Merge pull request #5963 from xyzmaker123/transactions-filtering
Browse files Browse the repository at this point in the history
Add missing filtering on lists
  • Loading branch information
ripcurlx authored Jan 26, 2022
2 parents bd0db17 + 98a8a2e commit ffd2a92
Show file tree
Hide file tree
Showing 54 changed files with 1,406 additions and 1,651 deletions.
10 changes: 0 additions & 10 deletions core/src/main/java/bisq/core/trade/bisq_v1/TradeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,6 @@ public String getMarketDescription(Trade trade) {
return getCurrencyPair(trade.getOffer().getCurrencyCode());
}

public String getPaymentMethodNameWithCountryCode(Trade trade) {
if (trade == null)
return "";

Offer offer = trade.getOffer();
checkNotNull(offer);
checkNotNull(offer.getPaymentMethod());
return offer.getPaymentMethodNameWithCountryCode();
}

/**
* Returns a string describing a trader's role for a given trade.
* @param trade Trade
Expand Down
73 changes: 73 additions & 0 deletions desktop/src/main/java/bisq/desktop/components/list/FilterBox.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.desktop.components.list;

import bisq.desktop.components.AutoTooltipLabel;
import bisq.desktop.components.InputTextField;
import bisq.desktop.util.filtering.FilterableListItem;

import bisq.core.locale.Res;

import javafx.scene.control.TableView;
import javafx.scene.layout.HBox;

import javafx.geometry.Insets;
import javafx.beans.value.ChangeListener;
import javafx.collections.transformation.FilteredList;

public class FilterBox extends HBox {
private final InputTextField textField;
private FilteredList<? extends FilterableListItem> filteredList;

private ChangeListener<String> listener;

public FilterBox() {
super();
setSpacing(5.0);

AutoTooltipLabel label = new AutoTooltipLabel(Res.get("shared.filter"));
HBox.setMargin(label, new Insets(5.0, 0, 0, 10.0));

textField = new InputTextField();
textField.setMinWidth(500);

getChildren().addAll(label, textField);
}

public void initialize(FilteredList<? extends FilterableListItem> filteredList,
TableView<? extends FilterableListItem> tableView) {
this.filteredList = filteredList;
listener = (observable, oldValue, newValue) -> {
tableView.getSelectionModel().clearSelection();
applyFilteredListPredicate(textField.getText());
};
}

public void activate() {
textField.textProperty().addListener(listener);
applyFilteredListPredicate(textField.getText());
}

public void deactivate() {
textField.textProperty().removeListener(listener);
}

private void applyFilteredListPredicate(String filterString) {
filteredList.setPredicate(item -> item.match(filterString));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package bisq.desktop.main.funds.deposit;

import bisq.desktop.util.filtering.FilterableListItem;
import bisq.desktop.components.indicator.TxConfidenceIndicator;
import bisq.desktop.util.GUIUtil;

Expand All @@ -34,6 +35,8 @@

import com.google.common.base.Suppliers;

import org.apache.commons.lang3.StringUtils;

import javafx.scene.control.Tooltip;

import javafx.beans.property.SimpleStringProperty;
Expand All @@ -44,7 +47,7 @@
import lombok.extern.slf4j.Slf4j;

@Slf4j
class DepositListItem {
class DepositListItem implements FilterableListItem {
private final StringProperty balance = new SimpleStringProperty();
private final BtcWalletService walletService;
private Coin balanceAsCoin;
Expand Down Expand Up @@ -149,4 +152,18 @@ public Coin getBalanceAsCoin() {
public int getNumTxOutputs() {
return numTxOutputs;
}

@Override
public boolean match(String filterString) {
if (filterString.isEmpty()) {
return true;
}
if (StringUtils.containsIgnoreCase(getAddressString(), filterString)) {
return true;
}
if (StringUtils.containsIgnoreCase(getUsage(), filterString)) {
return true;
}
return getBalance().contains(filterString);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.geometry.Insets?>
<?import bisq.desktop.components.list.FilterBox?>
<VBox fx:id="root" fx:controller="bisq.desktop.main.funds.deposit.DepositView"
spacing="10" xmlns:fx="http://javafx.com/fxml">
<padding>
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0"/>
</padding>

<FilterBox fx:id="filterBox" />
<TableView fx:id="tableView" VBox.vgrow="ALWAYS">
<columns>
<TableColumn fx:id="addressColumn" minWidth="320"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import bisq.desktop.components.HyperlinkWithIcon;
import bisq.desktop.components.InputTextField;
import bisq.desktop.components.TitledGroupBg;
import bisq.desktop.components.list.FilterBox;
import bisq.desktop.main.overlays.popups.Popup;
import bisq.desktop.main.overlays.windows.QRCodeWindow;
import bisq.desktop.util.GUIUtil;
Expand Down Expand Up @@ -80,6 +81,7 @@

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;
import javafx.collections.transformation.SortedList;

import javafx.util.Callback;
Expand All @@ -91,14 +93,19 @@

import org.jetbrains.annotations.NotNull;

import static bisq.desktop.util.FormBuilder.*;
import static bisq.desktop.util.FormBuilder.addAddressTextField;
import static bisq.desktop.util.FormBuilder.addButtonCheckBoxWithBox;
import static bisq.desktop.util.FormBuilder.addInputTextField;
import static bisq.desktop.util.FormBuilder.addTitledGroupBg;

@FxmlView
public class DepositView extends ActivatableView<VBox, Void> {

@FXML
GridPane gridPane;
@FXML
FilterBox filterBox;
@FXML
TableView<DepositListItem> tableView;
@FXML
TableColumn<DepositListItem, DepositListItem> addressColumn, balanceColumn, confirmationsColumn, usageColumn;
Expand All @@ -114,7 +121,8 @@ public class DepositView extends ActivatableView<VBox, Void> {
private final CoinFormatter formatter;
private String paymentLabelString;
private final ObservableList<DepositListItem> observableList = FXCollections.observableArrayList();
private final SortedList<DepositListItem> sortedList = new SortedList<>(observableList);
private final FilteredList<DepositListItem> filteredList = new FilteredList<>(observableList);
private final SortedList<DepositListItem> sortedList = new SortedList<>(filteredList);
private BalanceListener balanceListener;
private Subscription amountTextFieldSubscription;
private ChangeListener<DepositListItem> tableViewSelectionListener;
Expand All @@ -135,7 +143,7 @@ private DepositView(BtcWalletService walletService,

@Override
public void initialize() {

filterBox.initialize(filteredList, tableView);
paymentLabelString = Res.get("funds.deposit.fundBisqWallet");
addressColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.address")));
balanceColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.balanceWithCur", Res.getBaseCurrencyCode())));
Expand Down Expand Up @@ -238,6 +246,8 @@ public void onBalanceChanged(Coin balance, Transaction tx) {

@Override
protected void activate() {
filterBox.activate();

tableView.getSelectionModel().selectedItemProperty().addListener(tableViewSelectionListener);
sortedList.comparatorProperty().bind(tableView.comparatorProperty());

Expand All @@ -255,6 +265,7 @@ protected void activate() {

@Override
protected void deactivate() {
filterBox.deactivate();
tableView.getSelectionModel().selectedItemProperty().removeListener(tableViewSelectionListener);
sortedList.comparatorProperty().unbind();
observableList.forEach(DepositListItem::cleanup);
Expand All @@ -267,7 +278,6 @@ protected void deactivate() {
// UI handlers
///////////////////////////////////////////////////////////////////////////////////////////


private void fillForm(String address) {
titledGroupBg.setVisible(true);
titledGroupBg.setManaged(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

package bisq.desktop.main.funds.locked;

import bisq.desktop.util.filtering.FilterableListItem;
import bisq.desktop.components.AutoTooltipLabel;
import bisq.desktop.util.DisplayUtils;
import bisq.desktop.util.filtering.FilteringUtils;

import bisq.core.btc.listeners.BalanceListener;
import bisq.core.btc.model.AddressEntry;
Expand All @@ -32,13 +34,15 @@
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.Transaction;

import org.apache.commons.lang3.StringUtils;

import javafx.scene.control.Label;

import lombok.Getter;

import javax.annotation.Nullable;

class LockedListItem {
class LockedListItem implements FilterableListItem {
private final BalanceListener balanceListener;
private final BtcWalletService btcWalletService;
private final CoinFormatter formatter;
Expand Down Expand Up @@ -117,4 +121,28 @@ public String getDateString() {
DisplayUtils.formatDateTime(trade.getDate()) :
Res.get("shared.noDateAvailable");
}

@Override
public boolean match(String filterString) {
if (filterString.isEmpty())
return true;

if (StringUtils.containsIgnoreCase(getDetails(), filterString)) {
return true;
}

if (StringUtils.containsIgnoreCase(getDateString(), filterString)) {
return true;
}

if (StringUtils.containsIgnoreCase(getAddressString(), filterString)) {
return true;
}

if (StringUtils.containsIgnoreCase(getBalanceString(), filterString)) {
return true;
}

return FilteringUtils.match(getTrade(), filterString);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@
<?import javafx.scene.layout.Region?>
<?import javafx.scene.layout.VBox?>
<?import javafx.geometry.Insets?>
<?import bisq.desktop.components.list.FilterBox?>
<VBox fx:id="root" fx:controller="bisq.desktop.main.funds.locked.LockedView"
spacing="10" xmlns:fx="http://javafx.com/fxml">
<padding>
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0"/>
</padding>

<FilterBox fx:id="filterBox" />
<TableView fx:id="tableView" VBox.vgrow="ALWAYS">
<columns>
<TableColumn fx:id="dateColumn" minWidth="180" maxWidth="180"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import bisq.desktop.components.AutoTooltipLabel;
import bisq.desktop.components.ExternalHyperlink;
import bisq.desktop.components.HyperlinkWithIcon;
import bisq.desktop.components.list.FilterBox;
import bisq.desktop.main.overlays.windows.OfferDetailsWindow;
import bisq.desktop.main.overlays.windows.TradeDetailsWindow;
import bisq.desktop.util.GUIUtil;
Expand Down Expand Up @@ -71,6 +72,7 @@
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;
import javafx.collections.transformation.SortedList;

import javafx.util.Callback;
Expand All @@ -83,6 +85,8 @@

@FxmlView
public class LockedView extends ActivatableView<VBox, Void> {
@FXML
FilterBox filterBox;
@FXML
TableView<LockedListItem> tableView;
@FXML
Expand All @@ -102,7 +106,8 @@ public class LockedView extends ActivatableView<VBox, Void> {
private final OfferDetailsWindow offerDetailsWindow;
private final TradeDetailsWindow tradeDetailsWindow;
private final ObservableList<LockedListItem> observableList = FXCollections.observableArrayList();
private final SortedList<LockedListItem> sortedList = new SortedList<>(observableList);
private final FilteredList<LockedListItem> filteredList = new FilteredList<>(observableList);
private final SortedList<LockedListItem> sortedList = new SortedList<>(filteredList);
private BalanceListener balanceListener;
private ListChangeListener<OpenOffer> openOfferListChangeListener;
private ListChangeListener<Trade> tradeListChangeListener;
Expand Down Expand Up @@ -131,6 +136,7 @@ private LockedView(BtcWalletService btcWalletService,

@Override
public void initialize() {
filterBox.initialize(filteredList, tableView);
dateColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.dateTime")));
detailsColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.details")));
addressColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.address")));
Expand Down Expand Up @@ -168,6 +174,7 @@ 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());
Expand Down Expand Up @@ -206,6 +213,7 @@ protected void activate() {

@Override
protected void deactivate() {
filterBox.deactivate();
openOfferManager.getObservableList().removeListener(openOfferListChangeListener);
tradeManager.getObservableList().removeListener(tradeListChangeListener);
sortedList.comparatorProperty().unbind();
Expand Down
Loading

0 comments on commit ffd2a92

Please sign in to comment.