Search in sources :

Example 61 with FileChooser

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

the class TrafficProfileDialogController method handleLoadProfileBtnClick.

/**
     * Handle load profile button click
     *
     * @param event
     */
@FXML
public void handleLoadProfileBtnClick(MouseEvent event) {
    String loadFileName = "";
    try {
        FileChooser fileChooser = FileChooserFactory.get();
        FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("YAML Files (*.yaml)", "*.yaml");
        FileChooser.ExtensionFilter allFilesFilter = new FileChooser.ExtensionFilter("All files ", "*.*");
        fileChooser.getExtensionFilters().add(extFilter);
        fileChooser.getExtensionFilters().add(allFilesFilter);
        fileChooser.setTitle("Load Profile File");
        String loadFolderPath = PreferencesManager.getInstance().getLoadLocation();
        if (!Util.isNullOrEmpty(loadFolderPath) && new File(loadFolderPath).exists()) {
            fileChooser.setInitialDirectory(new File(loadFolderPath));
        }
        File loadedFile = fileChooser.showOpenDialog(((Button) (event.getSource())).getScene().getWindow());
        if (loadedFile != null) {
            loadFileName = loadedFile.getName();
            // check if exists in list or not
            if (!ProfileManager.getInstance().isFileExists(loadedFile.getName())) {
                // Read Selected File.
                Profile[] yamlTrafficProfile = trafficProfile.getTrafficProfile(loadedFile);
                // make a copy of selected file
                File localFile = trafficProfile.convertTrafficProfileToYamlFile(yamlTrafficProfile, loadedFile.getName());
                // add it to list
                profileListView.getItems().add(localFile.getName());
                // save the new selected profile
                ProfileManager.getInstance().updateProfilesList(localFile, true);
            }
            profileListView.getSelectionModel().select(loadedFile.getName());
            // enaprofileListView.getSelectionModel().select(localFile.getName());ble delete profile btn
            disableProfileFunctionBtn(false);
        }
    } catch (IOException ex) {
        Alert alert = Util.getAlert(AlertType.ERROR);
        alert.setContentText("Error loading file " + loadFileName);
        alert.showAndWait();
        LOG.error("Error loading the profile", ex);
    }
}
Also used : Button(javafx.scene.control.Button) FileChooser(javafx.stage.FileChooser) Alert(javafx.scene.control.Alert) IOException(java.io.IOException) File(java.io.File) Profile(com.exalttech.trex.remote.models.profiles.Profile) FXML(javafx.fxml.FXML)

Example 62 with FileChooser

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

the class SaveAsTask method start.

public static void start() {
    final ResourceBundle resources = ResourceUtils.getBundle();
    final File current = new File(EngineFactory.getActiveDatabase());
    final FileChooser fileChooser = FileChooserFactory.getDataStoreChooser();
    fileChooser.setInitialDirectory(current.getParentFile());
    fileChooser.setTitle(resources.getString("Title.SaveAs"));
    final File newFile = fileChooser.showSaveDialog(MainView.getPrimaryStage());
    if (newFile != null) {
        final SaveAsTask saveAsTask = new SaveAsTask(newFile);
        new Thread(saveAsTask).start();
        StaticUIMethods.displayTaskProgress(saveAsTask);
    }
}
Also used : FileChooser(javafx.stage.FileChooser) ResourceBundle(java.util.ResourceBundle) File(java.io.File)

Example 63 with FileChooser

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

the class FileChooserFactory method getDataStoreChooser.

/**
     * Returns a {@code FileChooser} configured to filter the supplied jGnash file types
     *
     * @param types {@code DataStoreType} to filter on
     * @return a configured FileChooser
     */
public static FileChooser getDataStoreChooser(final DataStoreType... types) {
    final FileChooser fileChooser = new FileChooser();
    final String[] ext = new String[types.length];
    final StringBuilder description = new StringBuilder(ResourceUtils.getString("Label.jGnashFiles") + " (");
    for (int i = 0; i < types.length; i++) {
        ext[i] = "*" + types[i].getDataStore().getFileExt();
        description.append("*");
        description.append(types[i].getDataStore().getFileExt());
        if (i < types.length - 1) {
            description.append(", ");
        }
    }
    description.append(')');
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter(description.toString(), ext));
    return fileChooser;
}
Also used : FileChooser(javafx.stage.FileChooser)

Example 64 with FileChooser

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

FileChooser (javafx.stage.FileChooser)64 File (java.io.File)59 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)4 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