From afca0efdc2d09104ce3d7752b47df5e275cab179 Mon Sep 17 00:00:00 2001 From: colinhex Date: Thu, 7 Oct 2021 15:06:59 +0200 Subject: [PATCH 01/47] add prototype --- src/main/java/org/jabref/gui/JabRefFrame.java | 39 ++++++--- .../jabref/gui/actions/StandardActions.java | 1 - .../importer/GenerateEntryFromIdAction.java | 39 +++++++++ .../importer/GenerateEntryFromIdDialog.fxml | 21 +++++ .../importer/GenerateEntryFromIdDialog.java | 48 +++++++++++ .../logic/importer/CompositeIdFetcher.java | 79 +++++++++++++++++++ 6 files changed, 217 insertions(+), 10 deletions(-) create mode 100644 src/main/java/org/jabref/gui/importer/GenerateEntryFromIdAction.java create mode 100644 src/main/java/org/jabref/gui/importer/GenerateEntryFromIdDialog.fxml create mode 100644 src/main/java/org/jabref/gui/importer/GenerateEntryFromIdDialog.java create mode 100644 src/main/java/org/jabref/logic/importer/CompositeIdFetcher.java diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 22ab411189c..69e5e609baf 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -40,11 +40,7 @@ import javafx.scene.control.skin.TabPaneSkin; import javafx.scene.input.KeyEvent; import javafx.scene.input.TransferMode; -import javafx.scene.layout.BorderPane; -import javafx.scene.layout.HBox; -import javafx.scene.layout.Priority; -import javafx.scene.layout.Region; -import javafx.scene.layout.VBox; +import javafx.scene.layout.*; import javafx.scene.shape.Rectangle; import javafx.stage.Stage; @@ -86,10 +82,8 @@ import org.jabref.gui.help.ErrorConsoleAction; import org.jabref.gui.help.HelpAction; import org.jabref.gui.help.SearchForUpdateAction; -import org.jabref.gui.importer.ImportCommand; -import org.jabref.gui.importer.ImportEntriesDialog; -import org.jabref.gui.importer.NewDatabaseAction; -import org.jabref.gui.importer.NewEntryAction; +import org.jabref.gui.icon.IconTheme; +import org.jabref.gui.importer.*; import org.jabref.gui.importer.actions.OpenDatabaseAction; import org.jabref.gui.importer.fetcher.LookupIdentifierAction; import org.jabref.gui.integrity.IntegrityCheckAction; @@ -172,6 +166,7 @@ public class JabRefFrame extends BorderPane { private TabPane tabbedPane; private SidePane sidePane; private PopOver progressViewPopOver; + private PopOver entryFromIdPopOver; private final TaskExecutor taskExecutor; @@ -475,6 +470,31 @@ private Node createToolbar() { final Button pushToApplicationButton = factory.createIconButton(pushToApplicationAction.getActionInformation(), pushToApplicationAction); pushToApplicationsManager.registerReconfigurable(pushToApplicationButton); + // Create New Entry From ID Button + + Button newEntryFromIdButton = new Button(); + newEntryFromIdButton.setGraphic(IconTheme.JabRefIcons.IMPORT.getGraphicNode()); + newEntryFromIdButton.setStyle("-fx-background-color: transparent;"); + newEntryFromIdButton.setStyle("-fx-border-color: transparent;"); + newEntryFromIdButton.setOnMouseClicked(event -> { + GenerateEntryFromIdDialog entryFromId = new GenerateEntryFromIdDialog(this, dialogService, prefs, factory); + + if (entryFromIdPopOver == null) { + entryFromIdPopOver = new PopOver(entryFromId.getDialogPane()); + entryFromIdPopOver.setTitle(Localization.lang("Entry From ID")); + entryFromIdPopOver.setArrowLocation(PopOver.ArrowLocation.TOP_CENTER); + entryFromIdPopOver.setContentNode(entryFromId.getDialogPane()); + entryFromIdPopOver.show(newEntryFromIdButton); + } else if (entryFromIdPopOver.isShowing()) { + entryFromIdPopOver.hide(); + } else { + entryFromIdPopOver.setContentNode(entryFromId.getDialogPane()); + entryFromIdPopOver.show(newEntryFromIdButton); + } + }); + + // Setup Toolbar + ToolBar toolBar = new ToolBar( new HBox( @@ -491,6 +511,7 @@ private Node createToolbar() { new HBox( factory.createIconButton(StandardActions.NEW_ARTICLE, new NewEntryAction(this, StandardEntryType.Article, dialogService, prefs, stateManager)), factory.createIconButton(StandardActions.NEW_ENTRY, new NewEntryAction(this, dialogService, prefs, stateManager)), + newEntryFromIdButton, factory.createIconButton(StandardActions.NEW_ENTRY_FROM_PLAIN_TEXT, new ExtractBibtexAction(dialogService, prefs, stateManager)), factory.createIconButton(StandardActions.DELETE_ENTRY, new EditAction(StandardActions.DELETE_ENTRY, this, stateManager)) ), diff --git a/src/main/java/org/jabref/gui/actions/StandardActions.java b/src/main/java/org/jabref/gui/actions/StandardActions.java index cbe51b9db9e..9c2b75fe9e1 100644 --- a/src/main/java/org/jabref/gui/actions/StandardActions.java +++ b/src/main/java/org/jabref/gui/actions/StandardActions.java @@ -131,7 +131,6 @@ public enum StandardActions implements Action { LIBRARY_PROPERTIES(Localization.lang("Library properties")), EDIT_PREAMBLE(Localization.lang("Edit preamble")), EDIT_STRINGS(Localization.lang("Edit string constants"), IconTheme.JabRefIcons.EDIT_STRINGS, KeyBinding.EDIT_STRINGS), - FIND_DUPLICATES(Localization.lang("Find duplicates"), IconTheme.JabRefIcons.FIND_DUPLICATES), MERGE_ENTRIES(Localization.lang("Merge entries"), IconTheme.JabRefIcons.MERGE_ENTRIES, KeyBinding.MERGE_ENTRIES), RESOLVE_DUPLICATE_KEYS(Localization.lang("Resolve duplicate citation keys"), Localization.lang("Find and remove duplicate citation keys"), KeyBinding.RESOLVE_DUPLICATE_CITATION_KEYS), diff --git a/src/main/java/org/jabref/gui/importer/GenerateEntryFromIdAction.java b/src/main/java/org/jabref/gui/importer/GenerateEntryFromIdAction.java new file mode 100644 index 00000000000..763df8e54d0 --- /dev/null +++ b/src/main/java/org/jabref/gui/importer/GenerateEntryFromIdAction.java @@ -0,0 +1,39 @@ +package org.jabref.gui.importer; + + +import org.jabref.gui.DialogService; +import org.jabref.gui.JabRefFrame; +import org.jabref.gui.actions.SimpleCommand; +import org.jabref.logic.importer.CompositeIdFetcher; +import org.jabref.model.entry.BibEntry; +import org.jabref.preferences.PreferencesService; + +import java.util.Optional; + +public class GenerateEntryFromIdAction extends SimpleCommand { + private final JabRefFrame jabRefFrame; + private final DialogService dialogService; + private final PreferencesService preferencesService; + private final String id; + + public GenerateEntryFromIdAction(JabRefFrame jabRefFrame, DialogService dialogService, PreferencesService preferencesService, String id) { + this.jabRefFrame = jabRefFrame; + this.dialogService = dialogService; + this.preferencesService = preferencesService; + this.id = id; + } + + @Override + public void execute() { + Optional fetchedEntry; + + CompositeIdFetcher compositeIdFetcher = new CompositeIdFetcher(preferencesService.getImportFormatPreferences()); + fetchedEntry = compositeIdFetcher.performSearchById(id); + + fetchedEntry.ifPresentOrElse( + bibEntry -> jabRefFrame.getCurrentLibraryTab().insertEntry(bibEntry), + () -> dialogService.showErrorDialogAndWait("Could not generate an entry from this ID") + ); + } + +} diff --git a/src/main/java/org/jabref/gui/importer/GenerateEntryFromIdDialog.fxml b/src/main/java/org/jabref/gui/importer/GenerateEntryFromIdDialog.fxml new file mode 100644 index 00000000000..5778143bc91 --- /dev/null +++ b/src/main/java/org/jabref/gui/importer/GenerateEntryFromIdDialog.fxml @@ -0,0 +1,21 @@ + + + + + + + + + + + +