use of org.jabref.gui.util.FileDialogConfiguration in project jabref by JabRef.
the class FileLinksUpgradeWarning method performAction.
/**
* This method presents a dialog box explaining and offering to make the
* changes. If the user confirms, the changes are performed.
* @param panel
* @param parserResult
*/
@Override
public void performAction(BasePanel panel, ParserResult parserResult) {
if (!isThereSomethingToBeDone()) {
// Nothing to do, just return.
return;
}
JCheckBox changeSettings = new JCheckBox(Localization.lang("Change table column and General fields settings to use the new feature"), offerChangeSettings);
JCheckBox changeDatabase = new JCheckBox(Localization.lang("Upgrade old external file links to use the new feature"), offerChangeDatabase);
JCheckBox setFileDir = new JCheckBox(Localization.lang("Set main external file directory") + ":", offerSetFileDir);
JTextField fileDir = new JTextField(30);
JCheckBox doNotShowDialog = new JCheckBox(Localization.lang("Do not show these options in the future"), false);
JPanel message = new JPanel();
FormBuilder formBuilder = FormBuilder.create().layout(new FormLayout("left:pref", "p"));
// Keep the formatting of these lines. Otherwise, strings have to be translated again.
// See updated JabRef_en.properties modifications by python syncLang.py -s -u
int row = 1;
formBuilder.add(new JLabel("<html>" + Localization.lang("This library uses outdated file links.") + "<br><br>" + Localization.lang("JabRef no longer supports 'ps' or 'pdf' fields.<br>File links are now stored in the 'file' field and files are stored in an external file directory.<br>To make use of this feature, JabRef needs to upgrade file links.<br><br>") + "<p>" + Localization.lang("Do you want JabRef to do the following operations?") + "</html>")).xy(1, row);
if (offerChangeSettings) {
formBuilder.appendRows("2dlu, p");
row += 2;
formBuilder.add(changeSettings).xy(1, row);
}
if (offerChangeDatabase) {
formBuilder.appendRows("2dlu, p");
row += 2;
formBuilder.add(changeDatabase).xy(1, row);
}
if (offerSetFileDir) {
if (Globals.prefs.hasKey(FieldName.PDF + FileDirectoryPreferences.DIR_SUFFIX)) {
fileDir.setText(Globals.prefs.get(FieldName.PDF + FileDirectoryPreferences.DIR_SUFFIX));
} else {
fileDir.setText(Globals.prefs.get(FieldName.PS + FileDirectoryPreferences.DIR_SUFFIX));
}
JPanel builderPanel = new JPanel();
builderPanel.add(setFileDir);
builderPanel.add(fileDir);
JButton browse = new JButton(Localization.lang("Browse"));
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build();
DialogService ds = new FXDialogService();
browse.addActionListener(e -> DefaultTaskExecutor.runInJavaFXThread(() -> ds.showFileOpenDialog(fileDialogConfiguration).ifPresent(f -> fileDir.setText(f.toAbsolutePath().toString()))));
builderPanel.add(browse);
formBuilder.appendRows("2dlu, p");
row += 2;
formBuilder.add(builderPanel).xy(1, row);
}
formBuilder.appendRows("6dlu, p");
formBuilder.add(doNotShowDialog).xy(1, row + 2);
message.add(formBuilder.build());
int answer = JOptionPane.showConfirmDialog(panel.frame(), message, Localization.lang("Upgrade file"), JOptionPane.YES_NO_OPTION);
if (doNotShowDialog.isSelected()) {
Globals.prefs.putBoolean(JabRefPreferences.SHOW_FILE_LINKS_UPGRADE_WARNING, false);
}
if (answer == JOptionPane.YES_OPTION) {
makeChanges(panel, parserResult, changeSettings.isSelected(), changeDatabase.isSelected(), setFileDir.isSelected() ? fileDir.getText() : null);
}
}
use of org.jabref.gui.util.FileDialogConfiguration in project jabref by JabRef.
the class SaveDatabaseAction method saveAs.
public void saveAs() throws Exception {
// configure file dialog
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().addExtensionFilter(FileExtensions.BIBTEX_DB).withDefaultExtension(FileExtensions.BIBTEX_DB).withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build();
DialogService ds = new FXDialogService();
Optional<Path> path = DefaultTaskExecutor.runInJavaFXThread(() -> ds.showFileSaveDialog(fileDialogConfiguration));
if (path.isPresent()) {
saveAs(path.get().toFile());
} else {
canceled = true;
return;
}
}
use of org.jabref.gui.util.FileDialogConfiguration in project jabref by JabRef.
the class LinkedFilesEditorViewModel method addNewFile.
public void addNewFile() {
Path workingDirectory = databaseContext.getFirstExistingFileDir(Globals.prefs.getFileDirectoryPreferences()).orElse(Paths.get(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)));
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().withInitialDirectory(workingDirectory).build();
List<Path> fileDirectories = databaseContext.getFileDirectoriesAsPaths(Globals.prefs.getFileDirectoryPreferences());
dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(newFile -> {
LinkedFile newLinkedFile = fromFile(newFile, fileDirectories);
files.add(new LinkedFileViewModel(newLinkedFile));
});
}
use of org.jabref.gui.util.FileDialogConfiguration in project jabref by JabRef.
the class OpenDatabaseAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
List<Path> filesToOpen = new ArrayList<>();
if (showDialog) {
DialogService ds = new FXDialogService();
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().addExtensionFilter(FileExtensions.BIBTEX_DB).withDefaultExtension(FileExtensions.BIBTEX_DB).withInitialDirectory(Paths.get(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY))).build();
List<Path> chosenFiles = DefaultTaskExecutor.runInJavaFXThread(() -> ds.showFileOpenDialogAndGetMultipleFiles(fileDialogConfiguration));
filesToOpen.addAll(chosenFiles);
} else {
LOGGER.info(Action.NAME + " " + e.getActionCommand());
filesToOpen.add(Paths.get(StringUtil.getCorrectFileName(e.getActionCommand(), "bib")));
}
openFiles(filesToOpen, true);
}
use of org.jabref.gui.util.FileDialogConfiguration in project jabref by JabRef.
the class AppendDatabaseAction method action.
@Override
public void action() {
filesToOpen.clear();
final MergeDialog dialog = new MergeDialog(frame, Localization.lang("Append library"), true);
dialog.setLocationRelativeTo(panel);
dialog.setVisible(true);
if (dialog.isOkPressed()) {
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().withDefaultExtension(FileExtensions.BIBTEX_DB).withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build();
DialogService dialogService = new FXDialogService();
List<Path> chosen = DefaultTaskExecutor.runInJavaFXThread(() -> dialogService.showFileOpenDialogAndGetMultipleFiles(fileDialogConfiguration));
if (chosen.isEmpty()) {
return;
}
filesToOpen.addAll(chosen);
// Run the actual open in a thread to prevent the program
// locking until the file is loaded.
JabRefExecutorService.INSTANCE.execute(() -> openIt(dialog.importEntries(), dialog.importStrings(), dialog.importGroups(), dialog.importSelectorWords()));
}
}
Aggregations