Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement an interface to import PDF metadata from multiple sources (XMP, Grobid, ...) #7929

Merged
merged 128 commits into from
Aug 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
22f0241
GrobidPdfMetadataImporter implemented
btut Jul 20, 2021
8effaa9
Fixed class when accessing resources
btut Jul 20, 2021
5d487d2
Draft of merge dialog
btut Jul 20, 2021
96cd5cf
Default to first available entry
btut Jul 21, 2021
8b5510e
Changed layout
btut Jul 21, 2021
3a4a01a
Checkstyle
btut Jul 21, 2021
8314855
Bind buttons with equal content together
btut Jul 21, 2021
05964bc
Use TextArea only for multiline fields
btut Jul 23, 2021
0f64b1c
Use SplitPane
btut Jul 23, 2021
1260cf9
Fixed scaling of labels
btut Jul 23, 2021
97fb43d
Add tooltip for toggle buttons
btut Jul 23, 2021
733415f
Implemented loading BibEntries in background
btut Jul 23, 2021
620424c
Implemented DOI Lookup button
btut Jul 23, 2021
46bf75a
Changed Button content to TextFlow
btut Jul 24, 2021
f036112
Change DOI button to icon
btut Jul 28, 2021
a5d216c
Use FileHelper method to get extension
btut Jul 28, 2021
d9dc84e
Use ellipsing text flow
btut Jul 28, 2021
6e6b5bc
Ignore empty fields
btut Jul 28, 2021
3546715
Use jsoup to issue POST request
btut Jul 28, 2021
6906d11
Removed unnecessary field
btut Jul 28, 2021
c9e4c06
Reverted URLDownload
btut Jul 28, 2021
f319fc7
Enable VGrow
btut Jul 28, 2021
993ad84
Insets and DiffHighlighting
btut Jul 30, 2021
8a7b80f
GrobidPdfMetadataImporter implemented
btut Jul 20, 2021
6fe2a23
Fixed class when accessing resources
btut Jul 20, 2021
f99bc52
Use FileHelper method to get extension
btut Jul 28, 2021
1d64d80
Use jsoup to issue POST request
btut Jul 28, 2021
f591bfc
Removed unnecessary field
btut Jul 28, 2021
b2bd365
Reverted URLDownload
btut Jul 28, 2021
e458c77
Changelog entry
btut Jul 30, 2021
5478585
Add pdf link to imported entry
btut Jul 30, 2021
d0cc663
Remove citationkey from Grobid
btut Jul 30, 2021
2cd78fc
FirstPageImporter
btut Jul 30, 2021
eb22157
Fixed grammar mistake in CHANGELOG.md
btut Jul 30, 2021
3ac0094
Fixed Grobid tests
btut Jul 30, 2021
c87ed4e
Fixed Grobid URL
btut Jul 30, 2021
3d8c4da
Checkstyle
btut Jul 30, 2021
168b866
Fixed doc
btut Jul 30, 2021
42adea9
Checkstyle
btut Jul 30, 2021
980af83
MVVM split
btut Aug 1, 2021
73dc505
Use JSoup for plaintext citations as well
btut Aug 1, 2021
33cbc95
Merge branch 'improvement/morePdfImporters' into improvement/pdfMetad…
btut Aug 1, 2021
d841207
Actual MVVM
btut Aug 2, 2021
616e73d
Fixes and styling
btut Aug 2, 2021
e2a215e
Cleanup Diff-highlighting
btut Aug 2, 2021
44dfebd
Checkstyle
btut Aug 2, 2021
1841cdf
Prettier loading indicator
btut Aug 2, 2021
7ce7105
Renamed FirstPageImporter to PdfVerbatimBibTextImporter
btut Aug 4, 2021
53d8e9a
Fixed getName (no importer)
btut Aug 4, 2021
9080f14
Renamed Grobid importer to match convention
btut Aug 4, 2021
4c74d51
Fixed loading issue
btut Aug 5, 2021
2757be6
PdfEmbeddedBibTeXImporter
btut Aug 5, 2021
8a05c3e
Renamed PdfEmbeddedBibTeXImporter to PdfEmbeddedBibFileImporter
btut Aug 5, 2021
0c488ec
Checkstyle
btut Aug 5, 2021
02057f0
Remove debug output
btut Aug 5, 2021
3d66855
Checkstyle
btut Aug 5, 2021
fd8918b
PdfMergeMetadataImporter
btut Aug 5, 2021
56868f5
Add DOI and ISBN fetching in PdfMergeMetadataImporter
btut Aug 5, 2021
479a0bc
Fixed concurrent list access
btut Aug 5, 2021
cb6a910
Adapted tests to contain fetchable ID's
btut Aug 5, 2021
0b64ebd
Configurable diff-modes and styling
btut Aug 10, 2021
649049c
Localization
btut Aug 10, 2021
b6e3aaa
Refactor
btut Aug 10, 2021
7f78c9e
Merge branch 'main' of github.com:JabRef/jabref into improvement/pdfM…
btut Aug 10, 2021
e18eabd
Merge branch 'main' of github.com:JabRef/jabref into improvement/more…
btut Aug 10, 2021
1bf6409
Derive XMP preferences from importFormatPreferences
btut Aug 10, 2021
787e040
Localization
btut Aug 10, 2021
a3cdff9
Use Importers in JabRef
btut Aug 10, 2021
564988a
Remove unnecessary test documents
btut Aug 10, 2021
4db14f4
Fixed error introduced by refactor
btut Aug 10, 2021
ba13971
Fit field-editor-column to width
btut Aug 10, 2021
e3d279a
Checkstyle
btut Aug 11, 2021
25e7b2e
Localization in diff-mode
btut Aug 14, 2021
04eecaf
Grobid Timeout
btut Aug 14, 2021
b7e5b62
Null-check
btut Aug 14, 2021
5cbf919
Use MergeImporter as WebFetcher
btut Aug 14, 2021
1cb4dfc
Only force BibTeX import if everything else fails
btut Aug 16, 2021
3ab8ebb
Prioritize non-bruteforce importers that
btut Aug 16, 2021
7ba8b40
Checkstyle
btut Aug 16, 2021
eadbf67
Added explanaition on need for runInJavaFXThread
btut Aug 16, 2021
2b00f47
Styling for dark theme
btut Aug 16, 2021
18dbb67
Fixed WebFetchersTest
btut Aug 16, 2021
9a138b6
Added parse pdf metadata button to GUI
btut Aug 16, 2021
41de0d0
Changelog
btut Aug 16, 2021
4fdd850
Merge branch 'main' of github.com:JabRef/jabref into improvement/pdfM…
btut Aug 16, 2021
6cd9544
Fixed moving-text glitch
btut Aug 16, 2021
1f4bf84
Follow up on glitch-fix
btut Aug 16, 2021
0468e67
Checkstyle and localization
btut Aug 16, 2021
3d46df4
Grobid does not need localization
btut Aug 16, 2021
40b2759
Followup on removed Grobid localization
btut Aug 16, 2021
6324cf2
Fixed tests
btut Aug 16, 2021
54274be
Merge branch 'improvement/morePdfImporters' of github.com:btut/jabref…
btut Aug 16, 2021
089b025
Enable all importers
btut Aug 16, 2021
5cf2af7
Merge branch 'main' of github.com:JabRef/jabref into improvement/more…
btut Aug 16, 2021
b555ada
Checkstyle
btut Aug 16, 2021
a956a37
Merge branch 'improvement/morePdfImporters' of github.com:btut/jabref…
btut Aug 17, 2021
5994a5d
Merge branch 'main' of github.com:JabRef/jabref into improvement/pdfM…
btut Aug 17, 2021
44fee74
Improved display
btut Aug 18, 2021
7a98c8a
Modern switch statements
btut Aug 18, 2021
fb186e3
Fixed position of buttons in LinkedFilesEditor
calixtus Aug 18, 2021
63272bb
Merge remote-tracking branch 'btut/improvement/pdfMetadataImport' int…
calixtus Aug 18, 2021
9db1045
Merge branch 'main' of github.com:JabRef/jabref into improvement/pdfM…
btut Aug 18, 2021
8b1974c
Merge branch 'improvement/pdfMetadataImport' of github.com:btut/jabre…
btut Aug 18, 2021
9f69569
Collapse importers that yield no result
btut Aug 19, 2021
31b62a0
Settings for grobid
btut Aug 19, 2021
cdc9fb1
Merge branch 'main' of github.com:JabRef/jabref into useGrobidPreference
btut Aug 19, 2021
fcdb5a4
Use settings
btut Aug 19, 2021
7e918a3
Updated PdfImporter priorization
btut Aug 19, 2021
3440b32
Store opt-out preference
btut Aug 19, 2021
e5222ce
Partial implementation of opt-in/out dialogue
btut Aug 19, 2021
ef5444a
Show dialog before all Grobid actions
btut Aug 20, 2021
ffaeec5
Static code checks
btut Aug 20, 2021
4f4f398
Merge branch 'main' of github.com:JabRef/jabref into useGrobidPreference
btut Aug 20, 2021
e9ef2e3
Merge branch 'useGrobidPreference' into improvement/pdfMetadataImport
btut Aug 20, 2021
ae32a40
Use Grobid Settings and Opt-In dialog
btut Aug 20, 2021
bd6c8e4
Fix l10n issue (introduced in merge)
btut Aug 20, 2021
70a2e3e
Merge branch 'main' of github.com:JabRef/jabref into useGrobidPreference
btut Aug 20, 2021
51eb15d
Merge branch 'useGrobidPreference' into improvement/pdfMetadataImport
btut Aug 20, 2021
61b3b5b
Fixed missing import (introduced by merge)
btut Aug 20, 2021
3dbafbe
Merge branch 'useGrobidPreference' into improvement/pdfMetadataImport
btut Aug 20, 2021
69af125
Extract given-clause in test
btut Aug 21, 2021
f676003
Improved readability
btut Aug 21, 2021
1e97104
Changelog
btut Aug 21, 2021
43aaa05
Merge branch 'useGrobidPreference' into improvement/pdfMetadataImport
btut Aug 21, 2021
55a4653
Changelog update
btut Aug 21, 2021
f0afe0c
Merge branch 'useGrobidPreference' into improvement/pdfMetadataImport
btut Aug 21, 2021
87eded9
Renamed Entry to EntrySource
btut Aug 21, 2021
32c0a3d
Merge branch 'main' of github.com:JabRef/jabref into improvement/pdfM…
btut Aug 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We added a fulltext search feature. [#2838](https://github.com/JabRef/jabref/pull/2838)
- We improved the deduction of bib-entries from imported fulltext pdfs. [#7947](https://github.com/JabRef/jabref/pull/7947)
- We added unprotect_terms to the list of bracketed pattern modifiers [#7826](https://github.com/JabRef/jabref/pull/7960)
- We added a dialog that allows to parse metadata from linked pdfs. [#7929](https://github.com/JabRef/jabref/pull/7929)
- We added an icon picker in group edit dialog. [#6142](https://github.com/JabRef/jabref/issues/6142)
- We added a preference to Opt-In to JabRef's online metadata extraction service (Grobid) usage. [8002](https://github.com/JabRef/jabref/pull/8002)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ private void addLinkedFileFromURL(BibDatabaseContext databaseContext, URL url, B
databaseContext,
Globals.TASK_EXECUTOR,
dialogService,
preferences.getXmpPreferences(),
preferences.getFilePreferences(),
preferences,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this change necessary? We should focus the preferences passed around - and not enlarge the scope.

ExternalFileTypes.getInstance());

onlineFile.download();
Expand Down
87 changes: 61 additions & 26 deletions src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.List;
import java.util.Optional;
import java.util.function.BiPredicate;
import java.util.function.Supplier;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
Expand All @@ -35,23 +36,30 @@
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.icon.JabRefIcon;
import org.jabref.gui.linkedfile.LinkedFileEditDialogView;
import org.jabref.gui.mergeentries.MultiMergeEntriesView;
import org.jabref.gui.util.BackgroundTask;
import org.jabref.gui.util.ControlHelper;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.externalfiles.LinkedFileHandler;
import org.jabref.logic.importer.Importer;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.importer.fileformat.PdfContentImporter;
import org.jabref.logic.importer.fileformat.PdfEmbeddedBibFileImporter;
import org.jabref.logic.importer.fileformat.PdfGrobidImporter;
import org.jabref.logic.importer.fileformat.PdfVerbatimBibTextImporter;
import org.jabref.logic.importer.fileformat.PdfXmpImporter;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.net.URLDownload;
import org.jabref.logic.util.io.FileNameUniqueness;
import org.jabref.logic.util.io.FileUtil;
import org.jabref.logic.xmp.XmpPreferences;
import org.jabref.logic.xmp.XmpUtilWriter;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.LinkedFile;
import org.jabref.model.strings.StringUtil;
import org.jabref.model.util.FileHelper;
import org.jabref.model.util.OptionalUtil;
import org.jabref.preferences.FilePreferences;
import org.jabref.preferences.PreferencesService;

import de.saxsys.mvvmfx.utils.validation.FunctionBasedValidator;
import de.saxsys.mvvmfx.utils.validation.ValidationMessage;
Expand All @@ -69,12 +77,11 @@ public class LinkedFileViewModel extends AbstractViewModel {
private final DoubleProperty downloadProgress = new SimpleDoubleProperty(-1);
private final BooleanProperty downloadOngoing = new SimpleBooleanProperty(false);
private final BooleanProperty isAutomaticallyFound = new SimpleBooleanProperty(false);
private final BooleanProperty canWriteXMPMetadata = new SimpleBooleanProperty(false);
private final BooleanProperty isOfflinePdf = new SimpleBooleanProperty(false);
private final DialogService dialogService;
private final BibEntry entry;
private final TaskExecutor taskExecutor;
private final FilePreferences filePreferences;
private final XmpPreferences xmpPreferences;
private final PreferencesService preferences;
private final LinkedFileHandler linkedFileHandler;
private final ExternalFileTypes externalFileTypes;

Expand All @@ -85,38 +92,36 @@ public LinkedFileViewModel(LinkedFile linkedFile,
BibDatabaseContext databaseContext,
TaskExecutor taskExecutor,
DialogService dialogService,
XmpPreferences xmpPreferences,
FilePreferences filePreferences,
PreferencesService preferences,
ExternalFileTypes externalFileTypes) {

this.linkedFile = linkedFile;
this.filePreferences = filePreferences;
this.linkedFileHandler = new LinkedFileHandler(linkedFile, entry, databaseContext, filePreferences);
this.preferences = preferences;
this.linkedFileHandler = new LinkedFileHandler(linkedFile, entry, databaseContext, preferences.getFilePreferences());
this.databaseContext = databaseContext;
this.entry = entry;
this.dialogService = dialogService;
this.taskExecutor = taskExecutor;
this.externalFileTypes = externalFileTypes;
this.xmpPreferences = xmpPreferences;

fileExistsValidator = new FunctionBasedValidator<>(
linkedFile.linkProperty(),
link -> {
if (linkedFile.isOnlineLink()) {
return true;
} else {
Optional<Path> path = FileHelper.find(databaseContext, link, filePreferences);
Optional<Path> path = FileHelper.find(databaseContext, link, preferences.getFilePreferences());
return path.isPresent() && Files.exists(path.get());
}
},
ValidationMessage.warning(Localization.lang("Could not find file '%0'.", linkedFile.getLink())));

downloadOngoing.bind(downloadProgress.greaterThanOrEqualTo(0).and(downloadProgress.lessThan(1)));
canWriteXMPMetadata.setValue(!linkedFile.isOnlineLink() && linkedFile.getFileType().equalsIgnoreCase("pdf"));
isOfflinePdf.setValue(!linkedFile.isOnlineLink() && linkedFile.getFileType().equalsIgnoreCase("pdf"));
}

public BooleanProperty canWriteXMPMetadataProperty() {
return canWriteXMPMetadata;
public BooleanProperty isOfflinePdfProperty() {
return isOfflinePdf;
}

public boolean isAutomaticallyFound() {
Expand Down Expand Up @@ -211,7 +216,7 @@ public void openFolder() {
Optional<Path> resolvedPath = FileHelper.find(
databaseContext,
linkedFile.getLink(),
filePreferences);
preferences.getFilePreferences());

if (resolvedPath.isPresent()) {
JabRefDesktop.openFolderAndSelectFile(resolvedPath.get());
Expand Down Expand Up @@ -246,7 +251,7 @@ public void renameFileToName(String targetFileName) {
return;
}

Optional<Path> file = linkedFile.findIn(databaseContext, filePreferences);
Optional<Path> file = linkedFile.findIn(databaseContext, preferences.getFilePreferences());
if (file.isPresent()) {
performRenameWithConflictCheck(targetFileName);
} else {
Expand Down Expand Up @@ -283,13 +288,13 @@ public void moveToDefaultDirectory() {
}

// Get target folder
Optional<Path> fileDir = databaseContext.getFirstExistingFileDir(filePreferences);
Optional<Path> fileDir = databaseContext.getFirstExistingFileDir(preferences.getFilePreferences());
if (fileDir.isEmpty()) {
dialogService.showErrorDialogAndWait(Localization.lang("Move file"), Localization.lang("File directory is not set or does not exist!"));
return;
}

Optional<Path> file = linkedFile.findIn(databaseContext, filePreferences);
Optional<Path> file = linkedFile.findIn(databaseContext, preferences.getFilePreferences());
if ((file.isPresent())) {
// Found the linked file, so move it
try {
Expand Down Expand Up @@ -325,9 +330,9 @@ public boolean isGeneratedNameSameAsOriginal() {
* @return true if suggested filepath is same as existing filepath.
*/
public boolean isGeneratedPathSameAsOriginal() {
Optional<Path> newDir = databaseContext.getFirstExistingFileDir(filePreferences);
Optional<Path> newDir = databaseContext.getFirstExistingFileDir(preferences.getFilePreferences());

Optional<Path> currentDir = linkedFile.findIn(databaseContext, filePreferences).map(Path::getParent);
Optional<Path> currentDir = linkedFile.findIn(databaseContext, preferences.getFilePreferences()).map(Path::getParent);

BiPredicate<Path, Path> equality = (fileA, fileB) -> {
try {
Expand All @@ -351,7 +356,7 @@ public void moveToDefaultDirectoryAndRename() {
* successfully, does not exist in the first place or the user choose to remove it)
*/
public boolean delete() {
Optional<Path> file = linkedFile.findIn(databaseContext, filePreferences);
Optional<Path> file = linkedFile.findIn(databaseContext, preferences.getFilePreferences());

if (file.isEmpty()) {
LOGGER.warn("Could not find file " + linkedFile.getLink());
Expand Down Expand Up @@ -395,13 +400,13 @@ public void edit() {
public void writeXMPMetadata() {
// Localization.lang("Writing XMP metadata...")
BackgroundTask<Void> writeTask = BackgroundTask.wrap(() -> {
Optional<Path> file = linkedFile.findIn(databaseContext, filePreferences);
Optional<Path> file = linkedFile.findIn(databaseContext, preferences.getFilePreferences());
if (file.isEmpty()) {
// TODO: Print error message
// Localization.lang("PDF does not exist");
} else {
try {
XmpUtilWriter.writeXmp(file.get(), entry, databaseContext.getDatabase(), xmpPreferences);
XmpUtilWriter.writeXmp(file.get(), entry, databaseContext.getDatabase(), preferences.getXmpPreferences());
} catch (IOException | TransformerException ex) {
// TODO: Print error message
// Localization.lang("Error while writing") + " '" + file.toString() + "': " + ex;
Expand All @@ -421,7 +426,7 @@ public void download() {
throw new UnsupportedOperationException("In order to download the file it has to be an online link");
}
try {
Optional<Path> targetDirectory = databaseContext.getFirstExistingFileDir(filePreferences);
Optional<Path> targetDirectory = databaseContext.getFirstExistingFileDir(preferences.getFilePreferences());
if (targetDirectory.isEmpty()) {
dialogService.showErrorDialogAndWait(Localization.lang("Download file"), Localization.lang("File directory is not set or does not exist!"));
return;
Expand All @@ -443,7 +448,7 @@ public void download() {
}

if (!isDuplicate) {
LinkedFile newLinkedFile = LinkedFilesEditorViewModel.fromFile(destination, databaseContext.getFileDirectories(filePreferences), externalFileTypes);
LinkedFile newLinkedFile = LinkedFilesEditorViewModel.fromFile(destination, databaseContext.getFileDirectories(preferences.getFilePreferences()), externalFileTypes);
List<LinkedFile> linkedFiles = entry.getFiles();

entry.addLinkedFile(entry, linkedFile, newLinkedFile, linkedFiles);
Expand Down Expand Up @@ -495,7 +500,7 @@ public BackgroundTask<Path> prepareDownloadTask(Path targetDirectory, URLDownloa
String suggestedTypeName = externalFileType.getName();
linkedFile.setFileType(suggestedTypeName);
String suggestedName = linkedFileHandler.getSuggestedFileName(externalFileType.getExtension());
String fulltextDir = FileUtil.createDirNameFromPattern(databaseContext.getDatabase(), entry, filePreferences.getFileDirectoryPattern());
String fulltextDir = FileUtil.createDirNameFromPattern(databaseContext.getDatabase(), entry, preferences.getFilePreferences().getFileDirectoryPattern());
suggestedName = FileNameUniqueness.getNonOverWritingFileName(targetDirectory.resolve(fulltextDir), suggestedName);
return targetDirectory.resolve(fulltextDir).resolve(suggestedName);
})
Expand Down Expand Up @@ -538,4 +543,34 @@ public LinkedFile getFile() {
public ValidationStatus fileExistsValidationStatus() {
return fileExistsValidator.getValidationStatus();
}

public void parsePdfMetadataAndShowMergeDialog() {
linkedFile.findIn(databaseContext, preferences.getFilePreferences()).ifPresent(filePath -> {
MultiMergeEntriesView dialog = new MultiMergeEntriesView(preferences, taskExecutor);
dialog.addSource(Localization.lang("Entry"), entry);
dialog.addSource(Localization.lang("Verbatim"), wrapImporterToSupplier(new PdfVerbatimBibTextImporter(preferences.getImportFormatPreferences()), filePath));
dialog.addSource(Localization.lang("Embedded"), wrapImporterToSupplier(new PdfEmbeddedBibFileImporter(preferences.getImportFormatPreferences()), filePath));
dialog.addSource("Grobid", wrapImporterToSupplier(new PdfGrobidImporter(preferences.getImportSettingsPreferences(), preferences.getImportFormatPreferences()), filePath));
dialog.addSource(Localization.lang("XMP metadata"), wrapImporterToSupplier(new PdfXmpImporter(preferences.getXmpPreferences()), filePath));
dialog.addSource(Localization.lang("Content"), wrapImporterToSupplier(new PdfContentImporter(preferences.getImportFormatPreferences()), filePath));
dialog.showAndWait().ifPresent(newEntry -> {
databaseContext.getDatabase().removeEntry(entry);
databaseContext.getDatabase().insertEntry(newEntry);
});
});
}

private Supplier<BibEntry> wrapImporterToSupplier(Importer importer, Path filePath) {
return () -> {
try {
ParserResult parserResult = importer.importDatabase(filePath, preferences.getDefaultEncoding());
if (parserResult.isInvalid() || parserResult.isEmpty() || !parserResult.getDatabase().hasEntries()) {
return null;
}
return parserResult.getDatabase().getEntries().get(0);
} catch (IOException e) {
return null;
}
};
}
}
20 changes: 16 additions & 4 deletions src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import javafx.scene.input.MouseEvent;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.text.Text;

import org.jabref.gui.DialogService;
Expand All @@ -34,6 +35,7 @@
import org.jabref.gui.autocompleter.SuggestionProvider;
import org.jabref.gui.copyfiles.CopySingleFileAction;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.importer.GrobidOptInDialogHelper;
import org.jabref.gui.keyboard.KeyBinding;
import org.jabref.gui.util.BindingsHelper;
import org.jabref.gui.util.TaskExecutor;
Expand Down Expand Up @@ -81,7 +83,7 @@ public LinkedFilesEditor(Field field,

ViewModelListCellFactory<LinkedFileViewModel> cellFactory = new ViewModelListCellFactory<LinkedFileViewModel>()
.withStringTooltip(LinkedFileViewModel::getDescription)
.withGraphic(LinkedFilesEditor::createFileDisplay)
.withGraphic(this::createFileDisplay)
.withContextMenu(this::createContextMenuForFile)
.withOnMouseClickedEvent(this::handleItemMouseClick)
.setOnDragDetected(this::handleOnDragDetected)
Expand Down Expand Up @@ -142,7 +144,7 @@ private void handleOnDragDropped(LinkedFileViewModel originalItem, DragEvent eve
event.consume();
}

private static Node createFileDisplay(LinkedFileViewModel linkedFile) {
private Node createFileDisplay(LinkedFileViewModel linkedFile) {
PseudoClass opacity = PseudoClass.getPseudoClass("opacity");

Node icon = linkedFile.getTypeIcon().getGraphicNode();
Expand All @@ -162,6 +164,7 @@ private static Node createFileDisplay(LinkedFileViewModel linkedFile) {
progressIndicator.visibleProperty().bind(linkedFile.downloadOngoingProperty());

HBox info = new HBox(8);
HBox.setHgrow(info, Priority.ALWAYS);
info.setStyle("-fx-padding: 0.5em 0 0.5em 0;"); // To align with buttons below which also have 0.5em padding
info.getChildren().setAll(icon, link, desc, progressIndicator);

Expand All @@ -174,14 +177,23 @@ private static Node createFileDisplay(LinkedFileViewModel linkedFile) {

Button writeXMPMetadata = IconTheme.JabRefIcons.IMPORT.asButton();
writeXMPMetadata.setTooltip(new Tooltip(Localization.lang("Write BibTeXEntry as XMP metadata to PDF.")));
writeXMPMetadata.visibleProperty().bind(linkedFile.canWriteXMPMetadataProperty());
writeXMPMetadata.visibleProperty().bind(linkedFile.isOfflinePdfProperty());
writeXMPMetadata.setOnAction(event -> linkedFile.writeXMPMetadata());
writeXMPMetadata.getStyleClass().setAll("icon-button");

Button parsePdfMetadata = IconTheme.JabRefIcons.FILE_SEARCH.asButton();
parsePdfMetadata.setTooltip(new Tooltip(Localization.lang("Parse Metadata from PDF.")));
parsePdfMetadata.visibleProperty().bind(linkedFile.isOfflinePdfProperty());
parsePdfMetadata.setOnAction(event -> {
GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(dialogService);
linkedFile.parsePdfMetadataAndShowMergeDialog();
});
parsePdfMetadata.getStyleClass().setAll("icon-button");

HBox container = new HBox(10);
container.setPrefHeight(Double.NEGATIVE_INFINITY);

container.getChildren().addAll(acceptAutoLinkedFile, info, writeXMPMetadata);
container.getChildren().addAll(acceptAutoLinkedFile, info, writeXMPMetadata, parsePdfMetadata);

return container;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ public LinkedFileViewModel fromFile(Path file) {
databaseContext,
taskExecutor,
dialogService,
preferences.getXmpPreferences(),
preferences.getFilePreferences(),
preferences,
externalFileTypes);
}

Expand All @@ -123,8 +122,7 @@ private List<LinkedFileViewModel> parseToFileViewModel(String stringValue) {
databaseContext,
taskExecutor,
dialogService,
preferences.getXmpPreferences(),
preferences.getFilePreferences(),
preferences,
externalFileTypes))
.collect(Collectors.toList());
}
Expand Down Expand Up @@ -154,8 +152,7 @@ public void addNewFile() {
databaseContext,
taskExecutor,
dialogService,
preferences.getXmpPreferences(),
preferences.getFilePreferences(),
preferences,
externalFileTypes));
});
}
Expand Down Expand Up @@ -192,8 +189,7 @@ private List<LinkedFileViewModel> findAssociatedNotLinkedFiles(BibEntry entry) {
databaseContext,
taskExecutor,
dialogService,
preferences.getXmpPreferences(),
preferences.getFilePreferences(),
preferences,
externalFileTypes);
newLinkedFile.markAsAutomaticallyFound();
result.add(newLinkedFile);
Expand Down Expand Up @@ -243,8 +239,7 @@ private void addFromURL(URL url) {
databaseContext,
taskExecutor,
dialogService,
preferences.getXmpPreferences(),
preferences.getFilePreferences(),
preferences,
externalFileTypes);
files.add(onlineFile);
onlineFile.download();
Expand Down
Loading