Example usage for javafx.scene.control ComboBox setConverter

List of usage examples for javafx.scene.control ComboBox setConverter

Introduction

In this page you can find the example usage for javafx.scene.control ComboBox setConverter.

Prototype

public final void setConverter(StringConverter<T> value) 

Source Link

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group(), 450, 250);
    ObservableList<String> list = FXCollections.observableArrayList("1", "2", "3", "4");
    ComboBox<String> emailComboBox = new ComboBox<String>();
    emailComboBox.setItems(list);//  ww w  . j a v a2s.  c o m
    emailComboBox.setValue("A");

    StringConverter sc = new ShortStringConverter();
    emailComboBox.setConverter(sc);

    GridPane grid = new GridPane();
    grid.setVgap(4);
    grid.setHgap(10);
    grid.setPadding(new Insets(5, 5, 5, 5));
    grid.add(new Label("To: "), 0, 0);
    grid.add(emailComboBox, 1, 0);

    Group root = (Group) scene.getRoot();
    root.getChildren().add(grid);
    stage.setScene(scene);
    stage.show();

}

From source file:io.bitsquare.gui.components.paymentmethods.BankForm.java

@Override
public void addFormForAddAccount() {
    gridRowFrom = gridRow + 1;//from w w w.  j  a v a  2 s.c o  m

    Tuple3<Label, ComboBox, ComboBox> tuple3 = addLabelComboBoxComboBox(gridPane, ++gridRow, "Country:");

    ComboBox<Region> regionComboBox = tuple3.second;
    regionComboBox.setPromptText("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()));

    ComboBox<Country> countryComboBox = tuple3.third;
    countryComboBox.setVisibleRowCount(15);
    countryComboBox.setDisable(true);
    countryComboBox.setPromptText("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) {
            if (selectedItem.code.equals("US")) {
                new Popup<>().information(
                        "Bank transfer with WIRE or ACH is not supported for the US because WIRE is too expensive and ACH has a high chargeback risk.\n\n"
                                + "Please use payment methods \"ClearXchange\", \"US Postal Money Order\" or \"Cash/ATM Deposit\" instead.")
                        .onClose(() -> closeHandler.run()).show();
            } else {
                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(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)));
        }
    });

    currencyComboBox = addLabelComboBox(gridPane, ++gridRow, "Currency:").second;
    currencyComboBox.setPromptText("Select currency");
    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(
                    "Are you sure you want to choose a currency other than the country's default currency?")
                    .actionButtonText("Yes").onAction(() -> {
                        paymentAccount.setSingleTradeCurrency(selectedItem);
                        autoFillNameTextField();
                    }).closeButtonText("No, restore default currency")
                    .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, "Bank name:");
    bankNameInputTextField = bankNameTuple.second;

    bankNameInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        bankAccountContractData.setBankName(newValue);
        updateFromInputs();

    });

    bankIdTuple = addLabelInputTextField(gridPane, ++gridRow, BankUtil.getBankIdLabel(""));
    bankIdLabel = bankIdTuple.first;
    bankIdInputTextField = bankIdTuple.second;
    bankIdInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        bankAccountContractData.setBankId(newValue);
        updateFromInputs();

    });

    branchIdTuple = addLabelInputTextField(gridPane, ++gridRow, BankUtil.getBranchIdLabel(""));
    branchIdLabel = branchIdTuple.first;
    branchIdInputTextField = branchIdTuple.second;
    branchIdInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        bankAccountContractData.setBranchId(newValue);
        updateFromInputs();

    });

    accountNrTuple = addLabelInputTextField(gridPane, ++gridRow, BankUtil.getAccountNrLabel(""));
    accountNrLabel = accountNrTuple.first;
    accountNrInputTextField = accountNrTuple.second;
    accountNrInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        bankAccountContractData.setAccountNr(newValue);
        updateFromInputs();

    });

    accountTypeTuple = addLabelComboBox(gridPane, ++gridRow, "");
    accountTypeLabel = accountTypeTuple.first;
    accountTypeComboBox = accountTypeTuple.second;
    accountTypeComboBox.setPromptText("Select account type");
    accountTypeComboBox.setOnAction(e -> {
        if (BankUtil.isAccountTypeRequired(bankAccountContractData.getCountryCode())) {
            bankAccountContractData.setAccountType(accountTypeComboBox.getSelectionModel().getSelectedItem());
            updateFromInputs();
        }
    });

    addAllowedPeriod();
    addAccountNameTextFieldWithAutoFillCheckBox();

    updateFromInputs();
}

From source file:io.bitsquare.gui.components.paymentmethods.CashDepositForm.java

