diff --git a/CHANGELOG.md b/CHANGELOG.md index bc7848cae18..939201c7de7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,6 +66,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - The `day` part of the biblatex `date` field is now exported to the corresponding `day` field in MS-Office XML. [#2691](https://github.com/JabRef/jabref/issues/2691) ### Fixed + - We fixed an issue of duplicate keys after using a fetcher, e.g., DOI or ISBN [#2867](https://github.com/JabRef/jabref/issues/2687) - We fixed an issue that prevented multiple parallel JabRef instances from terminating gracefully. [#2698](https://github.com/JabRef/jabref/issues/2698) - We fixed an issue where authors with multiple surnames were not presented correctly in the main table. [#2534](https://github.com/JabRef/jabref/issues/2534) - Repairs the handling of apostrophes in the LaTeX to unicode conversion. [#2500](https://github.com/JabRef/jabref/issues/2500) diff --git a/src/main/java/org/jabref/gui/EntryTypeDialog.java b/src/main/java/org/jabref/gui/EntryTypeDialog.java index ef4c51a467a..159e88b11f8 100644 --- a/src/main/java/org/jabref/gui/EntryTypeDialog.java +++ b/src/main/java/org/jabref/gui/EntryTypeDialog.java @@ -28,6 +28,7 @@ import org.jabref.Globals; import org.jabref.gui.keyboard.KeyBinding; +import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.IdBasedFetcher; import org.jabref.logic.importer.WebFetchers; @@ -96,7 +97,6 @@ private JPanel createEntryGroupsPanel() { if (!customTypes.isEmpty()) { panel.add(createEntryGroupPanel(Localization.lang("Custom"), customTypes)); } - } else { panel.add(createEntryGroupPanel("BibTeX", BibtexEntryTypes.ALL)); panel.add(createEntryGroupPanel("IEEETran", IEEETranEntryTypes.ALL)); @@ -182,7 +182,7 @@ private JPanel createIdFetcherPanel() { JPanel jPanel = new JPanel(); GridBagConstraints constraints = new GridBagConstraints(); - constraints.insets = new Insets(4,4,4,4); + constraints.insets = new Insets(4, 4, 4, 4); GridBagLayout layout = new GridBagLayout(); jPanel.setLayout(layout); @@ -305,15 +305,19 @@ protected void done() { try { Optional result = get(); if (result.isPresent()) { - frame.getCurrentBasePanel().insertEntry(result.get()); + final BibEntry bibEntry = result.get(); + // Regenerate CiteKey of imported BibEntry + BibtexKeyPatternUtil.makeAndSetLabel(Globals.prefs.getBibtexKeyPatternPreferences().getKeyPattern(), frame.getCurrentBasePanel().getDatabase(), bibEntry, Globals.prefs.getBibtexKeyPatternPreferences()); + + frame.getCurrentBasePanel().insertEntry(bibEntry); dispose(); } else if (searchID.trim().isEmpty()) { JOptionPane.showMessageDialog(frame, Localization.lang("The given search ID was empty."), Localization.lang("Empty search ID"), JOptionPane.WARNING_MESSAGE); } else if (!fetcherException) { - JOptionPane.showMessageDialog(frame, Localization.lang("Fetcher_'%0'_did_not_find_an_entry_for_id_'%1'.", fetcher.getName(), searchID)+ "\n" + fetcherExceptionMessage, Localization.lang("No files found."), JOptionPane.WARNING_MESSAGE); + JOptionPane.showMessageDialog(frame, Localization.lang("Fetcher_'%0'_did_not_find_an_entry_for_id_'%1'.", fetcher.getName(), searchID) + "\n" + fetcherExceptionMessage, Localization.lang("No files found."), JOptionPane.WARNING_MESSAGE); } else { JOptionPane.showMessageDialog(frame, - Localization.lang("Error while fetching from %0", fetcher.getName()) +"." + "\n" + fetcherExceptionMessage, + Localization.lang("Error while fetching from %0", fetcher.getName()) + "." + "\n" + fetcherExceptionMessage, Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); } fetcherWorker = new FetcherWorker(); @@ -328,5 +332,4 @@ protected void done() { } } } - } diff --git a/src/main/java/org/jabref/gui/importer/fetcher/IdBasedEntryFetcher.java b/src/main/java/org/jabref/gui/importer/fetcher/IdBasedEntryFetcher.java deleted file mode 100644 index 13e93e64d4e..00000000000 --- a/src/main/java/org/jabref/gui/importer/fetcher/IdBasedEntryFetcher.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.jabref.gui.importer.fetcher; - -import java.util.Objects; -import java.util.Optional; - -import javax.swing.JPanel; - -import org.jabref.gui.importer.ImportInspectionDialog; -import org.jabref.logic.help.HelpFile; -import org.jabref.logic.importer.FetcherException; -import org.jabref.logic.importer.IdBasedFetcher; -import org.jabref.logic.importer.ImportInspector; -import org.jabref.logic.importer.OutputPrinter; -import org.jabref.logic.l10n.Localization; -import org.jabref.model.entry.BibEntry; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -public class IdBasedEntryFetcher implements EntryFetcher { - - private static final Log LOGGER = LogFactory.getLog(IdBasedEntryFetcher.class); - private final IdBasedFetcher fetcher; - - public IdBasedEntryFetcher(IdBasedFetcher fetcher) { - this.fetcher = Objects.requireNonNull(fetcher); - } - - @Override - public boolean processQuery(String query, ImportInspector inspector, OutputPrinter status) { - - status.setStatus(Localization.lang("Processing %0", query)); - try { - Optional match = fetcher.performSearchById(query); - match.ifPresent(inspector::addEntry); - return match.isPresent(); - } catch (FetcherException e) { - LOGGER.error("Error while fetching from " + getTitle(), e); - ((ImportInspectionDialog)inspector).showErrorMessage(this.getTitle(), e.getLocalizedMessage()); - } - - return false; - } - - @Override - public String getTitle() { - return fetcher.getName(); - } - - @Override - public HelpFile getHelpPage() { - return fetcher.getHelpPage(); - } - - @Override - public JPanel getOptionsPanel() { - // not supported - return null; - } - - @Override - public void stopFetching() { - // not supported - } -}