diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index f43f1a6d02..9c2796c68a 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -311,6 +311,9 @@ market.tabs.spreadCurrency=Offers by Currency market.tabs.spreadPayment=Offers by Payment Method market.tabs.trades=Trades +# OfferBookView +market.offerBook.filterPrompt=Offer ID, address... + # OfferBookChartView market.offerBook.sellOffersHeaderLabel=Sell {0} to market.offerBook.buyOffersHeaderLabel=Buy {0} from diff --git a/desktop/src/main/java/haveno/desktop/components/AutoTooltipTextField.java b/desktop/src/main/java/haveno/desktop/components/AutoTooltipTextField.java new file mode 100644 index 0000000000..1473ed0940 --- /dev/null +++ b/desktop/src/main/java/haveno/desktop/components/AutoTooltipTextField.java @@ -0,0 +1,45 @@ +/* + * 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 . + */ + +package haveno.desktop.components; + +import com.jfoenix.controls.JFXTextField; +import com.jfoenix.skins.JFXTextFieldSkin; +import javafx.scene.control.Skin; +import javafx.scene.control.TextField; + +public class AutoTooltipTextField extends JFXTextField { + + public AutoTooltipTextField() { + super(); + } + + public AutoTooltipTextField(String text) { + super(text); + } + + @Override + protected Skin createDefaultSkin() { + return new AutoTooltipTextFieldSkin(this); + } + + private class AutoTooltipTextFieldSkin extends JFXTextFieldSkin { + public AutoTooltipTextFieldSkin(TextField textField) { + super(textField); + } + } +} diff --git a/desktop/src/main/java/haveno/desktop/main/offer/offerbook/OfferBookView.java b/desktop/src/main/java/haveno/desktop/main/offer/offerbook/OfferBookView.java index ac10fd7d2a..f033304211 100644 --- a/desktop/src/main/java/haveno/desktop/main/offer/offerbook/OfferBookView.java +++ b/desktop/src/main/java/haveno/desktop/main/offer/offerbook/OfferBookView.java @@ -46,6 +46,7 @@ import haveno.desktop.components.AutoTooltipButton; import haveno.desktop.components.AutoTooltipLabel; import haveno.desktop.components.AutoTooltipSlideToggleButton; import haveno.desktop.components.AutoTooltipTableColumn; +import haveno.desktop.components.AutoTooltipTextField; import haveno.desktop.components.AutocompleteComboBox; import haveno.desktop.components.ColoredDecimalPlacesWithZerosText; import haveno.desktop.components.HyperlinkWithIcon; @@ -107,6 +108,7 @@ import java.util.Map; import java.util.Optional; import static haveno.desktop.util.FormBuilder.addTitledGroupBg; +import static haveno.desktop.util.FormBuilder.addTopLabelAutoToolTipTextField; abstract public class OfferBookView extends ActivatableViewAndModel { @@ -122,6 +124,7 @@ abstract public class OfferBookView currencyComboBox; private AutocompleteComboBox paymentMethodComboBox; private AutoTooltipButton createOfferButton; + private AutoTooltipTextField filterInputField; private AutoTooltipSlideToggleButton matchingOffersToggle; private AutoTooltipTableColumn amountColumn; private AutoTooltipTableColumn volumeColumn; @@ -212,8 +215,13 @@ abstract public class OfferBookView autoToolTipTextField = addTopLabelAutoToolTipTextField(Res.get("shared.filter")); + VBox filterBox = autoToolTipTextField.first; + filterInputField = autoToolTipTextField.third; + filterInputField.setPromptText(Res.get("market.offerBook.filterPrompt")); + offerToolsBox.getChildren().addAll(currencyBoxTuple.first, paymentBoxTuple.first, - matchingOffersToggle, getSpacer(), createOfferButtonStack); + filterBox, matchingOffersToggle, getSpacer(), createOfferButtonStack); GridPane.setHgrow(offerToolsBox, Priority.ALWAYS); GridPane.setRowIndex(offerToolsBox, gridRow); @@ -427,6 +435,10 @@ abstract public class OfferBookView { + model.onFilterKeyTyped(filterInputField.getText()); + }); } private void updatePaymentMethodComboBoxEditor() { diff --git a/desktop/src/main/java/haveno/desktop/main/offer/offerbook/OfferBookViewModel.java b/desktop/src/main/java/haveno/desktop/main/offer/offerbook/OfferBookViewModel.java index 234460120d..37e9f0a4ef 100644 --- a/desktop/src/main/java/haveno/desktop/main/offer/offerbook/OfferBookViewModel.java +++ b/desktop/src/main/java/haveno/desktop/main/offer/offerbook/OfferBookViewModel.java @@ -121,6 +121,7 @@ abstract class OfferBookViewModel extends ActivatableViewModel { PaymentMethod selectedPaymentMethod = getShowAllEntryForPaymentMethod(); boolean isTabSelected; + String filterText = ""; final BooleanProperty showAllTradeCurrenciesProperty = new SimpleBooleanProperty(true); final BooleanProperty disableMatchToggle = new SimpleBooleanProperty(); final IntegerProperty maxPlacesForAmount = new SimpleIntegerProperty(); @@ -269,6 +270,11 @@ abstract class OfferBookViewModel extends ActivatableViewModel { } } + void onFilterKeyTyped(String filterText) { + this.filterText = filterText; + filterOffers(); + } + abstract void saveSelectedCurrencyCodeInPreferences(OfferDirection direction, String code); protected void onSetPaymentMethod(PaymentMethod paymentMethod) { @@ -566,7 +572,17 @@ abstract class OfferBookViewModel extends ActivatableViewModel { Predicate predicate = useOffersMatchingMyAccountsFilter ? getCurrencyAndMethodPredicate(direction, selectedTradeCurrency).and(getOffersMatchingMyAccountsPredicate()) : getCurrencyAndMethodPredicate(direction, selectedTradeCurrency); - filteredItems.setPredicate(predicate); + + if (!filterText.isEmpty()) { + Predicate nextPredicate=offerBookListItem -> + offerBookListItem.getOffer().getOfferPayload().getOwnerNodeAddress().getFullAddress().contains(filterText); + nextPredicate=nextPredicate.or(offerBookListItem -> + offerBookListItem.getOffer().getId().contains(filterText)); + + filteredItems.setPredicate(predicate.and(nextPredicate)); + } else { + filteredItems.setPredicate(predicate); + } } abstract Predicate getCurrencyAndMethodPredicate(OfferDirection direction, diff --git a/desktop/src/main/java/haveno/desktop/util/FormBuilder.java b/desktop/src/main/java/haveno/desktop/util/FormBuilder.java index cae26b805a..4181245d0f 100644 --- a/desktop/src/main/java/haveno/desktop/util/FormBuilder.java +++ b/desktop/src/main/java/haveno/desktop/util/FormBuilder.java @@ -36,6 +36,7 @@ import haveno.desktop.components.AutoTooltipCheckBox; import haveno.desktop.components.AutoTooltipLabel; import haveno.desktop.components.AutoTooltipRadioButton; import haveno.desktop.components.AutoTooltipSlideToggleButton; +import haveno.desktop.components.AutoTooltipTextField; import haveno.desktop.components.AutocompleteComboBox; import haveno.desktop.components.BalanceTextField; import haveno.desktop.components.BusyAnimation; @@ -1286,6 +1287,20 @@ public class FormBuilder { return new Tuple3<>(vBox, label, comboBox); } + public static Tuple3 addTopLabelAutoToolTipTextField(String title) { + return addTopLabelAutoToolTipTextField(title, 0); + } + + public static Tuple3 addTopLabelAutoToolTipTextField(String title, int top) { + Label label = getTopLabel(title); + VBox vBox = getTopLabelVBox(top); + + final AutoTooltipTextField textField = new AutoTooltipTextField(); + vBox.getChildren().addAll(label, textField); + + return new Tuple3<>(vBox, label, textField); + } + @NotNull private static VBox getTopLabelVBox(int top) { VBox vBox = new VBox();