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));
}
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();
}
}
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;
}
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());
}
}
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);
}
});
}
}
Aggregations