From 0f0b645f720060030d5d57cc89ac88b72d266bda Mon Sep 17 00:00:00 2001 From: bvcxza <175357591+bvcxza@users.noreply.github.com> Date: Thu, 1 Aug 2024 08:46:38 -0300 Subject: [PATCH] use AutocompleteComboBox to create new payment method --- .../TraditionalAccountsView.java | 22 +++++++++++++------ .../java/haveno/desktop/util/FormBuilder.java | 18 +++++++++++++++ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/desktop/src/main/java/haveno/desktop/main/account/content/traditionalaccounts/TraditionalAccountsView.java b/desktop/src/main/java/haveno/desktop/main/account/content/traditionalaccounts/TraditionalAccountsView.java index 3962d559..ae2b0a1b 100644 --- a/desktop/src/main/java/haveno/desktop/main/account/content/traditionalaccounts/TraditionalAccountsView.java +++ b/desktop/src/main/java/haveno/desktop/main/account/content/traditionalaccounts/TraditionalAccountsView.java @@ -72,6 +72,7 @@ import haveno.core.trade.HavenoUtils; import haveno.core.util.FormattingUtils; import haveno.core.util.coin.CoinFormatter; import haveno.desktop.common.view.FxmlView; +import haveno.desktop.components.AutocompleteComboBox; import haveno.desktop.components.TitledGroupBg; import haveno.desktop.components.paymentmethods.AchTransferForm; import haveno.desktop.components.paymentmethods.AdvancedCashForm; @@ -144,7 +145,6 @@ import java.util.stream.Collectors; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.scene.control.Button; -import javafx.scene.control.ComboBox; import javafx.scene.control.Label; import javafx.scene.control.ListView; import javafx.scene.layout.GridPane; @@ -181,7 +181,7 @@ public class TraditionalAccountsView extends PaymentAccountsView paymentMethodComboBox; + private AutocompleteComboBox paymentMethodComboBox; private PaymentMethodForm paymentMethodForm; private TitledGroupBg accountTitledGroupBg; private Button saveNewAccountButton; @@ -463,14 +463,16 @@ public class TraditionalAccountsView extends PaymentAccountsView list = PaymentMethod.paymentMethods.stream() .filter(PaymentMethod::isTraditional) .sorted() .collect(Collectors.toList()); - paymentMethodComboBox.setItems(FXCollections.observableArrayList(list)); + paymentMethodComboBox.setAutocompleteItems(FXCollections.observableArrayList(list)); paymentMethodComboBox.setConverter(new StringConverter<>() { @Override public String toString(PaymentMethod paymentMethod) { @@ -479,10 +481,15 @@ public class TraditionalAccountsView extends PaymentAccountsView Res.get(item.getId()).equals(s)) + .findAny().orElse(null); } }); - paymentMethodComboBox.setOnAction(e -> { + paymentMethodComboBox.setOnChangeConfirmed(e -> { if (paymentMethodForm != null) { FormBuilder.removeRowsFromGridPane(root, 3, paymentMethodForm.getGridRow() + 1); GridPane.setRowSpan(accountTitledGroupBg, paymentMethodForm.getRowSpan() + 1); @@ -550,6 +557,7 @@ public class TraditionalAccountsView extends PaymentAccountsView AutocompleteComboBox addAutocompleteComboBox(GridPane gridPane, int rowIndex, String title, double top) { + var comboBox = new AutocompleteComboBox(); + comboBox.setLabelFloat(true); + comboBox.setPromptText(title); + comboBox.setMaxWidth(Double.MAX_VALUE); + + // Default ComboBox does not show promptText after clear selection. + // https://stackoverflow.com/questions/50569330/how-to-reset-combobox-and-display-prompttext?noredirect=1&lq=1 + comboBox.setButtonCell(getComboBoxButtonCell(title, comboBox)); + + GridPane.setRowIndex(comboBox, rowIndex); + GridPane.setColumnIndex(comboBox, 0); + GridPane.setMargin(comboBox, new Insets(top + Layout.FLOATING_LABEL_DISTANCE, 0, 0, 0)); + gridPane.getChildren().add(comboBox); + + return comboBox; + } + /////////////////////////////////////////////////////////////////////////////////////////// // Label + AutocompleteComboBox ///////////////////////////////////////////////////////////////////////////////////////////