Search in sources :

Example 66 with FileChooser

use of javafx.stage.FileChooser in project trex-stateless-gui by cisco-system-traffic-generator.

the class FileManager method getSelectedFile.

/**
 * Return selected file
 *
 * @param windowTitle
 * @param fileName
 * @param window
 * @param type
 * @param filePath
 * @param isExport
 * @return
 */
public static File getSelectedFile(String windowTitle, String fileName, Window window, FileType type, String filePath, boolean isExport) {
    FileChooser fileChooser = FileChooserFactory.get();
    fileChooser.setTitle(windowTitle);
    fileChooser.setInitialFileName(fileName);
    FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter(type.getFilterDescription(), type.getFilterExtension());
    fileChooser.getExtensionFilters().add(extFilter);
    FileChooser.ExtensionFilter allFilesFilter = new FileChooser.ExtensionFilter("All files ", "*.*");
    fileChooser.getExtensionFilters().add(allFilesFilter);
    if (!Util.isNullOrEmpty(filePath) && new File(filePath).exists()) {
        fileChooser.setInitialDirectory(new File(filePath));
    }
    if (isExport) {
        return fileChooser.showSaveDialog(window);
    } else {
        return fileChooser.showOpenDialog(window);
    }
}
Also used : FileChooser(javafx.stage.FileChooser) File(java.io.File)

Example 67 with FileChooser

use of javafx.stage.FileChooser in project jgnash by ccavanaugh.

the class MenuBarController method handleApplyStyleAction.

@FXML
private void handleApplyStyleAction() {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle(resources.getString("Title.Open"));
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter(resources.getString("Label.CssFiles"), "*.css"));
    final File file = fileChooser.showOpenDialog(MainView.getPrimaryStage());
    if (file != null && FileUtils.getFileExtension(file.toString()).equalsIgnoreCase("css")) {
        if (ThemeManager.setUserStyle(file.toPath())) {
            JavaFXUtils.runLater(() -> StaticUIMethods.displayMessage(resources.getString("Message.Info.RestartToApply")));
        }
    }
}
Also used : FileChooser(javafx.stage.FileChooser) File(java.io.File) FXML(javafx.fxml.FXML)

Example 68 with FileChooser

use of javafx.stage.FileChooser 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 69 with FileChooser

use of javafx.stage.FileChooser in project jgnash by ccavanaugh.

the class ReportActions method exportBalanceByMonthCSVReport.

public static void exportBalanceByMonthCSVReport() {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    final Preferences preferences = Preferences.userNodeForPackage(ReportActions.class);
    final FXMLUtils.Pair<BalanceByMonthOptionsDialogController> pair = FXMLUtils.load(BalanceByMonthOptionsDialogController.class.getResource("BalanceByMonthOptionsDialog.fxml"), ResourceUtils.getString("Title.ReportOptions"));
    pair.getController().forceDefaultCurrencyProperty().set(preferences.getBoolean(FORCE_CURRENCY, false));
    pair.getStage().setResizable(false);
    pair.getStage().showAndWait();
    final boolean vertical = pair.getController().isVertical();
    final boolean forceCurrency = pair.getController().forceDefaultCurrencyProperty().get();
    final Optional<LocalDate[]> optional = pair.getController().getDates();
    optional.ifPresent(localDates -> {
        final String lastDir = preferences.get(LAST_DIR, null);
        preferences.putBoolean(FORCE_CURRENCY, forceCurrency);
        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("CSV", "*.csv"));
        final File file = fileChooser.showSaveDialog(MainView.getPrimaryStage());
        if (file != null) {
            preferences.put(LAST_DIR, file.getParent());
            final BalanceByMonthCSVReport report;
            if (forceCurrency) {
                report = new BalanceByMonthCSVReport(file.getAbsolutePath(), localDates[0], localDates[1], engine.getDefaultCurrency(), vertical, AccountBalanceDisplayManager::convertToSelectedBalanceMode);
            } else {
                report = new BalanceByMonthCSVReport(file.getAbsolutePath(), localDates[0], localDates[1], null, vertical, AccountBalanceDisplayManager::convertToSelectedBalanceMode);
            }
            report.run();
        }
    });
}
Also used : FXMLUtils(jgnash.uifx.util.FXMLUtils) BalanceByMonthCSVReport(jgnash.report.BalanceByMonthCSVReport) FileChooser(javafx.stage.FileChooser) Preferences(java.util.prefs.Preferences) File(java.io.File) Engine(jgnash.engine.Engine)

Example 70 with FileChooser

use of javafx.stage.FileChooser 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)

Aggregations

FileChooser (javafx.stage.FileChooser)208 File (java.io.File)189 IOException (java.io.IOException)55 FXML (javafx.fxml.FXML)49 Preferences (java.util.prefs.Preferences)24 Button (javafx.scene.control.Button)21 ArrayList (java.util.ArrayList)19 VBox (javafx.scene.layout.VBox)15 ResourceBundle (java.util.ResourceBundle)14 ExtensionFilter (javafx.stage.FileChooser.ExtensionFilter)14 Stage (javafx.stage.Stage)14 Label (javafx.scene.control.Label)13 Alert (javafx.scene.control.Alert)12 List (java.util.List)11 TextField (javafx.scene.control.TextField)11 ScriptException (javax.script.ScriptException)11 Scene (javafx.scene.Scene)10 Map (java.util.Map)9 ObservableList (javafx.collections.ObservableList)9 MenuItem (javafx.scene.control.MenuItem)9