mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 07:07:43 +01:00
Add missing filtering on lists - adapt PendingTradesView to use FilterBox
This commit is contained in:
parent
75b9902e97
commit
752606d788
6 changed files with 67 additions and 100 deletions
|
@ -175,16 +175,6 @@ public class TradeUtil {
|
|||
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
|
||||
|
|
|
@ -57,6 +57,7 @@ import bisq.core.trade.protocol.bisq_v1.DisputeProtocol;
|
|||
import bisq.core.trade.protocol.bisq_v1.SellerProtocol;
|
||||
import bisq.core.user.Preferences;
|
||||
import bisq.core.util.FormattingUtils;
|
||||
import bisq.core.util.coin.CoinFormatter;
|
||||
|
||||
import bisq.network.p2p.P2PService;
|
||||
|
||||
|
@ -71,6 +72,8 @@ import org.bitcoinj.core.TransactionConfidence;
|
|||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
|
@ -109,6 +112,7 @@ public class PendingTradesDataModel extends ActivatableDataModel {
|
|||
public final WalletPasswordWindow walletPasswordWindow;
|
||||
private final NotificationCenter notificationCenter;
|
||||
private final OfferUtil offerUtil;
|
||||
private final CoinFormatter btcFormatter;
|
||||
|
||||
final ObservableList<PendingTradesListItem> list = FXCollections.observableArrayList();
|
||||
private final ListChangeListener<Trade> tradesListChangeListener;
|
||||
|
@ -145,7 +149,8 @@ public class PendingTradesDataModel extends ActivatableDataModel {
|
|||
Navigation navigation,
|
||||
WalletPasswordWindow walletPasswordWindow,
|
||||
NotificationCenter notificationCenter,
|
||||
OfferUtil offerUtil) {
|
||||
OfferUtil offerUtil,
|
||||
@Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter formatter) {
|
||||
this.tradeManager = tradeManager;
|
||||
this.btcWalletService = btcWalletService;
|
||||
this.pubKeyRing = pubKeyRing;
|
||||
|
@ -161,6 +166,7 @@ public class PendingTradesDataModel extends ActivatableDataModel {
|
|||
this.walletPasswordWindow = walletPasswordWindow;
|
||||
this.notificationCenter = notificationCenter;
|
||||
this.offerUtil = offerUtil;
|
||||
this.btcFormatter = formatter;
|
||||
|
||||
tradesListChangeListener = change -> onListChanged();
|
||||
notificationCenter.setSelectItemByTradeIdConsumer(this::selectItemByTradeId);
|
||||
|
@ -381,7 +387,7 @@ public class PendingTradesDataModel extends ActivatableDataModel {
|
|||
private void onListChanged() {
|
||||
list.clear();
|
||||
list.addAll(tradeManager.getObservableList().stream()
|
||||
.map(PendingTradesListItem::new)
|
||||
.map(trade -> new PendingTradesListItem(trade, btcFormatter))
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
// we sort by date, earliest first
|
||||
|
|
|
@ -17,39 +17,67 @@
|
|||
|
||||
package bisq.desktop.main.portfolio.pendingtrades;
|
||||
|
||||
import bisq.core.monetary.Price;
|
||||
import bisq.core.monetary.Volume;
|
||||
import bisq.desktop.util.filtering.FilterableListItem;
|
||||
|
||||
import bisq.core.trade.model.bisq_v1.Trade;
|
||||
import bisq.core.util.FormattingUtils;
|
||||
import bisq.core.util.coin.CoinFormatter;
|
||||
|
||||
import org.bitcoinj.core.Coin;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javafx.beans.property.ReadOnlyObjectProperty;
|
||||
import static bisq.core.locale.CurrencyUtil.getCurrencyPair;
|
||||
|
||||
/**
|
||||
* We could remove that wrapper if it is not needed for additional UI only fields.
|
||||
*/
|
||||
public class PendingTradesListItem {
|
||||
|
||||
public class PendingTradesListItem implements FilterableListItem {
|
||||
public static final Logger log = LoggerFactory.getLogger(PendingTradesListItem.class);
|
||||
private final CoinFormatter btcFormatter;
|
||||
private final Trade trade;
|
||||
|
||||
public PendingTradesListItem(Trade trade) {
|
||||
public PendingTradesListItem(Trade trade, CoinFormatter btcFormatter) {
|
||||
this.trade = trade;
|
||||
this.btcFormatter = btcFormatter;
|
||||
}
|
||||
|
||||
public Trade getTrade() {
|
||||
return trade;
|
||||
}
|
||||
|
||||
public ReadOnlyObjectProperty<Coin> tradeAmountProperty() {
|
||||
return trade.amountProperty();
|
||||
public String getPriceAsString() {
|
||||
return FormattingUtils.formatPrice(trade.getPrice());
|
||||
}
|
||||
|
||||
public ReadOnlyObjectProperty<Volume> tradeVolumeProperty() {
|
||||
return trade.volumeProperty();
|
||||
public String getAmountAsString() {
|
||||
return btcFormatter.formatCoin(trade.getAmount());
|
||||
}
|
||||
|
||||
public Price getPrice() {
|
||||
return trade.getPrice();
|
||||
public String getPaymentMethod() {
|
||||
return trade.getOffer().getPaymentMethodNameWithCountryCode();
|
||||
}
|
||||
|
||||
public String getMarketDescription() {
|
||||
return getCurrencyPair(trade.getOffer().getCurrencyCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean match(String filterString) {
|
||||
if (filterString.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
if (getTrade().getId().contains(filterString)) {
|
||||
return true;
|
||||
}
|
||||
if (getAmountAsString().contains(filterString)) {
|
||||
return true;
|
||||
}
|
||||
if (getPaymentMethod().contains(filterString)) {
|
||||
return true;
|
||||
}
|
||||
if (getMarketDescription().contains(filterString)) {
|
||||
return true;
|
||||
}
|
||||
return getPriceAsString().contains(filterString);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,22 +21,13 @@
|
|||
<?import javafx.scene.control.TableView?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import bisq.desktop.components.AutoTooltipLabel?>
|
||||
<?import bisq.desktop.components.InputTextField?>
|
||||
<?import bisq.desktop.components.list.FilterBox?>
|
||||
<VBox fx:id="root" fx:controller="bisq.desktop.main.portfolio.pendingtrades.PendingTradesView"
|
||||
spacing="20" xmlns:fx="http://javafx.com/fxml">
|
||||
<padding>
|
||||
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0"/>
|
||||
</padding>
|
||||
<HBox spacing="5.0">
|
||||
<AutoTooltipLabel fx:id="filterLabel">
|
||||
<HBox.margin>
|
||||
<Insets top="5.0" left="10.0" />
|
||||
</HBox.margin>
|
||||
</AutoTooltipLabel>
|
||||
<InputTextField fx:id="filterTextField" minWidth="500"/>
|
||||
</HBox>
|
||||
<FilterBox fx:id="filterBox" />
|
||||
<TableView fx:id="tableView" VBox.vgrow="SOMETIMES">
|
||||
<columns>
|
||||
<TableColumn fx:id="tradeIdColumn" minWidth="100"/>
|
||||
|
|
|
@ -22,8 +22,8 @@ import bisq.desktop.common.view.ActivatableViewAndModel;
|
|||
import bisq.desktop.common.view.FxmlView;
|
||||
import bisq.desktop.components.AutoTooltipLabel;
|
||||
import bisq.desktop.components.HyperlinkWithIcon;
|
||||
import bisq.desktop.components.InputTextField;
|
||||
import bisq.desktop.components.PeerInfoIconTrading;
|
||||
import bisq.desktop.components.list.FilterBox;
|
||||
import bisq.desktop.main.MainView;
|
||||
import bisq.desktop.main.overlays.popups.Popup;
|
||||
import bisq.desktop.main.overlays.windows.TradeDetailsWindow;
|
||||
|
@ -43,9 +43,7 @@ import bisq.core.support.traderchat.TraderChatManager;
|
|||
import bisq.core.trade.model.bisq_v1.Contract;
|
||||
import bisq.core.trade.model.bisq_v1.Trade;
|
||||
import bisq.core.user.Preferences;
|
||||
import bisq.core.util.FormattingUtils;
|
||||
import bisq.core.util.VolumeUtil;
|
||||
import bisq.core.util.coin.CoinFormatter;
|
||||
|
||||
import bisq.network.p2p.NodeAddress;
|
||||
|
||||
|
@ -121,15 +119,12 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
|
|||
private final TradeDetailsWindow tradeDetailsWindow;
|
||||
private final Navigation navigation;
|
||||
private final KeyRing keyRing;
|
||||
private final CoinFormatter formatter;
|
||||
private final PrivateNotificationManager privateNotificationManager;
|
||||
private final boolean useDevPrivilegeKeys;
|
||||
private final boolean useDevModeHeader;
|
||||
private final Preferences preferences;
|
||||
@FXML
|
||||
AutoTooltipLabel filterLabel;
|
||||
@FXML
|
||||
InputTextField filterTextField;
|
||||
FilterBox filterBox;
|
||||
@FXML
|
||||
TableView<PendingTradesListItem> tableView;
|
||||
@FXML
|
||||
|
@ -157,7 +152,6 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
|
|||
private ChangeListener<Trade.DisputeState> disputeStateListener;
|
||||
private ChangeListener<MediationResultState> mediationResultStateListener;
|
||||
private ChangeListener<Number> getMempoolStatusListener;
|
||||
private ChangeListener<String> filterTextFieldListener;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -169,7 +163,6 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
|
|||
TradeDetailsWindow tradeDetailsWindow,
|
||||
Navigation navigation,
|
||||
KeyRing keyRing,
|
||||
@Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter formatter,
|
||||
PrivateNotificationManager privateNotificationManager,
|
||||
Preferences preferences,
|
||||
@Named(Config.USE_DEV_PRIVILEGE_KEYS) boolean useDevPrivilegeKeys,
|
||||
|
@ -178,7 +171,6 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
|
|||
this.tradeDetailsWindow = tradeDetailsWindow;
|
||||
this.navigation = navigation;
|
||||
this.keyRing = keyRing;
|
||||
this.formatter = formatter;
|
||||
this.privateNotificationManager = privateNotificationManager;
|
||||
this.preferences = preferences;
|
||||
this.useDevPrivilegeKeys = useDevPrivilegeKeys;
|
||||
|
@ -187,12 +179,6 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
|
|||
|
||||
@Override
|
||||
public void initialize() {
|
||||
filterTextFieldListener = (observable, oldValue, newValue) -> {
|
||||
tableView.getSelectionModel().clearSelection();
|
||||
applyFilteredListPredicate(filterTextField.getText());
|
||||
};
|
||||
filterLabel.setText(Res.get("shared.filter"));
|
||||
|
||||
priceColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.price")));
|
||||
amountColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.amountWithCur", Res.getBaseCurrencyCode())));
|
||||
volumeColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.amount")));
|
||||
|
@ -225,14 +211,14 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
|
|||
dateColumn.setComparator(Comparator.comparing(o -> o.getTrade().getDate()));
|
||||
volumeColumn.setComparator(Comparator.comparing(o -> o.getTrade().getVolume(), Comparator.nullsFirst(Comparator.naturalOrder())));
|
||||
amountColumn.setComparator(Comparator.comparing(o -> o.getTrade().getAmount(), Comparator.nullsFirst(Comparator.naturalOrder())));
|
||||
priceColumn.setComparator(Comparator.comparing(item -> FormattingUtils.formatPrice(item.getPrice())));
|
||||
priceColumn.setComparator(Comparator.comparing(PendingTradesListItem::getPriceAsString));
|
||||
paymentMethodColumn.setComparator(Comparator.comparing(
|
||||
item -> item.getTrade().getOffer() != null ?
|
||||
Res.get(item.getTrade().getOffer().getPaymentMethod().getId()) :
|
||||
null,
|
||||
Comparator.nullsFirst(Comparator.naturalOrder())));
|
||||
|
||||
marketColumn.setComparator(Comparator.comparing(model::getMarketLabel));
|
||||
marketColumn.setComparator(Comparator.comparing(PendingTradesListItem::getMarketDescription));
|
||||
roleColumn.setComparator(Comparator.comparing(model::getMyRole));
|
||||
avatarColumn.setComparator(Comparator.comparing(
|
||||
o -> model.getNumPastTrades(o.getTrade()),
|
||||
|
@ -300,8 +286,8 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
|
|||
sortedList.comparatorProperty().bind(tableView.comparatorProperty());
|
||||
tableView.setItems(sortedList);
|
||||
|
||||
filterTextField.textProperty().addListener(filterTextFieldListener);
|
||||
applyFilteredListPredicate(filterTextField.getText());
|
||||
filterBox.initialize(filteredList, tableView); // here because filteredList is instantiated here
|
||||
filterBox.activate();
|
||||
|
||||
updateMoveTradeToFailedColumnState();
|
||||
|
||||
|
@ -358,7 +344,7 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
|
|||
|
||||
@Override
|
||||
protected void deactivate() {
|
||||
filterTextField.textProperty().removeListener(filterTextFieldListener);
|
||||
filterBox.deactivate();
|
||||
sortedList.comparatorProperty().unbind();
|
||||
selectedItemSubscription.unsubscribe();
|
||||
selectedTableItemSubscription.unsubscribe();
|
||||
|
@ -372,31 +358,6 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
|
|||
scene.removeEventHandler(KeyEvent.KEY_RELEASED, keyEventEventHandler);
|
||||
}
|
||||
|
||||
private void applyFilteredListPredicate(String filterString) {
|
||||
filteredList.setPredicate(item -> {
|
||||
if (filterString.isEmpty())
|
||||
return true;
|
||||
|
||||
if (item.getTrade().getId().contains(filterString)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (formatter.formatCoin(item.getTrade().getAmount()).contains(filterString)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (model.getPaymentMethod(item).contains(filterString)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (model.getMarketLabel(item).contains(filterString)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return FormattingUtils.formatPrice(item.getPrice()).contains(filterString);
|
||||
});
|
||||
}
|
||||
|
||||
private void removeSelectedSubView() {
|
||||
if (selectedSubView != null) {
|
||||
selectedSubView.deactivate();
|
||||
|
@ -727,7 +688,7 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
|
|||
public void updateItem(final PendingTradesListItem item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (item != null && !empty)
|
||||
setGraphic(new AutoTooltipLabel(formatter.formatCoin(item.getTrade().getAmount())));
|
||||
setGraphic(new AutoTooltipLabel(item.getAmountAsString()));
|
||||
else
|
||||
setGraphic(null);
|
||||
}
|
||||
|
@ -748,7 +709,7 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
|
|||
public void updateItem(final PendingTradesListItem item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (item != null && !empty)
|
||||
setGraphic(new AutoTooltipLabel(FormattingUtils.formatPrice(item.getPrice())));
|
||||
setGraphic(new AutoTooltipLabel(item.getPriceAsString()));
|
||||
else
|
||||
setGraphic(null);
|
||||
}
|
||||
|
@ -795,7 +756,7 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
|
|||
public void updateItem(final PendingTradesListItem item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (item != null && !empty)
|
||||
setGraphic(new AutoTooltipLabel(model.getPaymentMethod(item)));
|
||||
setGraphic(new AutoTooltipLabel(item.getPaymentMethod()));
|
||||
else
|
||||
setGraphic(null);
|
||||
}
|
||||
|
@ -815,7 +776,12 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
|
|||
@Override
|
||||
public void updateItem(final PendingTradesListItem item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
setGraphic(new AutoTooltipLabel(model.getMarketLabel(item)));
|
||||
|
||||
if (item != null && !empty) {
|
||||
setGraphic(new AutoTooltipLabel(item.getMarketDescription()));
|
||||
} else {
|
||||
setGraphic(null);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -245,16 +245,6 @@ public class PendingTradesViewModel extends ActivatableWithDataModel<PendingTrad
|
|||
return sellerState;
|
||||
}
|
||||
|
||||
public String getPayoutAmount() {
|
||||
return dataModel.getTrade() != null
|
||||
? btcFormatter.formatCoinWithCode(dataModel.getTrade().getPayoutAmount())
|
||||
: "";
|
||||
}
|
||||
|
||||
String getMarketLabel(PendingTradesListItem item) {
|
||||
return item == null ? "" : tradeUtil.getMarketDescription(item.getTrade());
|
||||
}
|
||||
|
||||
public String getRemainingTradeDurationAsWords() {
|
||||
checkNotNull(dataModel.getTrade(), "model's trade must not be null");
|
||||
return tradeUtil.getRemainingTradeDurationAsWords(dataModel.getTrade());
|
||||
|
@ -297,10 +287,6 @@ public class PendingTradesViewModel extends ActivatableWithDataModel<PendingTrad
|
|||
}
|
||||
}
|
||||
|
||||
String getPaymentMethod(PendingTradesListItem item) {
|
||||
return item == null ? "" : tradeUtil.getPaymentMethodNameWithCountryCode(item.getTrade());
|
||||
}
|
||||
|
||||
// summary
|
||||
public String getTradeVolume() {
|
||||
return dataModel.getTrade() != null
|
||||
|
|
Loading…
Add table
Reference in a new issue