Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
8 changes: 5 additions & 3 deletions src/main/java/org/jabref/gui/JabRefMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,12 @@ private static void applyPreferences(PreferencesService preferences) {
Globals.journalAbbreviationRepository = JournalAbbreviationLoader.loadRepository(preferences.getJournalAbbreviationPreferences());

// Build list of Import and Export formats
Globals.IMPORT_FORMAT_READER.resetImportFormats(preferences.getImporterPreferences(),
Globals.IMPORT_FORMAT_READER.resetImportFormats(
preferences.getImporterPreferences(),
preferences.getImportFormatPreferences(),
preferences.getXmpPreferences(), Globals.getFileUpdateMonitor());
Globals.entryTypesManager.addCustomOrModifiedTypes(preferences.getBibEntryTypes(BibDatabaseMode.BIBTEX),
Globals.getFileUpdateMonitor());
Globals.entryTypesManager.addCustomOrModifiedTypes(
preferences.getBibEntryTypes(BibDatabaseMode.BIBTEX),
preferences.getBibEntryTypes(BibDatabaseMode.BIBLATEX));
Globals.exportFactory = ExporterFactory.create(
preferences.getCustomExportFormats(Globals.journalAbbreviationRepository),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public StringProperty inputTextProperty() {
}

public void startParsing() {
if (preferencesService.getImporterPreferences().isGrobidEnabled()) {
if (preferencesService.getGrobidPreferences().isGrobidEnabled()) {
parseUsingGrobid();
} else {
parseUsingBibtexExtractor();
Expand All @@ -78,7 +78,7 @@ private void parseUsingBibtexExtractor() {
}

private void parseUsingGrobid() {
GrobidCitationFetcher grobidCitationFetcher = new GrobidCitationFetcher(preferencesService.getImporterPreferences(), preferencesService.getImportFormatPreferences());
GrobidCitationFetcher grobidCitationFetcher = new GrobidCitationFetcher(preferencesService.getGrobidPreferences(), preferencesService.getImportFormatPreferences());
BackgroundTask.wrap(() -> grobidCitationFetcher.performSearch(inputTextProperty.getValue()))
.onRunning(() -> dialogService.notify(Localization.lang("Your text is being parsed...")))
.onFailure((e) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public ExtractBibtexAction(DialogService dialogService, PreferencesService prefe
@Override
public void execute() {
DialogService dialogService = Injector.instantiateModelOrService(DialogService.class);
GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(dialogService, preferencesService.getImporterPreferences());
GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(dialogService, preferencesService.getGrobidPreferences());
dialogService.showCustomDialogAndWait(new ExtractBibtexDialog());
}
}
3 changes: 1 addition & 2 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,9 @@ private void setupToolBar() {
if (fetcher instanceof PdfMergeMetadataImporter.EntryBasedFetcherWrapper) {
// Handle Grobid Opt-In in case of the PdfMergeMetadataImporter
fetcherMenuItem.setOnAction(event -> {
GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(dialogService, preferencesService.getImporterPreferences());
GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(dialogService, preferencesService.getGrobidPreferences());
PdfMergeMetadataImporter.EntryBasedFetcherWrapper pdfMergeMetadataImporter =
new PdfMergeMetadataImporter.EntryBasedFetcherWrapper(
preferencesService.getImporterPreferences(),
preferencesService.getImportFormatPreferences(),
preferencesService.getFilePreferences(),
databaseContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ public ImportHandler(BibDatabaseContext database,
this.importFormatReader = importFormatReader;

this.linker = new ExternalFilesEntryLinker(preferencesService.getFilePreferences(), database);
this.contentImporter = new ExternalFilesContentImporter(
preferencesService.getGeneralPreferences(),
preferencesService.getImporterPreferences(),
preferencesService.getImportFormatPreferences());
this.contentImporter = new ExternalFilesContentImporter(preferencesService.getImportFormatPreferences());
this.undoManager = undoManager;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,8 @@ public void parsePdfMetadataAndShowMergeDialog() {
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));
if (preferences.getImporterPreferences().isGrobidEnabled()) {
dialog.addSource("Grobid", wrapImporterToSupplier(new PdfGrobidImporter(preferences.getImporterPreferences(), preferences.getImportFormatPreferences()), filePath));
if (preferences.getGrobidPreferences().isGrobidEnabled()) {
dialog.addSource("Grobid", wrapImporterToSupplier(new PdfGrobidImporter(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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private Node createFileDisplay(LinkedFileViewModel linkedFile) {
parsePdfMetadata.setTooltip(new Tooltip(Localization.lang("Parse Metadata from PDF.")));
parsePdfMetadata.visibleProperty().bind(linkedFile.isOfflinePdfProperty());
parsePdfMetadata.setOnAction(event -> {
GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(dialogService, preferencesService.getImporterPreferences());
GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(dialogService, preferencesService.getGrobidPreferences());
linkedFile.parsePdfMetadataAndShowMergeDialog();
});
parsePdfMetadata.getStyleClass().setAll("icon-button");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.jabref.gui.importer;

import org.jabref.gui.DialogService;
import org.jabref.logic.importer.ImporterPreferences;
import org.jabref.logic.importer.fetcher.GrobidPreferences;
import org.jabref.logic.l10n.Localization;

/**
Expand All @@ -18,7 +18,7 @@ public class GrobidOptInDialogHelper {
* @param dialogService the DialogService to use
* @return if the user enabled Grobid, either in the past or after being asked by the dialog.
*/
public static boolean showAndWaitIfUserIsUndecided(DialogService dialogService, ImporterPreferences preferences) {
public static boolean showAndWaitIfUserIsUndecided(DialogService dialogService, GrobidPreferences preferences) {
if (preferences.isGrobidEnabled()) {
return true;
}
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/org/jabref/gui/importer/ImportAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,25 @@ private List<ImportFormatReader.UnknownFormatImport> doImport(List<Path> files)
if (importer.isEmpty()) {
// Unknown format:
DefaultTaskExecutor.runAndWaitInJavaFXThread(() -> {
if (fileIsPdf(filename) && GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(frame.getDialogService(), prefs.getImporterPreferences())) {
Globals.IMPORT_FORMAT_READER.resetImportFormats(prefs.getImporterPreferences(), prefs.getImportFormatPreferences(), prefs.getXmpPreferences(), Globals.getFileUpdateMonitor());
if (fileIsPdf(filename) && GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(frame.getDialogService(), prefs.getGrobidPreferences())) {
Globals.IMPORT_FORMAT_READER.resetImportFormats(
prefs.getImporterPreferences(),
prefs.getImportFormatPreferences(),
Globals.getFileUpdateMonitor());
}
frame.getDialogService().notify(Localization.lang("Importing in unknown format") + "...");
});
// This import method never throws an IOException:
imports.add(Globals.IMPORT_FORMAT_READER.importUnknownFormat(filename, Globals.getFileUpdateMonitor()));
} else {
DefaultTaskExecutor.runAndWaitInJavaFXThread(() -> {
if ((importer.get() instanceof PdfGrobidImporter) || ((importer.get() instanceof PdfMergeMetadataImporter) && GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(frame.getDialogService(), prefs.getImporterPreferences()))) {
Globals.IMPORT_FORMAT_READER.resetImportFormats(prefs.getImporterPreferences(), prefs.getImportFormatPreferences(), prefs.getXmpPreferences(), Globals.getFileUpdateMonitor());
if ((importer.get() instanceof PdfGrobidImporter) || (
(importer.get() instanceof PdfMergeMetadataImporter)
&& GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(frame.getDialogService(), prefs.getGrobidPreferences()))) {
Globals.IMPORT_FORMAT_READER.resetImportFormats(
prefs.getImporterPreferences(),
prefs.getImportFormatPreferences(),
Globals.getFileUpdateMonitor());
}
frame.getDialogService().notify(Localization.lang("Importing in %0 format", importer.get().getName()) + "...");
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ public CustomImporterTabViewModel(PreferencesService preferences, DialogService

@Override
public void setValues() {
Set<CustomImporter> importersLogic = preferences.getCustomImportFormats();
Set<CustomImporter> importersLogic = preferences.getImporterPreferences().getCustomImportList();
for (CustomImporter importer : importersLogic) {
importers.add(new ImporterViewModel(importer));
}
}

@Override
public void storeSettings() {
preferences.storeCustomImportFormats(importers.stream()
.map(ImporterViewModel::getLogic)
.collect(Collectors.toSet()));
preferences.getImporterPreferences().getCustomImportList().clear();
preferences.getImporterPreferences().getCustomImportList().addAll(importers.stream()
.map(ImporterViewModel::getLogic)
.collect(Collectors.toSet()));
Globals.IMPORT_FORMAT_READER.resetImportFormats(
preferences.getImporterPreferences(),
preferences.getImportFormatPreferences(),
preferences.getXmpPreferences(),
Globals.getFileUpdateMonitor());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public String getTabName() {
}

public void initialize() {
this.viewModel = new ImportExportTabViewModel(preferencesService, preferencesService.getDOIPreferences(), dialogService, preferencesService.getImportExportPreferences());
this.viewModel = new ImportExportTabViewModel(preferencesService, dialogService);

useCustomDOI.selectedProperty().bindBidirectional(viewModel.useCustomDOIProperty());
useCustomDOIName.textProperty().bindBidirectional(viewModel.useCustomDOINameProperty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.jabref.logic.importer.ImporterPreferences;
import org.jabref.logic.importer.WebFetchers;
import org.jabref.logic.importer.fetcher.CustomizableKeyFetcher;
import org.jabref.logic.importer.fetcher.GrobidPreferences;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.net.URLDownload;
import org.jabref.logic.preferences.DOIPreferences;
Expand Down Expand Up @@ -61,17 +62,19 @@ public class ImportExportTabViewModel implements PreferenceTabViewModel {
private final DialogService dialogService;
private final PreferencesService preferencesService;
private final DOIPreferences doiPreferences;
private final GrobidPreferences grobidPreferences;
private final ImporterPreferences importerPreferences;
private final SaveOrderConfig initialExportOrder;
private final ImportExportPreferences importExportPreferences;

public ImportExportTabViewModel(PreferencesService preferencesService, DOIPreferences doiPreferences, DialogService dialogService, ImportExportPreferences importExportPreferences) {
public ImportExportTabViewModel(PreferencesService preferencesService, DialogService dialogService) {
this.dialogService = dialogService;
this.preferencesService = preferencesService;
this.importerPreferences = preferencesService.getImporterPreferences();
this.doiPreferences = doiPreferences;
this.grobidPreferences = preferencesService.getGrobidPreferences();
this.doiPreferences = preferencesService.getDOIPreferences();
this.initialExportOrder = preferencesService.getExportSaveOrder();
this.importExportPreferences = importExportPreferences;
this.importExportPreferences = preferencesService.getImportExportPreferences();
}

@Override
Expand All @@ -95,18 +98,18 @@ public void setValues() {
.map(SortCriterionViewModel::new)
.toList());

grobidEnabledProperty.setValue(importerPreferences.isGrobidEnabled());
grobidURLProperty.setValue(importerPreferences.getGrobidURL());
grobidEnabledProperty.setValue(grobidPreferences.isGrobidEnabled());
grobidURLProperty.setValue(grobidPreferences.getGrobidURL());

apiKeys.setValue(FXCollections.observableArrayList(preferencesService.getImporterPreferences().getApiKeys()));
}

@Override
public void storeSettings() {
importerPreferences.setGenerateNewKeyOnImport(generateKeyOnImportProperty.getValue());
importerPreferences.setGrobidEnabled(grobidEnabledProperty.getValue());
importerPreferences.setGrobidOptOut(importerPreferences.isGrobidOptOut());
importerPreferences.setGrobidURL(grobidURLProperty.getValue());
grobidPreferences.setGrobidEnabled(grobidEnabledProperty.getValue());
grobidPreferences.setGrobidOptOut(grobidPreferences.isGrobidOptOut());
grobidPreferences.setGrobidURL(grobidURLProperty.getValue());

doiPreferences.setUseCustom(useCustomDOIProperty.get());
doiPreferences.setDefaultBaseURI(useCustomDOINameProperty.getValue().trim());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,22 @@
import java.nio.file.Path;

import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.logic.importer.ImporterPreferences;
import org.jabref.logic.importer.OpenDatabase;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.importer.fileformat.PdfMergeMetadataImporter;
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.preferences.GeneralPreferences;

public class ExternalFilesContentImporter {

private final GeneralPreferences generalPreferences;
private final ImporterPreferences importerPreferences;
private final ImportFormatPreferences importFormatPreferences;

public ExternalFilesContentImporter(GeneralPreferences generalPreferences, ImporterPreferences importerPreferences, ImportFormatPreferences importFormatPreferences) {
this.generalPreferences = generalPreferences;
this.importerPreferences = importerPreferences;
public ExternalFilesContentImporter(ImportFormatPreferences importFormatPreferences) {
this.importFormatPreferences = importFormatPreferences;
}

public ParserResult importPDFContent(Path file) {
try {
return new PdfMergeMetadataImporter(importerPreferences, importFormatPreferences).importDatabase(file);
return new PdfMergeMetadataImporter(importFormatPreferences).importDatabase(file);
} catch (IOException e) {
return ParserResult.fromError(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,38 @@
package org.jabref.logic.importer;

import java.util.Set;

import org.jabref.logic.bibtex.FieldContentFormatterPreferences;
import org.jabref.logic.citationkeypattern.CitationKeyPatternPreferences;
import org.jabref.logic.importer.fileformat.CustomImporter;
import org.jabref.logic.importer.fetcher.GrobidPreferences;
import org.jabref.logic.preferences.DOIPreferences;
import org.jabref.logic.xmp.XmpPreferences;

public class ImportFormatPreferences {

private final Set<CustomImporter> customImportList;
private final Character keywordSeparator;
private final CitationKeyPatternPreferences citationKeyPatternPreferences;
private final FieldContentFormatterPreferences fieldContentFormatterPreferences;
private final XmpPreferences xmpPreferences;
private final DOIPreferences doiPreferences;
private final GrobidPreferences grobidPreferences;

public ImportFormatPreferences(Set<CustomImporter> customImportList,
Character keywordSeparator,
public ImportFormatPreferences(Character keywordSeparator,
CitationKeyPatternPreferences citationKeyPatternPreferences,
FieldContentFormatterPreferences fieldContentFormatterPreferences,
XmpPreferences xmpPreferences,
DOIPreferences doiPreferences) {
this.customImportList = customImportList;
DOIPreferences doiPreferences,
GrobidPreferences grobidPreferences) {
this.keywordSeparator = keywordSeparator;
this.citationKeyPatternPreferences = citationKeyPatternPreferences;
this.fieldContentFormatterPreferences = fieldContentFormatterPreferences;
this.xmpPreferences = xmpPreferences;
this.doiPreferences = doiPreferences;
this.grobidPreferences = grobidPreferences;
}

public DOIPreferences getDoiPreferences() {
return doiPreferences;
}

/**
* @deprecated importer should not know about the other custom importers
*/
@Deprecated
public Set<CustomImporter> getCustomImportList() {
return customImportList;
}

public Character getKeywordSeparator() {
return keywordSeparator;
}
Expand All @@ -58,4 +48,8 @@ public FieldContentFormatterPreferences getFieldContentFormatterPreferences() {
public XmpPreferences getXmpPreferences() {
return xmpPreferences;
}

public GrobidPreferences getGrobidPreferences() {
return grobidPreferences;
}
}
Loading