31 lines
1.1 KiB
Java
31 lines
1.1 KiB
Java
package me.teridax.jcash.gui;
|
|
|
|
import me.teridax.jcash.banking.BankingManagementSystem;
|
|
|
|
import javax.swing.*;
|
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
|
|
|
public class Loader {
|
|
|
|
private static final FileNameExtensionFilter FILE_FILTER = new FileNameExtensionFilter("Comma separated value spreadsheet", "csv", "CSV");
|
|
|
|
public static BankingManagementSystem load() throws IllegalStateException {
|
|
var fileChooser = new JFileChooser();
|
|
fileChooser.setMultiSelectionEnabled(false);
|
|
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
|
fileChooser.setFileFilter(FILE_FILTER);
|
|
fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
|
|
fileChooser.setAcceptAllFileFilterUsed(false);
|
|
|
|
if (fileChooser.showDialog(null, "Load database") == JFileChooser.APPROVE_OPTION) {
|
|
try {
|
|
return BankingManagementSystem.loadFromCsv(fileChooser.getSelectedFile().toPath());
|
|
} catch (Exception e) {
|
|
throw new IllegalStateException("Unable to load database", e);
|
|
}
|
|
}
|
|
|
|
throw new IllegalStateException("No file selected");
|
|
}
|
|
}
|