From 7b784586364cd804110fa740125218a942ed7c5a Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Tue, 24 Jul 2018 17:04:03 +0200 Subject: [PATCH] Rewrite web search pane in JavaFX (#4203) * Replace old fetcher stuff in command line interface * Remove cli output * Make help file optional * Rework web search pane in javafx * Show web search and group panes by default * Use better binding and init default fetcher in view model as it should be * remove obsolete l10n keys set search button to default so search can be executed by hitting enter * fix wrong string util class --- .../org/jabref/cli/ArgumentProcessor.java | 61 +++-- .../cli/ImportInspectionCommandLine.java | 38 --- .../java/org/jabref/gui/EntryTypeDialog.java | 3 +- src/main/java/org/jabref/gui/JabRefFrame.java | 6 +- .../java/org/jabref/gui/SidePaneManager.java | 8 +- .../java/org/jabref/gui/help/HelpAction.java | 11 +- .../gui/importer/ImportInspectionDialog.java | 37 +-- .../gui/importer/fetcher/EntryFetcher.java | 72 ------ .../gui/importer/fetcher/EntryFetchers.java | 24 -- .../gui/importer/fetcher/GeneralFetcher.java | 216 ------------------ .../fetcher/SearchBasedEntryFetcher.java | 67 ------ .../gui/importer/fetcher/WebSearchPane.java | 107 +++++++++ .../fetcher/WebSearchPaneViewModel.java | 114 +++++++++ .../jabref/gui/search/SearchTextField.java | 4 +- .../gui/util/ViewModelListCellFactory.java | 6 + .../logic/importer/ImportInspector.java | 36 --- .../org/jabref/logic/importer/WebFetcher.java | 6 +- .../importer/fetcher/ACMPortalFetcher.java | 5 +- .../importer/fetcher/AbstractIsbnFetcher.java | 6 +- .../jabref/logic/importer/fetcher/ArXiv.java | 4 +- .../fetcher/AstrophysicsDataSystem.java | 5 +- .../logic/importer/fetcher/CiteSeer.java | 5 +- .../logic/importer/fetcher/DBLPFetcher.java | 5 +- .../logic/importer/fetcher/DOAJFetcher.java | 5 +- .../jabref/logic/importer/fetcher/DiVA.java | 5 +- .../logic/importer/fetcher/DoiFetcher.java | 4 +- .../logic/importer/fetcher/GoogleScholar.java | 4 +- .../logic/importer/fetcher/GvkFetcher.java | 5 +- .../jabref/logic/importer/fetcher/IEEE.java | 4 +- .../importer/fetcher/INSPIREFetcher.java | 5 +- .../importer/fetcher/MedlineFetcher.java | 5 +- .../logic/importer/fetcher/RfcFetcher.java | 5 +- .../importer/fetcher/SpringerFetcher.java | 4 +- .../logic/importer/fetcher/TitleFetcher.java | 4 +- .../jabref/preferences/JabRefPreferences.java | 8 +- src/main/resources/l10n/JabRef_en.properties | 4 - .../fetcher/AstrophysicsDataSystemTest.java | 2 +- .../importer/fetcher/DoiFetcherTest.java | 2 +- .../importer/fetcher/GvkFetcherTest.java | 2 +- .../importer/fetcher/IsbnFetcherTest.java | 2 +- .../fetcher/IsbnViaChimboriFetcherTest.java | 2 +- .../fetcher/IsbnViaEbookDeFetcherTest.java | 2 +- .../importer/fetcher/MedlineFetcherTest.java | 2 +- .../importer/fetcher/RfcFetcherTest.java | 2 +- .../importer/fetcher/TitleFetcherTest.java | 2 +- 45 files changed, 343 insertions(+), 583 deletions(-) delete mode 100644 src/main/java/org/jabref/cli/ImportInspectionCommandLine.java delete mode 100644 src/main/java/org/jabref/gui/importer/fetcher/EntryFetcher.java delete mode 100644 src/main/java/org/jabref/gui/importer/fetcher/EntryFetchers.java delete mode 100644 src/main/java/org/jabref/gui/importer/fetcher/GeneralFetcher.java delete mode 100644 src/main/java/org/jabref/gui/importer/fetcher/SearchBasedEntryFetcher.java create mode 100644 src/main/java/org/jabref/gui/importer/fetcher/WebSearchPane.java create mode 100644 src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java delete mode 100644 src/main/java/org/jabref/logic/importer/ImportInspector.java diff --git a/src/main/java/org/jabref/cli/ArgumentProcessor.java b/src/main/java/org/jabref/cli/ArgumentProcessor.java index 7df241a209d..4bf16b3fe85 100644 --- a/src/main/java/org/jabref/cli/ArgumentProcessor.java +++ b/src/main/java/org/jabref/cli/ArgumentProcessor.java @@ -5,7 +5,6 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Locale; @@ -16,8 +15,6 @@ import org.jabref.Globals; import org.jabref.JabRefException; import org.jabref.gui.externalfiles.AutoSetLinks; -import org.jabref.gui.importer.fetcher.EntryFetcher; -import org.jabref.gui.importer.fetcher.EntryFetchers; import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator; import org.jabref.logic.exporter.BibDatabaseWriter; import org.jabref.logic.exporter.BibtexDatabaseWriter; @@ -28,12 +25,15 @@ import org.jabref.logic.exporter.SavePreferences; import org.jabref.logic.exporter.SaveSession; import org.jabref.logic.exporter.TemplateExporter; +import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.ImportException; import org.jabref.logic.importer.ImportFormatReader; import org.jabref.logic.importer.OpenDatabase; import org.jabref.logic.importer.OutputPrinter; import org.jabref.logic.importer.ParseException; import org.jabref.logic.importer.ParserResult; +import org.jabref.logic.importer.SearchBasedFetcher; +import org.jabref.logic.importer.WebFetchers; import org.jabref.logic.importer.fileformat.BibtexParser; import org.jabref.logic.l10n.Localization; import org.jabref.logic.layout.LayoutFormatterPreferences; @@ -538,15 +538,12 @@ private void regenerateBibtexKeys(List loaded) { /** * Run an entry fetcher from the command line. - *

- * Note that this only works headlessly if the EntryFetcher does not show any GUI. * - * @param fetchCommand A string containing both the fetcher to use (id of EntryFetcherExtension minus Fetcher) and + * @param fetchCommand A string containing both the name of the fetcher to use and * the search query, separated by a : * @return A parser result containing the entries fetched or null if an error occurred. */ private Optional fetch(String fetchCommand) { - if ((fetchCommand == null) || !fetchCommand.contains(":") || (fetchCommand.split(":").length != 2)) { System.out.println(Localization.lang("Expected syntax for --fetch=':'")); System.out.println(Localization.lang("The following fetchers are available:")); @@ -555,38 +552,36 @@ private Optional fetch(String fetchCommand) { String[] split = fetchCommand.split(":"); String engine = split[0]; + String query = split[1]; - EntryFetchers fetchers = new EntryFetchers(Globals.journalAbbreviationLoader); - EntryFetcher fetcher = null; - for (EntryFetcher e : fetchers.getEntryFetchers()) { - if (engine.equalsIgnoreCase(e.getClass().getSimpleName().replace("Fetcher", ""))) { - fetcher = e; - } - } - - if (fetcher == null) { + List fetchers = WebFetchers.getSearchBasedFetchers(Globals.prefs.getImportFormatPreferences()); + Optional selectedFetcher = fetchers.stream() + .filter(fetcher -> fetcher.getName().equalsIgnoreCase(engine)) + .findFirst(); + if (!selectedFetcher.isPresent()) { System.out.println(Localization.lang("Could not find fetcher '%0'", engine)); - System.out.println(Localization.lang("The following fetchers are available:")); - - for (EntryFetcher e : fetchers.getEntryFetchers()) { - System.out.println( - " " + e.getClass().getSimpleName().replace("Fetcher", "").toLowerCase(Locale.ENGLISH)); - } - return Optional.empty(); - } - String query = split[1]; - System.out.println(Localization.lang("Running query '%0' with fetcher '%1'.", query, engine) + " " - + Localization.lang("Please wait...")); - Collection result = new ImportInspectionCommandLine().query(query, fetcher); + System.out.println(Localization.lang("The following fetchers are available:")); + fetchers.forEach(fetcher -> System.out.println(" " + fetcher.getName())); - if (result.isEmpty()) { - System.out.println( - Localization.lang("Query '%0' with fetcher '%1' did not return any results.", query, engine)); return Optional.empty(); + } else { + System.out.println(Localization.lang("Running query '%0' with fetcher '%1'.", query, engine)); + System.out.print(Localization.lang("Please wait...")); + try { + List matches = selectedFetcher.get().performSearch(query); + if (matches.isEmpty()) { + System.out.println("\r" + Localization.lang("No results found.")); + return Optional.empty(); + } else { + System.out.println("\r" + Localization.lang("Found %0 results.", String.valueOf(matches.size()))); + return Optional.of(new ParserResult(matches)); + } + } catch (FetcherException e) { + LOGGER.error("Error while fetching", e); + return Optional.empty(); + } } - - return Optional.of(new ParserResult(result)); } public boolean isBlank() { diff --git a/src/main/java/org/jabref/cli/ImportInspectionCommandLine.java b/src/main/java/org/jabref/cli/ImportInspectionCommandLine.java deleted file mode 100644 index bf3d66ba544..00000000000 --- a/src/main/java/org/jabref/cli/ImportInspectionCommandLine.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.jabref.cli; - -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; - -import org.jabref.gui.importer.fetcher.EntryFetcher; -import org.jabref.logic.importer.ImportInspector; -import org.jabref.logic.importer.OutputPrinter; -import org.jabref.logic.l10n.Localization; -import org.jabref.model.entry.BibEntry; - -public class ImportInspectionCommandLine implements ImportInspector { - - private final List entries = new LinkedList<>(); - - private final OutputPrinter status = new SystemOutputPrinter(); - - @Override - public void addEntry(BibEntry entry) { - entries.add(entry); - } - - @Override - public void setProgress(int current, int max) { - status.setStatus(Localization.lang("Progress: %0 of %1", String.valueOf(current), String - .valueOf(max))); - } - - public Collection query(String query, EntryFetcher fetcher) { - entries.clear(); - if (fetcher.processQuery(query, ImportInspectionCommandLine.this, status)) { - return entries; - } - return Collections.emptyList(); - } -} diff --git a/src/main/java/org/jabref/gui/EntryTypeDialog.java b/src/main/java/org/jabref/gui/EntryTypeDialog.java index b4cdc9a0abc..93cc5a73a3d 100644 --- a/src/main/java/org/jabref/gui/EntryTypeDialog.java +++ b/src/main/java/org/jabref/gui/EntryTypeDialog.java @@ -9,6 +9,7 @@ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.concurrent.ExecutionException; @@ -316,7 +317,7 @@ protected void done() { final BasePanel panel = frame.getCurrentBasePanel(); ImportInspectionDialog diag = new ImportInspectionDialog(frame, panel, Localization.lang("Import"), false); - diag.addEntry(bibEntry); + diag.addEntries(Collections.singletonList(bibEntry)); diag.entryListComplete(); diag.setVisible(true); diag.toFront(); diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 0cc4029ed91..2776ed0d70a 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -254,7 +254,7 @@ private void init() { // groupSidePane.getToggleCommand().setSelected(sidePaneManager.isComponentVisible(GroupSidePane.class)); //previewToggle.setSelected(Globals.prefs.getPreviewPreferences().isPreviewPanelEnabled()); - //generalFetcher.getToggleCommand().setSelected(sidePaneManager.isComponentVisible(GeneralFetcher.class)); + //generalFetcher.getToggleCommand().setSelected(sidePaneManager.isComponentVisible(WebSearchPane.class)); //openOfficePanel.getToggleCommand().setSelected(sidePaneManager.isComponentVisible(OpenOfficeSidePanel.class)); // TODO: Can't notify focus listener since it is expecting a swing component //Globals.getFocusListener().setFocused(currentBasePanel.getMainTable()); @@ -397,7 +397,7 @@ public void openAction(String filePath) { * The MacAdapter calls this method when "About" is selected from the application menu. */ public void about() { - HelpAction.getCommand().execute(); + HelpAction.getMainHelpPageCommand().execute(); } public JabRefPreferences prefs() { @@ -924,7 +924,7 @@ private MenuBar createMenu() { ); help.getItems().addAll( - factory.createMenuItem(StandardActions.HELP, HelpAction.getCommand()), + factory.createMenuItem(StandardActions.HELP, HelpAction.getMainHelpPageCommand()), factory.createMenuItem(StandardActions.OPEN_FORUM, new OpenBrowserAction("http://discourse.jabref.org/")), new SeparatorMenuItem(), diff --git a/src/main/java/org/jabref/gui/SidePaneManager.java b/src/main/java/org/jabref/gui/SidePaneManager.java index ca122c86a71..5a09bdcd1ab 100644 --- a/src/main/java/org/jabref/gui/SidePaneManager.java +++ b/src/main/java/org/jabref/gui/SidePaneManager.java @@ -10,7 +10,7 @@ import org.jabref.Globals; import org.jabref.gui.collab.FileUpdatePanel; import org.jabref.gui.groups.GroupSidePane; -import org.jabref.gui.importer.fetcher.GeneralFetcher; +import org.jabref.gui.importer.fetcher.WebSearchPane; import org.jabref.gui.openoffice.OpenOfficeSidePanel; import org.jabref.logic.openoffice.OpenOfficePreferences; import org.jabref.preferences.JabRefPreferences; @@ -33,7 +33,7 @@ public SidePaneManager(JabRefPreferences preferences, JabRefFrame frame) { Stream.of( new FileUpdatePanel(this), new GroupSidePane(this, preferences, frame.getDialogService()), - new GeneralFetcher(this, preferences, frame), + new WebSearchPane(this, preferences, frame), new OpenOfficeSidePanel(this, openOfficePreferences, frame)) .forEach(pane -> components.put(pane.getType(), pane)); @@ -45,6 +45,10 @@ public SidePaneManager(JabRefPreferences preferences, JabRefFrame frame) { show(SidePaneType.OPEN_OFFICE); } + if (preferences.getBoolean(JabRefPreferences.WEB_SEARCH_VISIBLE)) { + show(SidePaneType.WEB_SEARCH); + } + updateView(); } diff --git a/src/main/java/org/jabref/gui/help/HelpAction.java b/src/main/java/org/jabref/gui/help/HelpAction.java index 402d8900a13..ab7ae84e027 100644 --- a/src/main/java/org/jabref/gui/help/HelpAction.java +++ b/src/main/java/org/jabref/gui/help/HelpAction.java @@ -110,7 +110,7 @@ public void actionPerformed(ActionEvent e) { openHelpPage(helpPage); } - public static SimpleCommand getCommand() { + public static SimpleCommand getMainHelpPageCommand() { return new SimpleCommand() { @Override public void execute() { @@ -118,4 +118,13 @@ public void execute() { } }; } + + public SimpleCommand getCommand() { + return new SimpleCommand() { + @Override + public void execute() { + openHelpPage(helpPage); + } + }; + } } diff --git a/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java b/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java index 8b53cfd793b..84fcef65d67 100644 --- a/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java +++ b/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java @@ -84,7 +84,6 @@ import org.jabref.logic.bibtex.comparator.FieldComparator; import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator; import org.jabref.logic.help.HelpFile; -import org.jabref.logic.importer.ImportInspector; import org.jabref.logic.importer.OutputPrinter; import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.UpdateField; @@ -144,7 +143,7 @@ * receiving this call). */ -public class ImportInspectionDialog extends JabRefDialog implements ImportInspector, OutputPrinter { +public class ImportInspectionDialog extends JabRefDialog implements OutputPrinter { private static final Logger LOGGER = LoggerFactory.getLogger(ImportInspectionDialog.class); private static final List INSPECTION_FIELDS = Arrays.asList(FieldName.AUTHOR, FieldName.TITLE, FieldName.YEAR, BibEntry.KEY_FIELD); @@ -168,7 +167,6 @@ public class ImportInspectionDialog extends JabRefDialog implements ImportInspec */ private final List entriesToDelete = new ArrayList<>(); private final String undoName; - private final List callBacks = new ArrayList<>(); private final boolean newDatabase; private final JPopupMenu popup = new JPopupMenu(); private final JButton deselectAllDuplicates = new JButton(Localization.lang("Deselect all duplicates")); @@ -286,7 +284,6 @@ public ImportInspectionDialog(JabRefFrame frame, BasePanel panel, String undoNam generate.setEnabled(false); ok.addActionListener(new OkListener()); cancel.addActionListener(e -> { - signalStopFetching(); dispose(); frame.output(Localization.lang("Import canceled by user")); }); @@ -297,7 +294,6 @@ public ImportInspectionDialog(JabRefFrame frame, BasePanel panel, String undoNam generateKeys(); // Generate the keys. }); stop.addActionListener(e -> { - signalStopFetching(); entryListComplete(); }); selectAll.addActionListener(new SelectionButton(true)); @@ -345,29 +341,6 @@ public void actionPerformed(ActionEvent e) { } - /* (non-Javadoc) - * @see package org.jabref.logic.importer.ImportInspector#setProgress(int, int) - */ - @Override - public void setProgress(int current, int max) { - SwingUtilities.invokeLater(() -> { - progressBar.setIndeterminate(false); - progressBar.setMinimum(0); - progressBar.setMaximum(max); - progressBar.setValue(current); - }); - } - - /* (non-Javadoc) - * @see package org.jabref.logic.importer.ImportInspector#addEntry(org.jabref.model.entry.BibEntry) - */ - @Override - public void addEntry(BibEntry entry) { - List list = new ArrayList<>(); - list.add(entry); - addEntries(list); - } - public void addEntries(Collection entriesToAdd) { for (BibEntry entry : entriesToAdd) { @@ -559,14 +532,6 @@ private AbstractAction getAction(GroupTreeNode node) { return action; } - public void addCallBack(CallBack cb) { - callBacks.add(cb); - } - - private void signalStopFetching() { - callBacks.forEach(CallBack::stopFetching); - } - private void setWidths() { TableColumnModel cm = glTable.getColumnModel(); cm.getColumn(0).setPreferredWidth(55); diff --git a/src/main/java/org/jabref/gui/importer/fetcher/EntryFetcher.java b/src/main/java/org/jabref/gui/importer/fetcher/EntryFetcher.java deleted file mode 100644 index f2470d68fb3..00000000000 --- a/src/main/java/org/jabref/gui/importer/fetcher/EntryFetcher.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.jabref.gui.importer.fetcher; - -import javax.swing.JPanel; - -import org.jabref.gui.importer.ImportInspectionDialog; -import org.jabref.logic.help.HelpFile; -import org.jabref.logic.importer.ImportInspector; -import org.jabref.logic.importer.OutputPrinter; - -/** - * @Deprecated - * Use {@link SearchBasedEntryFetcher} instead
- * Implement this interface to add another activeFetcher (something that grabs records - * from the Web for JabRef). Have a look at the existing implemenations - * IEEEXploreFetcher, JStorFetcher and - * CiteSeerEntryFetcher. - * - * Note: You also need to implement the method stopFetching from - * ImportInspectionDialog.Callback - * - * A Fetcher should not execute any GUI Operations, because it might be run in - * headless mode, but rather use the OutputPrinter for talking to the user. - */ -@Deprecated -public interface EntryFetcher extends ImportInspectionDialog.CallBack { - - /** - * Handle a query entered by the user. - * - * The method is expected to block the caller until all entries have been - * reported to the inspector. - * - * @param query - * The query text. - * @param inspector - * The dialog to add imported entries to. - * @param status - * An OutputPrinter passed to the activeFetcher for reporting about the - * status of the fetching. - * - * @return True if the query was completed successfully, false if an error - * occurred. - */ - boolean processQuery(String query, ImportInspector inspector, OutputPrinter status); - - /** - * The title for this activeFetcher, displayed in the menu and in the side pane. - * - * @return The title - */ - String getTitle(); - - /** - * Get the name of the help page for this activeFetcher. - * - * If given, a question mark is displayed in the side pane which leads to - * the help page. - * - * @return The {@link HelpFile} enum constant for the help page - */ - HelpFile getHelpPage(); - - /** - * If this activeFetcher requires additional options, a panel for setting up these - * should be returned in a JPanel by this method. This JPanel will be added - * to the side pane component automatically. - * - * @return Options panel for this activeFetcher or null if this activeFetcher does not - * have any options. - */ - JPanel getOptionsPanel(); -} diff --git a/src/main/java/org/jabref/gui/importer/fetcher/EntryFetchers.java b/src/main/java/org/jabref/gui/importer/fetcher/EntryFetchers.java deleted file mode 100644 index 353eddde4ae..00000000000 --- a/src/main/java/org/jabref/gui/importer/fetcher/EntryFetchers.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.jabref.gui.importer.fetcher; - -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; - -import org.jabref.Globals; -import org.jabref.logic.importer.WebFetchers; -import org.jabref.logic.journals.JournalAbbreviationLoader; - -public class EntryFetchers { - - private final List entryFetchers = new LinkedList<>(); - - public EntryFetchers(JournalAbbreviationLoader abbreviationLoader) { - WebFetchers.getSearchBasedFetchers(Globals.prefs.getImportFormatPreferences()).stream() - .map(SearchBasedEntryFetcher::new) - .forEach(entryFetchers::add); - } - - public List getEntryFetchers() { - return Collections.unmodifiableList(this.entryFetchers); - } -} diff --git a/src/main/java/org/jabref/gui/importer/fetcher/GeneralFetcher.java b/src/main/java/org/jabref/gui/importer/fetcher/GeneralFetcher.java deleted file mode 100644 index a5bdd0696e3..00000000000 --- a/src/main/java/org/jabref/gui/importer/fetcher/GeneralFetcher.java +++ /dev/null @@ -1,216 +0,0 @@ -package org.jabref.gui.importer.fetcher; - -import java.awt.BorderLayout; -import java.awt.CardLayout; -import java.awt.Dimension; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.Arrays; -import java.util.Comparator; -import java.util.List; - -import javax.swing.BorderFactory; -import javax.swing.JButton; -import javax.swing.JComboBox; -import javax.swing.JPanel; -import javax.swing.JTextField; -import javax.swing.SwingUtilities; - -import javafx.embed.swing.SwingNode; -import javafx.scene.Node; -import javafx.scene.layout.Priority; - -import org.jabref.Globals; -import org.jabref.JabRefExecutorService; -import org.jabref.gui.JabRefFrame; -import org.jabref.gui.SidePaneComponent; -import org.jabref.gui.SidePaneManager; -import org.jabref.gui.SidePaneType; -import org.jabref.gui.actions.Action; -import org.jabref.gui.actions.StandardActions; -import org.jabref.gui.help.HelpAction; -import org.jabref.gui.icon.IconTheme; -import org.jabref.gui.importer.ImportInspectionDialog; -import org.jabref.logic.l10n.Localization; -import org.jabref.logic.util.OS; -import org.jabref.preferences.JabRefPreferences; - -public class GeneralFetcher extends SidePaneComponent implements ActionListener { - - private final JTextField tf = new JTextField(); - - private final CardLayout optionsCards = new CardLayout(); - private final JPanel optionsPanel = new JPanel(optionsCards); - private final JPanel optPanel = new JPanel(new BorderLayout()); - - private final JabRefFrame frame; - private final JabRefPreferences preferences; - private EntryFetcher activeFetcher; - - public GeneralFetcher(SidePaneManager sidePaneManager, JabRefPreferences preferences, JabRefFrame frame) { - super(sidePaneManager, IconTheme.JabRefIcons.WWW, Localization.lang("Web search")); - this.frame = frame; - this.preferences = preferences; - } - - @Override - public Action getToggleAction() { - return StandardActions.TOGGLE_WEB_SEARCH; - } - - @Override - protected Node createContentPane() { - List fetchers = new EntryFetchers(Globals.journalAbbreviationLoader).getEntryFetchers(); - EntryFetcher[] fetcherArray = fetchers.toArray(new EntryFetcher[fetchers.size()]); - Arrays.sort(fetcherArray, new EntryFetcherComparator()); - String[] choices = new String[fetcherArray.length]; - for (int i = 0; i < fetcherArray.length; i++) { - choices[i] = fetcherArray[i].getTitle(); - } - JComboBox fetcherChoice = new JComboBox<>(choices); - int defaultFetcher = preferences.getInt(JabRefPreferences.SELECTED_FETCHER_INDEX); - if (defaultFetcher >= fetcherArray.length) { - defaultFetcher = 0; - } - this.activeFetcher = fetcherArray[defaultFetcher]; - fetcherChoice.setSelectedIndex(defaultFetcher); - if (this.activeFetcher.getOptionsPanel() != null) { - optPanel.add(this.activeFetcher.getOptionsPanel(), BorderLayout.CENTER); - } - HelpAction help = new HelpAction(activeFetcher.getHelpPage()); - JButton helpBut = help.getHelpButton(); - helpBut.setEnabled(activeFetcher.getHelpPage() != null); - - fetcherChoice.addActionListener(actionEvent -> { - activeFetcher = fetcherArray[fetcherChoice.getSelectedIndex()]; - preferences.putInt(JabRefPreferences.SELECTED_FETCHER_INDEX, fetcherChoice.getSelectedIndex()); - if (activeFetcher.getHelpPage() == null) { - helpBut.setEnabled(false); - } else { - help.setHelpFile(activeFetcher.getHelpPage()); - helpBut.setEnabled(true); - } - optionsCards.show(optionsPanel, String.valueOf(fetcherChoice.getSelectedIndex())); - optPanel.removeAll(); - if (activeFetcher.getOptionsPanel() != null) { - optPanel.add(activeFetcher.getOptionsPanel(), BorderLayout.CENTER); - } - }); - - helpBut.setMargin(new Insets(0, 0, 0, 0)); - tf.setPreferredSize(new Dimension(1, tf.getPreferredSize().height)); - if (OS.OS_X) { - tf.putClientProperty("JTextField.variant", "search"); - } - - tf.setName("tf"); - // add action to reset-button. resets tf and requests focus - JButton reset = new JButton(Localization.lang("Reset")); - reset.addActionListener(event -> { - tf.setText(""); - tf.requestFocus(); - }); - - JPanel main = new JPanel(); - GridBagLayout gbl = new GridBagLayout(); - main.setLayout(gbl); - GridBagConstraints con = new GridBagConstraints(); - con.fill = GridBagConstraints.BOTH; - con.insets = new Insets(0, 0, 2, 0); - con.gridwidth = GridBagConstraints.REMAINDER; - con.weightx = 1; - con.weighty = 1; - con.insets = new Insets(1, 0, 1, 0); - con.fill = GridBagConstraints.BOTH; - gbl.setConstraints(fetcherChoice, con); - main.add(fetcherChoice); - con.insets = new Insets(0, 0, 0, 0); - gbl.setConstraints(tf, con); - main.add(tf); - - // Go Button - con.weighty = 0; - con.gridwidth = 1; - JButton go = new JButton(Localization.lang("Fetch")); - gbl.setConstraints(go, con); - main.add(go); - - // Reset Button - reset.setName("reset"); - gbl.setConstraints(reset, con); - main.add(reset); - - // Help Button - con.gridwidth = GridBagConstraints.REMAINDER; - gbl.setConstraints(helpBut, con); - main.add(helpBut); - - gbl.setConstraints(optPanel, con); - main.add(optPanel); - - main.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); - go.addActionListener(this); - tf.addActionListener(this); - - SwingNode swingNode = new SwingNode(); - SwingUtilities.invokeLater(() -> swingNode.setContent(main)); - return swingNode; - } - - @Override - public SidePaneType getType() { - return SidePaneType.WEB_SEARCH; - } - - @Override - public void actionPerformed(ActionEvent e) { - if (tf.getText().trim().isEmpty()) { - frame.output(Localization.lang("Please enter a search string")); - return; - } - - if (frame.getCurrentBasePanel() == null) { - frame.output(Localization.lang("Please open or start a new library before searching")); - return; - } - - final ImportInspectionDialog dialog = new ImportInspectionDialog(frame, frame.getCurrentBasePanel(), - activeFetcher.getTitle(), false); - dialog.addCallBack(activeFetcher); - dialog.setVisible(true); - - JabRefExecutorService.INSTANCE.execute(() -> { - if (activeFetcher.processQuery(tf.getText().trim(), dialog, dialog)) { - dialog.entryListComplete(); - } else { - dialog.dispose(); - } - }); - } - - @Override - public void beforeClosing() { - preferences.putBoolean(JabRefPreferences.WEB_SEARCH_VISIBLE, Boolean.FALSE); - } - - @Override - public void afterOpening() { - preferences.putBoolean(JabRefPreferences.WEB_SEARCH_VISIBLE, Boolean.TRUE); - } - - @Override - public Priority getResizePolicy() { - return Priority.NEVER; - } - - private static class EntryFetcherComparator implements Comparator { - - @Override - public int compare(EntryFetcher entryFetcher, EntryFetcher entryFetcher1) { - return entryFetcher.getTitle().compareTo(entryFetcher1.getTitle()); - } - } -} diff --git a/src/main/java/org/jabref/gui/importer/fetcher/SearchBasedEntryFetcher.java b/src/main/java/org/jabref/gui/importer/fetcher/SearchBasedEntryFetcher.java deleted file mode 100644 index b5d3f398a28..00000000000 --- a/src/main/java/org/jabref/gui/importer/fetcher/SearchBasedEntryFetcher.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.jabref.gui.importer.fetcher; - -import java.util.List; -import java.util.Objects; - -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.ImportInspector; -import org.jabref.logic.importer.OutputPrinter; -import org.jabref.logic.importer.SearchBasedFetcher; -import org.jabref.logic.l10n.Localization; -import org.jabref.model.entry.BibEntry; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Wrapper around {@link SearchBasedFetcher} which implements the old {@link EntryFetcher} interface. - */ -public class SearchBasedEntryFetcher implements EntryFetcher { - - private static final Logger LOGGER = LoggerFactory.getLogger(SearchBasedEntryFetcher.class); - private final SearchBasedFetcher fetcher; - - public SearchBasedEntryFetcher(SearchBasedFetcher fetcher) { - this.fetcher = Objects.requireNonNull(fetcher); - } - - @Override - public boolean processQuery(String query, ImportInspector inspector, OutputPrinter status) { - status.setStatus(Localization.lang("Processing %0", query)); - try { - List matches = fetcher.performSearch(query); - matches.forEach(inspector::addEntry); - return !matches.isEmpty(); - } 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 - } -} diff --git a/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPane.java b/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPane.java new file mode 100644 index 00000000000..1f9c0d637d6 --- /dev/null +++ b/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPane.java @@ -0,0 +1,107 @@ +package org.jabref.gui.importer.fetcher; + +import javafx.geometry.Pos; +import javafx.scene.Node; +import javafx.scene.control.Button; +import javafx.scene.control.ComboBox; +import javafx.scene.control.TextField; +import javafx.scene.layout.HBox; +import javafx.scene.layout.Priority; +import javafx.scene.layout.StackPane; +import javafx.scene.layout.VBox; + +import org.jabref.gui.JabRefFrame; +import org.jabref.gui.SidePaneComponent; +import org.jabref.gui.SidePaneManager; +import org.jabref.gui.SidePaneType; +import org.jabref.gui.actions.Action; +import org.jabref.gui.actions.ActionFactory; +import org.jabref.gui.actions.StandardActions; +import org.jabref.gui.help.HelpAction; +import org.jabref.gui.icon.IconTheme; +import org.jabref.gui.search.SearchTextField; +import org.jabref.gui.util.ViewModelListCellFactory; +import org.jabref.logic.importer.SearchBasedFetcher; +import org.jabref.logic.l10n.Localization; +import org.jabref.preferences.JabRefPreferences; + +import org.fxmisc.easybind.EasyBind; + +public class WebSearchPane extends SidePaneComponent { + + private final JabRefPreferences preferences; + private final WebSearchPaneViewModel viewModel; + + public WebSearchPane(SidePaneManager sidePaneManager, JabRefPreferences preferences, JabRefFrame frame) { + super(sidePaneManager, IconTheme.JabRefIcons.WWW, Localization.lang("Web search")); + this.preferences = preferences; + this.viewModel = new WebSearchPaneViewModel(preferences.getImportFormatPreferences(), frame, preferences); + } + + @Override + public Action getToggleAction() { + return StandardActions.TOGGLE_WEB_SEARCH; + } + + @Override + protected Node createContentPane() { + // Setup combo box for fetchers + ComboBox fetchers = new ComboBox<>(); + new ViewModelListCellFactory() + .withText(SearchBasedFetcher::getName) + .install(fetchers); + fetchers.itemsProperty().bind(viewModel.fetchersProperty()); + fetchers.valueProperty().bindBidirectional(viewModel.selectedFetcherProperty()); + fetchers.setMaxWidth(Double.POSITIVE_INFINITY); + + // Create help button for currently selected fetcher + StackPane helpButtonContainer = new StackPane(); + ActionFactory factory = new ActionFactory(preferences.getKeyBindingRepository()); + EasyBind.subscribe(viewModel.selectedFetcherProperty(), fetcher -> { + if ((fetcher != null) && fetcher.getHelpPage().isPresent()) { + HelpAction helpCommand = new HelpAction(fetcher.getHelpPage().get()); + Button helpButton = factory.createIconButton(StandardActions.HELP, helpCommand.getCommand()); + helpButtonContainer.getChildren().setAll(helpButton); + } else { + helpButtonContainer.getChildren().clear(); + } + }); + HBox fetcherContainer = new HBox(fetchers, helpButtonContainer); + HBox.setHgrow(fetchers, Priority.ALWAYS); + + // Create text field for query input + TextField query = SearchTextField.create(); + viewModel.queryProperty().bind(query.textProperty()); + + // Create button that triggers search + Button search = new Button(Localization.lang("Search")); + search.setDefaultButton(true); + search.setOnAction(event -> viewModel.search()); + + // Put everything together + VBox container = new VBox(); + container.setAlignment(Pos.CENTER); + container.getChildren().addAll(fetcherContainer, query, search); + return container; + } + + @Override + public SidePaneType getType() { + return SidePaneType.WEB_SEARCH; + } + + @Override + public void beforeClosing() { + preferences.putBoolean(JabRefPreferences.WEB_SEARCH_VISIBLE, Boolean.FALSE); + } + + @Override + public void afterOpening() { + preferences.putBoolean(JabRefPreferences.WEB_SEARCH_VISIBLE, Boolean.TRUE); + } + + @Override + public Priority getResizePolicy() { + return Priority.NEVER; + } +} diff --git a/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java b/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java new file mode 100644 index 00000000000..c38e2c4c4b8 --- /dev/null +++ b/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java @@ -0,0 +1,114 @@ +package org.jabref.gui.importer.fetcher; + +import java.util.Comparator; +import java.util.List; + +import javafx.beans.property.ListProperty; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleListProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; + +import org.jabref.JabRefExecutorService; +import org.jabref.gui.JabRefFrame; +import org.jabref.gui.importer.ImportInspectionDialog; +import org.jabref.logic.importer.FetcherException; +import org.jabref.logic.importer.ImportFormatPreferences; +import org.jabref.logic.importer.SearchBasedFetcher; +import org.jabref.logic.importer.WebFetcher; +import org.jabref.logic.importer.WebFetchers; +import org.jabref.logic.l10n.Localization; +import org.jabref.model.entry.BibEntry; +import org.jabref.model.strings.StringUtil; +import org.jabref.preferences.JabRefPreferences; + +import org.fxmisc.easybind.EasyBind; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class WebSearchPaneViewModel { + + private static final Logger LOGGER = LoggerFactory.getLogger(WebSearchPaneViewModel.class); + + private final ObjectProperty selectedFetcher = new SimpleObjectProperty<>(); + private final ListProperty fetchers = new SimpleListProperty<>(FXCollections.observableArrayList()); + private final StringProperty query = new SimpleStringProperty(); + private final JabRefFrame frame; + + public WebSearchPaneViewModel(ImportFormatPreferences importPreferences, JabRefFrame frame, JabRefPreferences preferences) { + // TODO: Rework so that we don't rely on JabRefFrame and not the complete preferences + this.frame = frame; + + List allFetchers = WebFetchers.getSearchBasedFetchers(importPreferences); + allFetchers.sort(Comparator.comparing(WebFetcher::getName)); + fetchers.setAll(allFetchers); + + // Choose last-selected fetcher as default + int defaultFetcherIndex = preferences.getInt(JabRefPreferences.SELECTED_FETCHER_INDEX); + if ((defaultFetcherIndex <= 0) || (defaultFetcherIndex >= fetchers.size())) { + selectedFetcherProperty().setValue(fetchers.get(0)); + } else { + selectedFetcherProperty().setValue(fetchers.get(defaultFetcherIndex)); + } + EasyBind.subscribe(selectedFetcherProperty(), newFetcher -> { + int newIndex = fetchers.indexOf(newFetcher); + preferences.putInt(JabRefPreferences.SELECTED_FETCHER_INDEX, newIndex); + }); + } + + public ObservableList getFetchers() { + return fetchers.get(); + } + + public ListProperty fetchersProperty() { + return fetchers; + } + + public SearchBasedFetcher getSelectedFetcher() { + return selectedFetcher.get(); + } + + public ObjectProperty selectedFetcherProperty() { + return selectedFetcher; + } + + public String getQuery() { + return query.get(); + } + + public StringProperty queryProperty() { + return query; + } + + public void search() { + if (StringUtil.isBlank(getQuery())) { + frame.output(Localization.lang("Please enter a search string")); + return; + } + + if (frame.getCurrentBasePanel() == null) { + frame.output(Localization.lang("Please open or start a new library before searching")); + return; + } + + SearchBasedFetcher activeFetcher = getSelectedFetcher(); + final ImportInspectionDialog dialog = new ImportInspectionDialog(frame, frame.getCurrentBasePanel(), + activeFetcher.getName(), false); + dialog.setVisible(true); + + JabRefExecutorService.INSTANCE.execute(() -> { + dialog.setStatus(Localization.lang("Processing %0", getQuery())); + try { + List matches = activeFetcher.performSearch(getQuery().trim()); + dialog.addEntries(matches); + dialog.entryListComplete(); + } catch (FetcherException e) { + LOGGER.error("Error while fetching from " + activeFetcher.getName(), e); + dialog.showErrorMessage(activeFetcher.getName(), e.getLocalizedMessage()); + } + }); + } +} diff --git a/src/main/java/org/jabref/gui/search/SearchTextField.java b/src/main/java/org/jabref/gui/search/SearchTextField.java index b752b744ccf..cbb8ef0e650 100644 --- a/src/main/java/org/jabref/gui/search/SearchTextField.java +++ b/src/main/java/org/jabref/gui/search/SearchTextField.java @@ -1,7 +1,5 @@ package org.jabref.gui.search; -import javafx.scene.control.TextField; - import org.jabref.gui.icon.IconTheme; import org.jabref.logic.l10n.Localization; @@ -10,7 +8,7 @@ public class SearchTextField { - public static TextField create() { + public static CustomTextField create() { CustomTextField textField = (CustomTextField) TextFields.createClearableTextField(); textField.setPromptText(Localization.lang("Search") + "..."); textField.setLeft(IconTheme.JabRefIcons.SEARCH.getGraphicNode()); diff --git a/src/main/java/org/jabref/gui/util/ViewModelListCellFactory.java b/src/main/java/org/jabref/gui/util/ViewModelListCellFactory.java index e33bd4cbccc..e628e1c371e 100644 --- a/src/main/java/org/jabref/gui/util/ViewModelListCellFactory.java +++ b/src/main/java/org/jabref/gui/util/ViewModelListCellFactory.java @@ -3,6 +3,7 @@ import java.util.function.BiConsumer; import javafx.scene.Node; +import javafx.scene.control.ComboBox; import javafx.scene.control.ContextMenu; import javafx.scene.control.ListCell; import javafx.scene.control.ListView; @@ -107,6 +108,11 @@ public ViewModelListCellFactory setOnDragOver(BiConsumer comboBox) { + comboBox.setButtonCell(this.call(null)); + comboBox.setCellFactory(this); + } + @Override public ListCell call(ListView param) { diff --git a/src/main/java/org/jabref/logic/importer/ImportInspector.java b/src/main/java/org/jabref/logic/importer/ImportInspector.java deleted file mode 100644 index 80ec91e9bb5..00000000000 --- a/src/main/java/org/jabref/logic/importer/ImportInspector.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.jabref.logic.importer; - -import org.jabref.model.entry.BibEntry; - -/** - * An ImportInspector can be passed to a EntryFetcher and will receive entries - * as they are fetched from somewhere. - * - * Currently there are two implementations: ImportInspectionDialog and - * ImportInspectionCommandLine - * - */ -public interface ImportInspector { - - /** - * Notify the ImportInspector about the progress of the operation. - * - * The Inspector for instance could display a progress bar with the given - * values. - * - * @param current - * A number that is related to the work already done. - * - * @param max - * A current estimate for the total amount of work to be done. - */ - void setProgress(int current, int max); - - /** - * Add the given entry to the list of entries managed by the inspector. - * - * @param entry - * The entry to add. - */ - void addEntry(BibEntry entry); -} diff --git a/src/main/java/org/jabref/logic/importer/WebFetcher.java b/src/main/java/org/jabref/logic/importer/WebFetcher.java index c33531ac5eb..6f300d67df2 100644 --- a/src/main/java/org/jabref/logic/importer/WebFetcher.java +++ b/src/main/java/org/jabref/logic/importer/WebFetcher.java @@ -1,5 +1,7 @@ package org.jabref.logic.importer; +import java.util.Optional; + import org.jabref.logic.help.HelpFile; /** @@ -20,7 +22,7 @@ public interface WebFetcher { * * @return the {@link HelpFile} enum constant for the help page */ - default HelpFile getHelpPage() { - return null; // no help page by default + default Optional getHelpPage() { + return Optional.empty(); // no help page by default } } diff --git a/src/main/java/org/jabref/logic/importer/fetcher/ACMPortalFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/ACMPortalFetcher.java index 059fcbaff21..e36f730366b 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/ACMPortalFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/ACMPortalFetcher.java @@ -4,6 +4,7 @@ import java.net.URISyntaxException; import java.net.URL; import java.util.Objects; +import java.util.Optional; import org.jabref.logic.help.HelpFile; import org.jabref.logic.importer.FetcherException; @@ -31,8 +32,8 @@ public String getName() { } @Override - public HelpFile getHelpPage() { - return HelpFile.FETCHER_ACM; + public Optional getHelpPage() { + return Optional.of(HelpFile.FETCHER_ACM); } private static String createQueryString(String query) { diff --git a/src/main/java/org/jabref/logic/importer/fetcher/AbstractIsbnFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/AbstractIsbnFetcher.java index 52a252f69e2..c70a9e1b34f 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/AbstractIsbnFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/AbstractIsbnFetcher.java @@ -1,5 +1,7 @@ package org.jabref.logic.importer.fetcher; +import java.util.Optional; + import org.jabref.logic.help.HelpFile; import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.IdBasedParserFetcher; @@ -19,8 +21,8 @@ public AbstractIsbnFetcher(ImportFormatPreferences importFormatPreferences) { } @Override - public HelpFile getHelpPage() { - return HelpFile.FETCHER_ISBN; + public Optional getHelpPage() { + return Optional.of(HelpFile.FETCHER_ISBN); } protected void ensureThatIsbnIsValid(String identifier) throws FetcherException { diff --git a/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java b/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java index 108820515c8..bab25ab4aa7 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java @@ -250,8 +250,8 @@ public String getName() { } @Override - public HelpFile getHelpPage() { - return HelpFile.FETCHER_OAI2_ARXIV; + public Optional getHelpPage() { + return Optional.of(HelpFile.FETCHER_OAI2_ARXIV); } @Override diff --git a/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java b/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java index 1ff7a6d7c89..6b99f420526 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java @@ -9,6 +9,7 @@ import java.util.Collections; import java.util.List; import java.util.Objects; +import java.util.Optional; import org.jabref.logic.cleanup.MoveFieldCleanup; import org.jabref.logic.formatter.bibtexfields.ClearFormatter; @@ -115,8 +116,8 @@ public URL getURLForID(String identifier) throws URISyntaxException, MalformedUR } @Override - public HelpFile getHelpPage() { - return HelpFile.FETCHER_ADS; + public Optional getHelpPage() { + return Optional.of(HelpFile.FETCHER_ADS); } @Override diff --git a/src/main/java/org/jabref/logic/importer/fetcher/CiteSeer.java b/src/main/java/org/jabref/logic/importer/fetcher/CiteSeer.java index 8d244b101f8..56777a8809c 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/CiteSeer.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/CiteSeer.java @@ -7,6 +7,7 @@ import java.net.URL; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -37,8 +38,8 @@ public String getName() { } @Override - public HelpFile getHelpPage() { - return HelpFile.FETCHER_CITESEERX; + public Optional getHelpPage() { + return Optional.of(HelpFile.FETCHER_CITESEERX); } @Override diff --git a/src/main/java/org/jabref/logic/importer/fetcher/DBLPFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/DBLPFetcher.java index c422a9c28ca..57937051561 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/DBLPFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/DBLPFetcher.java @@ -4,6 +4,7 @@ import java.net.URISyntaxException; import java.net.URL; import java.util.Objects; +import java.util.Optional; import org.jabref.logic.cleanup.DoiCleanup; import org.jabref.logic.formatter.bibtexfields.ClearFormatter; @@ -71,8 +72,8 @@ public String getName() { } @Override - public HelpFile getHelpPage() { - return HelpFile.FETCHER_DBLP; + public Optional getHelpPage() { + return Optional.of(HelpFile.FETCHER_DBLP); } } diff --git a/src/main/java/org/jabref/logic/importer/fetcher/DOAJFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/DOAJFetcher.java index 981ab58ea52..67bc0dc97ac 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/DOAJFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/DOAJFetcher.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; +import java.util.Optional; import java.util.stream.Collectors; import org.jabref.logic.help.HelpFile; @@ -157,8 +158,8 @@ public String getName() { } @Override - public HelpFile getHelpPage() { - return HelpFile.FETCHER_DOAJ; + public Optional getHelpPage() { + return Optional.of(HelpFile.FETCHER_DOAJ); } @Override diff --git a/src/main/java/org/jabref/logic/importer/fetcher/DiVA.java b/src/main/java/org/jabref/logic/importer/fetcher/DiVA.java index d3c56712371..5a876fd9ff8 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/DiVA.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/DiVA.java @@ -3,6 +3,7 @@ import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; +import java.util.Optional; import org.jabref.logic.help.HelpFile; import org.jabref.logic.importer.FetcherException; @@ -32,8 +33,8 @@ public String getName() { } @Override - public HelpFile getHelpPage() { - return HelpFile.FETCHER_DIVA; + public Optional getHelpPage() { + return Optional.of(HelpFile.FETCHER_DIVA); } @Override diff --git a/src/main/java/org/jabref/logic/importer/fetcher/DoiFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/DoiFetcher.java index 766f2570164..0deb118292e 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/DoiFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/DoiFetcher.java @@ -38,8 +38,8 @@ public String getName() { } @Override - public HelpFile getHelpPage() { - return HelpFile.FETCHER_DOI; + public Optional getHelpPage() { + return Optional.of(HelpFile.FETCHER_DOI); } @Override diff --git a/src/main/java/org/jabref/logic/importer/fetcher/GoogleScholar.java b/src/main/java/org/jabref/logic/importer/fetcher/GoogleScholar.java index 466d0259f29..24a061a26b5 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/GoogleScholar.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/GoogleScholar.java @@ -117,8 +117,8 @@ public String getName() { } @Override - public HelpFile getHelpPage() { - return HelpFile.FETCHER_GOOGLE_SCHOLAR; + public Optional getHelpPage() { + return Optional.of(HelpFile.FETCHER_GOOGLE_SCHOLAR); } @Override diff --git a/src/main/java/org/jabref/logic/importer/fetcher/GvkFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/GvkFetcher.java index 963ff5ab5e4..67b9879ec35 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/GvkFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/GvkFetcher.java @@ -8,6 +8,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Objects; +import java.util.Optional; import java.util.stream.Collectors; import org.jabref.logic.help.HelpFile; @@ -34,8 +35,8 @@ public String getName() { } @Override - public HelpFile getHelpPage() { - return HelpFile.FETCHER_GVK; + public Optional getHelpPage() { + return Optional.of(HelpFile.FETCHER_GVK); } private String getSearchQueryStringForComplexQuery(List queryList) { diff --git a/src/main/java/org/jabref/logic/importer/fetcher/IEEE.java b/src/main/java/org/jabref/logic/importer/fetcher/IEEE.java index dd9a00ceab2..ac8192a2360 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/IEEE.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/IEEE.java @@ -228,7 +228,7 @@ public String getName() { } @Override - public HelpFile getHelpPage() { - return HelpFile.FETCHER_IEEEXPLORE; + public Optional getHelpPage() { + return Optional.of(HelpFile.FETCHER_IEEEXPLORE); } } diff --git a/src/main/java/org/jabref/logic/importer/fetcher/INSPIREFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/INSPIREFetcher.java index 761a59e72ef..2229d752d66 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/INSPIREFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/INSPIREFetcher.java @@ -7,6 +7,7 @@ import java.net.URL; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -48,8 +49,8 @@ public String getName() { } @Override - public HelpFile getHelpPage() { - return HelpFile.FETCHER_INSPIRE; + public Optional getHelpPage() { + return Optional.of(HelpFile.FETCHER_INSPIRE); } @Override diff --git a/src/main/java/org/jabref/logic/importer/fetcher/MedlineFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/MedlineFetcher.java index 11e8420955c..0b8ace85d7d 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/MedlineFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/MedlineFetcher.java @@ -12,6 +12,7 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; +import java.util.Optional; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamConstants; @@ -127,8 +128,8 @@ public String getName() { } @Override - public HelpFile getHelpPage() { - return HelpFile.FETCHER_MEDLINE; + public Optional getHelpPage() { + return Optional.of(HelpFile.FETCHER_MEDLINE); } @Override diff --git a/src/main/java/org/jabref/logic/importer/fetcher/RfcFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/RfcFetcher.java index 5840c25cc15..19f6128e708 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/RfcFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/RfcFetcher.java @@ -3,6 +3,7 @@ import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; +import java.util.Optional; import org.jabref.logic.help.HelpFile; import org.jabref.logic.importer.FetcherException; @@ -33,8 +34,8 @@ public String getName() { } @Override - public HelpFile getHelpPage() { - return HelpFile.FETCHER_RFC; + public Optional getHelpPage() { + return Optional.of(HelpFile.FETCHER_RFC); } @Override diff --git a/src/main/java/org/jabref/logic/importer/fetcher/SpringerFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/SpringerFetcher.java index 58471c00305..213fe7c79ac 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/SpringerFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/SpringerFetcher.java @@ -147,8 +147,8 @@ public String getName() { } @Override - public HelpFile getHelpPage() { - return HelpFile.FETCHER_SPRINGER; + public Optional getHelpPage() { + return Optional.of(HelpFile.FETCHER_SPRINGER); } @Override diff --git a/src/main/java/org/jabref/logic/importer/fetcher/TitleFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/TitleFetcher.java index 881b738edde..5fea61c0e8f 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/TitleFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/TitleFetcher.java @@ -25,8 +25,8 @@ public String getName() { } @Override - public HelpFile getHelpPage() { - return HelpFile.FETCHER_TITLE; + public Optional getHelpPage() { + return Optional.of(HelpFile.FETCHER_TITLE); } @Override diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 6270350cc84..a6b4b65d800 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -702,8 +702,8 @@ private JabRefPreferences() { defaults.put(EMAIL_SUBJECT, Localization.lang("References")); defaults.put(OPEN_FOLDERS_OF_ATTACHED_FILES, Boolean.FALSE); defaults.put(ALLOW_FILE_AUTO_OPEN_BROWSE, Boolean.TRUE); - defaults.put(WEB_SEARCH_VISIBLE, Boolean.FALSE); - defaults.put(GROUP_SIDEPANE_VISIBLE, Boolean.FALSE); + defaults.put(WEB_SEARCH_VISIBLE, Boolean.TRUE); + defaults.put(GROUP_SIDEPANE_VISIBLE, Boolean.TRUE); defaults.put(SELECTED_FETCHER_INDEX, 0); defaults.put(BIB_LOC_AS_PRIMARY_DIR, Boolean.FALSE); defaults.put(DB_CONNECT_SERVER_TYPE, "MySQL"); @@ -1035,6 +1035,10 @@ public void putInt(String key, int value) { prefs.putInt(key, value); } + public void putInt(String key, Number value) { + prefs.putInt(key, value.intValue()); + } + public void putDouble(String key, double value) { prefs.putDouble(key, value); } diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 55b6f2209de..d2de9afd87d 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -416,8 +416,6 @@ External\ programs=External programs External\ viewer\ called=External viewer called -Fetch=Fetch - Field=Field field=field @@ -1180,7 +1178,6 @@ Your\ new\ key\ bindings\ have\ been\ stored.=Your new key bindings have been st The\ following\ fetchers\ are\ available\:=The following fetchers are available: Could\ not\ find\ fetcher\ '%0'=Could not find fetcher '%0' Running\ query\ '%0'\ with\ fetcher\ '%1'.=Running query '%0' with fetcher '%1'. -Query\ '%0'\ with\ fetcher\ '%1'\ did\ not\ return\ any\ results.=Query '%0' with fetcher '%1' did not return any results. Move\ file=Move file Rename\ file=Rename file @@ -1192,7 +1189,6 @@ Could\ not\ move\ file\ '%0'.=Could not move file '%0'. Could\ not\ find\ file\ '%0'.=Could not find file '%0'. Number\ of\ entries\ successfully\ imported=Number of entries successfully imported Import\ canceled\ by\ user=Import canceled by user -Progress\:\ %0\ of\ %1=Progress: %0 of %1 Error\ while\ fetching\ from\ %0=Error while fetching from %0 Show\ search\ results\ in\ a\ window=Show search results in a window diff --git a/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java b/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java index ee5f4c4e2bd..2aedc5c0473 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java @@ -136,7 +136,7 @@ public void setUp() throws Exception { @Test public void testHelpPage() { - assertEquals("ADS", fetcher.getHelpPage().getPageName()); + assertEquals("ADS", fetcher.getHelpPage().get().getPageName()); } @Test diff --git a/src/test/java/org/jabref/logic/importer/fetcher/DoiFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/DoiFetcherTest.java index 177d48b7123..d6411540e39 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/DoiFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/DoiFetcherTest.java @@ -56,7 +56,7 @@ public void testGetName() { @Test public void testGetHelpPage() { - assertEquals("DOItoBibTeX", fetcher.getHelpPage().getPageName()); + assertEquals("DOItoBibTeX", fetcher.getHelpPage().get().getPageName()); } @Test diff --git a/src/test/java/org/jabref/logic/importer/fetcher/GvkFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/GvkFetcherTest.java index 7701d92504d..fc8f1c7e12d 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/GvkFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/GvkFetcherTest.java @@ -63,7 +63,7 @@ public void testGetName() { @Test public void testGetHelpPage() { - assertEquals("GVK", fetcher.getHelpPage().getPageName()); + assertEquals("GVK", fetcher.getHelpPage().get().getPageName()); } @Test diff --git a/src/test/java/org/jabref/logic/importer/fetcher/IsbnFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/IsbnFetcherTest.java index 6567c692f96..a8a6f0fd40a 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/IsbnFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/IsbnFetcherTest.java @@ -48,7 +48,7 @@ public void testName() { @Test public void testHelpPage() { - assertEquals("ISBNtoBibTeX", fetcher.getHelpPage().getPageName()); + assertEquals("ISBNtoBibTeX", fetcher.getHelpPage().get().getPageName()); } @Test diff --git a/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaChimboriFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaChimboriFetcherTest.java index 658099683a7..101df5f27ac 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaChimboriFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaChimboriFetcherTest.java @@ -44,7 +44,7 @@ public void testName() { @Test @Override public void testHelpPage() { - assertEquals("ISBNtoBibTeX", fetcher.getHelpPage().getPageName()); + assertEquals("ISBNtoBibTeX", fetcher.getHelpPage().get().getPageName()); } @Test diff --git a/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaEbookDeFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaEbookDeFetcherTest.java index aafc965b53c..a20318709b1 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaEbookDeFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaEbookDeFetcherTest.java @@ -44,7 +44,7 @@ public void testName() { @Test @Override public void testHelpPage() { - assertEquals("ISBNtoBibTeX", fetcher.getHelpPage().getPageName()); + assertEquals("ISBNtoBibTeX", fetcher.getHelpPage().get().getPageName()); } @Test diff --git a/src/test/java/org/jabref/logic/importer/fetcher/MedlineFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/MedlineFetcherTest.java index 289aeecf698..54e7ac3944a 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/MedlineFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/MedlineFetcherTest.java @@ -128,7 +128,7 @@ public void testGetName() { @Test public void testGetHelpPage() { - assertEquals("Medline", fetcher.getHelpPage().getPageName()); + assertEquals("Medline", fetcher.getHelpPage().get().getPageName()); } @Test diff --git a/src/test/java/org/jabref/logic/importer/fetcher/RfcFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/RfcFetcherTest.java index 1ed849969ae..146be5a7e35 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/RfcFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/RfcFetcherTest.java @@ -48,7 +48,7 @@ public void getNameReturnsEqualIdName() { @Test public void getHelpPageReturnsEqualHelpPage() { - assertEquals("RFCtoBibTeX", fetcher.getHelpPage().getPageName()); + assertEquals("RFCtoBibTeX", fetcher.getHelpPage().get().getPageName()); } @Test diff --git a/src/test/java/org/jabref/logic/importer/fetcher/TitleFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/TitleFetcherTest.java index d4b37535b8f..728ef5de1b9 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/TitleFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/TitleFetcherTest.java @@ -43,7 +43,7 @@ public void testGetName() { @Test public void testGetHelpPage() { - assertEquals("TitleToBibTeX", fetcher.getHelpPage().getPageName()); + assertEquals("TitleToBibTeX", fetcher.getHelpPage().get().getPageName()); } @Test