From 00b41cf53742ab7518adaf93899ba6345d00d107 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Sun, 24 Aug 2014 14:01:28 +0200 Subject: [PATCH] fixed problems with caching --- .../gui/components/CachingTabPane.java | 4 +- .../io/bitsquare/gui/components/Popups.java | 9 +- .../gui/settings/SettingsController.java | 100 +++++++++--------- .../bitsquare/gui/settings/SettingsView.fxml | 2 +- .../createoffer/CreateOfferController.java | 13 +++ .../gui/util/BitSquareFormatter.java | 2 +- .../io/bitsquare/locale/LanguageUtil.java | 6 +- src/main/resources/logback.xml | 35 +++--- 8 files changed, 98 insertions(+), 73 deletions(-) diff --git a/src/main/java/io/bitsquare/gui/components/CachingTabPane.java b/src/main/java/io/bitsquare/gui/components/CachingTabPane.java index 8779105596..dac0c98ddb 100644 --- a/src/main/java/io/bitsquare/gui/components/CachingTabPane.java +++ b/src/main/java/io/bitsquare/gui/components/CachingTabPane.java @@ -50,9 +50,9 @@ public class CachingTabPane extends TabPane selectedTabIndex = (indexObject == null) ? 0 : (int) indexObject; // if selectedTabIndex = 0 the the change listener will not fire so we load it manually - // if (selectedTabIndex == 0) loadView(); + if (selectedTabIndex == 0) loadView(); - //getSelectionModel().select(selectedTabIndex); + getSelectionModel().select(selectedTabIndex); } public ViewController loadViewAndGetChildController(String fxmlView) diff --git a/src/main/java/io/bitsquare/gui/components/Popups.java b/src/main/java/io/bitsquare/gui/components/Popups.java index f09ec305ca..5759fd60f1 100644 --- a/src/main/java/io/bitsquare/gui/components/Popups.java +++ b/src/main/java/io/bitsquare/gui/components/Popups.java @@ -26,9 +26,9 @@ public class Popups } // Confirm - public static void openConfirmPopup(String title, String message) + public static Action openConfirmPopup(String title, String message) { - openConfirmPopup(title, message, null); + return openConfirmPopup(title, message, null); } public static Action openConfirmPopup(String title, String message, String masthead) @@ -36,6 +36,11 @@ public class Popups List actions = new ArrayList<>(); actions.add(Dialog.Actions.OK); actions.add(Dialog.Actions.CANCEL); + return openConfirmPopup(title, message, masthead, actions); + } + + public static Action openConfirmPopup(String title, String message, String masthead, List actions) + { return Dialogs.create().owner(BitSquare.getPrimaryStage()).title(title).message(message).masthead(masthead).actions(actions).showConfirm(); } diff --git a/src/main/java/io/bitsquare/gui/settings/SettingsController.java b/src/main/java/io/bitsquare/gui/settings/SettingsController.java index b987fe00b6..a511d2a18b 100644 --- a/src/main/java/io/bitsquare/gui/settings/SettingsController.java +++ b/src/main/java/io/bitsquare/gui/settings/SettingsController.java @@ -9,6 +9,7 @@ import io.bitsquare.di.GuiceFXMLLoader; import io.bitsquare.gui.CachedViewController; import io.bitsquare.gui.NavigationItem; import io.bitsquare.gui.ViewController; +import io.bitsquare.gui.components.Popups; import io.bitsquare.gui.util.BitSquareValidator; import io.bitsquare.gui.util.ImageUtil; import io.bitsquare.locale.*; @@ -37,6 +38,8 @@ import javafx.stage.Stage; import javafx.util.Callback; import javafx.util.StringConverter; import javax.inject.Inject; +import org.controlsfx.control.action.Action; +import org.controlsfx.dialog.Dialog; // TODO separate in 2 view/controllers public class SettingsController extends CachedViewController @@ -90,8 +93,14 @@ public class SettingsController extends CachedViewController countryList = FXCollections.observableArrayList(new ArrayList<>()); arbitratorList = FXCollections.observableArrayList(new ArrayList<>()); - addLanguage(LanguageUtil.getDefaultLanguageLocale()); - addCountry(CountryUtil.getDefaultCountry()); + if (Locale.getDefault() != null) + { + addLanguage(LanguageUtil.getDefaultLanguageLocale()); + addCountry(CountryUtil.getDefaultCountry()); + } + + // Add english as default as well + addLanguage(LanguageUtil.getEnglishLanguageLocale()); } } @@ -129,12 +138,6 @@ public class SettingsController extends CachedViewController @Override public ViewController loadViewAndGetChildController(NavigationItem navigationItem) { - - /*if (childController instanceof CachedViewController) - ((CachedViewController) childController).deactivate(); - else if (childController != null) - childController.terminate();*/ - // TODO // caching causes exception final GuiceFXMLLoader loader = new GuiceFXMLLoader(getClass().getResource(navigationItem.getFxmlUrl()), false); @@ -211,7 +214,7 @@ public class SettingsController extends CachedViewController } @FXML - public void onAddArbitrator() + public void onOpenArbitratorScreen() { loadViewAndGetChildController(NavigationItem.ARBITRATOR_OVERVIEW); } @@ -255,6 +258,7 @@ public class SettingsController extends CachedViewController @FXML public void onAddBankAccount() { + saveBankAccount(); resetBankAccountInput(); } @@ -268,17 +272,13 @@ public class SettingsController extends CachedViewController void onSaveBankAccount() { saveBankAccount(); - } /////////////////////////////////////////////////////////////////////////////////////////// // Private methods /////////////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////// // General Settings - /////////////////////////////////////////////////////////////////////////////////////////// - private void setupGeneralSettingsScreen() { initLanguage(); @@ -321,9 +321,7 @@ public class SettingsController extends CachedViewController if (item != null && !empty) { label.setText(item.getDisplayName()); - removeButton.setOnAction(actionEvent -> removeLanguage(item)); - setGraphic(hBox); } else @@ -407,9 +405,7 @@ public class SettingsController extends CachedViewController if (item != null && !empty) { label.setText(item.getName()); - removeButton.setOnAction(actionEvent -> removeCountry(item)); - setGraphic(hBox); } else @@ -477,9 +473,7 @@ public class SettingsController extends CachedViewController if (item != null && !empty) { label.setText(item.getName()); - removeButton.setOnAction(actionEvent -> removeArbitrator(item)); - setGraphic(hBox); } else @@ -493,44 +487,43 @@ public class SettingsController extends CachedViewController arbitratorsListView.setItems(arbitratorList); } - private void addLanguage(Locale item) + private void addLanguage(Locale locale) { - if (!languageList.contains(item) && item != null) + if (locale != null && !languageList.contains(locale)) { - languageList.add(item); - settings.addAcceptedLanguageLocale(item); - + languageList.add(locale); + settings.addAcceptedLanguageLocale(locale); } } - private void removeLanguage(Locale item) + private void removeLanguage(Locale locale) { - languageList.remove(item); - settings.removeAcceptedLanguageLocale(item); + languageList.remove(locale); + settings.removeAcceptedLanguageLocale(locale); saveSettings(); } - private void addCountry(Country item) + private void addCountry(Country country) { - if (!countryList.contains(item) && item != null) + if (!countryList.contains(country) && country != null) { - countryList.add(item); - settings.addAcceptedCountry(item); + countryList.add(country); + settings.addAcceptedCountry(country); saveSettings(); } } - private void removeCountry(Country item) + private void removeCountry(Country country) { - countryList.remove(item); - settings.removeAcceptedCountry(item); + countryList.remove(country); + settings.removeAcceptedCountry(country); saveSettings(); } - private void removeArbitrator(Arbitrator item) + private void removeArbitrator(Arbitrator arbitrator) { - arbitratorList.remove(item); - settings.removeAcceptedArbitrator(item); + arbitratorList.remove(arbitrator); + settings.removeAcceptedArbitrator(arbitrator); saveSettings(); } @@ -545,10 +538,7 @@ public class SettingsController extends CachedViewController } - /////////////////////////////////////////////////////////////////////////////////////////// // Bank Account Settings - /////////////////////////////////////////////////////////////////////////////////////////// - private void initBankAccountScreen() { initBankAccountComboBox(); @@ -578,14 +568,13 @@ public class SettingsController extends CachedViewController bankAccountCurrencyComboBox.getSelectionModel().selectFirst(); bankAccountRegionComboBox.getSelectionModel().select(3); bankAccountCountryComboBox.getSelectionModel().select(5); - bankAccountTitleTextField.setText("dummy"); - bankAccountHolderNameTextField.setText("dummy"); - bankAccountPrimaryIDTextField.setText("dummy"); - bankAccountSecondaryIDTextField.setText("dummy"); + bankAccountTitleTextField.setText("dummy title"); + bankAccountHolderNameTextField.setText("dummy name"); + bankAccountPrimaryIDTextField.setText("dummy primary ID"); + bankAccountSecondaryIDTextField.setText("dummy secondary ID"); + if (user.getCurrentBankAccount() == null) - { onSaveBankAccount(); - } } } @@ -616,20 +605,19 @@ public class SettingsController extends CachedViewController bankAccountComboBox.setItems(FXCollections.observableArrayList(user.getBankAccounts())); bankAccountComboBox.setConverter(new StringConverter() { - @Override public String toString(BankAccount bankAccount) { return bankAccount.getAccountTitle(); } - @Override public BankAccount fromString(String s) { return null; } }); + BankAccount currentBankAccount = user.getCurrentBankAccount(); if (currentBankAccount != null) { @@ -644,14 +632,12 @@ public class SettingsController extends CachedViewController bankAccountTypesComboBox.setItems(FXCollections.observableArrayList(BankAccountType.getAllBankAccountTypes())); bankAccountTypesComboBox.setConverter(new StringConverter() { - @Override public String toString(BankAccountType bankAccountTypeInfo) { return Localisation.get(bankAccountTypeInfo.toString()); } - @Override public BankAccountType fromString(String s) { @@ -762,6 +748,20 @@ public class SettingsController extends CachedViewController saveUser(); initBankAccountScreen(); + + if (!settings.getAcceptedCountries().contains(bankAccount.getCountry())) + { + List actions = new ArrayList<>(); + actions.add(Dialog.Actions.YES); + actions.add(Dialog.Actions.NO); + + Action response = Popups.openConfirmPopup("Warning", + "The country of your bank account is not included in the accepted countries in the general settings.\n\nDo you want to add it automatically?", + null, + actions); + if (response == Dialog.Actions.YES) + addCountry(bankAccount.getCountry()); + } } } diff --git a/src/main/java/io/bitsquare/gui/settings/SettingsView.fxml b/src/main/java/io/bitsquare/gui/settings/SettingsView.fxml index ac36e52268..a5f9483fa6 100644 --- a/src/main/java/io/bitsquare/gui/settings/SettingsView.fxml +++ b/src/main/java/io/bitsquare/gui/settings/SettingsView.fxml @@ -25,7 +25,7 @@ -