use of io.bitsquare.storage.Storage in project bitsquare by bitsquare.
the class GUIUtil method importAccounts.
public static void importAccounts(User user, String fileName, Preferences preferences, Stage stage) {
FileChooser fileChooser = new FileChooser();
fileChooser.setInitialDirectory(new File(preferences.getDefaultPath()));
fileChooser.setTitle("Select path to " + fileName);
File file = fileChooser.showOpenDialog(stage.getOwner());
if (file != null) {
String path = file.getAbsolutePath();
if (Paths.get(path).getFileName().toString().equals(fileName)) {
String directory = Paths.get(path).getParent().toString();
preferences.setDefaultPath(directory);
Storage<ArrayList<PaymentAccount>> paymentAccountsStorage = new Storage<>(new File(directory));
ArrayList<PaymentAccount> persisted = paymentAccountsStorage.initAndGetPersistedWithFileName(fileName);
if (persisted != null) {
final StringBuilder msg = new StringBuilder();
persisted.stream().forEach(paymentAccount -> {
final String id = paymentAccount.getId();
if (user.getPaymentAccount(id) == null) {
user.addPaymentAccount(paymentAccount);
msg.append("Trading account with id ").append(id).append("\n");
} else {
msg.append("We did not import trading account with id ").append(id).append(" because it exists already.\n");
}
});
new Popup<>().feedback("Trading account imported from path:\n" + path + "\n\nImported accounts:\n" + msg).show();
} else {
new Popup<>().warning("No exported trading accounts has been found at path: " + path + ".\n" + "File name is " + fileName + ".").show();
}
} else {
new Popup<>().warning("The selected file is not the expected file for import. The expected file name is: " + fileName + ".").show();
}
}
}
use of io.bitsquare.storage.Storage in project bitsquare by bitsquare.
the class GUIUtil method exportAccounts.
public static void exportAccounts(ArrayList<PaymentAccount> accounts, String fileName, Preferences preferences, Stage stage) {
if (!accounts.isEmpty()) {
String directory = getDirectoryFormChooser(preferences, stage);
Storage<ArrayList<PaymentAccount>> paymentAccountsStorage = new Storage<>(new File(directory));
paymentAccountsStorage.initAndGetPersisted(accounts, fileName);
paymentAccountsStorage.queueUpForSave();
new Popup<>().feedback("Trading accounts saved to path:\n" + Paths.get(directory, fileName).toAbsolutePath()).show();
} else {
new Popup<>().warning("You don't have trading accounts set up for exporting.").show();
}
}
Aggregations