use of jgnash.report.table.AbstractReportTableModel in project jgnash by ccavanaugh.
the class StaticAccountsMethods method exportAccountTree.
static void exportAccountTree() {
final ResourceBundle resources = ResourceUtils.getBundle();
final Preferences pref = Preferences.userNodeForPackage(StaticAccountsMethods.class);
final FileChooser fileChooser = new FileChooser();
final File initialDirectory = new File(pref.get(EXPORT_DIR, System.getProperty("user.home")));
// Protect against an IllegalArgumentException
if (initialDirectory.isDirectory()) {
fileChooser.setInitialDirectory(initialDirectory);
}
fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter(resources.getString("Label.CsvFiles") + " (*.csv)", "*.csv"), new FileChooser.ExtensionFilter(resources.getString("Label.SpreadsheetFiles") + " (*.xls)", "*.xls"), new FileChooser.ExtensionFilter(resources.getString("Label.SpreadsheetFiles") + " (*.xlsx)", "*.xlsx"));
final File file = fileChooser.showSaveDialog(MainView.getPrimaryStage());
final File exportFile;
if (file != null) {
if (!FileUtils.fileHasExtension(file.getName())) {
// fix up the file name if the user did not specify it
final String fileExtension = fileChooser.getSelectedExtensionFilter().getExtensions().get(0).substring(1);
exportFile = new File(FileUtils.stripFileExtension(file.getAbsolutePath()) + fileExtension);
} else {
exportFile = file;
}
pref.put(EXPORT_DIR, exportFile.getParentFile().getAbsolutePath());
final Task<Void> exportTask = new Task<>() {
@Override
protected Void call() {
updateMessage(resources.getString("Message.PleaseWait"));
updateProgress(-1, Long.MAX_VALUE);
if (FileUtils.getFileExtension(exportFile.getName()).contains(XLS)) {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
final AbstractReportTableModel reportTableModel = new ListOfAccountsReport.AccountListModel(engine.getAccountList(), engine.getDefaultCurrency());
Workbook.export(reportTableModel, exportFile);
} else {
CsvExport.exportAccountTree(EngineFactory.getEngine(EngineFactory.DEFAULT), exportFile.toPath());
}
return null;
}
};
new Thread(exportTask).start();
StaticUIMethods.displayTaskProgress(exportTask);
}
}
use of jgnash.report.table.AbstractReportTableModel in project jgnash by ccavanaugh.
the class ReportViewerDialogController method handleSaveAction.
@FXML
private void handleSaveAction() {
final Preferences pref = Preferences.userNodeForPackage(ReportViewerDialogController.class);
final FileChooser fileChooser = new FileChooser();
fileChooser.setTitle(ResourceUtils.getString("Title.SaveFile"));
final File initialDirectory = new File(pref.get(LAST_DIR, System.getProperty("user.home")));
// Protect against an IllegalArgumentException
if (initialDirectory.isDirectory()) {
fileChooser.setInitialDirectory(initialDirectory);
}
fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter(resources.getString("Label.PDFFiles") + " (.pdf)", "*.pdf", "*.PDF"), new FileChooser.ExtensionFilter(resources.getString("Label.SpreadsheetFiles") + " (*.xls, *.xlsx)", "*.xls", "*.xlsx"));
final File file = fileChooser.showSaveDialog(MainView.getPrimaryStage());
if (file != null) {
pref.put(LAST_DIR, file.getParent());
final String extension = FileUtils.getFileExtension(file.getAbsolutePath()).toLowerCase(Locale.ROOT);
switch(extension) {
case "pdf":
try {
report.get().saveToFile(file.toPath());
} catch (final IOException ex) {
StaticUIMethods.displayException(ex);
}
break;
case "xls":
case "xlsx":
final AbstractReportTableModel model = reportController.createReportModel();
Workbook.export(model, file);
break;
default:
break;
}
}
}
use of jgnash.report.table.AbstractReportTableModel in project jgnash by ccavanaugh.
the class BalanceSheetReportController method addTable.
private void addTable() {
final AbstractReportTableModel model = createReportModel();
report.clearReport();
report.setTitle(ResourceUtils.getString("Title.BalanceSheet"));
try {
report.addTable(model);
report.addFooter();
} catch (final IOException e) {
e.printStackTrace();
}
}
use of jgnash.report.table.AbstractReportTableModel in project jgnash by ccavanaugh.
the class ProfitLossReportController method addTable.
private void addTable() {
AbstractReportTableModel model = createReportModel();
report.clearReport();
report.setTitle(ResourceUtils.getString("Title.ProfitLoss"));
try {
report.addTable(model);
report.addFooter();
} catch (final IOException e) {
e.printStackTrace();
}
}
use of jgnash.report.table.AbstractReportTableModel in project jgnash by ccavanaugh.
the class RegisterActions method exportTransactions.
static void exportTransactions(final Account account, final LocalDate startDate, final LocalDate endDate) {
final ResourceBundle resources = ResourceUtils.getBundle();
final Preferences pref = Preferences.userNodeForPackage(RegisterActions.class);
final FileChooser fileChooser = new FileChooser();
final File initialDirectory = new File(pref.get(EXPORT_DIR, System.getProperty("user.home")));
// Protect against an IllegalArgumentException
if (initialDirectory.isDirectory()) {
fileChooser.setInitialDirectory(initialDirectory);
}
fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter(resources.getString("Label.CsvFiles") + " (*.csv)", "*.csv"), new FileChooser.ExtensionFilter(resources.getString("Label.OfxFiles") + " (*.ofx)", "*.ofx"), new FileChooser.ExtensionFilter(resources.getString("Label.SpreadsheetFiles") + " (*.xls)", "*.xls"), new FileChooser.ExtensionFilter(resources.getString("Label.SpreadsheetFiles") + " (*.xlsx)", "*.xlsx"));
final File file = fileChooser.showSaveDialog(MainView.getPrimaryStage());
final File exportFile;
if (file != null) {
if (!FileUtils.fileHasExtension(file.getName())) {
// fix up the file name if the user did not specify it
final String fileExtension = fileChooser.getSelectedExtensionFilter().getExtensions().get(0).substring(1);
exportFile = new File(FileUtils.stripFileExtension(file.getAbsolutePath()) + fileExtension);
} else {
exportFile = file;
}
pref.put(EXPORT_DIR, exportFile.getParentFile().getAbsolutePath());
final Task<Void> exportTask = new Task<>() {
@Override
protected Void call() {
updateMessage(resources.getString("Message.PleaseWait"));
updateProgress(-1, Long.MAX_VALUE);
if (OFX.equals(FileUtils.getFileExtension(exportFile.getName()))) {
final OfxExport export = new OfxExport(account, startDate, endDate, exportFile);
export.exportAccount();
} else if (FileUtils.getFileExtension(exportFile.getName()).contains(XLS)) {
final AbstractReportTableModel reportTableModel = AccountRegisterReport.createReportModel(account, startDate, endDate, false, "", "", true);
Workbook.export(reportTableModel, exportFile);
} else {
CsvExport.exportAccount(account, startDate, endDate, exportFile.toPath());
}
return null;
}
};
new Thread(exportTask).start();
StaticUIMethods.displayTaskProgress(exportTask);
}
}
Aggregations