Search in sources :

Example 1 with AccountNrValidator

use of bisq.desktop.util.validation.AccountNrValidator in project bisq-desktop by bisq-network.

the class BankForm method addFormForAddAccount.

@Override
public void addFormForAddAccount() {
    gridRowFrom = gridRow + 1;
    Tuple3<Label, ComboBox, ComboBox> tuple3 = addLabelComboBoxComboBox(gridPane, ++gridRow, Res.get("payment.country"));
    // noinspection unchecked,unchecked,unchecked
    ComboBox<Region> regionComboBox = tuple3.second;
    regionComboBox.setPromptText(Res.get("payment.select.region"));
    regionComboBox.setConverter(new StringConverter<Region>() {

        @Override
        public String toString(Region region) {
            return region.name;
        }

        @Override
        public Region fromString(String s) {
            return null;
        }
    });
    regionComboBox.setItems(FXCollections.observableArrayList(CountryUtil.getAllRegions()));
    // noinspection unchecked,unchecked,unchecked
    ComboBox<Country> countryComboBox = tuple3.third;
    countryComboBox.setVisibleRowCount(15);
    countryComboBox.setDisable(true);
    countryComboBox.setPromptText(Res.get("payment.select.country"));
    countryComboBox.setConverter(new StringConverter<Country>() {

        @Override
        public String toString(Country country) {
            return country.name + " (" + country.code + ")";
        }

        @Override
        public Country fromString(String s) {
            return null;
        }
    });
    countryComboBox.setOnAction(e -> {
        Country selectedItem = countryComboBox.getSelectionModel().getSelectedItem();
        if (selectedItem != null) {
            getCountryBasedPaymentAccount().setCountry(selectedItem);
            String countryCode = selectedItem.code;
            TradeCurrency currency = CurrencyUtil.getCurrencyByCountryCode(countryCode);
            paymentAccount.setSingleTradeCurrency(currency);
            currencyComboBox.setDisable(false);
            currencyComboBox.getSelectionModel().select(currency);
            bankIdLabel.setText(BankUtil.getBankIdLabel(countryCode));
            branchIdLabel.setText(BankUtil.getBranchIdLabel(countryCode));
            accountNrLabel.setText(BankUtil.getAccountNrLabel(countryCode));
            accountTypeLabel.setText(BankUtil.getAccountTypeLabel(countryCode));
            bankNameInputTextField.setText("");
            bankIdInputTextField.setText("");
            branchIdInputTextField.setText("");
            accountNrInputTextField.setText("");
            accountTypeComboBox.getSelectionModel().clearSelection();
            accountTypeComboBox.setItems(FXCollections.observableArrayList(BankUtil.getAccountTypeValues(countryCode)));
            if (BankUtil.useValidation(countryCode) && !validatorsApplied) {
                validatorsApplied = true;
                if (useHolderID)
                    holderIdInputTextField.setValidator(inputValidator);
                bankNameInputTextField.setValidator(inputValidator);
                bankIdInputTextField.setValidator(new BankIdValidator(countryCode));
                branchIdInputTextField.setValidator(new BranchIdValidator(countryCode));
                accountNrInputTextField.setValidator(new AccountNrValidator(countryCode));
            } else {
                validatorsApplied = false;
                if (useHolderID)
                    holderIdInputTextField.setValidator(null);
                bankNameInputTextField.setValidator(null);
                bankIdInputTextField.setValidator(null);
                branchIdInputTextField.setValidator(null);
                accountNrInputTextField.setValidator(null);
            }
            holderNameInputTextField.resetValidation();
            bankNameInputTextField.resetValidation();
            bankIdInputTextField.resetValidation();
            branchIdInputTextField.resetValidation();
            accountNrInputTextField.resetValidation();
            boolean requiresHolderId = BankUtil.isHolderIdRequired(countryCode);
            if (requiresHolderId) {
                holderNameInputTextField.minWidthProperty().unbind();
                holderNameInputTextField.setMinWidth(250);
            } else {
                holderNameInputTextField.minWidthProperty().bind(currencyComboBox.widthProperty());
            }
            if (useHolderID) {
                if (!requiresHolderId)
                    holderIdInputTextField.setText("");
                holderIdInputTextField.resetValidation();
                holderIdInputTextField.setVisible(requiresHolderId);
                holderIdInputTextField.setManaged(requiresHolderId);
                holderIdLabel.setText(BankUtil.getHolderIdLabel(countryCode));
                holderIdLabel.setVisible(requiresHolderId);
                holderIdLabel.setManaged(requiresHolderId);
            }
            boolean bankNameRequired = BankUtil.isBankNameRequired(countryCode);
            bankNameTuple.first.setVisible(bankNameRequired);
            bankNameTuple.first.setManaged(bankNameRequired);
            bankNameInputTextField.setVisible(bankNameRequired);
            bankNameInputTextField.setManaged(bankNameRequired);
            boolean bankIdRequired = BankUtil.isBankIdRequired(countryCode);
            bankIdTuple.first.setVisible(bankIdRequired);
            bankIdTuple.first.setManaged(bankIdRequired);
            bankIdInputTextField.setVisible(bankIdRequired);
            bankIdInputTextField.setManaged(bankIdRequired);
            boolean branchIdRequired = BankUtil.isBranchIdRequired(countryCode);
            branchIdTuple.first.setVisible(branchIdRequired);
            branchIdTuple.first.setManaged(branchIdRequired);
            branchIdInputTextField.setVisible(branchIdRequired);
            branchIdInputTextField.setManaged(branchIdRequired);
            boolean accountNrRequired = BankUtil.isAccountNrRequired(countryCode);
            accountNrTuple.first.setVisible(accountNrRequired);
            accountNrTuple.first.setManaged(accountNrRequired);
            accountNrInputTextField.setVisible(accountNrRequired);
            accountNrInputTextField.setManaged(accountNrRequired);
            boolean accountTypeRequired = BankUtil.isAccountTypeRequired(countryCode);
            accountTypeTuple.first.setVisible(accountTypeRequired);
            accountTypeTuple.first.setManaged(accountTypeRequired);
            accountTypeTuple.second.setVisible(accountTypeRequired);
            accountTypeTuple.second.setManaged(accountTypeRequired);
            updateFromInputs();
            onCountryChanged();
        }
    });
    regionComboBox.setOnAction(e -> {
        Region selectedItem = regionComboBox.getSelectionModel().getSelectedItem();
        if (selectedItem != null) {
            countryComboBox.setDisable(false);
            countryComboBox.setItems(FXCollections.observableArrayList(CountryUtil.getAllCountriesForRegion(selectedItem)));
        }
    });
    // noinspection unchecked
    currencyComboBox = addLabelComboBox(gridPane, ++gridRow, Res.getWithCol("shared.currency")).second;
    currencyComboBox.setPromptText(Res.get("list.currency.select"));
    currencyComboBox.setItems(FXCollections.observableArrayList(CurrencyUtil.getAllSortedFiatCurrencies()));
    currencyComboBox.setOnAction(e -> {
        TradeCurrency selectedItem = currencyComboBox.getSelectionModel().getSelectedItem();
        FiatCurrency defaultCurrency = CurrencyUtil.getCurrencyByCountryCode(countryComboBox.getSelectionModel().getSelectedItem().code);
        if (!defaultCurrency.equals(selectedItem)) {
            new Popup<>().warning(Res.get("payment.foreign.currency")).actionButtonText(Res.get("shared.yes")).onAction(() -> {
                paymentAccount.setSingleTradeCurrency(selectedItem);
                autoFillNameTextField();
            }).closeButtonText(Res.get("payment.restore.default")).onClose(() -> currencyComboBox.getSelectionModel().select(defaultCurrency)).show();
        } else {
            paymentAccount.setSingleTradeCurrency(selectedItem);
            autoFillNameTextField();
        }
    });
    currencyComboBox.setConverter(new StringConverter<TradeCurrency>() {

        @Override
        public String toString(TradeCurrency currency) {
            return currency.getNameAndCode();
        }

        @Override
        public TradeCurrency fromString(String string) {
            return null;
        }
    });
    currencyComboBox.setDisable(true);
    addAcceptedBanksForAddAccount();
    addHolderNameAndId();
    bankNameTuple = addLabelInputTextField(gridPane, ++gridRow, Res.get("payment.bank.name"));
    bankNameInputTextField = bankNameTuple.second;
    bankNameInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        bankAccountPayload.setBankName(newValue);
        updateFromInputs();
    });
    bankIdTuple = addLabelInputTextField(gridPane, ++gridRow, BankUtil.getBankIdLabel(""));
    bankIdLabel = bankIdTuple.first;
    bankIdInputTextField = bankIdTuple.second;
    bankIdInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        bankAccountPayload.setBankId(newValue);
        updateFromInputs();
    });
    branchIdTuple = addLabelInputTextField(gridPane, ++gridRow, BankUtil.getBranchIdLabel(""));
    branchIdLabel = branchIdTuple.first;
    branchIdInputTextField = branchIdTuple.second;
    branchIdInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        bankAccountPayload.setBranchId(newValue);
        updateFromInputs();
    });
    accountNrTuple = addLabelInputTextField(gridPane, ++gridRow, BankUtil.getAccountNrLabel(""));
    accountNrLabel = accountNrTuple.first;
    accountNrInputTextField = accountNrTuple.second;
    accountNrInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        bankAccountPayload.setAccountNr(newValue);
        updateFromInputs();
    });
    accountTypeTuple = addLabelComboBox(gridPane, ++gridRow, "");
    accountTypeLabel = accountTypeTuple.first;
    // noinspection unchecked
    accountTypeComboBox = accountTypeTuple.second;
    accountTypeComboBox.setPromptText(Res.get("payment.select.account"));
    accountTypeComboBox.setOnAction(e -> {
        if (BankUtil.isAccountTypeRequired(bankAccountPayload.getCountryCode())) {
            bankAccountPayload.setAccountType(accountTypeComboBox.getSelectionModel().getSelectedItem());
            updateFromInputs();
        }
    });
    addLimitations();
    addAccountNameTextFieldWithAutoFillCheckBox();
    updateFromInputs();
}
Also used : BankIdValidator(bisq.desktop.util.validation.BankIdValidator) TradeCurrency(bisq.core.locale.TradeCurrency) ComboBox(javafx.scene.control.ComboBox) Label(javafx.scene.control.Label) BranchIdValidator(bisq.desktop.util.validation.BranchIdValidator) Popup(bisq.desktop.main.overlays.popups.Popup) Region(bisq.core.locale.Region) Country(bisq.core.locale.Country) FiatCurrency(bisq.core.locale.FiatCurrency) AccountNrValidator(bisq.desktop.util.validation.AccountNrValidator)

