Search in sources :

Example 1 with Storage

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();
        }
    }
}
Also used : Storage(io.bitsquare.storage.Storage) PaymentAccount(io.bitsquare.payment.PaymentAccount) Popup(io.bitsquare.gui.main.overlays.popups.Popup) FileChooser(javafx.stage.FileChooser) File(java.io.File)

Example 2 with Storage

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();
    }
}
Also used : Storage(io.bitsquare.storage.Storage) Popup(io.bitsquare.gui.main.overlays.popups.Popup) File(java.io.File)

Aggregations

Popup (io.bitsquare.gui.main.overlays.popups.Popup)2 Storage (io.bitsquare.storage.Storage)2 File (java.io.File)2 PaymentAccount (io.bitsquare.payment.PaymentAccount)1 FileChooser (javafx.stage.FileChooser)1