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

Rewrite web search pane in JavaFX #4203

Merged
merged 8 commits into from
Jul 24, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
61 changes: 28 additions & 33 deletions src/main/java/org/jabref/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -538,15 +538,12 @@ private void regenerateBibtexKeys(List<ParserResult> loaded) {

/**
* Run an entry fetcher from the command line.
* <p>
* 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<ParserResult> fetch(String fetchCommand) {

if ((fetchCommand == null) || !fetchCommand.contains(":") || (fetchCommand.split(":").length != 2)) {
System.out.println(Localization.lang("Expected syntax for --fetch='<name of fetcher>:<query>'"));
System.out.println(Localization.lang("The following fetchers are available:"));
Expand All @@ -555,38 +552,36 @@ private Optional<ParserResult> 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<SearchBasedFetcher> fetchers = WebFetchers.getSearchBasedFetchers(Globals.prefs.getImportFormatPreferences());
Optional<SearchBasedFetcher> 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<BibEntry> 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<BibEntry> 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() {
Expand Down
38 changes: 0 additions & 38 deletions src/main/java/org/jabref/cli/ImportInspectionCommandLine.java

This file was deleted.

3 changes: 2 additions & 1 deletion src/main/java/org/jabref/gui/EntryTypeDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ private void init() {

// groupSidePane.getToggleCommand().setSelected(sidePaneManager.isComponentVisible(GroupSidePane.class));
Copy link
Member

Choose a reason for hiding this comment

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

Can this be removed or rewritten?

Copy link
Member Author

Choose a reason for hiding this comment

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

At some point we should show the toggle state in the menu and I would hence leave this there as a reminder. Sadly, there is still a lot of such uncommented old in the maintable / frame / base panel classes...

//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());
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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(),
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/org/jabref/gui/SidePaneManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));

Expand All @@ -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();
}

Expand Down
11 changes: 10 additions & 1 deletion src/main/java/org/jabref/gui/help/HelpAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,21 @@ public void actionPerformed(ActionEvent e) {
openHelpPage(helpPage);
}

public static SimpleCommand getCommand() {
public static SimpleCommand getMainHelpPageCommand() {
return new SimpleCommand() {
@Override
public void execute() {
openHelpPage(HelpFile.CONTENTS);
}
};
}

public SimpleCommand getCommand() {
return new SimpleCommand() {
@Override
public void execute() {
openHelpPage(helpPage);
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> INSPECTION_FIELDS = Arrays.asList(FieldName.AUTHOR, FieldName.TITLE, FieldName.YEAR, BibEntry.KEY_FIELD);
Expand All @@ -168,7 +167,6 @@ public class ImportInspectionDialog extends JabRefDialog implements ImportInspec
*/
private final List<BibEntry> entriesToDelete = new ArrayList<>();
private final String undoName;
private final List<CallBack> callBacks = new ArrayList<>();
private final boolean newDatabase;
private final JPopupMenu popup = new JPopupMenu();
private final JButton deselectAllDuplicates = new JButton(Localization.lang("Deselect all duplicates"));
Expand Down Expand Up @@ -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"));
});
Expand All @@ -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));
Expand Down Expand Up @@ -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<BibEntry> list = new ArrayList<>();
list.add(entry);
addEntries(list);
}

public void addEntries(Collection<BibEntry> entriesToAdd) {

for (BibEntry entry : entriesToAdd) {
Expand Down Expand Up @@ -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);
Expand Down
Loading