From 55026f43bd6045a2fb7e868710bea1353d7152b2 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Sun, 22 May 2016 23:16:50 +0200 Subject: [PATCH] Support EUR for SEPA countries which have non-EUR currency --- .../components/paymentmethods/SepaForm.java | 69 ++++++++++++++++--- 1 file changed, 61 insertions(+), 8 deletions(-) diff --git a/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/SepaForm.java b/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/SepaForm.java index a1b03f0b53..96f2221cc2 100644 --- a/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/SepaForm.java +++ b/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/SepaForm.java @@ -17,7 +17,6 @@ package io.bitsquare.gui.components.paymentmethods; -import io.bitsquare.common.util.Tuple3; import io.bitsquare.gui.components.InputTextField; import io.bitsquare.gui.util.BSFormatter; import io.bitsquare.gui.util.Layout; @@ -33,6 +32,7 @@ import javafx.geometry.VPos; import javafx.scene.control.*; import javafx.scene.layout.FlowPane; import javafx.scene.layout.GridPane; +import javafx.scene.layout.HBox; import javafx.scene.text.TextAlignment; import javafx.util.StringConverter; import org.apache.commons.lang3.StringUtils; @@ -55,6 +55,7 @@ public class SepaForm extends PaymentMethodForm { private TextField currencyTextField; private final List euroCountryCheckBoxes = new ArrayList<>(); private final List nonEuroCountryCheckBoxes = new ArrayList<>(); + private ComboBox currencyComboBox; public static int addFormForBuyer(GridPane gridPane, int gridRow, PaymentAccountContractData paymentAccountContractData) { addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, "Account holder name:", ((SepaAccountContractData) paymentAccountContractData).getHolderName()); @@ -98,10 +99,29 @@ public class SepaForm extends PaymentMethodForm { }); - Tuple3 tuple3 = addLabelComboBoxLabel(gridPane, ++gridRow, "Country of your Bank:", ""); - ComboBox countryComboBox = tuple3.second; - currencyTextField = tuple3.third; + + addLabel(gridPane, ++gridRow, "Country of your Bank:"); + HBox hBox = new HBox(); + hBox.setSpacing(10); + ComboBox countryComboBox = new ComboBox<>(); + currencyComboBox = new ComboBox<>(); + currencyTextField = new TextField(""); + currencyTextField.setEditable(false); + currencyTextField.setMouseTransparent(true); + currencyTextField.setFocusTraversable(false); currencyTextField.setMinWidth(300); + + currencyTextField.setVisible(false); + currencyTextField.setManaged(false); + currencyComboBox.setVisible(false); + currencyComboBox.setManaged(false); + + hBox.getChildren().addAll(countryComboBox, currencyTextField, currencyComboBox); + GridPane.setRowIndex(hBox, gridRow); + GridPane.setColumnIndex(hBox, 1); + gridPane.getChildren().add(hBox); + + countryComboBox.setPromptText("Select country of your Bank"); countryComboBox.setConverter(new StringConverter() { @Override @@ -118,8 +138,8 @@ public class SepaForm extends PaymentMethodForm { Country selectedItem = countryComboBox.getSelectionModel().getSelectedItem(); sepaAccount.setCountry(selectedItem); TradeCurrency currency = CurrencyUtil.getCurrencyByCountryCode(selectedItem.code); - sepaAccount.setSingleTradeCurrency(currency); - currencyTextField.setText("Currency: " + currency.getNameAndCode()); + setupCurrency(selectedItem, currency); + updateCountriesSelection(true, euroCountryCheckBoxes); updateCountriesSelection(true, nonEuroCountryCheckBoxes); updateFromInputs(); @@ -136,13 +156,46 @@ public class SepaForm extends PaymentMethodForm { countryComboBox.getSelectionModel().select(country); sepaAccount.setCountry(country); TradeCurrency currency = CurrencyUtil.getCurrencyByCountryCode(country.code); - sepaAccount.setSingleTradeCurrency(currency); - currencyTextField.setText("Currency: " + currency.getNameAndCode()); + setupCurrency(country, currency); } updateFromInputs(); } + private void setupCurrency(Country country, TradeCurrency currency) { + if (CountryUtil.getAllSepaEuroCountries().contains(country)) { + currencyTextField.setVisible(true); + currencyTextField.setManaged(true); + currencyComboBox.setVisible(false); + currencyComboBox.setManaged(false); + sepaAccount.setSingleTradeCurrency(currency); + currencyTextField.setText("Currency: " + currency.getNameAndCode()); + } else { + currencyComboBox.setVisible(true); + currencyComboBox.setManaged(true); + currencyTextField.setVisible(false); + currencyTextField.setManaged(false); + currencyComboBox.setItems(FXCollections.observableArrayList(currency, CurrencyUtil.getFiatCurrency("EUR").get())); + currencyComboBox.setOnAction(e2 -> { + sepaAccount.setSingleTradeCurrency(currencyComboBox.getSelectionModel().getSelectedItem()); + updateCountriesSelection(true, euroCountryCheckBoxes); + autoFillNameTextField(); + }); + currencyComboBox.setConverter(new StringConverter() { + @Override + public String toString(TradeCurrency currency) { + return currency.getNameAndCode(); + } + + @Override + public TradeCurrency fromString(String string) { + return null; + } + }); + currencyComboBox.getSelectionModel().select(0); + } + } + private void addEuroCountriesGrid(boolean isEditable) { addCountriesGrid(isEditable, "Accept trades from those Euro countries:", euroCountryCheckBoxes, CountryUtil.getAllSepaEuroCountries()); }