Example 2 with AccountNrValidator

use of bisq.desktop.util.validation.AccountNrValidator in project bisq-desktop by bisq-network.

the class CashDepositForm method addFormForAddAccount.

@Override
public void addFormForAddAccount() {
    gridRowFrom = gridRow + 1;
    Tuple3<Label, ComboBox, ComboBox> tuple3 = FormBuilder.addLabelComboBoxComboBox(gridPane, ++gridRow, Res.get("payment.country"));
    // noinspection unchecked,unchecked,unchecked
    ComboBox<Region> regionComboBox = tuple3.second;
    regionComboBox.setPromptText(Res.get("payment.select.region"));
    regionComboBox.setConverter(new StringConverter<Region>() {

        @Override
        public String toString(Region region) {
            return region.name;
        }

        @Override
        public Region fromString(String s) {
            return null;
        }
    });
    regionComboBox.setItems(FXCollections.observableArrayList(CountryUtil.getAllRegions()));
    // noinspection unchecked,unchecked,unchecked
    ComboBox<Country> countryComboBox = tuple3.third;
    countryComboBox.setVisibleRowCount(15);
    countryComboBox.setDisable(true);
    countryComboBox.setPromptText(Res.get("payment.select.country"));
    countryComboBox.setConverter(new StringConverter<Country>() {

        @Override
        public String toString(Country country) {
            return country.name + " (" + country.code + ")";
        }

        @Override
        public Country fromString(String s) {
            return null;
        }
    });
    countryComboBox.setOnAction(e -> {
        Country selectedItem = countryComboBox.getSelectionModel().getSelectedItem();
        if (selectedItem != null) {
            getCountryBasedPaymentAccount().setCountry(selectedItem);
            String countryCode = selectedItem.code;
            TradeCurrency currency = CurrencyUtil.getCurrencyByCountryCode(countryCode);
            paymentAccount.setSingleTradeCurrency(currency);
            currencyComboBox.setDisable(false);
            currencyComboBox.getSelectionModel().select(currency);
            bankIdLabel.setText(BankUtil.getBankIdLabel(countryCode));
            branchIdLabel.setText(BankUtil.getBranchIdLabel(countryCode));
            accountNrLabel.setText(BankUtil.getAccountNrLabel(countryCode));
            accountTypeLabel.setText(BankUtil.getAccountTypeLabel(countryCode));
            bankNameInputTextField.setText("");
            bankIdInputTextField.setText("");
            branchIdInputTextField.setText("");
            accountNrInputTextField.setText("");
            accountTypeComboBox.getSelectionModel().clearSelection();
            accountTypeComboBox.setItems(FXCollections.observableArrayList(BankUtil.getAccountTypeValues(countryCode)));
            if (BankUtil.useValidation(countryCode) && !validatorsApplied) {
                validatorsApplied = true;
                if (useHolderID)
                    holderIdInputTextField.setValidator(inputValidator);
                bankNameInputTextField.setValidator(inputValidator);
                bankIdInputTextField.setValidator(new BankIdValidator(countryCode));
                branchIdInputTextField.setValidator(new BranchIdValidator(countryCode));
                accountNrInputTextField.setValidator(new AccountNrValidator(countryCode));
            } else {
                validatorsApplied = false;
                if (useHolderID)
                    holderIdInputTextField.setValidator(null);
                bankNameInputTextField.setValidator(null);
                bankIdInputTextField.setValidator(null);
                branchIdInputTextField.setValidator(null);
                accountNrInputTextField.setValidator(null);
            }
            holderNameInputTextField.resetValidation();
            emailInputTextField.resetValidation();
            bankNameInputTextField.resetValidation();
            bankIdInputTextField.resetValidation();
            branchIdInputTextField.resetValidation();
            accountNrInputTextField.resetValidation();
            boolean requiresHolderId = BankUtil.isHolderIdRequired(countryCode);
            if (requiresHolderId) {
                holderNameInputTextField.minWidthProperty().unbind();
                holderNameInputTextField.setMinWidth(300);
            } else {
                holderNameInputTextField.minWidthProperty().bind(currencyComboBox.widthProperty());
            }
            if (useHolderID) {
                if (!requiresHolderId)
                    holderIdInputTextField.setText("");
                holderIdInputTextField.resetValidation();
                holderIdInputTextField.setVisible(requiresHolderId);
                holderIdInputTextField.setManaged(requiresHolderId);
                holderIdLabel.setText(BankUtil.getHolderIdLabel(countryCode));
                holderIdLabel.setVisible(requiresHolderId);
                holderIdLabel.setManaged(requiresHolderId);
            }
            boolean bankNameRequired = BankUtil.isBankNameRequired(countryCode);
            bankNameTuple.first.setVisible(bankNameRequired);
            bankNameTuple.first.setManaged(bankNameRequired);
            bankNameInputTextField.setVisible(bankNameRequired);
            bankNameInputTextField.setManaged(bankNameRequired);
            boolean bankIdRequired = BankUtil.isBankIdRequired(countryCode);
            bankIdTuple.first.setVisible(bankIdRequired);
            bankIdTuple.first.setManaged(bankIdRequired);
            bankIdInputTextField.setVisible(bankIdRequired);
            bankIdInputTextField.setManaged(bankIdRequired);
            boolean branchIdRequired = BankUtil.isBranchIdRequired(countryCode);
            branchIdTuple.first.setVisible(branchIdRequired);
            branchIdTuple.first.setManaged(branchIdRequired);
            branchIdInputTextField.setVisible(branchIdRequired);
            branchIdInputTextField.setManaged(branchIdRequired);
            boolean accountNrRequired = BankUtil.isAccountNrRequired(countryCode);
            accountNrTuple.first.setVisible(accountNrRequired);
            accountNrTuple.first.setManaged(accountNrRequired);
            accountNrInputTextField.setVisible(accountNrRequired);
            accountNrInputTextField.setManaged(accountNrRequired);
            boolean accountTypeRequired = BankUtil.isAccountTypeRequired(countryCode);
            accountTypeTuple.first.setVisible(accountTypeRequired);
            accountTypeTuple.first.setManaged(accountTypeRequired);
            accountTypeTuple.second.setVisible(accountTypeRequired);
            accountTypeTuple.second.setManaged(accountTypeRequired);
            updateFromInputs();
            onCountryChanged();
        }
    });
    regionComboBox.setOnAction(e -> {
        Region selectedItem = regionComboBox.getSelectionModel().getSelectedItem();
        if (selectedItem != null) {
            countryComboBox.setDisable(false);
            countryComboBox.setItems(FXCollections.observableArrayList(CountryUtil.getAllCountriesForRegion(selectedItem)));
        }
    });
    // noinspection unchecked
    currencyComboBox = FormBuilder.addLabelComboBox(gridPane, ++gridRow, Res.getWithCol("shared.currency")).second;
    currencyComboBox.setPromptText(Res.get("list.currency.select"));
    currencyComboBox.setItems(FXCollections.observableArrayList(CurrencyUtil.getAllSortedFiatCurrencies()));
    currencyComboBox.setOnAction(e -> {
        TradeCurrency selectedItem = currencyComboBox.getSelectionModel().getSelectedItem();
        FiatCurrency defaultCurrency = CurrencyUtil.getCurrencyByCountryCode(countryComboBox.getSelectionModel().getSelectedItem().code);
        if (!defaultCurrency.equals(selectedItem)) {
            new Popup<>().warning(Res.get("payment.foreign.currency")).actionButtonText(Res.get("shared.yes")).onAction(() -> {
                paymentAccount.setSingleTradeCurrency(selectedItem);
                autoFillNameTextField();
            }).closeButtonText(Res.get("payment.restore.default")).onClose(() -> currencyComboBox.getSelectionModel().select(defaultCurrency)).show();
        } else {
            paymentAccount.setSingleTradeCurrency(selectedItem);
            autoFillNameTextField();
        }
    });
    currencyComboBox.setConverter(new StringConverter<TradeCurrency>() {

        @Override
        public String toString(TradeCurrency currency) {
            return currency.getNameAndCode();
        }

        @Override
        public TradeCurrency fromString(String string) {
            return null;
        }
    });
    currencyComboBox.setDisable(true);
    addAcceptedBanksForAddAccount();
    addHolderNameAndId();
    bankNameTuple = FormBuilder.addLabelInputTextField(gridPane, ++gridRow, Res.get("payment.bank.name"));
    bankNameInputTextField = bankNameTuple.second;
    bankNameInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        cashDepositAccountPayload.setBankName(newValue);
        updateFromInputs();
    });
    bankIdTuple = FormBuilder.addLabelInputTextField(gridPane, ++gridRow, BankUtil.getBankIdLabel(""));
    bankIdLabel = bankIdTuple.first;
    bankIdInputTextField = bankIdTuple.second;
    bankIdInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        cashDepositAccountPayload.setBankId(newValue);
        updateFromInputs();
    });
    branchIdTuple = FormBuilder.addLabelInputTextField(gridPane, ++gridRow, BankUtil.getBranchIdLabel(""));
    branchIdLabel = branchIdTuple.first;
    branchIdInputTextField = branchIdTuple.second;
    branchIdInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        cashDepositAccountPayload.setBranchId(newValue);
        updateFromInputs();
    });
    accountNrTuple = FormBuilder.addLabelInputTextField(gridPane, ++gridRow, BankUtil.getAccountNrLabel(""));
    accountNrLabel = accountNrTuple.first;
    accountNrInputTextField = accountNrTuple.second;
    accountNrInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        cashDepositAccountPayload.setAccountNr(newValue);
        updateFromInputs();
    });
    accountTypeTuple = FormBuilder.addLabelComboBox(gridPane, ++gridRow, "");
    accountTypeLabel = accountTypeTuple.first;
    // noinspection unchecked
    accountTypeComboBox = accountTypeTuple.second;
    accountTypeComboBox.setPromptText(Res.get("payment.select.account"));
    accountTypeComboBox.setOnAction(e -> {
        if (BankUtil.isAccountTypeRequired(cashDepositAccountPayload.getCountryCode())) {
            cashDepositAccountPayload.setAccountType(accountTypeComboBox.getSelectionModel().getSelectedItem());
            updateFromInputs();
        }
    });
    TextArea requirementsTextArea = FormBuilder.addLabelTextArea(gridPane, ++gridRow, Res.get("payment.extras"), "").second;
    requirementsTextArea.setMinHeight(30);
    requirementsTextArea.setMaxHeight(30);
    requirementsTextArea.textProperty().addListener((ov, oldValue, newValue) -> {
        cashDepositAccountPayload.setRequirements(newValue);
        updateFromInputs();
    });
    addLimitations();
    addAccountNameTextFieldWithAutoFillCheckBox();
    updateFromInputs();
}
Also used : BankIdValidator(bisq.desktop.util.validation.BankIdValidator) TradeCurrency(bisq.core.locale.TradeCurrency) TextArea(javafx.scene.control.TextArea) ComboBox(javafx.scene.control.ComboBox) Label(javafx.scene.control.Label) BranchIdValidator(bisq.desktop.util.validation.BranchIdValidator) Popup(bisq.desktop.main.overlays.popups.Popup) Region(bisq.core.locale.Region) Country(bisq.core.locale.Country) FiatCurrency(bisq.core.locale.FiatCurrency) AccountNrValidator(bisq.desktop.util.validation.AccountNrValidator)

