use of javafx.stage.FileChooser in project bitsquare by bitsquare.
the class TraderDisputeView method onOpenAttachment.
private void onOpenAttachment(Attachment attachment) {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Save file to disk");
fileChooser.setInitialFileName(attachment.getFileName());
/* if (Utilities.isUnix())
fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));*/
File file = fileChooser.showSaveDialog(stage);
if (file != null) {
try (FileOutputStream fileOutputStream = new FileOutputStream(file.getAbsolutePath())) {
fileOutputStream.write(attachment.getBytes());
} catch (IOException e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
}
}
use of javafx.stage.FileChooser in project mybatis-generator-gui-extension by spawpaw.
the class FileChooserControl method bindProperties.
@Override
protected void bindProperties() {
label.setMinWidth(MIN_WIDTH_LEFT);
textField.textProperty().bindBidirectional(value);
label.textProperty().bindBidirectional(this.labelTextProperty);
button.setOnMouseClicked((event -> {
FileChooser fileChooser = new FileChooser();
File selectedFile = fileChooser.showOpenDialog(BaseController.primaryStage);
if (selectedFile != null) {
value.setValue(selectedFile.getAbsolutePath());
}
}));
}
use of javafx.stage.FileChooser in project bitsquare by bitsquare.
the class GUIUtil method exportCSV.
public static <T> void exportCSV(String fileName, CSVEntryConverter<T> headerConverter, CSVEntryConverter<T> contentConverter, T emptyItem, List<T> list, Stage stage) {
FileChooser fileChooser = new FileChooser();
fileChooser.setInitialFileName(fileName);
File file = fileChooser.showSaveDialog(stage);
try (OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(file, false), Charsets.UTF_8)) {
CSVWriter<T> headerWriter = new CSVWriterBuilder<T>(outputStreamWriter).strategy(CSVStrategy.UK_DEFAULT).entryConverter(headerConverter).build();
headerWriter.write(emptyItem);
CSVWriter<T> contentWriter = new CSVWriterBuilder<T>(outputStreamWriter).strategy(CSVStrategy.UK_DEFAULT).entryConverter(contentConverter).build();
contentWriter.writeAll(list);
} catch (RuntimeException | IOException e) {
e.printStackTrace();
log.error(e.getMessage());
new Popup().error("Exporting to CSV failed because of an error.\n" + "Error = " + e.getMessage());
}
}
use of javafx.stage.FileChooser in project jgnash by ccavanaugh.
the class BudgetViewController method handleExportAction.
@FXML
private void handleExportAction() {
Objects.requireNonNull(budgetTableController);
final Preferences pref = Preferences.userNodeForPackage(BudgetViewController.class);
final FileChooser fileChooser = new FileChooser();
fileChooser.setInitialDirectory(new File(pref.get(EXPORT_DIR, System.getProperty("user.home"))));
fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter(resources.getString("Label.SpreadsheetFiles") + " (*.xls, *.xlsx)", "*.xls", "*.xlsx"));
final File file = fileChooser.showSaveDialog(MainView.getPrimaryStage());
if (file != null) {
pref.put(EXPORT_DIR, file.getParentFile().getAbsolutePath());
final Task<Void> exportTask = new Task<Void>() {
@Override
protected Void call() throws Exception {
updateMessage(resources.getString("Message.PleaseWait"));
updateProgress(-1, Long.MAX_VALUE);
BudgetResultsExport.exportBudgetResultsModel(file.toPath(), budgetTableController.getBudgetResultsModel());
return null;
}
};
new Thread(exportTask).start();
StaticUIMethods.displayTaskProgress(exportTask);
}
}
use of javafx.stage.FileChooser in project jgnash by ccavanaugh.
the class AttachmentPane method attachmentAction.
private void attachmentAction() {
final Preferences pref = Preferences.userNodeForPackage(this.getClass());
final String baseFile = EngineFactory.getActiveDatabase();
final List<String> extensions = new ArrayList<>();
for (final String suffix : ImageIO.getReaderFileSuffixes()) {
extensions.add("*." + suffix);
}
final FileChooser fileChooser = new FileChooser();
fileChooser.setTitle(resources.getString("Title.SelFile"));
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter(resources.getString("Title.ImageFiles"), extensions));
final String lastDirectory = pref.get(LAST_DIR, null);
if (lastDirectory != null) {
fileChooser.setInitialDirectory(new File(lastDirectory));
}
if (attachment.get() != null) {
final Path path = attachment.get().getFileName();
if (path != null) {
fileChooser.setInitialFileName(path.toString());
}
}
final File selectedFile = fileChooser.showOpenDialog(MainView.getPrimaryStage());
if (selectedFile != null) {
// save last good directory location
pref.put(LAST_DIR, selectedFile.getParent());
boolean result = true;
// TODO, add option to copy the file instead of moving it
final Path attachmentDirectory = AttachmentUtils.getAttachmentDirectory(Paths.get(baseFile));
if (baseFile.startsWith(EngineFactory.REMOTE_PREFIX)) {
// working remotely
moveAttachment = true;
} else if (attachmentDirectory != null && !attachmentDirectory.toString().equals(selectedFile.getParent())) {
String message = ResourceUtils.getString("Message.Warn.MoveFile", selectedFile.toString(), attachmentDirectory.toString());
if (!StaticUIMethods.showConfirmationDialog(resources.getString("Title.MoveFile"), message).getButtonData().isCancelButton()) {
moveAttachment = true;
final Path newPath = Paths.get(AttachmentUtils.getAttachmentDirectory(Paths.get(baseFile)) + FileUtils.separator + selectedFile.getName());
if (Files.exists(newPath)) {
message = ResourceUtils.getString("Message.Warn.SameFile", selectedFile.toString(), attachmentDirectory.toString());
StaticUIMethods.displayWarning(message);
moveAttachment = false;
result = false;
}
} else {
result = false;
}
}
if (result) {
attachment.set(selectedFile.toPath());
}
}
}
Aggregations