Skip to content

Commit

Permalink
Move and rename "Mass Getting bibliographic data" action
Browse files Browse the repository at this point in the history
- Relocate action from Right-click menu to "Lookup" menu for consistency

- Rename action from "Mass Getting" to "Get bibliographic data from DOI/ISBN/... (fully automated)"

- Other modifications not finished yet
  • Loading branch information
KUMOAWAI committed Oct 20, 2024
1 parent 012dd9a commit f8267ac
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/actions/StandardActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public enum StandardActions implements Action {
OPEN_URL(Localization.lang("Open URL or DOI"), IconTheme.JabRefIcons.WWW, KeyBinding.OPEN_URL_OR_DOI),
SEARCH_SHORTSCIENCE(Localization.lang("Search ShortScience")),
MERGE_WITH_FETCHED_ENTRY(Localization.lang("Get bibliographic data from %0", "DOI/ISBN/...")),
BATCH_MERGE_WITH_FETCHED_ENTRIES(Localization.lang("Mass getting bibliographic data from %0", "DOI/ISBN/...")),
MASS_GET_BIBLIOGRAPHIC_DATA(Localization.lang("Get bibliographic data from %0 (fully automated)", "DOI/ISBN/...")),
ATTACH_FILE(Localization.lang("Attach file"), IconTheme.JabRefIcons.ATTACH_FILE),
ATTACH_FILE_FROM_URL(Localization.lang("Attach file from URL"), IconTheme.JabRefIcons.DOWNLOAD_FILE),
PRIORITY(Localization.lang("Priority"), IconTheme.JabRefIcons.PRIORITY),
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/org/jabref/gui/frame/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.jabref.gui.maintable.NewLibraryFromPdfActionOffline;
import org.jabref.gui.maintable.NewLibraryFromPdfActionOnline;
import org.jabref.gui.mergeentries.MergeEntriesAction;
import org.jabref.gui.mergeentries.MultiEntryMergeWithFetchedDataAction;
import org.jabref.gui.plaincitationparser.PlainCitationParserAction;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.gui.preferences.ShowPreferencesAction;
Expand Down Expand Up @@ -273,7 +274,22 @@ private void createMenu() {

new SeparatorMenuItem(),

factory.createMenuItem(StandardActions.FIND_UNLINKED_FILES, new FindUnlinkedFilesAction(dialogService, stateManager))
factory.createMenuItem(StandardActions.FIND_UNLINKED_FILES, new FindUnlinkedFilesAction(dialogService, stateManager)),

new SeparatorMenuItem(),

// Adding new menu item for mass bibliographic data fetching
factory.createMenuItem(
StandardActions.MASS_GET_BIBLIOGRAPHIC_DATA,
new MultiEntryMergeWithFetchedDataAction(
frame::getCurrentLibraryTab,
preferences,
taskExecutor,
dialogService,
undoManager,
stateManager
)
)
);

final MenuItem pushToApplicationMenuItem = factory.createMenuItem(pushToApplicationCommand.getAction(), pushToApplicationCommand);
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/jabref/gui/maintable/RightClickMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.jabref.gui.menus.ChangeEntryTypeMenu;
import org.jabref.gui.mergeentries.MergeEntriesAction;
import org.jabref.gui.mergeentries.MergeWithFetchedEntryAction;
import org.jabref.gui.mergeentries.MultiEntryMergeWithFetchedDataAction;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.gui.preview.CopyCitationAction;
import org.jabref.gui.preview.PreviewPreferences;
Expand Down Expand Up @@ -93,8 +92,7 @@ public static ContextMenu create(BibEntryTableViewModel entry,
new SeparatorMenuItem(),

new ChangeEntryTypeMenu(libraryTab.getSelectedEntries(), libraryTab.getBibDatabaseContext(), undoManager, entryTypesManager).asSubMenu(),
factory.createMenuItem(StandardActions.MERGE_WITH_FETCHED_ENTRY, new MergeWithFetchedEntryAction(dialogService, stateManager, taskExecutor, preferences, undoManager)),
factory.createMenuItem(StandardActions.BATCH_MERGE_WITH_FETCHED_ENTRIES, new MultiEntryMergeWithFetchedDataAction(libraryTab, preferences, taskExecutor, libraryTab.getBibDatabaseContext(), dialogService, undoManager))
factory.createMenuItem(StandardActions.MERGE_WITH_FETCHED_ENTRY, new MergeWithFetchedEntryAction(dialogService, stateManager, taskExecutor, preferences, undoManager))
);

EasyBind.subscribe(preferences.getGrobidPreferences().grobidEnabledProperty(), enabled -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,51 +1,74 @@
package org.jabref.gui.mergeentries;

import java.util.List;
import java.util.function.Supplier;

import javax.swing.undo.UndoManager;

import org.jabref.gui.DialogService;
import org.jabref.gui.LibraryTab;
import org.jabref.gui.StateManager;
import org.jabref.gui.actions.ActionHelper;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.logic.util.TaskExecutor;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Action for merging multiple entries with fetched data from identifiers like DOI or arXiv.
*/
public class MultiEntryMergeWithFetchedDataAction extends SimpleCommand {

private final LibraryTab libraryTab;
private static final Logger LOGGER = LoggerFactory.getLogger(MultiEntryMergeWithFetchedDataAction.class);

private final Supplier<LibraryTab> tabSupplier;
private final GuiPreferences preferences;
private final TaskExecutor taskExecutor;
private final BibDatabaseContext bibDatabaseContext;
private final DialogService dialogService;
private final UndoManager undoManager;

public MultiEntryMergeWithFetchedDataAction(LibraryTab libraryTab,
public MultiEntryMergeWithFetchedDataAction(Supplier<LibraryTab> tabSupplier,
GuiPreferences preferences,
TaskExecutor taskExecutor,
BibDatabaseContext bibDatabaseContext,
DialogService dialogService,
UndoManager undoManager) {
this.libraryTab = libraryTab;
UndoManager undoManager,
StateManager stateManager) {
this.tabSupplier = tabSupplier;
this.preferences = preferences;
this.taskExecutor = taskExecutor;
this.bibDatabaseContext = bibDatabaseContext;
this.dialogService = dialogService;
this.undoManager = undoManager;

// Binding to only execute if a database is open
this.executable.bind(ActionHelper.needsDatabase(stateManager));
}

@Override
public void execute() {
List<BibEntry> selectedEntries = libraryTab.getSelectedEntries();
LibraryTab libraryTab = tabSupplier.get();

// Ensure that libraryTab is present
if (libraryTab == null) {
LOGGER.error("Action 'Multi Entry Merge' must be disabled when no database is open.");
return;
}

List<BibEntry> selectedEntries = libraryTab.getDatabase().getEntries();

// If no entries are selected, log and do not execute
if (selectedEntries.isEmpty()) {
dialogService.notify("No entries selected for merging.");
return;
}

// Create an instance of FetchAndMergeEntry
// Create an instance of FetchAndMergeEntry to perform the batch fetch and merge operation
BibDatabaseContext bibDatabaseContext = libraryTab.getBibDatabaseContext();
FetchAndMergeEntry fetchAndMergeEntry = new FetchAndMergeEntry(bibDatabaseContext, taskExecutor, preferences, dialogService, undoManager);

// Perform the batch fetch and merge operation
fetchAndMergeEntry.fetchAndMergeBatch(selectedEntries);
}
}

0 comments on commit f8267ac

Please sign in to comment.