-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
32d7400
commit 4325489
Showing
6 changed files
with
370 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
167 changes: 0 additions & 167 deletions
167
src/main/java/org/jabref/gui/referencemetadata/FetchReferenceMetadata.java
This file was deleted.
Oops, something went wrong.
90 changes: 90 additions & 0 deletions
90
src/main/java/org/jabref/gui/referencemetadata/ReferenceMetadataFetcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package org.jabref.gui.referencemetadata; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import javax.swing.undo.UndoManager; | ||
|
||
import javafx.collections.ObservableList; | ||
import javafx.concurrent.Task; | ||
|
||
import org.jabref.gui.DialogService; | ||
import org.jabref.gui.JabRefFrame; | ||
import org.jabref.gui.StateManager; | ||
import org.jabref.gui.actions.SimpleCommand; | ||
import org.jabref.gui.undo.NamedCompound; | ||
import org.jabref.gui.util.BindingsHelper; | ||
import org.jabref.gui.util.TaskExecutor; | ||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.model.database.BibDatabaseContext; | ||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.preferences.JabRefPreferences; | ||
|
||
import static org.jabref.gui.actions.ActionHelper.needsDatabase; | ||
import static org.jabref.gui.actions.ActionHelper.needsEntriesSelected; | ||
|
||
/** | ||
* This class allows fetching the reference metadata (e.g. citation counts) from the web for the currently selected entries in a library. | ||
*/ | ||
public class ReferenceMetadataFetcher extends SimpleCommand { | ||
|
||
private static boolean USE_REFERENCE_METADATA_FETCHER_GOOGLE_SCHOLAR = true; | ||
|
||
private final DialogService dialogService; | ||
private final JabRefPreferences preferences; | ||
private final StateManager stateManager; | ||
private UndoManager undoManager; | ||
private TaskExecutor taskExecutor; | ||
|
||
public ReferenceMetadataFetcher(JabRefFrame frame, JabRefPreferences preferences, StateManager stateManager, UndoManager undoManager, TaskExecutor taskExecutor) { | ||
this.dialogService = frame.getDialogService(); | ||
this.preferences = preferences; | ||
this.stateManager = stateManager; | ||
this.undoManager = undoManager; | ||
this.taskExecutor = taskExecutor; | ||
|
||
this.executable.bind(needsDatabase(this.stateManager).and(needsEntriesSelected(stateManager))); | ||
this.statusMessage.bind(BindingsHelper.ifThenElse(executable, Localization.lang("This operation fetches reference metadata for the currently selected entries online."), Localization.lang("This operation requires one or more entries to be selected."))); | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
BibDatabaseContext database = stateManager.getActiveDatabase().orElseThrow(() -> new NullPointerException("Database null")); | ||
ObservableList<BibEntry> entries = stateManager.getSelectedEntries(); | ||
|
||
final NamedCompound nc = new NamedCompound(Localization.lang("Fetch reference metadata")); | ||
|
||
Task<List<BibEntry>> fetchReferenceMetadataTask = new Task<List<BibEntry>>() { | ||
|
||
@Override | ||
protected List<BibEntry> call() { | ||
|
||
if (USE_REFERENCE_METADATA_FETCHER_GOOGLE_SCHOLAR) { | ||
ReferenceMetadataFetcherGoogleScholar rmfgs = new ReferenceMetadataFetcherGoogleScholar(); | ||
rmfgs.fetchFor(database, entries, dialogService); | ||
} | ||
|
||
return entries; | ||
} | ||
|
||
@Override | ||
protected void succeeded() { | ||
if (!getValue().isEmpty()) { | ||
if (nc.hasEdits()) { | ||
nc.end(); | ||
undoManager.addEdit(nc); | ||
} | ||
dialogService.notify(Localization.lang("Finished fetching reference metadata.")); | ||
} else { | ||
dialogService.notify(Localization.lang("Finished fetching reference metadata.") + " " + Localization.lang("There was nothing to do.")); | ||
} | ||
} | ||
}; | ||
|
||
dialogService.showProgressDialogAndWait( | ||
Localization.lang("Fetching reference metadata online"), | ||
Localization.lang("Querying reference metadata..."), | ||
fetchReferenceMetadataTask); | ||
taskExecutor.execute(fetchReferenceMetadataTask); | ||
} | ||
} |
Oops, something went wrong.