Search in sources :

Example 1 with AccountBalanceDisplayManager

use of jgnash.uifx.views.AccountBalanceDisplayManager in project jgnash by ccavanaugh.

the class ReportActions method exportProfitLossReport.

public static void exportProfitLossReport() {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    final CurrencyNode baseCommodity = engine.getDefaultCurrency();
    final FXMLUtils.Pair<DateRangeDialogController> pair = FXMLUtils.load(DateRangeDialogController.class.getResource("DateRangeDialog.fxml"), ResourceUtils.getString("Title.ReportOptions"));
    pair.getStage().setResizable(false);
    pair.getStage().showAndWait();
    final Optional<LocalDate[]> optional = pair.getController().getDates();
    optional.ifPresent(localDates -> {
        final Preferences preferences = Preferences.userNodeForPackage(ReportActions.class);
        final String lastDir = preferences.get(LAST_DIR, null);
        final FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle(ResourceUtils.getString("Title.SaveFile"));
        if (lastDir != null) {
            fileChooser.setInitialDirectory(new File(lastDir));
        }
        fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("TXT", "*.txt"));
        final File file = fileChooser.showSaveDialog(MainView.getPrimaryStage());
        if (file != null) {
            preferences.put(LAST_DIR, file.getParent());
            final ProfitLossTextReport report = new ProfitLossTextReport(file.getAbsolutePath(), localDates[0], localDates[1], baseCommodity, AccountBalanceDisplayManager::convertToSelectedBalanceMode);
            report.run();
        }
    });
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) FXMLUtils(jgnash.uifx.util.FXMLUtils) ProfitLossTextReport(jgnash.report.ProfitLossTextReport) FileChooser(javafx.stage.FileChooser) Preferences(java.util.prefs.Preferences) File(java.io.File) Engine(jgnash.engine.Engine) DateRangeDialogController(jgnash.uifx.control.DateRangeDialogController) AccountBalanceDisplayManager(jgnash.uifx.views.AccountBalanceDisplayManager)

Aggregations

File (java.io.File)1 Preferences (java.util.prefs.Preferences)1 FileChooser (javafx.stage.FileChooser)1 CurrencyNode (jgnash.engine.CurrencyNode)1 Engine (jgnash.engine.Engine)1 ProfitLossTextReport (jgnash.report.ProfitLossTextReport)1 DateRangeDialogController (jgnash.uifx.control.DateRangeDialogController)1 FXMLUtils (jgnash.uifx.util.FXMLUtils)1 AccountBalanceDisplayManager (jgnash.uifx.views.AccountBalanceDisplayManager)1