List of usage examples for javafx.stage FileChooser setInitialFileName
public final void setInitialFileName(final String value)
From source file:com.exalttech.trex.util.files.FileManager.java
/** * Return selected file// www. ja va2 s . c o m * * @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 = new FileChooser(); 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); } }
From source file:eu.over9000.skadi.ui.dialogs.PerformUpdateDialog.java
public PerformUpdateDialog(RemoteVersionResult newVersion) { this.chosen = new SimpleObjectProperty<>( Paths.get(SystemUtils.USER_HOME, newVersion.getVersion() + ".jar").toFile()); this.setHeaderText("Updating to " + newVersion.getVersion()); this.setTitle("Skadi Updater"); this.getDialogPane().getStyleClass().add("alert"); this.getDialogPane().getStyleClass().add("information"); final ButtonType restartButtonType = new ButtonType("Start New Version", ButtonBar.ButtonData.OK_DONE); this.getDialogPane().getButtonTypes().addAll(restartButtonType, ButtonType.CANCEL); Node btn = this.getDialogPane().lookupButton(restartButtonType); btn.setDisable(true);//from ww w . j a v a2 s.c om Label lbPath = new Label("Save as"); TextField tfPath = new TextField(); tfPath.textProperty() .bind(Bindings.createStringBinding(() -> this.chosen.get().getAbsolutePath(), this.chosen)); tfPath.setPrefColumnCount(40); tfPath.setEditable(false); Button btChangePath = GlyphsDude.createIconButton(FontAwesomeIcons.FOLDER_OPEN, "Browse..."); btChangePath.setOnAction(event -> { FileChooser fc = new FileChooser(); fc.setTitle("Save downloaded jar.."); fc.setInitialFileName(this.chosen.getValue().getName()); fc.getExtensionFilters().add(new FileChooser.ExtensionFilter("Jar File", ".jar")); fc.setInitialDirectory(this.chosen.getValue().getParentFile()); File selected = fc.showSaveDialog(this.getOwner()); if (selected != null) { this.chosen.set(selected); } }); ProgressBar pbDownload = new ProgressBar(0); pbDownload.setDisable(true); pbDownload.setMaxWidth(Double.MAX_VALUE); Label lbDownload = new Label("Download"); Label lbDownloadValue = new Label(); Button btDownload = GlyphsDude.createIconButton(FontAwesomeIcons.DOWNLOAD, "Start"); btDownload.setMaxWidth(Double.MAX_VALUE); btDownload.setOnAction(event -> { btChangePath.setDisable(true); btDownload.setDisable(true); this.downloadService = new DownloadService(newVersion.getDownloadURL(), this.chosen.getValue()); lbDownloadValue.textProperty().bind(this.downloadService.messageProperty()); pbDownload.progressProperty().bind(this.downloadService.progressProperty()); this.downloadService.setOnSucceeded(dlEvent -> { btn.setDisable(false); }); this.downloadService.setOnFailed(dlFailed -> { LOGGER.error("new version download failed", dlFailed.getSource().getException()); lbDownloadValue.textProperty().unbind(); lbDownloadValue.setText("Download failed, check log file for details."); }); this.downloadService.start(); }); final GridPane grid = new GridPane(); grid.setHgap(10); grid.setVgap(10); grid.add(lbPath, 0, 0); grid.add(tfPath, 1, 0); grid.add(btChangePath, 2, 0); grid.add(new Separator(), 0, 1, 3, 1); grid.add(lbDownload, 0, 2); grid.add(pbDownload, 1, 2); grid.add(btDownload, 2, 2); grid.add(lbDownloadValue, 1, 3); this.getDialogPane().setContent(grid); this.setResultConverter(btnType -> { if (btnType == restartButtonType) { return this.chosen.getValue(); } if (btnType == ButtonType.CANCEL) { if (this.downloadService.isRunning()) { this.downloadService.cancel(); } } return null; }); }
From source file:cz.lbenda.gui.controls.FileField.java
protected EventHandler<ActionEvent> buttonEventHandler() { return event -> { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle(CHOOSE_FILE_WINDOW_TITLE); fileChooser.getExtensionFilters().addAll(Constants.allFilesFilter); if (!StringUtils.isBlank(getText())) { fileChooser.setInitialFileName(getText()); File file = new File(getText()); if (file.isDirectory()) { fileChooser.setInitialDirectory(file); } else { fileChooser.setInitialDirectory(file.getParentFile()); }//w w w . ja v a 2s.c o m } File file; if (isSave()) { file = fileChooser.showSaveDialog(((Node) event.getSource()).getScene().getWindow()); } else { file = fileChooser.showOpenDialog(((Node) event.getSource()).getScene().getWindow()); } if (file != null) { setText(file.getAbsolutePath()); } }; }
From source file:com.esri.geoevent.test.performance.ui.ReportOptionsController.java
/** * Allows the user to select a report file to used when the reporting is * done./*from w w w . j ava2 s .c o m*/ * * @param event {@link ActionEvent} not used. */ @FXML private void chooseReportFile(final ActionEvent event) { File currentDir = Paths.get("").toAbsolutePath().toFile(); String reportTypeStr = report.getType().toString(); FileChooser fileChooser = new FileChooser(); fileChooser.setTitle(UIMessages.getMessage("UI_REPORT_FILE_CHOOSER_TITLE")); fileChooser.setInitialDirectory(currentDir); fileChooser.getExtensionFilters() .add(new FileChooser.ExtensionFilter(reportTypeStr, "*." + reportTypeStr.toLowerCase())); fileChooser.setInitialFileName(DEFAULT_REPORT_FILE_NAME + "." + reportTypeStr.toLowerCase()); File file = fileChooser.showSaveDialog(dialogStage); if (file != null) { updateSelectedReportFile(file.getAbsolutePath()); } }
From source file:org.craftercms.social.migration.controllers.MainController.java
@Override public void initialize(final URL location, final ResourceBundle resources) { configTable();//from w w w .ja v a 2s . c o m mnuQuit.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(final ActionEvent actionEvent) { stopTasks(); Platform.exit(); } }); ctxClearLog.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(final ActionEvent actionEvent) { logTable.getItems().clear(); } }); ctxClearProfileSelection.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(final ActionEvent actionEvent) { lstProfileScripts.getSelectionModel().clearSelection(); } }); ctxClearSocialSelection.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(final ActionEvent actionEvent) { lstSocialScripts.getSelectionModel().clearSelection(); } }); lstProfileScripts.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); lstSocialScripts.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); lstProfileScripts.setCellFactory(new Callback<ListView, ListCell>() { @Override public ListCell call(final ListView listView) { return new FileListCell(); } }); lstSocialScripts.setCellFactory(new Callback<ListView, ListCell>() { @Override public ListCell call(final ListView listView) { return new FileListCell(); } }); ctxReloadProfileScrp.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(final ActionEvent actionEvent) { lstProfileScripts.getItems().clear(); try { extractBuildInScripts("profile", lstProfileScripts); } catch (MigrationException e) { log.error("Unable to extract BuildIn scripts"); } loadScripts(MigrationTool.systemProperties.getString("crafter.migration.profile.scripts"), lstProfileScripts); } }); ctxReloadSocialScrp.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(final ActionEvent actionEvent) { lstSocialScripts.getItems().clear(); try { extractBuildInScripts("profile", lstSocialScripts); } catch (MigrationException e) { log.error("Unable to extract BuildIn scripts"); } loadScripts(MigrationTool.systemProperties.getString("crafter.migration.social.scripts"), lstSocialScripts); } }); final MigrationSelectionAction selectionEventHandler = new MigrationSelectionAction(); rbtMigrateProfile.setOnAction(selectionEventHandler); rbtMigrateSocial.setOnAction(selectionEventHandler); loadScripts(); loadDefaultValues(); saveLog.setAccelerator(new KeyCodeCombination(KeyCode.S, KeyCombination.CONTROL_DOWN)); saveLog.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(final ActionEvent event) { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Save Migration Log"); fileChooser.setInitialFileName("Crafter-Migration-" + new SimpleDateFormat("yyyy-MM-dd@HH_mm").format(new Date()) + ".html"); final File savedFile = fileChooser.showSaveDialog(scene.getWindow()); if (savedFile == null) { return; } try { getHtml(new FileWriter(savedFile)); log.info("Saved Html log file"); } catch (IOException | TransformerException ex) { log.error("Unable to save file", ex); } } }); mnuStart.setAccelerator(new KeyCodeCombination(KeyCode.F5)); mnuStart.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(final ActionEvent event) { if (currentTask == null || !currentTask.isRunning()) { ObservableList scriptsToRun; if (rbtMigrateProfile.isSelected()) { scriptsToRun = lstProfileScripts.getSelectionModel().getSelectedItems(); } else { scriptsToRun = lstSocialScripts.getSelectionModel().getSelectedItems(); } currentTask = new MigrationPipeService(logTable, pgbTaskProgress, srcHost.getText(), srcPort.getText(), srcDb.getText(), dstHost.getText(), dstPort.getText(), dstDb.getText(), scriptsToRun); } if (!currentTask.isRunning()) { final Thread t = new Thread(currentTask, "Migration Task"); t.start(); } } }); }
From source file:mesclasses.view.RootLayoutController.java
@FXML public void onExport() { File archive;//from ww w.ja v a 2s .co m try { archive = FileSaveUtil.archive(); } catch (IOException e) { notif(e); return; } FileChooser chooser = new FileChooser(); chooser.setTitle("Sauvegardez les donnes"); chooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("Archive MesClasses", "*.zip")); LOG.info("archiving in " + archive.getPath()); chooser.setInitialFileName(FilenameUtils.getName(archive.getPath())); File file = chooser.showSaveDialog(primaryStage); if (file != null) { try { FileUtils.moveFile(archive, file); } catch (IOException ex) { notif(ex); } displayNotification(MessageEvent.SUCCESS, "Donnes sauvegardes"); } }
From source file:org.martus.client.swingui.PureFxMainWindow.java
protected File showFileSaveDialog(String title, File directory, String defaultFilename, FormatFilter filter) { FileChooser fileChooser = createFileChooser(title, directory, filter); fileChooser.setInitialFileName(defaultFilename); return fileChooser.showSaveDialog(getActiveStage()); }
From source file:org.sandsoft.acefx.AceEditor.java
@FXML private void openButtonOnAction() { try {// w ww . ja v a2 s . co m FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Open file"); attachFilters(fileChooser); if (mFilePath != null) { fileChooser.setInitialFileName(mFilePath.getName()); fileChooser.setInitialDirectory(mFilePath.getParentFile()); } File file = fileChooser.showOpenDialog(this.getScene().getWindow()); if (file != null) { openFile(file); } } catch (Exception ex) { Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); } }
From source file:ipat_fx.FXMLDocumentController.java
@FXML private void saveOption(ActionEvent event) { FileChooser fc = new FileChooser(); File file = new File(contextPath + "Saves/"); if (!file.exists()) { file.mkdirs();// w ww.j a va 2 s. c o m } fc.setInitialDirectory(file); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss"); Date date = new Date(); fc.setInitialFileName("Ipat_" + dateFormat.format(date)); File dest = fc.showSaveDialog(null); File src = new File(dataPath); try { FileUtils.copyDirectory(src, dest); } catch (IOException ex) { Logger.getLogger(IPAT_FX.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.esri.geoevent.test.performance.ui.OrchestratorController.java
/** * Displays a file chooser to select a file location to save the * configuration file./* w ww. j a v a 2 s. co m*/ */ private void saveFixturesFile() { File currentDir = Paths.get("").toAbsolutePath().toFile(); FileChooser fileChooser = new FileChooser(); fileChooser.setTitle(UIMessages.getMessage("UI_SAVE_FILE_CHOOSER_TITLE")); fileChooser.setInitialDirectory(currentDir); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("XML", "*.xml")); fileChooser.setInitialFileName(DEFAULT_FIXTURES_FILE); File file = fileChooser.showSaveDialog(stage); if (file != null) { try { saveFile(file); } catch (Exception error) { //TODO: Improve error handling and reporting error.printStackTrace(); } } }