Search in sources :

Example 36 with FileChooser

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

the class TestTrafficProfiles method testExportProfileToJSON.

@Test
public void testExportProfileToJSON() throws Exception {
    prepareProfile();
    openTrafficProfilesDialog();
    final ListView profileList = lookup("#traffic-profile-dialog-profiles-list-view").query();
    Assert.assertTrue(profileList.getItems().contains("profile.yaml"));
    final FileChooser fileChooser = Mockito.spy(FileChooser.class);
    FileChooserFactory.set(fileChooser);
    final File result = new File(FileManager.getLocalFilePath() + "/profile.json");
    Mockito.doReturn(result).when(fileChooser).showSaveDialog(Mockito.any());
    tryCall(() -> {
        clickOn("profile.yaml");
        clickOn("#export-profile-to-json-button");
    }, () -> true);
    final File expected = new File(getResourcesFolder() + "/profile.json");
    Assert.assertTrue(FileUtils.contentEquals(expected, result));
}
Also used : ListView(javafx.scene.control.ListView) FileChooser(javafx.stage.FileChooser) File(java.io.File) Test(org.junit.Test)

Example 37 with FileChooser

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

the class ImportQifAction method showAndWait.

public static void showAndWait() {
    final ResourceBundle resources = ResourceUtils.getBundle();
    final FileChooser fileChooser = configureFileChooser();
    fileChooser.setTitle(resources.getString("Title.SelFile"));
    final File file = fileChooser.showOpenDialog(MainView.getPrimaryStage());
    if (file != null) {
        Preferences pref = Preferences.userNodeForPackage(ImportQifAction.class);
        pref.put(LAST_DIR, file.getParentFile().getAbsolutePath());
        new Thread(new ImportTask(file)).start();
    }
}
Also used : FileChooser(javafx.stage.FileChooser) ResourceBundle(java.util.ResourceBundle) Preferences(java.util.prefs.Preferences) File(java.io.File)

Example 38 with FileChooser

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

the class DatabasePathAction method configureFileChooser.

private static FileChooser configureFileChooser() {
    final ResourceBundle resources = ResourceUtils.getBundle();
    final Preferences pref = Preferences.userNodeForPackage(DatabasePathAction.class);
    final FileChooser fileChooser = new FileChooser();
    final File initialDirectory = new File(pref.get(LAST_DIR, System.getProperty("user.home")));
    // Protect against an IllegalArgumentException
    if (initialDirectory.isDirectory()) {
        fileChooser.setInitialDirectory(initialDirectory);
    }
    final List<String> types = new ArrayList<>();
    for (final DataStoreType dataStoreType : DataStoreType.values()) {
        types.add("*" + dataStoreType.getDataStore().getFileExt());
    }
    fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter(resources.getString("Label.jGnashFiles"), types));
    for (final DataStoreType dataStoreType : DataStoreType.values()) {
        fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter(dataStoreType.toString(), "*" + dataStoreType.getDataStore().getFileExt()));
    }
    fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("All Files", "*.*"));
    return fileChooser;
}
Also used : FileChooser(javafx.stage.FileChooser) ArrayList(java.util.ArrayList) ResourceBundle(java.util.ResourceBundle) Preferences(java.util.prefs.Preferences) File(java.io.File) DataStoreType(jgnash.engine.DataStoreType)

Example 39 with FileChooser

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

the class PackDatabaseDialogController method handleDatabaseButtonAction.

@FXML
private void handleDatabaseButtonAction() {
    final FileChooser fileChooser = FileChooserFactory.getDataStoreChooser(DataStoreType.H2_DATABASE, DataStoreType.HSQL_DATABASE);
    fileChooser.setTitle(resources.getString("Title.SelFile"));
    final File file = fileChooser.showOpenDialog(MainView.getPrimaryStage());
    if (file != null && file.exists()) {
        databaseTextField.setText(file.getAbsolutePath());
    }
}
Also used : FileChooser(javafx.stage.FileChooser) File(java.io.File) InjectFXML(jgnash.uifx.util.InjectFXML) FXML(javafx.fxml.FXML)

Example 40 with FileChooser

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

the class ExecuteJavaScriptAction method showAndWait.

public static void showAndWait() {
    final ResourceBundle resources = ResourceUtils.getBundle();
    final FileChooser fileChooser = configureFileChooser();
    fileChooser.setTitle(resources.getString("Title.SelFile"));
    final File file = fileChooser.showOpenDialog(MainView.getPrimaryStage());
    if (file != null) {
        Preferences pref = Preferences.userNodeForPackage(ExecuteJavaScriptAction.class);
        pref.put(LAST_DIR, file.getParentFile().getAbsolutePath());
        Platform.runLater(() -> {
            try (final Reader reader = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8)) {
                new ScriptEngineManager().getEngineByName("nashorn").eval(reader);
            } catch (IOException | ScriptException ex) {
                Logger.getLogger(ExecuteJavaScriptAction.class.getName()).log(Level.SEVERE, ex.toString(), ex);
            }
        });
    }
}
Also used : ScriptException(javax.script.ScriptException) FileChooser(javafx.stage.FileChooser) ScriptEngineManager(javax.script.ScriptEngineManager) Reader(java.io.Reader) ResourceBundle(java.util.ResourceBundle) IOException(java.io.IOException) Preferences(java.util.prefs.Preferences) File(java.io.File)

Aggregations

FileChooser (javafx.stage.FileChooser)65 File (java.io.File)60 Preferences (java.util.prefs.Preferences)21 IOException (java.io.IOException)17 ResourceBundle (java.util.ResourceBundle)11 FXML (javafx.fxml.FXML)11 FileOutputStream (java.io.FileOutputStream)5 ArrayList (java.util.ArrayList)5 Alert (javafx.scene.control.Alert)5 Button (javafx.scene.control.Button)5 Popup (io.bitsquare.gui.main.overlays.popups.Popup)3 List (java.util.List)3 GargoyleFileAlreadyExistException (com.kyj.fx.voeditor.visual.exceptions.GargoyleFileAlreadyExistException)2 Palette (fractal.Palette)2 Path (java.nio.file.Path)2 ObservableList (javafx.collections.ObservableList)2 FilteredList (javafx.collections.transformation.FilteredList)2 SortedList (javafx.collections.transformation.SortedList)2 Task (javafx.concurrent.Task)2 Insets (javafx.geometry.Insets)2