@Override
public void addFormForAddAccount() {
    gridRowFrom = gridRow + 1;//from   w  ww  . j av a 2s  .co m

    Tuple3<Label, ComboBox, ComboBox> tuple3 = addLabelComboBoxComboBox(gridPane, ++gridRow, "Country:");

    ComboBox<Region> regionComboBox = tuple3.second;
    regionComboBox.setPromptText("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()));

    ComboBox<Country> countryComboBox = tuple3.third;
    countryComboBox.setVisibleRowCount(15);
    countryComboBox.setDisable(true);
    countryComboBox.setPromptText("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();
            holderEmailInputTextField.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)));
        }
    });

    currencyComboBox = addLabelComboBox(gridPane, ++gridRow, "Currency:").second;
    currencyComboBox.setPromptText("Select currency");
    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(
                    "Are you sure you want to choose a currency other than the country's default currency?")
                    .actionButtonText("Yes").onAction(() -> {
                        paymentAccount.setSingleTradeCurrency(selectedItem);
                        autoFillNameTextField();
                    }).closeButtonText("No, restore default currency")
                    .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, "Bank name:");
    bankNameInputTextField = bankNameTuple.second;

    bankNameInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        cashDepositAccountContractData.setBankName(newValue);
        updateFromInputs();

    });

    bankIdTuple = addLabelInputTextField(gridPane, ++gridRow, BankUtil.getBankIdLabel(""));
    bankIdLabel = bankIdTuple.first;
    bankIdInputTextField = bankIdTuple.second;
    bankIdInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        cashDepositAccountContractData.setBankId(newValue);
        updateFromInputs();

    });

    branchIdTuple = addLabelInputTextField(gridPane, ++gridRow, BankUtil.getBranchIdLabel(""));
    branchIdLabel = branchIdTuple.first;
    branchIdInputTextField = branchIdTuple.second;
    branchIdInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        cashDepositAccountContractData.setBranchId(newValue);
        updateFromInputs();

    });

    accountNrTuple = addLabelInputTextField(gridPane, ++gridRow, BankUtil.getAccountNrLabel(""));
    accountNrLabel = accountNrTuple.first;
    accountNrInputTextField = accountNrTuple.second;
    accountNrInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        cashDepositAccountContractData.setAccountNr(newValue);
        updateFromInputs();

    });

    accountTypeTuple = addLabelComboBox(gridPane, ++gridRow, "");
    accountTypeLabel = accountTypeTuple.first;
    accountTypeComboBox = accountTypeTuple.second;
    accountTypeComboBox.setPromptText("Select account type");
    accountTypeComboBox.setOnAction(e -> {
        if (BankUtil.isAccountTypeRequired(cashDepositAccountContractData.getCountryCode())) {
            cashDepositAccountContractData
                    .setAccountType(accountTypeComboBox.getSelectionModel().getSelectedItem());
            updateFromInputs();
        }
    });

    TextArea requirementsTextArea = addLabelTextArea(gridPane, ++gridRow, "Extra requirements:", "").second;
    requirementsTextArea.setMinHeight(30);
    requirementsTextArea.setMaxHeight(30);
    requirementsTextArea.textProperty().addListener((ov, oldValue, newValue) -> {
        cashDepositAccountContractData.setRequirements(newValue);
        updateFromInputs();
    });

    addAllowedPeriod();
    addAccountNameTextFieldWithAutoFillCheckBox();

    updateFromInputs();
}

From source file:io.bitsquare.gui.components.paymentmethods.SepaForm.java

@Override
public void addFormForAddAccount() {
    gridRowFrom = gridRow + 1;/*from ww w  .  ja  va2s .  c o  m*/

    InputTextField holderNameInputTextField = addLabelInputTextField(gridPane, ++gridRow,
            "Account holder name:").second;
    holderNameInputTextField.setValidator(inputValidator);
    holderNameInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        sepaAccount.setHolderName(newValue);
        updateFromInputs();
    });

    ibanInputTextField = addLabelInputTextField(gridPane, ++gridRow, "IBAN:").second;
    ibanInputTextField.setValidator(ibanValidator);
    ibanInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        sepaAccount.setIban(newValue);
        updateFromInputs();

    });
    bicInputTextField = addLabelInputTextField(gridPane, ++gridRow, "BIC:").second;
    bicInputTextField.setValidator(bicValidator);
    bicInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        sepaAccount.setBic(newValue);
        updateFromInputs();

    });

    addLabel(gridPane, ++gridRow, "Country of bank:");
    HBox hBox = new HBox();
    hBox.setSpacing(10);
    ComboBox<Country> 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 bank");
    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();
        sepaAccount.setCountry(selectedItem);
        TradeCurrency currency = CurrencyUtil.getCurrencyByCountryCode(selectedItem.code);
        setupCurrency(selectedItem, currency);

        updateCountriesSelection(true, euroCountryCheckBoxes);
        updateCountriesSelection(true, nonEuroCountryCheckBoxes);
        updateFromInputs();
    });

    addEuroCountriesGrid(true);
    addNonEuroCountriesGrid(true);
    addAllowedPeriod();
    addAccountNameTextFieldWithAutoFillCheckBox();

    countryComboBox.setItems(FXCollections.observableArrayList(CountryUtil.getAllSepaCountries()));
    Country country = CountryUtil.getDefaultCountry();
    if (CountryUtil.getAllSepaCountries().contains(country)) {
        countryComboBox.getSelectionModel().select(country);
        sepaAccount.setCountry(country);
        TradeCurrency currency = CurrencyUtil.getCurrencyByCountryCode(country.code);
        setupCurrency(country, currency);
    }

    updateFromInputs();
}

