Fix bug that bank account list was not populated

This commit is contained in:
Manfred Karrer 2014-09-17 00:02:34 +02:00
parent d0ccc365dc
commit c668d3578d
3 changed files with 85 additions and 89 deletions

View file

@ -51,24 +51,23 @@ public class FiatAccountModel extends UIModel {
private final Settings settings; private final Settings settings;
private final Persistence persistence; private final Persistence persistence;
public final StringProperty title = new SimpleStringProperty(); final StringProperty title = new SimpleStringProperty();
public final StringProperty holderName = new SimpleStringProperty(); final StringProperty holderName = new SimpleStringProperty();
public final StringProperty primaryID = new SimpleStringProperty(); final StringProperty primaryID = new SimpleStringProperty();
public final StringProperty secondaryID = new SimpleStringProperty(); final StringProperty secondaryID = new SimpleStringProperty();
public final StringProperty primaryIDPrompt = new SimpleStringProperty(); final StringProperty primaryIDPrompt = new SimpleStringProperty();
public final StringProperty secondaryIDPrompt = new SimpleStringProperty(); final StringProperty secondaryIDPrompt = new SimpleStringProperty();
public final BooleanProperty countryNotInAcceptedCountriesList = new SimpleBooleanProperty(); final BooleanProperty countryNotInAcceptedCountriesList = new SimpleBooleanProperty();
public final ObjectProperty<BankAccountType> type = new SimpleObjectProperty<>(); final ObjectProperty<BankAccountType> type = new SimpleObjectProperty<>();
public final ObjectProperty<Country> country = new SimpleObjectProperty<>(); final ObjectProperty<Country> country = new SimpleObjectProperty<>();
public final ObjectProperty<Currency> currency = new SimpleObjectProperty<>(); final ObjectProperty<Currency> currency = new SimpleObjectProperty<>();
public final ObjectProperty<BankAccount> currentBankAccount = new SimpleObjectProperty<>();
public final ObservableList<BankAccountType> allTypes = FXCollections.observableArrayList(BankAccountType final ObservableList<BankAccountType> allTypes = FXCollections.observableArrayList(BankAccountType
.getAllBankAccountTypes()); .getAllBankAccountTypes());
public final ObservableList<BankAccount> allBankAccounts = FXCollections.observableArrayList(); final ObservableList<BankAccount> allBankAccounts = FXCollections.observableArrayList();
public final ObservableList<Currency> allCurrencies = FXCollections.observableArrayList(CurrencyUtil final ObservableList<Currency> allCurrencies = FXCollections.observableArrayList(CurrencyUtil
.getAllCurrencies()); .getAllCurrencies());
public final ObservableList<Region> allRegions = FXCollections.observableArrayList(CountryUtil.getAllRegions()); final ObservableList<Region> allRegions = FXCollections.observableArrayList(CountryUtil.getAllRegions());
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@ -76,7 +75,7 @@ public class FiatAccountModel extends UIModel {
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@Inject @Inject
private FiatAccountModel(User user, Persistence persistence, Settings settings) { FiatAccountModel(User user, Persistence persistence, Settings settings) {
this.persistence = persistence; this.persistence = persistence;
this.user = user; this.user = user;
this.settings = settings; this.settings = settings;
@ -97,7 +96,6 @@ public class FiatAccountModel extends UIModel {
public void activate() { public void activate() {
super.activate(); super.activate();
currentBankAccount.set(user.getCurrentBankAccount());
allBankAccounts.setAll(user.getBankAccounts()); allBankAccounts.setAll(user.getBankAccounts());
} }
@ -118,7 +116,7 @@ public class FiatAccountModel extends UIModel {
// Public // Public
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
public void saveBankAccount() { void saveBankAccount() {
BankAccount bankAccount = new BankAccount(type.get(), BankAccount bankAccount = new BankAccount(type.get(),
currency.get(), currency.get(),
country.get(), country.get(),
@ -133,7 +131,7 @@ public class FiatAccountModel extends UIModel {
reset(); reset();
} }
public void removeBankAccount() { void removeBankAccount() {
user.removeCurrentBankAccount(); user.removeCurrentBankAccount();
saveUser(); saveUser();
allBankAccounts.setAll(user.getBankAccounts()); 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 // 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 // already added it before
public void addCountryToAcceptedCountriesList() { void addCountryToAcceptedCountriesList() {
settings.addAcceptedCountry(country.get()); settings.addAcceptedCountry(country.get());
saveSettings(); saveSettings();
countryNotInAcceptedCountriesList.set(false); countryNotInAcceptedCountriesList.set(false);
} }
public void selectBankAccount(BankAccount bankAccount) { void selectBankAccount(BankAccount bankAccount) {
currentBankAccount.set(bankAccount);
user.setCurrentBankAccount(bankAccount); user.setCurrentBankAccount(bankAccount);
persistence.write(user); persistence.write(user);
@ -176,7 +172,7 @@ public class FiatAccountModel extends UIModel {
// Getters // Getters
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
public ObservableList<Country> getAllCountriesFor(Region selectedRegion) { ObservableList<Country> getAllCountriesFor(Region selectedRegion) {
return FXCollections.observableArrayList(CountryUtil.getAllCountriesFor(selectedRegion)); return FXCollections.observableArrayList(CountryUtil.getAllCountriesFor(selectedRegion));
} }
@ -185,7 +181,7 @@ public class FiatAccountModel extends UIModel {
// Setters // Setters
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
public void setType(BankAccountType type) { void setType(BankAccountType type) {
this.type.set(type); this.type.set(type);
if (type != null) { 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); this.country.set(country);
} }
public void setCurrency(Currency currency) { void setCurrency(Currency currency) {
this.currency.set(currency); this.currency.set(currency);
} }

View file

@ -48,18 +48,18 @@ public class FiatAccountPm extends PresentationModel<FiatAccountModel> {
private final BankAccountNumberValidator bankAccountNumberValidator; private final BankAccountNumberValidator bankAccountNumberValidator;
public final StringProperty title = new SimpleStringProperty(); final StringProperty title = new SimpleStringProperty();
public final StringProperty holderName = new SimpleStringProperty(); final StringProperty holderName = new SimpleStringProperty();
public final StringProperty primaryID = new SimpleStringProperty(); final StringProperty primaryID = new SimpleStringProperty();
public final StringProperty secondaryID = new SimpleStringProperty(); final StringProperty secondaryID = new SimpleStringProperty();
public final StringProperty primaryIDPrompt = new SimpleStringProperty(); final StringProperty primaryIDPrompt = new SimpleStringProperty();
public final StringProperty secondaryIDPrompt = new SimpleStringProperty(); final StringProperty secondaryIDPrompt = new SimpleStringProperty();
public final StringProperty selectionPrompt = new SimpleStringProperty(); final StringProperty selectionPrompt = new SimpleStringProperty();
public final BooleanProperty selectionDisable = new SimpleBooleanProperty(); final BooleanProperty selectionDisable = new SimpleBooleanProperty();
public final BooleanProperty saveButtonDisable = new SimpleBooleanProperty(true); final BooleanProperty saveButtonDisable = new SimpleBooleanProperty(true);
public final ObjectProperty<BankAccountType> type = new SimpleObjectProperty<>(); final ObjectProperty<BankAccountType> type = new SimpleObjectProperty<>();
public final ObjectProperty<Country> country = new SimpleObjectProperty<>(); final ObjectProperty<Country> country = new SimpleObjectProperty<>();
public final ObjectProperty<Currency> currency = new SimpleObjectProperty<>(); final ObjectProperty<Currency> currency = new SimpleObjectProperty<>();
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@ -67,7 +67,7 @@ public class FiatAccountPm extends PresentationModel<FiatAccountModel> {
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@Inject @Inject
private FiatAccountPm(FiatAccountModel model, BankAccountNumberValidator bankAccountNumberValidator) { FiatAccountPm(FiatAccountModel model, BankAccountNumberValidator bankAccountNumberValidator) {
super(model); super(model);
this.bankAccountNumberValidator = bankAccountNumberValidator; this.bankAccountNumberValidator = bankAccountNumberValidator;
} }
@ -79,8 +79,6 @@ public class FiatAccountPm extends PresentationModel<FiatAccountModel> {
@Override @Override
public void initialize() { public void initialize() {
super.initialize();
// input // input
title.bindBidirectional(model.title); title.bindBidirectional(model.title);
holderName.bindBidirectional(model.holderName); holderName.bindBidirectional(model.holderName);
@ -100,22 +98,16 @@ public class FiatAccountPm extends PresentationModel<FiatAccountModel> {
holderName.addListener((ov, oldValue, newValue) -> validateInput()); holderName.addListener((ov, oldValue, newValue) -> validateInput());
primaryID.addListener((ov, oldValue, newValue) -> validateInput()); primaryID.addListener((ov, oldValue, newValue) -> validateInput());
secondaryID.addListener((ov, oldValue, newValue) -> validateInput()); secondaryID.addListener((ov, oldValue, newValue) -> validateInput());
super.initialize();
} }
@Override @Override
public void activate() { public void activate() {
super.activate(); super.activate();
model.allBankAccounts.addListener((ListChangeListener<BankAccount>) change -> { model.allBankAccounts.addListener((ListChangeListener<BankAccount>) change -> applyAllBankAccounts());
if (model.allBankAccounts.isEmpty()) { applyAllBankAccounts();
selectionPrompt.set("No bank account available");
selectionDisable.set(true);
}
else {
selectionPrompt.set("Select bank account");
selectionDisable.set(false);
}
});
} }
@SuppressWarnings("EmptyMethod") @SuppressWarnings("EmptyMethod")
@ -135,7 +127,7 @@ public class FiatAccountPm extends PresentationModel<FiatAccountModel> {
// Public // Public
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
public InputValidator.ValidationResult requestSaveBankAccount() { InputValidator.ValidationResult requestSaveBankAccount() {
InputValidator.ValidationResult result = validateInput(); InputValidator.ValidationResult result = validateInput();
if (result.isValid) { if (result.isValid) {
model.saveBankAccount(); model.saveBankAccount();
@ -143,15 +135,15 @@ public class FiatAccountPm extends PresentationModel<FiatAccountModel> {
return result; return result;
} }
public void removeBankAccount() { void removeBankAccount() {
model.removeBankAccount(); model.removeBankAccount();
} }
public void addCountryToAcceptedCountriesList() { void addCountryToAcceptedCountriesList() {
model.addCountryToAcceptedCountriesList(); model.addCountryToAcceptedCountriesList();
} }
public void selectBankAccount(BankAccount bankAccount) { void selectBankAccount(BankAccount bankAccount) {
model.selectBankAccount(bankAccount); model.selectBankAccount(bankAccount);
} }
@ -160,7 +152,7 @@ public class FiatAccountPm extends PresentationModel<FiatAccountModel> {
// Converters // Converters
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
public StringConverter<BankAccountType> getTypesConverter() { StringConverter<BankAccountType> getTypesConverter() {
return new StringConverter<BankAccountType>() { return new StringConverter<BankAccountType>() {
@Override @Override
public String toString(BankAccountType TypeInfo) { public String toString(BankAccountType TypeInfo) {
@ -174,7 +166,7 @@ public class FiatAccountPm extends PresentationModel<FiatAccountModel> {
}; };
} }
public StringConverter<BankAccount> getSelectionConverter() { StringConverter<BankAccount> getSelectionConverter() {
return new StringConverter<BankAccount>() { return new StringConverter<BankAccount>() {
@Override @Override
public String toString(BankAccount bankAccount) { public String toString(BankAccount bankAccount) {
@ -188,7 +180,7 @@ public class FiatAccountPm extends PresentationModel<FiatAccountModel> {
}; };
} }
public StringConverter<Currency> getCurrencyConverter() { StringConverter<Currency> getCurrencyConverter() {
return new StringConverter<Currency>() { return new StringConverter<Currency>() {
@Override @Override
@ -204,7 +196,7 @@ public class FiatAccountPm extends PresentationModel<FiatAccountModel> {
}; };
} }
public StringConverter<Region> getRegionConverter() { StringConverter<Region> getRegionConverter() {
return new StringConverter<io.bitsquare.locale.Region>() { return new StringConverter<io.bitsquare.locale.Region>() {
@Override @Override
public String toString(io.bitsquare.locale.Region region) { public String toString(io.bitsquare.locale.Region region) {
@ -218,7 +210,7 @@ public class FiatAccountPm extends PresentationModel<FiatAccountModel> {
}; };
} }
public StringConverter<Country> getCountryConverter() { StringConverter<Country> getCountryConverter() {
return new StringConverter<Country>() { return new StringConverter<Country>() {
@Override @Override
public String toString(Country country) { public String toString(Country country) {
@ -237,35 +229,31 @@ public class FiatAccountPm extends PresentationModel<FiatAccountModel> {
// Getters // Getters
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
public ObservableList<BankAccountType> getAllTypes() { ObservableList<BankAccountType> getAllTypes() {
return model.allTypes; return model.allTypes;
} }
public ObjectProperty<BankAccount> getCurrentBankAccount() { ObservableList<BankAccount> getAllBankAccounts() {
return model.currentBankAccount;
}
public ObservableList<BankAccount> getAllBankAccounts() {
return model.allBankAccounts; return model.allBankAccounts;
} }
public ObservableList<Currency> getAllCurrencies() { ObservableList<Currency> getAllCurrencies() {
return model.allCurrencies; return model.allCurrencies;
} }
public ObservableList<Region> getAllRegions() { ObservableList<Region> getAllRegions() {
return model.allRegions; return model.allRegions;
} }
public BooleanProperty getCountryNotInAcceptedCountriesList() { BooleanProperty getCountryNotInAcceptedCountriesList() {
return model.countryNotInAcceptedCountriesList; return model.countryNotInAcceptedCountriesList;
} }
public ObservableList<Country> getAllCountriesFor(Region selectedRegion) { ObservableList<Country> getAllCountriesFor(Region selectedRegion) {
return model.getAllCountriesFor(selectedRegion); return model.getAllCountriesFor(selectedRegion);
} }
public BankAccountNumberValidator getBankAccountNumberValidator() { BankAccountNumberValidator getBankAccountNumberValidator() {
return bankAccountNumberValidator; return bankAccountNumberValidator;
} }
@ -274,17 +262,17 @@ public class FiatAccountPm extends PresentationModel<FiatAccountModel> {
// Setters // Setters
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
public void setType(BankAccountType type) { void setType(BankAccountType type) {
model.setType(type); model.setType(type);
validateInput(); validateInput();
} }
public void setCountry(Country country) { void setCountry(Country country) {
model.setCountry(country); model.setCountry(country);
validateInput(); validateInput();
} }
public void setCurrency(Currency currency) { void setCurrency(Currency currency) {
model.setCurrency(currency); model.setCurrency(currency);
validateInput(); validateInput();
} }
@ -294,6 +282,17 @@ public class FiatAccountPm extends PresentationModel<FiatAccountModel> {
// Private methods // 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() { private InputValidator.ValidationResult validateInput() {
InputValidator.ValidationResult result = bankAccountNumberValidator.validate(model.title.get()); InputValidator.ValidationResult result = bankAccountNumberValidator.validate(model.title.get());
if (result.isValid) { if (result.isValid) {

View file

@ -71,7 +71,7 @@ public class FiatAccountViewCB extends CachedViewCB<FiatAccountPm> implements Co
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@Inject @Inject
private FiatAccountViewCB(FiatAccountPm presentationModel) { FiatAccountViewCB(FiatAccountPm presentationModel) {
super(presentationModel); super(presentationModel);
} }
@ -82,11 +82,8 @@ public class FiatAccountViewCB extends CachedViewCB<FiatAccountPm> implements Co
@Override @Override
public void initialize(URL url, ResourceBundle rb) { public void initialize(URL url, ResourceBundle rb) {
super.initialize(url, rb);
typesComboBox.setItems(presentationModel.getAllTypes()); typesComboBox.setItems(presentationModel.getAllTypes());
typesComboBox.setConverter(presentationModel.getTypesConverter()); typesComboBox.setConverter(presentationModel.getTypesConverter());
selectionComboBox.setItems(presentationModel.getAllBankAccounts());
selectionComboBox.setConverter(presentationModel.getSelectionConverter()); selectionComboBox.setConverter(presentationModel.getSelectionConverter());
currencyComboBox.setItems(presentationModel.getAllCurrencies()); currencyComboBox.setItems(presentationModel.getAllCurrencies());
currencyComboBox.setConverter(presentationModel.getCurrencyConverter()); currencyComboBox.setConverter(presentationModel.getCurrencyConverter());
@ -98,6 +95,8 @@ public class FiatAccountViewCB extends CachedViewCB<FiatAccountPm> implements Co
holderNameTextField.setValidator(presentationModel.getBankAccountNumberValidator()); holderNameTextField.setValidator(presentationModel.getBankAccountNumberValidator());
primaryIDTextField.setValidator(presentationModel.getBankAccountNumberValidator()); primaryIDTextField.setValidator(presentationModel.getBankAccountNumberValidator());
secondaryIDTextField.setValidator(presentationModel.getBankAccountNumberValidator()); secondaryIDTextField.setValidator(presentationModel.getBankAccountNumberValidator());
super.initialize(url, rb);
} }
@Override @Override
@ -106,6 +105,8 @@ public class FiatAccountViewCB extends CachedViewCB<FiatAccountPm> implements Co
setupListeners(); setupListeners();
setupBindings(); setupBindings();
selectionComboBox.setItems(presentationModel.getAllBankAccounts());
} }
@SuppressWarnings("EmptyMethod") @SuppressWarnings("EmptyMethod")
@ -137,35 +138,35 @@ public class FiatAccountViewCB extends CachedViewCB<FiatAccountPm> implements Co
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@FXML @FXML
public void onSelectAccount() { void onSelectAccount() {
if (selectionComboBox.getSelectionModel().getSelectedItem() != null) if (selectionComboBox.getSelectionModel().getSelectedItem() != null)
presentationModel.selectBankAccount(selectionComboBox.getSelectionModel().getSelectedItem()); presentationModel.selectBankAccount(selectionComboBox.getSelectionModel().getSelectedItem());
} }
@FXML @FXML
public void onSelectType() { void onSelectType() {
presentationModel.setType(typesComboBox.getSelectionModel().getSelectedItem()); presentationModel.setType(typesComboBox.getSelectionModel().getSelectedItem());
} }
@FXML @FXML
public void onSelectCurrency() { void onSelectCurrency() {
presentationModel.setCurrency(currencyComboBox.getSelectionModel().getSelectedItem()); presentationModel.setCurrency(currencyComboBox.getSelectionModel().getSelectedItem());
} }
@FXML @FXML
private void onSelectRegion() { void onSelectRegion() {
countryComboBox.setVisible(true); countryComboBox.setVisible(true);
Region region = regionComboBox.getSelectionModel().getSelectedItem(); Region region = regionComboBox.getSelectionModel().getSelectedItem();
countryComboBox.setItems(presentationModel.getAllCountriesFor(region)); countryComboBox.setItems(presentationModel.getAllCountriesFor(region));
} }
@FXML @FXML
private void onSelectCountry() { void onSelectCountry() {
presentationModel.setCountry(countryComboBox.getSelectionModel().getSelectedItem()); presentationModel.setCountry(countryComboBox.getSelectionModel().getSelectedItem());
} }
@FXML @FXML
private void onSave() { void onSave() {
InputValidator.ValidationResult result = presentationModel.requestSaveBankAccount(); InputValidator.ValidationResult result = presentationModel.requestSaveBankAccount();
if (result.isValid) { if (result.isValid) {
selectionComboBox.getSelectionModel().select(null); selectionComboBox.getSelectionModel().select(null);
@ -175,24 +176,24 @@ public class FiatAccountViewCB extends CachedViewCB<FiatAccountPm> implements Co
} }
@FXML @FXML
private void onCompleted() { void onCompleted() {
if (parent != null) if (parent != null)
((MultiStepNavigation) parent).nextStep(this); ((MultiStepNavigation) parent).nextStep(this);
} }
@FXML @FXML
private void onRemoveAccount() { void onRemoveAccount() {
presentationModel.removeBankAccount(); presentationModel.removeBankAccount();
selectionComboBox.getSelectionModel().select(null); selectionComboBox.getSelectionModel().select(null);
} }
@FXML @FXML
private void onOpenSetupHelp() { void onOpenSetupHelp() {
Help.openWindow(HelpId.SETUP_FIAT_ACCOUNT); Help.openWindow(HelpId.SETUP_FIAT_ACCOUNT);
} }
@FXML @FXML
private void onOpenManageAccountsHelp() { void onOpenManageAccountsHelp() {
Help.openWindow(HelpId.MANAGE_FIAT_ACCOUNT); Help.openWindow(HelpId.MANAGE_FIAT_ACCOUNT);
} }