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 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<BankAccountType> type = new SimpleObjectProperty<>();
public final ObjectProperty<Country> country = new SimpleObjectProperty<>();
public final ObjectProperty<Currency> currency = new SimpleObjectProperty<>();
public final ObjectProperty<BankAccount> 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<BankAccountType> type = new SimpleObjectProperty<>();
final ObjectProperty<Country> country = new SimpleObjectProperty<>();
final ObjectProperty<Currency> currency = new SimpleObjectProperty<>();
public final ObservableList<BankAccountType> allTypes = FXCollections.observableArrayList(BankAccountType
final ObservableList<BankAccountType> allTypes = FXCollections.observableArrayList(BankAccountType
.getAllBankAccountTypes());
public final ObservableList<BankAccount> allBankAccounts = FXCollections.observableArrayList();
public final ObservableList<Currency> allCurrencies = FXCollections.observableArrayList(CurrencyUtil
final ObservableList<BankAccount> allBankAccounts = FXCollections.observableArrayList();
final ObservableList<Currency> allCurrencies = FXCollections.observableArrayList(CurrencyUtil
.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
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<Country> getAllCountriesFor(Region selectedRegion) {
ObservableList<Country> 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);
}

View File

@ -48,18 +48,18 @@ public class FiatAccountPm extends PresentationModel<FiatAccountModel> {
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<BankAccountType> type = new SimpleObjectProperty<>();
public final ObjectProperty<Country> country = new SimpleObjectProperty<>();
public final ObjectProperty<Currency> 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<BankAccountType> type = new SimpleObjectProperty<>();
final ObjectProperty<Country> country = new SimpleObjectProperty<>();
final ObjectProperty<Currency> currency = new SimpleObjectProperty<>();
///////////////////////////////////////////////////////////////////////////////////////////
@ -67,7 +67,7 @@ public class FiatAccountPm extends PresentationModel<FiatAccountModel> {
///////////////////////////////////////////////////////////////////////////////////////////
@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<FiatAccountModel> {
@Override
public void initialize() {
super.initialize();
// input
title.bindBidirectional(model.title);
holderName.bindBidirectional(model.holderName);
@ -100,22 +98,16 @@ public class FiatAccountPm extends PresentationModel<FiatAccountModel> {
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<BankAccount>) 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<BankAccount>) change -> applyAllBankAccounts());
applyAllBankAccounts();
}
@SuppressWarnings("EmptyMethod")
@ -135,7 +127,7 @@ public class FiatAccountPm extends PresentationModel<FiatAccountModel> {
// 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<FiatAccountModel> {
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<FiatAccountModel> {
// Converters
///////////////////////////////////////////////////////////////////////////////////////////
public StringConverter<BankAccountType> getTypesConverter() {
StringConverter<BankAccountType> getTypesConverter() {
return new StringConverter<BankAccountType>() {
@Override
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>() {
@Override
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>() {
@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>() {
@Override
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>() {
@Override
public String toString(Country country) {
@ -237,35 +229,31 @@ public class FiatAccountPm extends PresentationModel<FiatAccountModel> {
// Getters
///////////////////////////////////////////////////////////////////////////////////////////
public ObservableList<BankAccountType> getAllTypes() {
ObservableList<BankAccountType> getAllTypes() {
return model.allTypes;
}
public ObjectProperty<BankAccount> getCurrentBankAccount() {
return model.currentBankAccount;
}
public ObservableList<BankAccount> getAllBankAccounts() {
ObservableList<BankAccount> getAllBankAccounts() {
return model.allBankAccounts;
}
public ObservableList<Currency> getAllCurrencies() {
ObservableList<Currency> getAllCurrencies() {
return model.allCurrencies;
}
public ObservableList<Region> getAllRegions() {
ObservableList<Region> getAllRegions() {
return model.allRegions;
}
public BooleanProperty getCountryNotInAcceptedCountriesList() {
BooleanProperty getCountryNotInAcceptedCountriesList() {
return model.countryNotInAcceptedCountriesList;
}
public ObservableList<Country> getAllCountriesFor(Region selectedRegion) {
ObservableList<Country> getAllCountriesFor(Region selectedRegion) {
return model.getAllCountriesFor(selectedRegion);
}
public BankAccountNumberValidator getBankAccountNumberValidator() {
BankAccountNumberValidator getBankAccountNumberValidator() {
return bankAccountNumberValidator;
}
@ -274,17 +262,17 @@ public class FiatAccountPm extends PresentationModel<FiatAccountModel> {
// 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<FiatAccountModel> {
// 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) {

View File

@ -71,7 +71,7 @@ public class FiatAccountViewCB extends CachedViewCB<FiatAccountPm> implements Co
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
private FiatAccountViewCB(FiatAccountPm presentationModel) {
FiatAccountViewCB(FiatAccountPm presentationModel) {
super(presentationModel);
}
@ -82,11 +82,8 @@ public class FiatAccountViewCB extends CachedViewCB<FiatAccountPm> 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<FiatAccountPm> 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<FiatAccountPm> implements Co
setupListeners();
setupBindings();
selectionComboBox.setItems(presentationModel.getAllBankAccounts());
}
@SuppressWarnings("EmptyMethod")
@ -137,35 +138,35 @@ public class FiatAccountViewCB extends CachedViewCB<FiatAccountPm> 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<FiatAccountPm> 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);
}