From source file:gov.va.isaac.gui.refexViews.refexEdit.AddSememePopup.java

private void buildDataFields(boolean assemblageValid, DynamicSememeDataBI[] currentValues) {
    if (assemblageValid) {
        for (ReadOnlyStringProperty ssp : currentDataFieldWarnings_) {
            allValid_.removeBinding(ssp);
        }//  www  .  j  av  a 2 s  . c  o  m
        currentDataFieldWarnings_.clear();
        for (SememeGUIDataTypeNodeDetails nd : currentDataFields_) {
            nd.cleanupListener();
        }
        currentDataFields_.clear();

        GridPane gp = new GridPane();
        gp.setHgap(10.0);
        gp.setVgap(10.0);
        gp.setStyle("-fx-padding: 5;");
        int row = 0;
        boolean extraInfoColumnIsRequired = false;
        for (DynamicSememeColumnInfo ci : assemblageInfo_.getColumnInfo()) {
            SimpleStringProperty valueIsRequired = (ci.isColumnRequired() ? new SimpleStringProperty("")
                    : null);
            SimpleStringProperty defaultValueTooltip = ((ci.getDefaultColumnValue() == null
                    && ci.getValidator() == null) ? null : new SimpleStringProperty());
            ComboBox<DynamicSememeDataType> polymorphicType = null;

            Label l = new Label(ci.getColumnName());
            l.getStyleClass().add("boldLabel");
            l.setMinWidth(FxUtils.calculateNecessaryWidthOfBoldLabel(l));
            Tooltip.install(l, new Tooltip(ci.getColumnDescription()));
            int col = 0;
            gp.add(l, col++, row);

            if (ci.getColumnDataType() == DynamicSememeDataType.POLYMORPHIC) {
                polymorphicType = new ComboBox<>();
                polymorphicType.setEditable(false);
                polymorphicType.setConverter(new StringConverter<DynamicSememeDataType>() {

                    @Override
                    public String toString(DynamicSememeDataType object) {
                        return object.getDisplayName();
                    }

                    @Override
                    public DynamicSememeDataType fromString(String string) {
                        throw new RuntimeException("unecessary");
                    }
                });
                for (DynamicSememeDataType type : DynamicSememeDataType.values()) {
                    if (type == DynamicSememeDataType.POLYMORPHIC || type == DynamicSememeDataType.UNKNOWN) {
                        continue;
                    } else {
                        polymorphicType.getItems().add(type);
                    }
                }
                polymorphicType.getSelectionModel()
                        .select((currentValues == null ? DynamicSememeDataType.STRING
                                : (currentValues[row] == null ? DynamicSememeDataType.STRING
                                        : currentValues[row].getDynamicSememeDataType())));
            }

            SememeGUIDataTypeNodeDetails nd = SememeGUIDataTypeFXNodeBuilder.buildNodeForType(
                    ci.getColumnDataType(), ci.getDefaultColumnValue(),
                    (currentValues == null ? null : currentValues[row]), valueIsRequired, defaultValueTooltip,
                    (polymorphicType == null ? null
                            : polymorphicType.getSelectionModel().selectedItemProperty()),
                    allValid_, ci.getValidator(), ci.getValidatorData());

            currentDataFieldWarnings_.addAll(nd.getBoundToAllValid());
            if (ci.getColumnDataType() == DynamicSememeDataType.POLYMORPHIC) {
                nd.addUpdateParentListListener(currentDataFieldWarnings_);
            }

            currentDataFields_.add(nd);

            gp.add(nd.getNodeForDisplay(), col++, row);

            Label colType = new Label(ci.getColumnDataType().getDisplayName());
            colType.setMinWidth(FxUtils.calculateNecessaryWidthOfLabel(colType));
            gp.add((polymorphicType == null ? colType : polymorphicType), col++, row);

            if (ci.isColumnRequired() || ci.getDefaultColumnValue() != null || ci.getValidator() != null) {
                extraInfoColumnIsRequired = true;

                StackPane stackPane = new StackPane();
                stackPane.setMaxWidth(Double.MAX_VALUE);

                if (ci.getDefaultColumnValue() != null || ci.getValidator() != null) {
                    ImageView information = Images.INFORMATION.createImageView();
                    Tooltip tooltip = new Tooltip();
                    tooltip.textProperty().bind(defaultValueTooltip);
                    Tooltip.install(information, tooltip);
                    tooltip.setAutoHide(true);
                    information.setOnMouseClicked(
                            event -> tooltip.show(information, event.getScreenX(), event.getScreenY()));
                    stackPane.getChildren().add(information);
                }

                if (ci.isColumnRequired()) {
                    ImageView exclamation = Images.EXCLAMATION.createImageView();

                    final BooleanProperty showExclamation = new SimpleBooleanProperty(
                            StringUtils.isNotBlank(valueIsRequired.get()));
                    valueIsRequired.addListener((ChangeListener<String>) (observable, oldValue,
                            newValue) -> showExclamation.set(StringUtils.isNotBlank(newValue)));

                    exclamation.visibleProperty().bind(showExclamation);
                    Tooltip tooltip = new Tooltip();
                    tooltip.textProperty().bind(valueIsRequired);
                    Tooltip.install(exclamation, tooltip);
                    tooltip.setAutoHide(true);

                    exclamation.setOnMouseClicked(
                            event -> tooltip.show(exclamation, event.getScreenX(), event.getScreenY()));
                    stackPane.getChildren().add(exclamation);
                }

                gp.add(stackPane, col++, row);
            }
            row++;
        }

        ColumnConstraints cc = new ColumnConstraints();
        cc.setHgrow(Priority.NEVER);
        gp.getColumnConstraints().add(cc);

        cc = new ColumnConstraints();
        cc.setHgrow(Priority.ALWAYS);
        gp.getColumnConstraints().add(cc);

        cc = new ColumnConstraints();
        cc.setHgrow(Priority.NEVER);
        gp.getColumnConstraints().add(cc);

        if (extraInfoColumnIsRequired) {
            cc = new ColumnConstraints();
            cc.setHgrow(Priority.NEVER);
            gp.getColumnConstraints().add(cc);
        }

        if (row == 0) {
            sp_.setContent(new Label("This assemblage does not allow data fields"));
        } else {
            sp_.setContent(gp);
        }
        allValid_.invalidate();
    } else {
        sp_.setContent(null);
    }
}

