diff --git a/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountModel.java b/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountModel.java index cc66dc1a4d..562f967e6d 100644 --- a/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountModel.java +++ b/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountModel.java @@ -51,24 +51,23 @@ public class FiatAccountModel extends UIModel { private final Settings settings; private final Persistence persistence; - public final StringProperty title = new SimpleStringProperty(); - public final StringProperty holderName = new SimpleStringProperty(); - public final StringProperty primaryID = new SimpleStringProperty(); - public final StringProperty secondaryID = new SimpleStringProperty(); - public final StringProperty primaryIDPrompt = new SimpleStringProperty(); - public final StringProperty secondaryIDPrompt = new SimpleStringProperty(); - public final BooleanProperty countryNotInAcceptedCountriesList = new SimpleBooleanProperty(); - public final ObjectProperty type = new SimpleObjectProperty<>(); - public final ObjectProperty country = new SimpleObjectProperty<>(); - public final ObjectProperty currency = new SimpleObjectProperty<>(); - public final ObjectProperty currentBankAccount = new SimpleObjectProperty<>(); + final StringProperty title = new SimpleStringProperty(); + final StringProperty holderName = new SimpleStringProperty(); + final StringProperty primaryID = new SimpleStringProperty(); + final StringProperty secondaryID = new SimpleStringProperty(); + final StringProperty primaryIDPrompt = new SimpleStringProperty(); + final StringProperty secondaryIDPrompt = new SimpleStringProperty(); + final BooleanProperty countryNotInAcceptedCountriesList = new SimpleBooleanProperty(); + final ObjectProperty type = new SimpleObjectProperty<>(); + final ObjectProperty country = new SimpleObjectProperty<>(); + final ObjectProperty currency = new SimpleObjectProperty<>(); - public final ObservableList allTypes = FXCollections.observableArrayList(BankAccountType + final ObservableList allTypes = FXCollections.observableArrayList(BankAccountType .getAllBankAccountTypes()); - public final ObservableList allBankAccounts = FXCollections.observableArrayList(); - public final ObservableList allCurrencies = FXCollections.observableArrayList(CurrencyUtil + final ObservableList allBankAccounts = FXCollections.observableArrayList(); + final ObservableList allCurrencies = FXCollections.observableArrayList(CurrencyUtil .getAllCurrencies()); - public final ObservableList allRegions = FXCollections.observableArrayList(CountryUtil.getAllRegions()); + final ObservableList allRegions = FXCollections.observableArrayList(CountryUtil.getAllRegions()); /////////////////////////////////////////////////////////////////////////////////////////// @@ -76,7 +75,7 @@ public class FiatAccountModel extends UIModel { /////////////////////////////////////////////////////////////////////////////////////////// @Inject - private FiatAccountModel(User user, Persistence persistence, Settings settings) { + FiatAccountModel(User user, Persistence persistence, Settings settings) { this.persistence = persistence; this.user = user; this.settings = settings; @@ -97,7 +96,6 @@ public class FiatAccountModel extends UIModel { public void activate() { super.activate(); - currentBankAccount.set(user.getCurrentBankAccount()); allBankAccounts.setAll(user.getBankAccounts()); } @@ -118,7 +116,7 @@ public class FiatAccountModel extends UIModel { // Public /////////////////////////////////////////////////////////////////////////////////////////// - public void saveBankAccount() { + void saveBankAccount() { BankAccount bankAccount = new BankAccount(type.get(), currency.get(), country.get(), @@ -133,7 +131,7 @@ public class FiatAccountModel extends UIModel { reset(); } - public void removeBankAccount() { + void removeBankAccount() { user.removeCurrentBankAccount(); saveUser(); allBankAccounts.setAll(user.getBankAccounts()); @@ -142,15 +140,13 @@ public class FiatAccountModel extends UIModel { // We ask the user if he likes to add his own bank account country to the accepted country list if he has not // already added it before - public void addCountryToAcceptedCountriesList() { + void addCountryToAcceptedCountriesList() { settings.addAcceptedCountry(country.get()); saveSettings(); countryNotInAcceptedCountriesList.set(false); } - public void selectBankAccount(BankAccount bankAccount) { - currentBankAccount.set(bankAccount); - + void selectBankAccount(BankAccount bankAccount) { user.setCurrentBankAccount(bankAccount); persistence.write(user); @@ -176,7 +172,7 @@ public class FiatAccountModel extends UIModel { // Getters /////////////////////////////////////////////////////////////////////////////////////////// - public ObservableList getAllCountriesFor(Region selectedRegion) { + ObservableList getAllCountriesFor(Region selectedRegion) { return FXCollections.observableArrayList(CountryUtil.getAllCountriesFor(selectedRegion)); } @@ -185,7 +181,7 @@ public class FiatAccountModel extends UIModel { // Setters /////////////////////////////////////////////////////////////////////////////////////////// - public void setType(BankAccountType type) { + void setType(BankAccountType type) { this.type.set(type); if (type != null) { @@ -198,11 +194,11 @@ public class FiatAccountModel extends UIModel { } } - public void setCountry(Country country) { + void setCountry(Country country) { this.country.set(country); } - public void setCurrency(Currency currency) { + void setCurrency(Currency currency) { this.currency.set(currency); } diff --git a/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountPm.java b/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountPm.java index be322fe412..4aea0fa42d 100644 --- a/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountPm.java +++ b/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountPm.java @@ -48,18 +48,18 @@ public class FiatAccountPm extends PresentationModel { private final BankAccountNumberValidator bankAccountNumberValidator; - public final StringProperty title = new SimpleStringProperty(); - public final StringProperty holderName = new SimpleStringProperty(); - public final StringProperty primaryID = new SimpleStringProperty(); - public final StringProperty secondaryID = new SimpleStringProperty(); - public final StringProperty primaryIDPrompt = new SimpleStringProperty(); - public final StringProperty secondaryIDPrompt = new SimpleStringProperty(); - public final StringProperty selectionPrompt = new SimpleStringProperty(); - public final BooleanProperty selectionDisable = new SimpleBooleanProperty(); - public final BooleanProperty saveButtonDisable = new SimpleBooleanProperty(true); - public final ObjectProperty type = new SimpleObjectProperty<>(); - public final ObjectProperty country = new SimpleObjectProperty<>(); - public final ObjectProperty currency = new SimpleObjectProperty<>(); + final StringProperty title = new SimpleStringProperty(); + final StringProperty holderName = new SimpleStringProperty(); + final StringProperty primaryID = new SimpleStringProperty(); + final StringProperty secondaryID = new SimpleStringProperty(); + final StringProperty primaryIDPrompt = new SimpleStringProperty(); + final StringProperty secondaryIDPrompt = new SimpleStringProperty(); + final StringProperty selectionPrompt = new SimpleStringProperty(); + final BooleanProperty selectionDisable = new SimpleBooleanProperty(); + final BooleanProperty saveButtonDisable = new SimpleBooleanProperty(true); + final ObjectProperty type = new SimpleObjectProperty<>(); + final ObjectProperty country = new SimpleObjectProperty<>(); + final ObjectProperty currency = new SimpleObjectProperty<>(); /////////////////////////////////////////////////////////////////////////////////////////// @@ -67,7 +67,7 @@ public class FiatAccountPm extends PresentationModel { /////////////////////////////////////////////////////////////////////////////////////////// @Inject - private FiatAccountPm(FiatAccountModel model, BankAccountNumberValidator bankAccountNumberValidator) { + FiatAccountPm(FiatAccountModel model, BankAccountNumberValidator bankAccountNumberValidator) { super(model); this.bankAccountNumberValidator = bankAccountNumberValidator; } @@ -79,8 +79,6 @@ public class FiatAccountPm extends PresentationModel { @Override public void initialize() { - super.initialize(); - // input title.bindBidirectional(model.title); holderName.bindBidirectional(model.holderName); @@ -100,22 +98,16 @@ public class FiatAccountPm extends PresentationModel { holderName.addListener((ov, oldValue, newValue) -> validateInput()); primaryID.addListener((ov, oldValue, newValue) -> validateInput()); secondaryID.addListener((ov, oldValue, newValue) -> validateInput()); + + super.initialize(); } @Override public void activate() { super.activate(); - model.allBankAccounts.addListener((ListChangeListener) change -> { - if (model.allBankAccounts.isEmpty()) { - selectionPrompt.set("No bank account available"); - selectionDisable.set(true); - } - else { - selectionPrompt.set("Select bank account"); - selectionDisable.set(false); - } - }); + model.allBankAccounts.addListener((ListChangeListener) change -> applyAllBankAccounts()); + applyAllBankAccounts(); } @SuppressWarnings("EmptyMethod") @@ -135,7 +127,7 @@ public class FiatAccountPm extends PresentationModel { // Public /////////////////////////////////////////////////////////////////////////////////////////// - public InputValidator.ValidationResult requestSaveBankAccount() { + InputValidator.ValidationResult requestSaveBankAccount() { InputValidator.ValidationResult result = validateInput(); if (result.isValid) { model.saveBankAccount(); @@ -143,15 +135,15 @@ public class FiatAccountPm extends PresentationModel { return result; } - public void removeBankAccount() { + void removeBankAccount() { model.removeBankAccount(); } - public void addCountryToAcceptedCountriesList() { + void addCountryToAcceptedCountriesList() { model.addCountryToAcceptedCountriesList(); } - public void selectBankAccount(BankAccount bankAccount) { + void selectBankAccount(BankAccount bankAccount) { model.selectBankAccount(bankAccount); } @@ -160,7 +152,7 @@ public class FiatAccountPm extends PresentationModel { // Converters /////////////////////////////////////////////////////////////////////////////////////////// - public StringConverter getTypesConverter() { + StringConverter getTypesConverter() { return new StringConverter() { @Override public String toString(BankAccountType TypeInfo) { @@ -174,7 +166,7 @@ public class FiatAccountPm extends PresentationModel { }; } - public StringConverter getSelectionConverter() { + StringConverter getSelectionConverter() { return new StringConverter() { @Override public String toString(BankAccount bankAccount) { @@ -188,7 +180,7 @@ public class FiatAccountPm extends PresentationModel { }; } - public StringConverter getCurrencyConverter() { + StringConverter getCurrencyConverter() { return new StringConverter() { @Override @@ -204,7 +196,7 @@ public class FiatAccountPm extends PresentationModel { }; } - public StringConverter getRegionConverter() { + StringConverter getRegionConverter() { return new StringConverter() { @Override public String toString(io.bitsquare.locale.Region region) { @@ -218,7 +210,7 @@ public class FiatAccountPm extends PresentationModel { }; } - public StringConverter getCountryConverter() { + StringConverter getCountryConverter() { return new StringConverter() { @Override public String toString(Country country) { @@ -237,35 +229,31 @@ public class FiatAccountPm extends PresentationModel { // Getters /////////////////////////////////////////////////////////////////////////////////////////// - public ObservableList getAllTypes() { + ObservableList getAllTypes() { return model.allTypes; } - public ObjectProperty getCurrentBankAccount() { - return model.currentBankAccount; - } - - public ObservableList getAllBankAccounts() { + ObservableList getAllBankAccounts() { return model.allBankAccounts; } - public ObservableList getAllCurrencies() { + ObservableList getAllCurrencies() { return model.allCurrencies; } - public ObservableList getAllRegions() { + ObservableList getAllRegions() { return model.allRegions; } - public BooleanProperty getCountryNotInAcceptedCountriesList() { + BooleanProperty getCountryNotInAcceptedCountriesList() { return model.countryNotInAcceptedCountriesList; } - public ObservableList getAllCountriesFor(Region selectedRegion) { + ObservableList getAllCountriesFor(Region selectedRegion) { return model.getAllCountriesFor(selectedRegion); } - public BankAccountNumberValidator getBankAccountNumberValidator() { + BankAccountNumberValidator getBankAccountNumberValidator() { return bankAccountNumberValidator; } @@ -274,17 +262,17 @@ public class FiatAccountPm extends PresentationModel { // Setters /////////////////////////////////////////////////////////////////////////////////////////// - public void setType(BankAccountType type) { + void setType(BankAccountType type) { model.setType(type); validateInput(); } - public void setCountry(Country country) { + void setCountry(Country country) { model.setCountry(country); validateInput(); } - public void setCurrency(Currency currency) { + void setCurrency(Currency currency) { model.setCurrency(currency); validateInput(); } @@ -294,6 +282,17 @@ public class FiatAccountPm extends PresentationModel { // Private methods /////////////////////////////////////////////////////////////////////////////////////////// + private void applyAllBankAccounts() { + if (model.allBankAccounts.isEmpty()) { + selectionPrompt.set("No bank account available"); + selectionDisable.set(true); + } + else { + selectionPrompt.set("Select bank account"); + selectionDisable.set(false); + } + } + private InputValidator.ValidationResult validateInput() { InputValidator.ValidationResult result = bankAccountNumberValidator.validate(model.title.get()); if (result.isValid) { diff --git a/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountViewCB.java b/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountViewCB.java index 82027933ad..48407ebba1 100644 --- a/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountViewCB.java +++ b/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountViewCB.java @@ -71,7 +71,7 @@ public class FiatAccountViewCB extends CachedViewCB implements Co /////////////////////////////////////////////////////////////////////////////////////////// @Inject - private FiatAccountViewCB(FiatAccountPm presentationModel) { + FiatAccountViewCB(FiatAccountPm presentationModel) { super(presentationModel); } @@ -82,11 +82,8 @@ public class FiatAccountViewCB extends CachedViewCB implements Co @Override public void initialize(URL url, ResourceBundle rb) { - super.initialize(url, rb); - typesComboBox.setItems(presentationModel.getAllTypes()); typesComboBox.setConverter(presentationModel.getTypesConverter()); - selectionComboBox.setItems(presentationModel.getAllBankAccounts()); selectionComboBox.setConverter(presentationModel.getSelectionConverter()); currencyComboBox.setItems(presentationModel.getAllCurrencies()); currencyComboBox.setConverter(presentationModel.getCurrencyConverter()); @@ -98,6 +95,8 @@ public class FiatAccountViewCB extends CachedViewCB implements Co holderNameTextField.setValidator(presentationModel.getBankAccountNumberValidator()); primaryIDTextField.setValidator(presentationModel.getBankAccountNumberValidator()); secondaryIDTextField.setValidator(presentationModel.getBankAccountNumberValidator()); + + super.initialize(url, rb); } @Override @@ -106,6 +105,8 @@ public class FiatAccountViewCB extends CachedViewCB implements Co setupListeners(); setupBindings(); + + selectionComboBox.setItems(presentationModel.getAllBankAccounts()); } @SuppressWarnings("EmptyMethod") @@ -137,35 +138,35 @@ public class FiatAccountViewCB extends CachedViewCB implements Co /////////////////////////////////////////////////////////////////////////////////////////// @FXML - public void onSelectAccount() { + void onSelectAccount() { if (selectionComboBox.getSelectionModel().getSelectedItem() != null) presentationModel.selectBankAccount(selectionComboBox.getSelectionModel().getSelectedItem()); } @FXML - public void onSelectType() { + void onSelectType() { presentationModel.setType(typesComboBox.getSelectionModel().getSelectedItem()); } @FXML - public void onSelectCurrency() { + void onSelectCurrency() { presentationModel.setCurrency(currencyComboBox.getSelectionModel().getSelectedItem()); } @FXML - private void onSelectRegion() { + void onSelectRegion() { countryComboBox.setVisible(true); Region region = regionComboBox.getSelectionModel().getSelectedItem(); countryComboBox.setItems(presentationModel.getAllCountriesFor(region)); } @FXML - private void onSelectCountry() { + void onSelectCountry() { presentationModel.setCountry(countryComboBox.getSelectionModel().getSelectedItem()); } @FXML - private void onSave() { + void onSave() { InputValidator.ValidationResult result = presentationModel.requestSaveBankAccount(); if (result.isValid) { selectionComboBox.getSelectionModel().select(null); @@ -175,24 +176,24 @@ public class FiatAccountViewCB extends CachedViewCB implements Co } @FXML - private void onCompleted() { + void onCompleted() { if (parent != null) ((MultiStepNavigation) parent).nextStep(this); } @FXML - private void onRemoveAccount() { + void onRemoveAccount() { presentationModel.removeBankAccount(); selectionComboBox.getSelectionModel().select(null); } @FXML - private void onOpenSetupHelp() { + void onOpenSetupHelp() { Help.openWindow(HelpId.SETUP_FIAT_ACCOUNT); } @FXML - private void onOpenManageAccountsHelp() { + void onOpenManageAccountsHelp() { Help.openWindow(HelpId.MANAGE_FIAT_ACCOUNT); }