Example 3 with AccountNrValidator

use of bisq.desktop.util.validation.AccountNrValidator in project bisq-desktop by bisq-network.

the class FasterPaymentsForm method addFormForAddAccount.

@Override
public void addFormForAddAccount() {
    gridRowFrom = gridRow + 1;
    // do not translate as it is used in english only
    sortCodeInputTextField = addLabelInputTextField(gridPane, ++gridRow, "UK sort code:").second;
    sortCodeInputTextField.setValidator(inputValidator);
    sortCodeInputTextField.setValidator(new BranchIdValidator("GB"));
    sortCodeInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        fasterPaymentsAccount.setSortCode(newValue);
        updateFromInputs();
    });
    accountNrInputTextField = addLabelInputTextField(gridPane, ++gridRow, Res.get("payment.accountNr")).second;
    accountNrInputTextField.setValidator(new AccountNrValidator("GB"));
    accountNrInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        fasterPaymentsAccount.setAccountNr(newValue);
        updateFromInputs();
    });
    TradeCurrency singleTradeCurrency = fasterPaymentsAccount.getSingleTradeCurrency();
    String nameAndCode = singleTradeCurrency != null ? singleTradeCurrency.getNameAndCode() : "";
    addLabelTextField(gridPane, ++gridRow, Res.getWithCol("shared.currency"), nameAndCode);
    addLimitations();
    addAccountNameTextFieldWithAutoFillCheckBox();
}
Also used : TradeCurrency(bisq.core.locale.TradeCurrency) BranchIdValidator(bisq.desktop.util.validation.BranchIdValidator) AccountNrValidator(bisq.desktop.util.validation.AccountNrValidator)

Aggregations

TradeCurrency (bisq.core.locale.TradeCurrency)3 AccountNrValidator (bisq.desktop.util.validation.AccountNrValidator)3 BranchIdValidator (bisq.desktop.util.validation.BranchIdValidator)3 Country (bisq.core.locale.Country)2 FiatCurrency (bisq.core.locale.FiatCurrency)2 Region (bisq.core.locale.Region)2 Popup (bisq.desktop.main.overlays.popups.Popup)2 BankIdValidator (bisq.desktop.util.validation.BankIdValidator)2 ComboBox (javafx.scene.control.ComboBox)2 Label (javafx.scene.control.Label)2 TextArea (javafx.scene.control.TextArea)1