From source file:gov.va.isaac.gui.refexViews.refexEdit.AddRefexPopup.java

private void buildDataFields(boolean assemblageValid, RefexDynamicDataBI[] currentValues) {
    if (assemblageValid) {
        for (ReadOnlyStringProperty ssp : currentDataFieldWarnings_) {
            allValid_.removeBinding(ssp);
        }//from ww  w .jav a  2s .c o m
        currentDataFieldWarnings_.clear();
        for (RefexDataTypeNodeDetails nd : currentDataFields_) {
            nd.cleanupListener();
        }
        currentDataFields_.clear();

        GridPane gp = new GridPane();
        gp.setHgap(10.0);
        gp.setVgap(10.0);
        gp.setStyle("-fx-padding: 5;");
        int row = 0;
        boolean extraInfoColumnIsRequired = false;
        for (RefexDynamicColumnInfo ci : assemblageInfo_.getColumnInfo()) {
            SimpleStringProperty valueIsRequired = (ci.isColumnRequired() ? new SimpleStringProperty("")
                    : null);
            SimpleStringProperty defaultValueTooltip = ((ci.getDefaultColumnValue() == null
                    && ci.getValidator() == null) ? null : new SimpleStringProperty());
            ComboBox<RefexDynamicDataType> polymorphicType = null;

            Label l = new Label(ci.getColumnName());
            l.getStyleClass().add("boldLabel");
            l.setMinWidth(FxUtils.calculateNecessaryWidthOfBoldLabel(l));
            Tooltip.install(l, new Tooltip(ci.getColumnDescription()));
            int col = 0;
            gp.add(l, col++, row);

            if (ci.getColumnDataType() == RefexDynamicDataType.POLYMORPHIC) {
                polymorphicType = new ComboBox<>();
                polymorphicType.setEditable(false);
                polymorphicType.setConverter(new StringConverter<RefexDynamicDataType>() {

                    @Override
                    public String toString(RefexDynamicDataType object) {
                        return object.getDisplayName();
                    }

                    @Override
                    public RefexDynamicDataType fromString(String string) {
                        throw new RuntimeException("unecessary");
                    }
                });
                for (RefexDynamicDataType type : RefexDynamicDataType.values()) {
                    if (type == RefexDynamicDataType.POLYMORPHIC || type == RefexDynamicDataType.UNKNOWN) {
                        continue;
                    } else {
                        polymorphicType.getItems().add(type);
                    }
                }
                polymorphicType.getSelectionModel()
                        .select((currentValues == null ? RefexDynamicDataType.STRING
                                : (currentValues[row] == null ? RefexDynamicDataType.STRING
                                        : currentValues[row].getRefexDataType())));
            }

            RefexDataTypeNodeDetails nd = RefexDataTypeFXNodeBuilder.buildNodeForType(ci.getColumnDataType(),
                    ci.getDefaultColumnValue(), (currentValues == null ? null : currentValues[row]),
                    valueIsRequired, defaultValueTooltip,
                    (polymorphicType == null ? null
                            : polymorphicType.getSelectionModel().selectedItemProperty()),
                    allValid_, new SimpleObjectProperty<>(ci.getValidator()),
                    new SimpleObjectProperty<>(ci.getValidatorData()));

            currentDataFieldWarnings_.addAll(nd.getBoundToAllValid());
            if (ci.getColumnDataType() == RefexDynamicDataType.POLYMORPHIC) {
                nd.addUpdateParentListListener(currentDataFieldWarnings_);
            }

            currentDataFields_.add(nd);

            gp.add(nd.getNodeForDisplay(), col++, row);

            Label colType = new Label(ci.getColumnDataType().getDisplayName());
            colType.setMinWidth(FxUtils.calculateNecessaryWidthOfLabel(colType));
            gp.add((polymorphicType == null ? colType : polymorphicType), col++, row);

            if (ci.isColumnRequired() || ci.getDefaultColumnValue() != null || ci.getValidator() != null) {
                extraInfoColumnIsRequired = true;

                StackPane stackPane = new StackPane();
                stackPane.setMaxWidth(Double.MAX_VALUE);

                if (ci.getDefaultColumnValue() != null || ci.getValidator() != null) {
                    ImageView information = Images.INFORMATION.createImageView();
                    Tooltip tooltip = new Tooltip();
                    tooltip.textProperty().bind(defaultValueTooltip);
                    Tooltip.install(information, tooltip);
                    tooltip.setAutoHide(true);
                    information.setOnMouseClicked(
                            event -> tooltip.show(information, event.getScreenX(), event.getScreenY()));
                    stackPane.getChildren().add(information);
                }

                if (ci.isColumnRequired()) {
                    ImageView exclamation = Images.EXCLAMATION.createImageView();

                    final BooleanProperty showExclamation = new SimpleBooleanProperty(
                            StringUtils.isNotBlank(valueIsRequired.get()));
                    valueIsRequired.addListener((ChangeListener<String>) (observable, oldValue,
                            newValue) -> showExclamation.set(StringUtils.isNotBlank(newValue)));

                    exclamation.visibleProperty().bind(showExclamation);
                    Tooltip tooltip = new Tooltip();
                    tooltip.textProperty().bind(valueIsRequired);
                    Tooltip.install(exclamation, tooltip);
                    tooltip.setAutoHide(true);

                    exclamation.setOnMouseClicked(
                            event -> tooltip.show(exclamation, event.getScreenX(), event.getScreenY()));
                    stackPane.getChildren().add(exclamation);
                }

                gp.add(stackPane, col++, row);
            }
            row++;
        }

        ColumnConstraints cc = new ColumnConstraints();
        cc.setHgrow(Priority.NEVER);
        gp.getColumnConstraints().add(cc);

        cc = new ColumnConstraints();
        cc.setHgrow(Priority.ALWAYS);
        gp.getColumnConstraints().add(cc);

        cc = new ColumnConstraints();
        cc.setHgrow(Priority.NEVER);
        gp.getColumnConstraints().add(cc);

        if (extraInfoColumnIsRequired) {
            cc = new ColumnConstraints();
            cc.setHgrow(Priority.NEVER);
            gp.getColumnConstraints().add(cc);
        }

        if (row == 0) {
            sp_.setContent(new Label("This assemblage does not allow data fields"));
        } else {
            sp_.setContent(gp);
        }
        allValid_.invalidate();
    } else {
        sp_.setContent(null);
    }
}