Search in sources :

Example 1 with AbstractReportTableModel

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);
    }
}
Also used : Task(javafx.concurrent.Task) FileChooser(javafx.stage.FileChooser) ResourceBundle(java.util.ResourceBundle) Preferences(java.util.prefs.Preferences) File(java.io.File) AbstractReportTableModel(jgnash.report.table.AbstractReportTableModel) Engine(jgnash.engine.Engine)

Example 2 with AbstractReportTableModel

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;
        }
    }
}
Also used : FileChooser(javafx.stage.FileChooser) IOException(java.io.IOException) Preferences(java.util.prefs.Preferences) File(java.io.File) AbstractReportTableModel(jgnash.report.table.AbstractReportTableModel) FXML(javafx.fxml.FXML) InjectFXML(jgnash.uifx.util.InjectFXML)

Example 3 with AbstractReportTableModel

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();
    }
}
Also used : IOException(java.io.IOException) AbstractReportTableModel(jgnash.report.table.AbstractReportTableModel)

Example 4 with AbstractReportTableModel

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();
    }
}
Also used : IOException(java.io.IOException) AbstractReportTableModel(jgnash.report.table.AbstractReportTableModel)

Example 5 with AbstractReportTableModel

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);
    }
}
Also used : Task(javafx.concurrent.Task) FileChooser(javafx.stage.FileChooser) ResourceBundle(java.util.ResourceBundle) OfxExport(jgnash.convert.exportantur.ofx.OfxExport) Preferences(java.util.prefs.Preferences) File(java.io.File) AbstractReportTableModel(jgnash.report.table.AbstractReportTableModel)

Aggregations

AbstractReportTableModel (jgnash.report.table.AbstractReportTableModel)8 IOException (java.io.IOException)6 File (java.io.File)3 Preferences (java.util.prefs.Preferences)3 FileChooser (javafx.stage.FileChooser)3 ResourceBundle (java.util.ResourceBundle)2 Task (javafx.concurrent.Task)2 FXML (javafx.fxml.FXML)1 OfxExport (jgnash.convert.exportantur.ofx.OfxExport)1 Engine (jgnash.engine.Engine)1 InjectFXML (jgnash.uifx.util.InjectFXML)1