From 10394d277e1ef6dd3353bd658f2d14b7c31f31c0 Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> Date: Tue, 2 Jan 2024 09:17:42 +0100 Subject: [PATCH] Extract calls to JabRefFrame and substitute with LibraryTabContainer (#10724) * Extracted frame out of EditAction * Extracted frame out of EditAction * Extracted frame out of NewEntryAction * Extracted frame out of MergeReviewIntoCommentAction * Removed getTabbedPane and getBasePanelCount * Extracted call to libraryTab.frame() out of MainTableContextHeaderMenu * Extracted call to frame() out of RightClickMenu * Extracted call to frame() out of SaveDatabaseActionTest * Extracted calls to JabRefFrame * Extracted calls to JabRefFrame from NewSubLibraryAction and ConnectToSharedDatabaseCommand * Extracted calls to JabRefFrame from GenerateCitationKeyAction * Extracted calls to JabRefFrame from ImportCommand * Extracted calls to JabRefFrame from ExportCommand * Extracted calls to JabRefFrame from UndoRedoAction * Extracted calls to JabRefFrame from SaveAllAction * Extracted calls to JabRefFrame from LookupIdentifierAction * Extracted calls to JabRefFrame from StartNewStudyAction * Extracted calls to JabRefFrame from GlobalSearchBar * Extracted calls to JabRefFrame from CleanupAction * Extracted calls to JabRefFrame from DuplicateSearch * Extracted calls to JabRefFrame from ReplaceStringAction * Extracted calls to JabRefFrame from OpenEntryEditorAction * Extracted calls to JabRefFrame from PreviewSwitchAction * Extracted calls to JabRefFrame from IntegrityCheckAction * Extracted calls to JabRefFrame from AbbreviateAction * Extracted calls to JabRefFrame from GlobalSearchBarTest * Switched to suppliers * Reworded for consistency * Mark index based tab selectors as deprecated * Removed unused arg * Removed deprecated index based tab selector * Applied suggestions from pr comments --- .../org/jabref/gui/EntryTypeViewModel.java | 2 +- src/main/java/org/jabref/gui/JabRefFrame.java | 61 +++++++--------- src/main/java/org/jabref/gui/JabRefGUI.java | 27 ++++--- src/main/java/org/jabref/gui/LibraryTab.java | 47 +++++------- .../org/jabref/gui/LibraryTabContainer.java | 7 +- src/main/java/org/jabref/gui/MainMenu.java | 72 +++++++++---------- src/main/java/org/jabref/gui/MainToolBar.java | 28 ++++---- .../gui/auximport/NewSubLibraryAction.java | 15 ++-- .../GenerateCitationKeyAction.java | 24 +++++-- .../org/jabref/gui/cleanup/CleanupAction.java | 22 +++--- .../duplicationFinder/DuplicateSearch.java | 12 ++-- .../java/org/jabref/gui/edit/EditAction.java | 30 ++++---- .../jabref/gui/edit/ReplaceStringAction.java | 17 ++--- .../entryeditor/OpenEntryEditorAction.java | 12 ++-- .../gui/entryeditor/PreviewSwitchAction.java | 14 ++-- .../jabref/gui/exporter/ExportCommand.java | 12 ++-- .../org/jabref/gui/exporter/SaveAction.java | 12 ++-- .../jabref/gui/exporter/SaveAllAction.java | 14 ++-- .../importer/GenerateEntryFromIdAction.java | 5 +- .../jabref/gui/importer/ImportCommand.java | 12 ++-- .../gui/importer/NewDatabaseAction.java | 12 ++-- .../jabref/gui/importer/NewEntryAction.java | 26 +++---- .../importer/ParserResultWarningDialog.java | 30 ++------ .../actions/CheckForNewEntryTypesAction.java | 6 +- .../importer/actions/GUIPostOpenAction.java | 5 +- .../actions/MergeReviewIntoCommentAction.java | 6 +- .../importer/actions/OpenDatabaseAction.java | 31 ++++---- .../fetcher/LookupIdentifierAction.java | 17 +++-- .../gui/integrity/IntegrityCheckAction.java | 11 +-- .../jabref/gui/journals/AbbreviateAction.java | 24 ++++--- .../org/jabref/gui/maintable/MainTable.java | 19 ++--- .../maintable/MainTableHeaderContextMenu.java | 55 +++++++------- .../jabref/gui/maintable/RightClickMenu.java | 20 +++--- .../preferences/ShowPreferencesAction.java | 24 +++---- .../jabref/gui/search/GlobalSearchBar.java | 18 +++-- .../gui/search/SearchFieldRightClickMenu.java | 21 +++--- .../ConnectToSharedDatabaseCommand.java | 15 ++-- .../shared/SharedDatabaseLoginDialogView.java | 10 +-- .../SharedDatabaseLoginDialogViewModel.java | 12 ++-- .../gui/shared/SharedDatabaseUIManager.java | 22 +++--- .../gui/slr/ExistingStudySearchAction.java | 16 ++--- .../jabref/gui/slr/StartNewStudyAction.java | 17 +++-- .../gui/specialfields/SpecialFieldAction.java | 15 ++-- .../SpecialFieldMenuItemFactory.java | 13 ++-- .../specialfields/SpecialFieldViewModel.java | 7 +- .../org/jabref/gui/undo/UndoRedoAction.java | 15 ++-- .../gui/exporter/SaveDatabaseActionTest.java | 5 -- .../gui/importer/NewEntryActionTest.java | 32 +++------ .../gui/search/GlobalSearchBarTest.java | 12 ++-- 49 files changed, 469 insertions(+), 492 deletions(-) diff --git a/src/main/java/org/jabref/gui/EntryTypeViewModel.java b/src/main/java/org/jabref/gui/EntryTypeViewModel.java index 59d3cbbe217..b63718edeaf 100644 --- a/src/main/java/org/jabref/gui/EntryTypeViewModel.java +++ b/src/main/java/org/jabref/gui/EntryTypeViewModel.java @@ -196,7 +196,7 @@ public void runFetcherWorker() { Localization.lang("Return to dialog")); if (addEntryFlag) { new NewEntryAction( - libraryTab.frame(), + () -> libraryTab, StandardEntryType.Article, dialogService, preferencesService, diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 3f0f95a6955..926dc41d6ef 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -267,31 +267,31 @@ private void initKeyBindings() { getGlobalSearchBar().focus(); break; case NEW_ARTICLE: - new NewEntryAction(this, StandardEntryType.Article, dialogService, prefs, stateManager).execute(); + new NewEntryAction(this::getCurrentLibraryTab, StandardEntryType.Article, dialogService, prefs, stateManager).execute(); break; case NEW_BOOK: - new NewEntryAction(this, StandardEntryType.Book, dialogService, prefs, stateManager).execute(); + new NewEntryAction(this::getCurrentLibraryTab, StandardEntryType.Book, dialogService, prefs, stateManager).execute(); break; case NEW_INBOOK: - new NewEntryAction(this, StandardEntryType.InBook, dialogService, prefs, stateManager).execute(); + new NewEntryAction(this::getCurrentLibraryTab, StandardEntryType.InBook, dialogService, prefs, stateManager).execute(); break; case NEW_MASTERSTHESIS: - new NewEntryAction(this, StandardEntryType.MastersThesis, dialogService, prefs, stateManager).execute(); + new NewEntryAction(this::getCurrentLibraryTab, StandardEntryType.MastersThesis, dialogService, prefs, stateManager).execute(); break; case NEW_PHDTHESIS: - new NewEntryAction(this, StandardEntryType.PhdThesis, dialogService, prefs, stateManager).execute(); + new NewEntryAction(this::getCurrentLibraryTab, StandardEntryType.PhdThesis, dialogService, prefs, stateManager).execute(); break; case NEW_PROCEEDINGS: - new NewEntryAction(this, StandardEntryType.Proceedings, dialogService, prefs, stateManager).execute(); + new NewEntryAction(this::getCurrentLibraryTab, StandardEntryType.Proceedings, dialogService, prefs, stateManager).execute(); break; case NEW_TECHREPORT: - new NewEntryAction(this, StandardEntryType.TechReport, dialogService, prefs, stateManager).execute(); + new NewEntryAction(this::getCurrentLibraryTab, StandardEntryType.TechReport, dialogService, prefs, stateManager).execute(); break; case NEW_UNPUBLISHED: - new NewEntryAction(this, StandardEntryType.Unpublished, dialogService, prefs, stateManager).execute(); + new NewEntryAction(this::getCurrentLibraryTab, StandardEntryType.Unpublished, dialogService, prefs, stateManager).execute(); break; case NEW_INPROCEEDINGS: - new NewEntryAction(this, StandardEntryType.InProceedings, dialogService, prefs, stateManager).execute(); + new NewEntryAction(this::getCurrentLibraryTab, StandardEntryType.InProceedings, dialogService, prefs, stateManager).execute(); break; case PASTE: if (OS.OS_X) { // Workaround for a jdk issue that executes paste twice when using cmd+v in a TextField @@ -406,11 +406,11 @@ public boolean quit() { // Then ask if the user really wants to close, if the library has not been saved since last save. List filenames = new ArrayList<>(); - for (int i = 0; i < tabbedPane.getTabs().size(); i++) { - LibraryTab libraryTab = getLibraryTabAt(i); + for (LibraryTab libraryTab : getLibraryTabs()) { final BibDatabaseContext context = libraryTab.getBibDatabaseContext(); + if (libraryTab.isModified() && (context.getLocation() == DatabaseLocation.LOCAL)) { - tabbedPane.getSelectionModel().select(i); + showLibraryTab(libraryTab); if (!confirmClose(libraryTab)) { return false; } @@ -419,6 +419,7 @@ public boolean quit() { context.getDBMSSynchronizer().closeSharedDatabase(); context.clearDBMSSynchronizer(); } + AutosaveManager.shutdown(context); BackupManager.shutdown(context, prefs.getFilePreferences().getBackupDirectory(), prefs.getFilePreferences().shouldCreateBackup()); context.getDatabasePath().map(Path::toAbsolutePath).map(Path::toString).ifPresent(filenames::add); @@ -540,15 +541,6 @@ private void setDividerPosition() { } } - /** - * Returns the indexed LibraryTab. - * - * @param i Index of base - */ - public LibraryTab getLibraryTabAt(int i) { - return (LibraryTab) tabbedPane.getTabs().get(i); - } - /** * Returns a list of all LibraryTabs in this frame. */ @@ -559,6 +551,7 @@ public List getLibraryTabs() { .collect(Collectors.toList()); } + @Deprecated public void showLibraryTabAt(int i) { tabbedPane.getSelectionModel().select(i); } @@ -647,7 +640,7 @@ public void init() { } // Update search autocompleter with information for the correct database: - libraryTab.updateSearchManager(); + globalSearchBar.setAutoCompleter(libraryTab.getAutoCompleter()); libraryTab.getUndoManager().postUndoRedoEvent(); libraryTab.getMainTable().requestFocus(); @@ -671,21 +664,6 @@ public LibraryTab getCurrentLibraryTab() { return (LibraryTab) tabbedPane.getSelectionModel().getSelectedItem(); } - /** - * @return the BasePanel count. - */ - public int getBasePanelCount() { - return tabbedPane.getTabs().size(); - } - - /** - * @deprecated do not operate on tabs but on BibDatabaseContexts - */ - @Deprecated - public TabPane getTabbedPane() { - return tabbedPane; - } - /** * This method causes all open LibraryTabs to set up their tables anew. When called from PreferencesDialogViewModel, * this updates to the new settings. We need to notify all tabs about the changes to avoid problems when changing @@ -961,6 +939,15 @@ public Stage getMainStage() { return mainStage; } + /** + * Refreshes the ui after preferences changes + */ + public void refresh() { + globalSearchBar.updateHintVisibility(); + setupAllTables(); + getLibraryTabs().forEach(panel -> panel.getMainTable().getTableModel().refresh()); + } + /** * The action concerned with closing the window. */ diff --git a/src/main/java/org/jabref/gui/JabRefGUI.java b/src/main/java/org/jabref/gui/JabRefGUI.java index 9a402703619..134ff626773 100644 --- a/src/main/java/org/jabref/gui/JabRefGUI.java +++ b/src/main/java/org/jabref/gui/JabRefGUI.java @@ -51,11 +51,11 @@ public class JabRefGUI { private final List toOpenTab = new ArrayList<>(); public JabRefGUI(Stage mainStage, - List databases, + List parserResults, boolean isBlank, PreferencesService preferencesService, FileUpdateMonitor fileUpdateMonitor) { - this.parserResults = databases; + this.parserResults = parserResults; this.isBlank = isBlank; this.preferencesService = preferencesService; this.fileUpdateMonitor = fileUpdateMonitor; @@ -259,9 +259,15 @@ private void openDatabases() { } // Display warnings, if any - int tabNumber = 0; - for (ParserResult pr : parserResults) { - ParserResultWarningDialog.showParserResultWarningDialog(pr, mainFrame, tabNumber++); + for (int tabNumber = 0; tabNumber < parserResults.size(); tabNumber++) { + // ToDo: Method needs to be rewritten, because the index of the parser result and of the libraryTab may not + // be identical, if there are also other tabs opened, that are not libraryTabs. Currently there are none, + // therefor for now this ok. + ParserResult pr = parserResults.get(tabNumber); + if (pr.hasWarnings()) { + ParserResultWarningDialog.showParserResultWarningDialog(pr, mainFrame.getDialogService()); + mainFrame.showLibraryTabAt(tabNumber); + } } // After adding the databases, go through each and see if @@ -269,16 +275,7 @@ private void openDatabases() { // if we found new entry types that can be imported, or checking // if the database contents should be modified due to new features // in this version of JabRef. - // Note that we have to check whether i does not go over getBasePanelCount(). - // This is because importToOpen might have been used, which adds to - // loadedDatabases, but not to getBasePanelCount() - - for (int i = 0; (i < parserResults.size()) && (i < mainFrame.getBasePanelCount()); i++) { - ParserResult pr = parserResults.get(i); - LibraryTab libraryTab = mainFrame.getLibraryTabAt(i); - - OpenDatabaseAction.performPostOpenActions(libraryTab, pr); - } + parserResults.forEach(pr -> OpenDatabaseAction.performPostOpenActions(pr, mainFrame.getDialogService())); LOGGER.debug("Finished adding panels"); } diff --git a/src/main/java/org/jabref/gui/LibraryTab.java b/src/main/java/org/jabref/gui/LibraryTab.java index 137a9548678..341476d2098 100644 --- a/src/main/java/org/jabref/gui/LibraryTab.java +++ b/src/main/java/org/jabref/gui/LibraryTab.java @@ -27,6 +27,7 @@ import org.jabref.gui.autocompleter.AutoCompletePreferences; import org.jabref.gui.autocompleter.PersonNameSuggestionProvider; +import org.jabref.gui.autocompleter.SuggestionProvider; import org.jabref.gui.autocompleter.SuggestionProviders; import org.jabref.gui.autosaveandbackup.AutosaveManager; import org.jabref.gui.autosaveandbackup.BackupManager; @@ -62,6 +63,7 @@ import org.jabref.model.database.event.BibDatabaseContextChangedEvent; import org.jabref.model.database.event.EntriesAddedEvent; import org.jabref.model.database.event.EntriesRemovedEvent; +import org.jabref.model.entry.Author; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.entry.LinkedFile; @@ -84,7 +86,7 @@ public class LibraryTab extends Tab { private static final Logger LOGGER = LoggerFactory.getLogger(LibraryTab.class); - private final JabRefFrame frame; + private final LibraryTabContainer tabContainer; private final CountingUndoManager undoManager; private final DialogService dialogService; private final PreferencesService preferencesService; @@ -125,7 +127,7 @@ public class LibraryTab extends Tab { private final TaskExecutor taskExecutor; public LibraryTab(BibDatabaseContext bibDatabaseContext, - JabRefFrame frame, + LibraryTabContainer tabContainer, DialogService dialogService, PreferencesService preferencesService, StateManager stateManager, @@ -133,7 +135,7 @@ public LibraryTab(BibDatabaseContext bibDatabaseContext, BibEntryTypesManager entryTypesManager, CountingUndoManager undoManager, TaskExecutor taskExecutor) { - this.frame = Objects.requireNonNull(frame); + this.tabContainer = Objects.requireNonNull(tabContainer); this.bibDatabaseContext = Objects.requireNonNull(bibDatabaseContext); this.undoManager = undoManager; this.dialogService = dialogService; @@ -220,12 +222,12 @@ public Node createLoadingAnimationLayout() { public void onDatabaseLoadingStarted() { Node loadingLayout = createLoadingAnimationLayout(); getMainTable().placeholderProperty().setValue(loadingLayout); - frame.addTab(this, true); + tabContainer.addTab(this, true); } public void onDatabaseLoadingSucceed(ParserResult result) { BibDatabaseContext context = result.getDatabaseContext(); - OpenDatabaseAction.performPostOpenActions(this, result); + OpenDatabaseAction.performPostOpenActions(result, dialogService); feedData(context); @@ -411,10 +413,6 @@ public void setMode(BasePanelMode mode) { this.mode = mode; } - public JabRefFrame frame() { - return frame; - } - /** * Removes the selected entries from the database * @@ -469,12 +467,6 @@ public void insertEntry(final BibEntry bibEntry) { } } - /** - * This method is called from JabRefFrame when the user wants to create a new entry or entries. It is necessary when the user would expect the added entry or one of the added entries to be selected in the entry editor - * - * @param entries The new entries. - */ - public void insertEntries(final List entries) { if (!entries.isEmpty()) { bibDatabaseContext.getDatabase().insertEntries(entries); @@ -488,9 +480,9 @@ public void insertEntries(final List entries) { this.changedProperty.setValue(true); // The database just changed. if (preferencesService.getEntryEditorPreferences().shouldOpenOnNewEntry()) { - showAndEdit(entries.get(0)); + showAndEdit(entries.getFirst()); } - clearAndSelect(entries.get(0)); + clearAndSelect(entries.getFirst()); } } @@ -506,6 +498,7 @@ public void editEntryAndFocusField(BibEntry entry, Field field) { private void createMainTable() { mainTable = new MainTable(tableModel, this, + tabContainer, bibDatabaseContext, preferencesService, dialogService, @@ -558,21 +551,21 @@ public void setupMainPanel() { } /** - * Set up auto completion for this database + * Set up autocompletion for this database */ private void setupAutoCompletion() { AutoCompletePreferences autoCompletePreferences = preferencesService.getAutoCompletePreferences(); if (autoCompletePreferences.shouldAutoComplete()) { suggestionProviders = new SuggestionProviders(getDatabase(), Globals.journalAbbreviationRepository, autoCompletePreferences); } else { - // Create empty suggestion providers if auto completion is deactivated + // Create empty suggestion providers if auto-completion is deactivated suggestionProviders = new SuggestionProviders(); } searchAutoCompleter = new PersonNameSuggestionProvider(FieldFactory.getPersonNameFields(), getDatabase()); } - public void updateSearchManager() { - frame.getGlobalSearchBar().setAutoCompleter(searchAutoCompleter); + public SuggestionProvider getAutoCompleter() { + return searchAutoCompleter; } public EntryEditor getEntryEditor() { @@ -837,7 +830,7 @@ public static LibraryTab createLibraryTab(BackgroundTask dataLoadi DialogService dialogService, PreferencesService preferencesService, StateManager stateManager, - JabRefFrame frame, + LibraryTabContainer tabContainer, FileUpdateMonitor fileUpdateMonitor, BibEntryTypesManager entryTypesManager, CountingUndoManager undoManager, @@ -847,7 +840,7 @@ public static LibraryTab createLibraryTab(BackgroundTask dataLoadi LibraryTab newTab = new LibraryTab( context, - frame, + tabContainer, dialogService, preferencesService, stateManager, @@ -866,7 +859,7 @@ public static LibraryTab createLibraryTab(BackgroundTask dataLoadi } public static LibraryTab createLibraryTab(BibDatabaseContext databaseContext, - JabRefFrame frame, + LibraryTabContainer tabContainer, DialogService dialogService, PreferencesService preferencesService, StateManager stateManager, @@ -876,9 +869,9 @@ public static LibraryTab createLibraryTab(BibDatabaseContext databaseContext, TaskExecutor taskExecutor) { Objects.requireNonNull(databaseContext); - LibraryTab libraryTab = new LibraryTab( + return new LibraryTab( databaseContext, - frame, + tabContainer, dialogService, preferencesService, stateManager, @@ -886,8 +879,6 @@ public static LibraryTab createLibraryTab(BibDatabaseContext databaseContext, entryTypesManager, (CountingUndoManager) undoManager, taskExecutor); - - return libraryTab; } private class GroupTreeListener { diff --git a/src/main/java/org/jabref/gui/LibraryTabContainer.java b/src/main/java/org/jabref/gui/LibraryTabContainer.java index 4d3c504d503..c823e5c8892 100644 --- a/src/main/java/org/jabref/gui/LibraryTabContainer.java +++ b/src/main/java/org/jabref/gui/LibraryTabContainer.java @@ -5,8 +5,6 @@ import org.jabref.model.database.BibDatabaseContext; public interface LibraryTabContainer { - LibraryTab getLibraryTabAt(int i); - List getLibraryTabs(); LibraryTab getCurrentLibraryTab(); @@ -20,4 +18,9 @@ public interface LibraryTabContainer { void closeTab(LibraryTab libraryTab); void closeCurrentTab(); + + /** + * Refreshes the ui after changes to the preferences + */ + void refresh(); } diff --git a/src/main/java/org/jabref/gui/MainMenu.java b/src/main/java/org/jabref/gui/MainMenu.java index 589c740f448..c898417b927 100644 --- a/src/main/java/org/jabref/gui/MainMenu.java +++ b/src/main/java/org/jabref/gui/MainMenu.java @@ -133,9 +133,9 @@ private void createMenu() { factory.createMenuItem(StandardActions.NEW_LIBRARY, new NewDatabaseAction(frame, preferencesService)), factory.createMenuItem(StandardActions.OPEN_LIBRARY, frame.getOpenDatabaseAction()), frame.getFileHistory(), - factory.createMenuItem(StandardActions.SAVE_LIBRARY, new SaveAction(SaveAction.SaveMethod.SAVE, frame, dialogService, preferencesService, stateManager)), - factory.createMenuItem(StandardActions.SAVE_LIBRARY_AS, new SaveAction(SaveAction.SaveMethod.SAVE_AS, frame, dialogService, preferencesService, stateManager)), - factory.createMenuItem(StandardActions.SAVE_ALL, new SaveAllAction(frame, preferencesService)), + factory.createMenuItem(StandardActions.SAVE_LIBRARY, new SaveAction(SaveAction.SaveMethod.SAVE, frame::getCurrentLibraryTab, dialogService, preferencesService, stateManager)), + factory.createMenuItem(StandardActions.SAVE_LIBRARY_AS, new SaveAction(SaveAction.SaveMethod.SAVE_AS, frame::getCurrentLibraryTab, dialogService, preferencesService, stateManager)), + factory.createMenuItem(StandardActions.SAVE_ALL, new SaveAllAction(frame::getLibraryTabs, preferencesService, dialogService)), factory.createMenuItem(StandardActions.CLOSE_LIBRARY, new JabRefFrame.CloseDatabaseAction(frame)), new SeparatorMenuItem(), @@ -145,19 +145,19 @@ private void createMenu() { factory.createMenuItem(StandardActions.IMPORT_INTO_NEW_LIBRARY, new ImportCommand(frame, ImportCommand.ImportMethod.AS_NEW, preferencesService, stateManager, fileUpdateMonitor, taskExecutor, dialogService))), factory.createSubMenu(StandardActions.EXPORT, - factory.createMenuItem(StandardActions.EXPORT_ALL, new ExportCommand(ExportCommand.ExportMethod.EXPORT_ALL, frame, stateManager, dialogService, preferencesService, entryTypesManager, abbreviationRepository, taskExecutor)), - factory.createMenuItem(StandardActions.EXPORT_SELECTED, new ExportCommand(ExportCommand.ExportMethod.EXPORT_SELECTED, frame, stateManager, dialogService, preferencesService, entryTypesManager, abbreviationRepository, taskExecutor)), - factory.createMenuItem(StandardActions.SAVE_SELECTED_AS_PLAIN_BIBTEX, new SaveAction(SaveAction.SaveMethod.SAVE_SELECTED, frame, dialogService, preferencesService, stateManager))), + factory.createMenuItem(StandardActions.EXPORT_ALL, new ExportCommand(ExportCommand.ExportMethod.EXPORT_ALL, frame::getCurrentLibraryTab, stateManager, dialogService, preferencesService, entryTypesManager, abbreviationRepository, taskExecutor)), + factory.createMenuItem(StandardActions.EXPORT_SELECTED, new ExportCommand(ExportCommand.ExportMethod.EXPORT_SELECTED, frame::getCurrentLibraryTab, stateManager, dialogService, preferencesService, entryTypesManager, abbreviationRepository, taskExecutor)), + factory.createMenuItem(StandardActions.SAVE_SELECTED_AS_PLAIN_BIBTEX, new SaveAction(SaveAction.SaveMethod.SAVE_SELECTED, frame::getCurrentLibraryTab, dialogService, preferencesService, stateManager))), new SeparatorMenuItem(), factory.createSubMenu(StandardActions.REMOTE_DB, - factory.createMenuItem(StandardActions.CONNECT_TO_SHARED_DB, new ConnectToSharedDatabaseCommand(frame)), + factory.createMenuItem(StandardActions.CONNECT_TO_SHARED_DB, new ConnectToSharedDatabaseCommand(frame, dialogService)), factory.createMenuItem(StandardActions.PULL_CHANGES_FROM_SHARED_DB, new PullChangesFromSharedAction(stateManager))), new SeparatorMenuItem(), - factory.createMenuItem(StandardActions.SHOW_PREFS, new ShowPreferencesAction(frame)), + factory.createMenuItem(StandardActions.SHOW_PREFS, new ShowPreferencesAction(frame, dialogService)), new SeparatorMenuItem(), @@ -165,14 +165,14 @@ private void createMenu() { ); edit.getItems().addAll( - factory.createMenuItem(StandardActions.UNDO, new UndoRedoAction(StandardActions.UNDO, frame, dialogService, stateManager)), - factory.createMenuItem(StandardActions.REDO, new UndoRedoAction(StandardActions.REDO, frame, dialogService, stateManager)), + factory.createMenuItem(StandardActions.UNDO, new UndoRedoAction(StandardActions.UNDO, frame::getCurrentLibraryTab, dialogService, stateManager)), + factory.createMenuItem(StandardActions.REDO, new UndoRedoAction(StandardActions.REDO, frame::getCurrentLibraryTab, dialogService, stateManager)), new SeparatorMenuItem(), - factory.createMenuItem(StandardActions.CUT, new EditAction(StandardActions.CUT, frame, stateManager)), + factory.createMenuItem(StandardActions.CUT, new EditAction(StandardActions.CUT, frame::getCurrentLibraryTab, stateManager, undoManager)), - factory.createMenuItem(StandardActions.COPY, new EditAction(StandardActions.COPY, frame, stateManager)), + factory.createMenuItem(StandardActions.COPY, new EditAction(StandardActions.COPY, frame::getCurrentLibraryTab, stateManager, undoManager)), factory.createSubMenu(StandardActions.COPY_MORE, factory.createMenuItem(StandardActions.COPY_TITLE, new CopyMoreAction(StandardActions.COPY_TITLE, dialogService, stateManager, clipBoardManager, preferencesService, abbreviationRepository)), factory.createMenuItem(StandardActions.COPY_KEY, new CopyMoreAction(StandardActions.COPY_KEY, dialogService, stateManager, clipBoardManager, preferencesService, abbreviationRepository)), @@ -182,12 +182,12 @@ private void createMenu() { factory.createMenuItem(StandardActions.COPY_CITATION_PREVIEW, new CopyCitationAction(CitationStyleOutputFormat.HTML, dialogService, stateManager, clipBoardManager, taskExecutor, preferencesService, abbreviationRepository)), factory.createMenuItem(StandardActions.EXPORT_SELECTED_TO_CLIPBOARD, new ExportToClipboardAction(dialogService, stateManager, clipBoardManager, taskExecutor, preferencesService))), - factory.createMenuItem(StandardActions.PASTE, new EditAction(StandardActions.PASTE, frame, stateManager)), + factory.createMenuItem(StandardActions.PASTE, new EditAction(StandardActions.PASTE, frame::getCurrentLibraryTab, stateManager, undoManager)), new SeparatorMenuItem(), - factory.createMenuItem(StandardActions.REPLACE_ALL, new ReplaceStringAction(frame, stateManager)), - factory.createMenuItem(StandardActions.GENERATE_CITE_KEYS, new GenerateCitationKeyAction(frame, dialogService, stateManager, taskExecutor, preferencesService)), + factory.createMenuItem(StandardActions.REPLACE_ALL, new ReplaceStringAction(frame::getCurrentLibraryTab, stateManager, dialogService)), + factory.createMenuItem(StandardActions.GENERATE_CITE_KEYS, new GenerateCitationKeyAction(frame::getCurrentLibraryTab, dialogService, stateManager, taskExecutor, preferencesService, undoManager)), new SeparatorMenuItem(), @@ -200,12 +200,12 @@ private void createMenu() { specialFieldsSeparator, // ToDo: SpecialField needs the active BasePanel to mark it as changed. // Refactor BasePanel, should mark the BibDatabaseContext or the UndoManager as dirty instead! - SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.RANKING, factory, frame, dialogService, preferencesService, undoManager, stateManager), - SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.RELEVANCE, factory, frame, dialogService, preferencesService, undoManager, stateManager), - SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.QUALITY, factory, frame, dialogService, preferencesService, undoManager, stateManager), - SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.PRINTED, factory, frame, dialogService, preferencesService, undoManager, stateManager), - SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.PRIORITY, factory, frame, dialogService, preferencesService, undoManager, stateManager), - SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.READ_STATUS, factory, frame, dialogService, preferencesService, undoManager, stateManager)); + SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.RANKING, factory, frame::getCurrentLibraryTab, dialogService, preferencesService, undoManager, stateManager), + SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.RELEVANCE, factory, frame::getCurrentLibraryTab, dialogService, preferencesService, undoManager, stateManager), + SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.QUALITY, factory, frame::getCurrentLibraryTab, dialogService, preferencesService, undoManager, stateManager), + SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.PRINTED, factory, frame::getCurrentLibraryTab, dialogService, preferencesService, undoManager, stateManager), + SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.PRIORITY, factory, frame::getCurrentLibraryTab, dialogService, preferencesService, undoManager, stateManager), + SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.READ_STATUS, factory, frame::getCurrentLibraryTab, dialogService, preferencesService, undoManager, stateManager)); edit.addEventHandler(ActionEvent.ACTION, event -> { // Work around for mac only issue, where cmd+v on a dialogue triggers the paste action of menu item, resulting in addition of the pasted content in the MainTable. // If the mainscreen is not focused, the actions captured by menu are consumed. @@ -216,9 +216,9 @@ private void createMenu() { // @formatter:off library.getItems().addAll( - factory.createMenuItem(StandardActions.NEW_ENTRY, new NewEntryAction(frame, dialogService, preferencesService, stateManager)), + factory.createMenuItem(StandardActions.NEW_ENTRY, new NewEntryAction(frame::getCurrentLibraryTab, dialogService, preferencesService, stateManager)), factory.createMenuItem(StandardActions.NEW_ENTRY_FROM_PLAIN_TEXT, new ExtractBibtexAction(dialogService, preferencesService, stateManager)), - factory.createMenuItem(StandardActions.DELETE_ENTRY, new EditAction(StandardActions.DELETE_ENTRY, frame, stateManager)), + factory.createMenuItem(StandardActions.DELETE_ENTRY, new EditAction(StandardActions.DELETE_ENTRY, frame::getCurrentLibraryTab, stateManager, undoManager)), new SeparatorMenuItem(), @@ -226,10 +226,10 @@ private void createMenu() { ); quality.getItems().addAll( - factory.createMenuItem(StandardActions.FIND_DUPLICATES, new DuplicateSearch(frame, dialogService, stateManager, preferencesService, entryTypesManager, taskExecutor)), + factory.createMenuItem(StandardActions.FIND_DUPLICATES, new DuplicateSearch(frame::getCurrentLibraryTab, dialogService, stateManager, preferencesService, entryTypesManager, taskExecutor)), factory.createMenuItem(StandardActions.MERGE_ENTRIES, new MergeEntriesAction(dialogService, stateManager, preferencesService)), - factory.createMenuItem(StandardActions.CHECK_INTEGRITY, new IntegrityCheckAction(frame, preferencesService, dialogService, stateManager, taskExecutor, abbreviationRepository, predatoryJournalRepository)), - factory.createMenuItem(StandardActions.CLEANUP_ENTRIES, new CleanupAction(frame, preferencesService, dialogService, stateManager, taskExecutor)), + factory.createMenuItem(StandardActions.CHECK_INTEGRITY, new IntegrityCheckAction(frame::getCurrentLibraryTab, preferencesService, dialogService, stateManager, taskExecutor, abbreviationRepository, predatoryJournalRepository)), + factory.createMenuItem(StandardActions.CLEANUP_ENTRIES, new CleanupAction(frame::getCurrentLibraryTab, preferencesService, dialogService, stateManager, taskExecutor, undoManager)), new SeparatorMenuItem(), @@ -238,16 +238,16 @@ private void createMenu() { new SeparatorMenuItem(), factory.createSubMenu(StandardActions.ABBREVIATE, - factory.createMenuItem(StandardActions.ABBREVIATE_DEFAULT, new AbbreviateAction(StandardActions.ABBREVIATE_DEFAULT, frame, dialogService, stateManager, preferencesService.getJournalAbbreviationPreferences(), abbreviationRepository, taskExecutor)), - factory.createMenuItem(StandardActions.ABBREVIATE_DOTLESS, new AbbreviateAction(StandardActions.ABBREVIATE_DOTLESS, frame, dialogService, stateManager, preferencesService.getJournalAbbreviationPreferences(), abbreviationRepository, taskExecutor)), - factory.createMenuItem(StandardActions.ABBREVIATE_SHORTEST_UNIQUE, new AbbreviateAction(StandardActions.ABBREVIATE_SHORTEST_UNIQUE, frame, dialogService, stateManager, preferencesService.getJournalAbbreviationPreferences(), abbreviationRepository, taskExecutor))), + factory.createMenuItem(StandardActions.ABBREVIATE_DEFAULT, new AbbreviateAction(StandardActions.ABBREVIATE_DEFAULT, frame::getCurrentLibraryTab, dialogService, stateManager, preferencesService.getJournalAbbreviationPreferences(), abbreviationRepository, taskExecutor, undoManager)), + factory.createMenuItem(StandardActions.ABBREVIATE_DOTLESS, new AbbreviateAction(StandardActions.ABBREVIATE_DOTLESS, frame::getCurrentLibraryTab, dialogService, stateManager, preferencesService.getJournalAbbreviationPreferences(), abbreviationRepository, taskExecutor, undoManager)), + factory.createMenuItem(StandardActions.ABBREVIATE_SHORTEST_UNIQUE, new AbbreviateAction(StandardActions.ABBREVIATE_SHORTEST_UNIQUE, frame::getCurrentLibraryTab, dialogService, stateManager, preferencesService.getJournalAbbreviationPreferences(), abbreviationRepository, taskExecutor, undoManager))), - factory.createMenuItem(StandardActions.UNABBREVIATE, new AbbreviateAction(StandardActions.UNABBREVIATE, frame, dialogService, stateManager, preferencesService.getJournalAbbreviationPreferences(), abbreviationRepository, taskExecutor)) + factory.createMenuItem(StandardActions.UNABBREVIATE, new AbbreviateAction(StandardActions.UNABBREVIATE, frame::getCurrentLibraryTab, dialogService, stateManager, preferencesService.getJournalAbbreviationPreferences(), abbreviationRepository, taskExecutor, undoManager)) ); Menu lookupIdentifiers = factory.createSubMenu(StandardActions.LOOKUP_DOC_IDENTIFIER); for (IdFetcher fetcher : WebFetchers.getIdFetchers(preferencesService.getImportFormatPreferences())) { - LookupIdentifierAction identifierAction = new LookupIdentifierAction<>(frame, fetcher, stateManager, undoManager, taskExecutor); + LookupIdentifierAction identifierAction = new LookupIdentifierAction<>(fetcher, stateManager, undoManager, dialogService, taskExecutor); lookupIdentifiers.getItems().add(factory.createMenuItem(identifierAction.getAction(), identifierAction)); } @@ -265,7 +265,7 @@ private void createMenu() { tools.getItems().addAll( factory.createMenuItem(StandardActions.PARSE_LATEX, new ParseLatexAction(stateManager)), - factory.createMenuItem(StandardActions.NEW_SUB_LIBRARY_FROM_AUX, new NewSubLibraryAction(frame, stateManager)), + factory.createMenuItem(StandardActions.NEW_SUB_LIBRARY_FROM_AUX, new NewSubLibraryAction(frame, stateManager, dialogService)), new SeparatorMenuItem(), @@ -281,7 +281,7 @@ private void createMenu() { new SeparatorMenuItem(), // Systematic Literature Review (SLR) - factory.createMenuItem(StandardActions.START_NEW_STUDY, new StartNewStudyAction(frame, fileUpdateMonitor, taskExecutor, preferencesService, stateManager)), + factory.createMenuItem(StandardActions.START_NEW_STUDY, new StartNewStudyAction(frame, frame::getOpenDatabaseAction, fileUpdateMonitor, taskExecutor, preferencesService, stateManager, dialogService)), factory.createMenuItem(StandardActions.EDIT_EXISTING_STUDY, new EditExistingStudyAction(dialogService, stateManager)), factory.createMenuItem(StandardActions.UPDATE_SEARCH_RESULTS_OF_STUDY, new ExistingStudySearchAction(frame, frame.getOpenDatabaseAction(), dialogService, fileUpdateMonitor, taskExecutor, preferencesService, stateManager)), @@ -299,13 +299,13 @@ private void createMenu() { new SeparatorMenuItem(), - factory.createMenuItem(StandardActions.NEXT_PREVIEW_STYLE, new PreviewSwitchAction(PreviewSwitchAction.Direction.NEXT, frame, stateManager)), - factory.createMenuItem(StandardActions.PREVIOUS_PREVIEW_STYLE, new PreviewSwitchAction(PreviewSwitchAction.Direction.PREVIOUS, frame, stateManager)), + factory.createMenuItem(StandardActions.NEXT_PREVIEW_STYLE, new PreviewSwitchAction(PreviewSwitchAction.Direction.NEXT, frame::getCurrentLibraryTab, stateManager)), + factory.createMenuItem(StandardActions.PREVIOUS_PREVIEW_STYLE, new PreviewSwitchAction(PreviewSwitchAction.Direction.PREVIOUS, frame::getCurrentLibraryTab, stateManager)), new SeparatorMenuItem(), factory.createMenuItem(StandardActions.SHOW_PDF_VIEWER, new ShowDocumentViewerAction(stateManager, preferencesService)), - factory.createMenuItem(StandardActions.EDIT_ENTRY, new OpenEntryEditorAction(frame, stateManager)), + factory.createMenuItem(StandardActions.EDIT_ENTRY, new OpenEntryEditorAction(frame::getCurrentLibraryTab, stateManager)), factory.createMenuItem(StandardActions.OPEN_CONSOLE, new OpenConsoleAction(stateManager, preferencesService, dialogService)) ); diff --git a/src/main/java/org/jabref/gui/MainToolBar.java b/src/main/java/org/jabref/gui/MainToolBar.java index 1e89db1b724..1882b6a4ecf 100644 --- a/src/main/java/org/jabref/gui/MainToolBar.java +++ b/src/main/java/org/jabref/gui/MainToolBar.java @@ -44,7 +44,7 @@ import org.controlsfx.control.TaskProgressView; public class MainToolBar extends ToolBar { - private final JabRefFrame frame; + private final LibraryTabContainer frame; private final PushToApplicationCommand pushToApplicationCommand; private final GlobalSearchBar globalSearchBar; private final DialogService dialogService; @@ -58,7 +58,7 @@ public class MainToolBar extends ToolBar { private PopOver entryFromIdPopOver; private PopOver progressViewPopOver; - public MainToolBar(JabRefFrame frame, + public MainToolBar(LibraryTabContainer tabContainer, PushToApplicationCommand pushToApplicationCommand, GlobalSearchBar globalSearchBar, DialogService dialogService, @@ -68,7 +68,7 @@ public MainToolBar(JabRefFrame frame, TaskExecutor taskExecutor, BibEntryTypesManager entryTypesManager, CountingUndoManager undoManager) { - this.frame = frame; + this.frame = tabContainer; this.pushToApplicationCommand = pushToApplicationCommand; this.globalSearchBar = globalSearchBar; this.dialogService = dialogService; @@ -97,7 +97,7 @@ private void createToolBar() { new HBox( factory.createIconButton(StandardActions.NEW_LIBRARY, new NewDatabaseAction(frame, preferencesService)), factory.createIconButton(StandardActions.OPEN_LIBRARY, new OpenDatabaseAction(frame, preferencesService, dialogService, stateManager, fileUpdateMonitor, entryTypesManager, undoManager, taskExecutor)), - factory.createIconButton(StandardActions.SAVE_LIBRARY, new SaveAction(SaveAction.SaveMethod.SAVE, frame, dialogService, preferencesService, stateManager))), + factory.createIconButton(StandardActions.SAVE_LIBRARY, new SaveAction(SaveAction.SaveMethod.SAVE, frame::getCurrentLibraryTab, dialogService, preferencesService, stateManager))), leftSpacer, @@ -106,27 +106,27 @@ private void createToolBar() { rightSpacer, new HBox( - factory.createIconButton(StandardActions.NEW_ARTICLE, new NewEntryAction(frame, StandardEntryType.Article, dialogService, preferencesService, stateManager)), - factory.createIconButton(StandardActions.NEW_ENTRY, new NewEntryAction(frame, dialogService, preferencesService, stateManager)), + factory.createIconButton(StandardActions.NEW_ARTICLE, new NewEntryAction(frame::getCurrentLibraryTab, StandardEntryType.Article, dialogService, preferencesService, stateManager)), + factory.createIconButton(StandardActions.NEW_ENTRY, new NewEntryAction(frame::getCurrentLibraryTab, dialogService, preferencesService, stateManager)), createNewEntryFromIdButton(), factory.createIconButton(StandardActions.NEW_ENTRY_FROM_PLAIN_TEXT, new ExtractBibtexAction(dialogService, preferencesService, stateManager)), - factory.createIconButton(StandardActions.DELETE_ENTRY, new EditAction(StandardActions.DELETE_ENTRY, frame, stateManager))), + factory.createIconButton(StandardActions.DELETE_ENTRY, new EditAction(StandardActions.DELETE_ENTRY, frame::getCurrentLibraryTab, stateManager, undoManager))), new Separator(Orientation.VERTICAL), new HBox( - factory.createIconButton(StandardActions.UNDO, new UndoRedoAction(StandardActions.UNDO, frame, dialogService, stateManager)), - factory.createIconButton(StandardActions.REDO, new UndoRedoAction(StandardActions.REDO, frame, dialogService, stateManager)), - factory.createIconButton(StandardActions.CUT, new EditAction(StandardActions.CUT, frame, stateManager)), - factory.createIconButton(StandardActions.COPY, new EditAction(StandardActions.COPY, frame, stateManager)), - factory.createIconButton(StandardActions.PASTE, new EditAction(StandardActions.PASTE, frame, stateManager))), + factory.createIconButton(StandardActions.UNDO, new UndoRedoAction(StandardActions.UNDO, frame::getCurrentLibraryTab, dialogService, stateManager)), + factory.createIconButton(StandardActions.REDO, new UndoRedoAction(StandardActions.REDO, frame::getCurrentLibraryTab, dialogService, stateManager)), + factory.createIconButton(StandardActions.CUT, new EditAction(StandardActions.CUT, frame::getCurrentLibraryTab, stateManager, undoManager)), + factory.createIconButton(StandardActions.COPY, new EditAction(StandardActions.COPY, frame::getCurrentLibraryTab, stateManager, undoManager)), + factory.createIconButton(StandardActions.PASTE, new EditAction(StandardActions.PASTE, frame::getCurrentLibraryTab, stateManager, undoManager))), new Separator(Orientation.VERTICAL), new HBox( pushToApplicationButton, - factory.createIconButton(StandardActions.GENERATE_CITE_KEYS, new GenerateCitationKeyAction(frame, dialogService, stateManager, taskExecutor, preferencesService)), - factory.createIconButton(StandardActions.CLEANUP_ENTRIES, new CleanupAction(frame, preferencesService, dialogService, stateManager, taskExecutor))), + factory.createIconButton(StandardActions.GENERATE_CITE_KEYS, new GenerateCitationKeyAction(frame::getCurrentLibraryTab, dialogService, stateManager, taskExecutor, preferencesService, undoManager)), + factory.createIconButton(StandardActions.CLEANUP_ENTRIES, new CleanupAction(frame::getCurrentLibraryTab, preferencesService, dialogService, stateManager, taskExecutor, undoManager))), new Separator(Orientation.VERTICAL), diff --git a/src/main/java/org/jabref/gui/auximport/NewSubLibraryAction.java b/src/main/java/org/jabref/gui/auximport/NewSubLibraryAction.java index 65cc37abfd9..2af0171b5da 100644 --- a/src/main/java/org/jabref/gui/auximport/NewSubLibraryAction.java +++ b/src/main/java/org/jabref/gui/auximport/NewSubLibraryAction.java @@ -1,12 +1,10 @@ package org.jabref.gui.auximport; import org.jabref.gui.DialogService; -import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTabContainer; import org.jabref.gui.StateManager; import org.jabref.gui.actions.SimpleCommand; -import com.airhacks.afterburner.injection.Injector; - import static org.jabref.gui.actions.ActionHelper.needsDatabase; /** @@ -16,17 +14,18 @@ */ public class NewSubLibraryAction extends SimpleCommand { - private final JabRefFrame jabRefFrame; + private final LibraryTabContainer tabContainer; + private final DialogService dialogService; - public NewSubLibraryAction(JabRefFrame jabRefFrame, StateManager stateManager) { - this.jabRefFrame = jabRefFrame; + public NewSubLibraryAction(LibraryTabContainer tabContainer, StateManager stateManager, DialogService dialogService) { + this.tabContainer = tabContainer; + this.dialogService = dialogService; this.executable.bind(needsDatabase(stateManager)); } @Override public void execute() { - DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); - dialogService.showCustomDialogAndWait(new FromAuxDialog(jabRefFrame)); + dialogService.showCustomDialogAndWait(new FromAuxDialog(tabContainer)); } } diff --git a/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java b/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java index 5cc07a31c71..b5fd088e9d1 100644 --- a/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java +++ b/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java @@ -2,9 +2,12 @@ import java.util.List; import java.util.function.Consumer; +import java.util.function.Supplier; + +import javax.swing.undo.UndoManager; import org.jabref.gui.DialogService; -import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTab; import org.jabref.gui.StateManager; import org.jabref.gui.actions.ActionHelper; import org.jabref.gui.actions.SimpleCommand; @@ -20,7 +23,7 @@ public class GenerateCitationKeyAction extends SimpleCommand { - private final JabRefFrame frame; + private final Supplier tabSupplier; private final DialogService dialogService; private final StateManager stateManager; @@ -29,13 +32,20 @@ public class GenerateCitationKeyAction extends SimpleCommand { private final TaskExecutor taskExecutor; private final PreferencesService preferencesService; - - public GenerateCitationKeyAction(JabRefFrame frame, DialogService dialogService, StateManager stateManager, TaskExecutor taskExecutor, PreferencesService preferencesService) { - this.frame = frame; + private final UndoManager undoManager; + + public GenerateCitationKeyAction(Supplier tabSupplier, + DialogService dialogService, + StateManager stateManager, + TaskExecutor taskExecutor, + PreferencesService preferencesService, + UndoManager undoManager) { + this.tabSupplier = tabSupplier; this.dialogService = dialogService; this.stateManager = stateManager; this.taskExecutor = taskExecutor; this.preferencesService = preferencesService; + this.undoManager = undoManager; this.executable.bind(ActionHelper.needsEntriesSelected(stateManager)); } @@ -131,10 +141,10 @@ protected Void call() { public BackgroundTask onSuccess(Consumer onSuccess) { // register the undo event only if new citation keys were generated if (compound.hasEdits()) { - frame.getUndoManager().addEdit(compound); + undoManager.addEdit(compound); } - frame.getCurrentLibraryTab().markBaseChanged(); + tabSupplier.get().markBaseChanged(); dialogService.notify(formatOutputMessage(Localization.lang("Generated citation key for"), entries.size())); return super.onSuccess(onSuccess); } diff --git a/src/main/java/org/jabref/gui/cleanup/CleanupAction.java b/src/main/java/org/jabref/gui/cleanup/CleanupAction.java index 5cf61dceaee..f4f75a2ad74 100644 --- a/src/main/java/org/jabref/gui/cleanup/CleanupAction.java +++ b/src/main/java/org/jabref/gui/cleanup/CleanupAction.java @@ -2,9 +2,12 @@ import java.util.List; import java.util.Optional; +import java.util.function.Supplier; + +import javax.swing.undo.UndoManager; import org.jabref.gui.DialogService; -import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTab; import org.jabref.gui.StateManager; import org.jabref.gui.actions.ActionHelper; import org.jabref.gui.actions.SimpleCommand; @@ -22,25 +25,28 @@ public class CleanupAction extends SimpleCommand { - private final JabRefFrame frame; + private final Supplier tabSupplier; private final PreferencesService preferences; private final DialogService dialogService; private final StateManager stateManager; private final TaskExecutor taskExecutor; + private final UndoManager undoManager; private boolean isCanceled; private int modifiedEntriesCount; - public CleanupAction(JabRefFrame frame, + public CleanupAction(Supplier tabSupplier, PreferencesService preferences, DialogService dialogService, StateManager stateManager, - TaskExecutor taskExecutor) { - this.frame = frame; + TaskExecutor taskExecutor, + UndoManager undoManager) { + this.tabSupplier = tabSupplier; this.preferences = preferences; this.dialogService = dialogService; this.stateManager = stateManager; this.taskExecutor = taskExecutor; + this.undoManager = undoManager; this.executable.bind(ActionHelper.needsEntriesSelected(stateManager)); } @@ -118,8 +124,8 @@ private void showResults() { } if (modifiedEntriesCount > 0) { - frame.getCurrentLibraryTab().updateEntryEditorIfShowing(); - frame.getCurrentLibraryTab().markBaseChanged(); + tabSupplier.get().updateEntryEditorIfShowing(); + tabSupplier.get().markBaseChanged(); } if (modifiedEntriesCount == 0) { @@ -141,7 +147,7 @@ private void cleanup(BibDatabaseContext databaseContext, CleanupPreferences clea ce.end(); if (ce.hasEdits()) { modifiedEntriesCount++; - frame.getUndoManager().addEdit(ce); + undoManager.addEdit(ce); } } } diff --git a/src/main/java/org/jabref/gui/duplicationFinder/DuplicateSearch.java b/src/main/java/org/jabref/gui/duplicationFinder/DuplicateSearch.java index 0beda09fdf5..a6bb39a936f 100644 --- a/src/main/java/org/jabref/gui/duplicationFinder/DuplicateSearch.java +++ b/src/main/java/org/jabref/gui/duplicationFinder/DuplicateSearch.java @@ -10,6 +10,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Supplier; import javafx.beans.binding.Bindings; import javafx.beans.property.SimpleIntegerProperty; @@ -17,7 +18,6 @@ import org.jabref.gui.DialogService; import org.jabref.gui.JabRefExecutorService; -import org.jabref.gui.JabRefFrame; import org.jabref.gui.LibraryTab; import org.jabref.gui.StateManager; import org.jabref.gui.actions.SimpleCommand; @@ -41,7 +41,7 @@ public class DuplicateSearch extends SimpleCommand { - private final JabRefFrame frame; + private final Supplier tabSupplier; private final BlockingQueue> duplicates = new LinkedBlockingQueue<>(); private final AtomicBoolean libraryAnalyzed = new AtomicBoolean(); @@ -57,13 +57,13 @@ public class DuplicateSearch extends SimpleCommand { private final BibEntryTypesManager entryTypesManager; private final TaskExecutor taskExecutor; - public DuplicateSearch(JabRefFrame frame, + public DuplicateSearch(Supplier tabSupplier, DialogService dialogService, StateManager stateManager, PreferencesService prefs, BibEntryTypesManager entryTypesManager, TaskExecutor taskExecutor) { - this.frame = frame; + this.tabSupplier = tabSupplier; this.dialogService = dialogService; this.stateManager = stateManager; this.prefs = prefs; @@ -156,7 +156,7 @@ private DuplicateSearchResult verifyDuplicates() { } private void askResolveStrategy(DuplicateSearchResult result, BibEntry first, BibEntry second, DuplicateResolverType resolverType) { - DuplicateResolverDialog dialog = new DuplicateResolverDialog(first, second, resolverType, frame.getCurrentLibraryTab().getBibDatabaseContext(), stateManager, dialogService, prefs); + DuplicateResolverDialog dialog = new DuplicateResolverDialog(first, second, resolverType, tabSupplier.get().getBibDatabaseContext(), stateManager, dialogService, prefs); dialog.titleProperty().bind(Bindings.concat(dialog.getTitle()).concat(" (").concat(duplicateProgress.getValue()).concat("/").concat(duplicateTotal).concat(")")); @@ -189,7 +189,7 @@ private void handleDuplicates(DuplicateSearchResult result) { return; } - LibraryTab libraryTab = frame.getCurrentLibraryTab(); + LibraryTab libraryTab = tabSupplier.get(); final NamedCompound compoundEdit = new NamedCompound(Localization.lang("duplicate removal")); // Now, do the actual removal: if (!result.getToRemove().isEmpty()) { diff --git a/src/main/java/org/jabref/gui/edit/EditAction.java b/src/main/java/org/jabref/gui/edit/EditAction.java index b0daa482cb0..be8472a1585 100644 --- a/src/main/java/org/jabref/gui/edit/EditAction.java +++ b/src/main/java/org/jabref/gui/edit/EditAction.java @@ -1,9 +1,13 @@ package org.jabref.gui.edit; +import java.util.function.Supplier; + +import javax.swing.undo.UndoManager; + import javafx.scene.control.TextInputControl; import javafx.scene.web.WebView; -import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTab; import org.jabref.gui.StateManager; import org.jabref.gui.actions.ActionHelper; import org.jabref.gui.actions.SimpleCommand; @@ -21,14 +25,16 @@ public class EditAction extends SimpleCommand { private static final Logger LOGGER = LoggerFactory.getLogger(EditAction.class); - private final JabRefFrame frame; + private final Supplier tabSupplier; private final StandardActions action; private final StateManager stateManager; + private final UndoManager undoManager; - public EditAction(StandardActions action, JabRefFrame frame, StateManager stateManager) { + public EditAction(StandardActions action, Supplier tabSupplier, StateManager stateManager, UndoManager undoManager) { this.action = action; - this.frame = frame; + this.tabSupplier = tabSupplier; this.stateManager = stateManager; + this.undoManager = undoManager; if (action == StandardActions.PASTE) { this.executable.bind(ActionHelper.needsDatabase(stateManager)); @@ -72,18 +78,18 @@ public void execute() { // Not sure what is selected -> copy/paste/cut selected entries except for Preview and CodeArea switch (action) { - case COPY -> frame.getCurrentLibraryTab().copy(); - case CUT -> frame.getCurrentLibraryTab().cut(); - case PASTE -> frame.getCurrentLibraryTab().paste(); - case DELETE_ENTRY -> frame.getCurrentLibraryTab().delete(false); + case COPY -> tabSupplier.get().copy(); + case CUT -> tabSupplier.get().cut(); + case PASTE -> tabSupplier.get().paste(); + case DELETE_ENTRY -> tabSupplier.get().delete(false); case UNDO -> { - if (frame.getUndoManager().canUndo()) { - frame.getUndoManager().undo(); + if (undoManager.canUndo()) { + undoManager.undo(); } } case REDO -> { - if (frame.getUndoManager().canRedo()) { - frame.getUndoManager().redo(); + if (undoManager.canRedo()) { + undoManager.redo(); } } default -> LOGGER.debug("Only cut/copy/paste/deleteEntry supported but got: {} and focus owner {}", action, focusOwner); diff --git a/src/main/java/org/jabref/gui/edit/ReplaceStringAction.java b/src/main/java/org/jabref/gui/edit/ReplaceStringAction.java index bf7b7e579d0..8339b5db7f3 100644 --- a/src/main/java/org/jabref/gui/edit/ReplaceStringAction.java +++ b/src/main/java/org/jabref/gui/edit/ReplaceStringAction.java @@ -1,25 +1,26 @@ package org.jabref.gui.edit; +import java.util.function.Supplier; + import org.jabref.gui.DialogService; -import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTab; import org.jabref.gui.StateManager; import org.jabref.gui.actions.ActionHelper; import org.jabref.gui.actions.SimpleCommand; -import com.airhacks.afterburner.injection.Injector; - public class ReplaceStringAction extends SimpleCommand { - private final JabRefFrame frame; + private final Supplier tabSupplier; + private final DialogService dialogService; - public ReplaceStringAction(JabRefFrame frame, StateManager stateManager) { - this.frame = frame; + public ReplaceStringAction(Supplier tabSupplier, StateManager stateManager, DialogService dialogService) { + this.tabSupplier = tabSupplier; + this.dialogService = dialogService; this.executable.bind(ActionHelper.needsDatabase(stateManager)); } @Override public void execute() { - DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); - dialogService.showCustomDialogAndWait(new ReplaceStringView(frame.getCurrentLibraryTab())); + dialogService.showCustomDialogAndWait(new ReplaceStringView(tabSupplier.get())); } } diff --git a/src/main/java/org/jabref/gui/entryeditor/OpenEntryEditorAction.java b/src/main/java/org/jabref/gui/entryeditor/OpenEntryEditorAction.java index 4fe0a8101b4..36758215401 100644 --- a/src/main/java/org/jabref/gui/entryeditor/OpenEntryEditorAction.java +++ b/src/main/java/org/jabref/gui/entryeditor/OpenEntryEditorAction.java @@ -1,17 +1,19 @@ package org.jabref.gui.entryeditor; -import org.jabref.gui.JabRefFrame; +import java.util.function.Supplier; + +import org.jabref.gui.LibraryTab; import org.jabref.gui.StateManager; import org.jabref.gui.actions.ActionHelper; import org.jabref.gui.actions.SimpleCommand; public class OpenEntryEditorAction extends SimpleCommand { - private final JabRefFrame frame; + private final Supplier tabSupplier; private final StateManager stateManager; - public OpenEntryEditorAction(JabRefFrame frame, StateManager stateManager) { - this.frame = frame; + public OpenEntryEditorAction(Supplier tabSupplier, StateManager stateManager) { + this.tabSupplier = tabSupplier; this.stateManager = stateManager; this.executable.bind(ActionHelper.needsEntriesSelected(stateManager)); @@ -19,7 +21,7 @@ public OpenEntryEditorAction(JabRefFrame frame, StateManager stateManager) { public void execute() { if (!stateManager.getSelectedEntries().isEmpty()) { - frame.getCurrentLibraryTab().showAndEdit(stateManager.getSelectedEntries().get(0)); + tabSupplier.get().showAndEdit(stateManager.getSelectedEntries().getFirst()); } } } diff --git a/src/main/java/org/jabref/gui/entryeditor/PreviewSwitchAction.java b/src/main/java/org/jabref/gui/entryeditor/PreviewSwitchAction.java index 366adcc70f8..aa98a5b7e24 100644 --- a/src/main/java/org/jabref/gui/entryeditor/PreviewSwitchAction.java +++ b/src/main/java/org/jabref/gui/entryeditor/PreviewSwitchAction.java @@ -1,6 +1,8 @@ package org.jabref.gui.entryeditor; -import org.jabref.gui.JabRefFrame; +import java.util.function.Supplier; + +import org.jabref.gui.LibraryTab; import org.jabref.gui.StateManager; import org.jabref.gui.actions.SimpleCommand; @@ -10,11 +12,11 @@ public class PreviewSwitchAction extends SimpleCommand { public enum Direction { PREVIOUS, NEXT } - private final JabRefFrame frame; + private final Supplier tabSupplier; private final Direction direction; - public PreviewSwitchAction(Direction direction, JabRefFrame frame, StateManager stateManager) { - this.frame = frame; + public PreviewSwitchAction(Direction direction, Supplier tabSupplier, StateManager stateManager) { + this.tabSupplier = tabSupplier; this.direction = direction; this.executable.bind(needsDatabase(stateManager)); @@ -23,9 +25,9 @@ public PreviewSwitchAction(Direction direction, JabRefFrame frame, StateManager @Override public void execute() { if (direction == Direction.NEXT) { - frame.getCurrentLibraryTab().getEntryEditor().nextPreviewStyle(); + tabSupplier.get().getEntryEditor().nextPreviewStyle(); } else { - frame.getCurrentLibraryTab().getEntryEditor().previousPreviewStyle(); + tabSupplier.get().getEntryEditor().previousPreviewStyle(); } } } diff --git a/src/main/java/org/jabref/gui/exporter/ExportCommand.java b/src/main/java/org/jabref/gui/exporter/ExportCommand.java index 02e034ae763..ccf81b353ff 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCommand.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCommand.java @@ -5,13 +5,13 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; +import java.util.function.Supplier; import java.util.stream.Collectors; import javafx.stage.FileChooser; import javafx.util.Duration; import org.jabref.gui.DialogService; -import org.jabref.gui.JabRefFrame; import org.jabref.gui.LibraryTab; import org.jabref.gui.StateManager; import org.jabref.gui.actions.ActionHelper; @@ -46,7 +46,7 @@ public enum ExportMethod { EXPORT_ALL, EXPORT_SELECTED } private static final Logger LOGGER = LoggerFactory.getLogger(ExportCommand.class); private final ExportMethod exportMethod; - private final JabRefFrame frame; + private final Supplier tabSupplier; private final StateManager stateManager; private final PreferencesService preferences; private final DialogService dialogService; @@ -55,7 +55,7 @@ public enum ExportMethod { EXPORT_ALL, EXPORT_SELECTED } private final TaskExecutor taskExecutor; public ExportCommand(ExportMethod exportMethod, - JabRefFrame frame, + Supplier tabSupplier, StateManager stateManager, DialogService dialogService, PreferencesService preferences, @@ -63,7 +63,7 @@ public ExportCommand(ExportMethod exportMethod, JournalAbbreviationRepository abbreviationRepository, TaskExecutor taskExecutor) { this.exportMethod = exportMethod; - this.frame = frame; + this.tabSupplier = tabSupplier; this.stateManager = stateManager; this.preferences = preferences; this.dialogService = dialogService; @@ -96,7 +96,7 @@ public void execute() { } private void export(Path file, FileChooser.ExtensionFilter selectedExtensionFilter, List exporters) { - String selectedExtension = selectedExtensionFilter.getExtensions().get(0).replace("*", ""); + String selectedExtension = selectedExtensionFilter.getExtensions().getFirst().replace("*", ""); if (!file.endsWith(selectedExtension)) { FileUtil.addExtension(file, selectedExtension); } @@ -135,7 +135,7 @@ private void export(Path file, FileChooser.ExtensionFilter selectedExtensionFilt return null; // can not use BackgroundTask.wrap(Runnable) because Runnable.run() can't throw Exceptions }) .onSuccess(save -> { - LibraryTab.DatabaseNotification notificationPane = frame.getCurrentLibraryTab().getNotificationPane(); + LibraryTab.DatabaseNotification notificationPane = tabSupplier.get().getNotificationPane(); notificationPane.notify( IconTheme.JabRefIcons.FOLDER.getGraphicNode(), Localization.lang("Export operation finished successfully."), diff --git a/src/main/java/org/jabref/gui/exporter/SaveAction.java b/src/main/java/org/jabref/gui/exporter/SaveAction.java index 6f726729034..d4fe785f229 100644 --- a/src/main/java/org/jabref/gui/exporter/SaveAction.java +++ b/src/main/java/org/jabref/gui/exporter/SaveAction.java @@ -1,8 +1,10 @@ package org.jabref.gui.exporter; +import java.util.function.Supplier; + import org.jabref.gui.DialogService; import org.jabref.gui.Globals; -import org.jabref.gui.LibraryTabContainer; +import org.jabref.gui.LibraryTab; import org.jabref.gui.StateManager; import org.jabref.gui.actions.ActionHelper; import org.jabref.gui.actions.SimpleCommand; @@ -16,18 +18,18 @@ public class SaveAction extends SimpleCommand { public enum SaveMethod { SAVE, SAVE_AS, SAVE_SELECTED } private final SaveMethod saveMethod; - private final LibraryTabContainer tabContainer; + private final Supplier tabSupplier; private final DialogService dialogService; private final PreferencesService preferencesService; public SaveAction(SaveMethod saveMethod, - LibraryTabContainer tabContainer, + Supplier tabSupplier, DialogService dialogService, PreferencesService preferencesService, StateManager stateManager) { this.saveMethod = saveMethod; - this.tabContainer = tabContainer; + this.tabSupplier = tabSupplier; this.dialogService = dialogService; this.preferencesService = preferencesService; @@ -41,7 +43,7 @@ public SaveAction(SaveMethod saveMethod, @Override public void execute() { SaveDatabaseAction saveDatabaseAction = new SaveDatabaseAction( - tabContainer.getCurrentLibraryTab(), + tabSupplier.get(), dialogService, preferencesService, Globals.entryTypesManager); diff --git a/src/main/java/org/jabref/gui/exporter/SaveAllAction.java b/src/main/java/org/jabref/gui/exporter/SaveAllAction.java index eb86c5df658..173de40ed0b 100644 --- a/src/main/java/org/jabref/gui/exporter/SaveAllAction.java +++ b/src/main/java/org/jabref/gui/exporter/SaveAllAction.java @@ -1,8 +1,10 @@ package org.jabref.gui.exporter; +import java.util.List; +import java.util.function.Supplier; + import org.jabref.gui.DialogService; import org.jabref.gui.Globals; -import org.jabref.gui.JabRefFrame; import org.jabref.gui.LibraryTab; import org.jabref.gui.actions.SimpleCommand; import org.jabref.logic.l10n.Localization; @@ -10,13 +12,13 @@ public class SaveAllAction extends SimpleCommand { - private final JabRefFrame frame; + private final Supplier> tabsSupplier; private final DialogService dialogService; private final PreferencesService preferencesService; - public SaveAllAction(JabRefFrame frame, PreferencesService preferencesService) { - this.frame = frame; - this.dialogService = frame.getDialogService(); + public SaveAllAction(Supplier> tabsSupplier, PreferencesService preferencesService, DialogService dialogService) { + this.tabsSupplier = tabsSupplier; + this.dialogService = dialogService; this.preferencesService = preferencesService; } @@ -24,7 +26,7 @@ public SaveAllAction(JabRefFrame frame, PreferencesService preferencesService) { public void execute() { dialogService.notify(Localization.lang("Saving all libraries...")); - for (LibraryTab libraryTab : frame.getLibraryTabs()) { + for (LibraryTab libraryTab : tabsSupplier.get()) { SaveDatabaseAction saveDatabaseAction = new SaveDatabaseAction(libraryTab, dialogService, preferencesService, Globals.entryTypesManager); boolean saveResult = saveDatabaseAction.save(); if (!saveResult) { diff --git a/src/main/java/org/jabref/gui/importer/GenerateEntryFromIdAction.java b/src/main/java/org/jabref/gui/importer/GenerateEntryFromIdAction.java index d6e36a5d1eb..22e520231b7 100644 --- a/src/main/java/org/jabref/gui/importer/GenerateEntryFromIdAction.java +++ b/src/main/java/org/jabref/gui/importer/GenerateEntryFromIdAction.java @@ -78,12 +78,11 @@ public void execute() { if (dialogService.showConfirmationDialogAndWait(Localization.lang("Failed to import by ID"), msg, Localization.lang("Add entry manually"))) { // add entry manually - new NewEntryAction(libraryTab.frame(), StandardEntryType.Article, dialogService, + new NewEntryAction(() -> libraryTab, StandardEntryType.Article, dialogService, preferencesService, stateManager).execute(); } }); - backgroundTask.onSuccess(bibEntry -> { - Optional result = bibEntry; + backgroundTask.onSuccess(result -> { if (result.isPresent()) { final BibEntry entry = result.get(); ImportHandler handler = new ImportHandler( diff --git a/src/main/java/org/jabref/gui/importer/ImportCommand.java b/src/main/java/org/jabref/gui/importer/ImportCommand.java index fd74e7a5199..14159adb9e5 100644 --- a/src/main/java/org/jabref/gui/importer/ImportCommand.java +++ b/src/main/java/org/jabref/gui/importer/ImportCommand.java @@ -12,8 +12,8 @@ import javafx.stage.FileChooser; import org.jabref.gui.DialogService; -import org.jabref.gui.JabRefFrame; import org.jabref.gui.LibraryTab; +import org.jabref.gui.LibraryTabContainer; import org.jabref.gui.StateManager; import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.util.BackgroundTask; @@ -48,7 +48,7 @@ public class ImportCommand extends SimpleCommand { public enum ImportMethod { AS_NEW, TO_EXISTING } - private final JabRefFrame frame; + private final LibraryTabContainer tabContainer; private final ImportMethod importMethod; private final DialogService dialogService; @@ -56,14 +56,14 @@ public enum ImportMethod { AS_NEW, TO_EXISTING } private final FileUpdateMonitor fileUpdateMonitor; private final TaskExecutor taskExecutor; - public ImportCommand(JabRefFrame frame, + public ImportCommand(LibraryTabContainer tabContainer, ImportMethod importMethod, PreferencesService preferencesService, StateManager stateManager, FileUpdateMonitor fileUpdateMonitor, TaskExecutor taskExecutor, DialogService dialogService) { - this.frame = frame; + this.tabContainer = tabContainer; this.importMethod = importMethod; this.preferencesService = preferencesService; this.fileUpdateMonitor = fileUpdateMonitor; @@ -107,7 +107,7 @@ private void importSingleFile(Path file, SortedSet importers, FileChoo if (importMethod == ImportMethod.AS_NEW) { task.onSuccess(parserResult -> { - frame.addTab(parserResult.getDatabaseContext(), true); + tabContainer.addTab(parserResult.getDatabaseContext(), true); dialogService.notify(Localization.lang("Imported entries") + ": " + parserResult.getDatabase().getEntries().size()); }) .onFailure(ex -> { @@ -116,7 +116,7 @@ private void importSingleFile(Path file, SortedSet importers, FileChoo }) .executeWith(taskExecutor); } else { - final LibraryTab libraryTab = frame.getCurrentLibraryTab(); + final LibraryTab libraryTab = tabContainer.getCurrentLibraryTab(); ImportEntriesDialog dialog = new ImportEntriesDialog(libraryTab.getBibDatabaseContext(), task); dialog.setTitle(Localization.lang("Import")); diff --git a/src/main/java/org/jabref/gui/importer/NewDatabaseAction.java b/src/main/java/org/jabref/gui/importer/NewDatabaseAction.java index f45cbbd2a70..d38a335ec3d 100644 --- a/src/main/java/org/jabref/gui/importer/NewDatabaseAction.java +++ b/src/main/java/org/jabref/gui/importer/NewDatabaseAction.java @@ -1,6 +1,6 @@ package org.jabref.gui.importer; -import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTabContainer; import org.jabref.gui.actions.SimpleCommand; import org.jabref.model.database.BibDatabaseContext; import org.jabref.preferences.PreferencesService; @@ -10,17 +10,17 @@ */ public class NewDatabaseAction extends SimpleCommand { - private final JabRefFrame jabRefFrame; + private final LibraryTabContainer tabContainer; private final PreferencesService preferencesService; /** * Constructs a command to create a new library of the default type * - * @param jabRefFrame the application frame of JabRef + * @param tabContainer the ui container for libraries * @param preferencesService the preferencesService of JabRef */ - public NewDatabaseAction(JabRefFrame jabRefFrame, PreferencesService preferencesService) { - this.jabRefFrame = jabRefFrame; + public NewDatabaseAction(LibraryTabContainer tabContainer, PreferencesService preferencesService) { + this.tabContainer = tabContainer; this.preferencesService = preferencesService; } @@ -28,6 +28,6 @@ public NewDatabaseAction(JabRefFrame jabRefFrame, PreferencesService preferences public void execute() { BibDatabaseContext bibDatabaseContext = new BibDatabaseContext(); bibDatabaseContext.setMode(preferencesService.getLibraryPreferences().getDefaultBibDatabaseMode()); - jabRefFrame.addTab(bibDatabaseContext, true); + tabContainer.addTab(bibDatabaseContext, true); } } diff --git a/src/main/java/org/jabref/gui/importer/NewEntryAction.java b/src/main/java/org/jabref/gui/importer/NewEntryAction.java index 4086cec912f..4737211f7fb 100644 --- a/src/main/java/org/jabref/gui/importer/NewEntryAction.java +++ b/src/main/java/org/jabref/gui/importer/NewEntryAction.java @@ -3,12 +3,14 @@ import java.util.HashMap; import java.util.Map; import java.util.Optional; +import java.util.function.Supplier; import org.jabref.gui.DialogService; import org.jabref.gui.EntryTypeView; -import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTab; import org.jabref.gui.StateManager; import org.jabref.gui.Telemetry; +import org.jabref.gui.actions.ActionHelper; import org.jabref.gui.actions.SimpleCommand; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.types.EntryType; @@ -17,13 +19,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.jabref.gui.actions.ActionHelper.needsDatabase; - public class NewEntryAction extends SimpleCommand { private static final Logger LOGGER = LoggerFactory.getLogger(NewEntryAction.class); - private final JabRefFrame jabRefFrame; + private final Supplier tabSupplier; /** * The type of the entry to create. @@ -34,39 +34,39 @@ public class NewEntryAction extends SimpleCommand { private final PreferencesService preferences; - public NewEntryAction(JabRefFrame jabRefFrame, DialogService dialogService, PreferencesService preferences, StateManager stateManager) { - this.jabRefFrame = jabRefFrame; + public NewEntryAction(Supplier tabSupplier, DialogService dialogService, PreferencesService preferences, StateManager stateManager) { + this.tabSupplier = tabSupplier; this.dialogService = dialogService; this.preferences = preferences; this.type = Optional.empty(); - this.executable.bind(needsDatabase(stateManager)); + this.executable.bind(ActionHelper.needsDatabase(stateManager)); } - public NewEntryAction(JabRefFrame jabRefFrame, EntryType type, DialogService dialogService, PreferencesService preferences, StateManager stateManager) { - this(jabRefFrame, dialogService, preferences, stateManager); + public NewEntryAction(Supplier tabSupplier, EntryType type, DialogService dialogService, PreferencesService preferences, StateManager stateManager) { + this(tabSupplier, dialogService, preferences, stateManager); this.type = Optional.of(type); } @Override public void execute() { - if (jabRefFrame.getBasePanelCount() <= 0) { + if (tabSupplier.get() == null) { LOGGER.error("Action 'New entry' must be disabled when no database is open."); return; } if (type.isPresent()) { - jabRefFrame.getCurrentLibraryTab().insertEntry(new BibEntry(type.get())); + tabSupplier.get().insertEntry(new BibEntry(type.get())); } else { - EntryTypeView typeChoiceDialog = new EntryTypeView(jabRefFrame.getCurrentLibraryTab(), dialogService, preferences); + EntryTypeView typeChoiceDialog = new EntryTypeView(tabSupplier.get(), dialogService, preferences); EntryType selectedType = dialogService.showCustomDialogAndWait(typeChoiceDialog).orElse(null); if (selectedType == null) { return; } trackNewEntry(selectedType); - jabRefFrame.getCurrentLibraryTab().insertEntry(new BibEntry(selectedType)); + tabSupplier.get().insertEntry(new BibEntry(selectedType)); } } diff --git a/src/main/java/org/jabref/gui/importer/ParserResultWarningDialog.java b/src/main/java/org/jabref/gui/importer/ParserResultWarningDialog.java index ec07cbc93b4..9605654a7e3 100644 --- a/src/main/java/org/jabref/gui/importer/ParserResultWarningDialog.java +++ b/src/main/java/org/jabref/gui/importer/ParserResultWarningDialog.java @@ -3,7 +3,7 @@ import java.util.List; import java.util.Objects; -import org.jabref.gui.JabRefFrame; +import org.jabref.gui.DialogService; import org.jabref.logic.importer.ParserResult; import org.jabref.logic.l10n.Localization; @@ -15,39 +15,19 @@ public class ParserResultWarningDialog { private ParserResultWarningDialog() { } - /** - * Shows a dialog with the warnings from an import or open of a file - * - * @param parserResult - ParserResult for the current import/open - * @param jabRefFrame - the JabRefFrame - */ - public static void showParserResultWarningDialog(final ParserResult parserResult, final JabRefFrame jabRefFrame) { - Objects.requireNonNull(parserResult); - Objects.requireNonNull(jabRefFrame); - showParserResultWarningDialog(parserResult, jabRefFrame, -1); - } - /** * Shows a dialog with the warnings from an import or open of a file * * @param parserResult - ParserResult for the current import/open - * @param jabRefFrame - the JabRefFrame - * @param dataBaseNumber - Database tab number to activate when showing the warning dialog */ - public static void showParserResultWarningDialog(final ParserResult parserResult, final JabRefFrame jabRefFrame, - final int dataBaseNumber) { + public static void showParserResultWarningDialog(final ParserResult parserResult, + final DialogService dialogService) { Objects.requireNonNull(parserResult); - Objects.requireNonNull(jabRefFrame); // Return if no warnings if (!(parserResult.hasWarnings())) { return; } - // Switch tab if asked to do so - if (dataBaseNumber >= 0) { - jabRefFrame.showLibraryTabAt(dataBaseNumber); - } - // Generate string with warning texts final List warnings = parserResult.warnings(); final StringBuilder dialogContent = new StringBuilder(); @@ -59,13 +39,13 @@ public static void showParserResultWarningDialog(final ParserResult parserResult // Generate dialog title String dialogTitle; - if (dataBaseNumber < 0 || parserResult.getPath().isEmpty()) { + if (parserResult.getPath().isEmpty()) { dialogTitle = Localization.lang("Warnings"); } else { dialogTitle = Localization.lang("Warnings") + " (" + parserResult.getPath().get().getFileName() + ")"; } // Show dialog - jabRefFrame.getDialogService().showWarningDialogAndWait(dialogTitle, dialogContent.toString()); + dialogService.showWarningDialogAndWait(dialogTitle, dialogContent.toString()); } } diff --git a/src/main/java/org/jabref/gui/importer/actions/CheckForNewEntryTypesAction.java b/src/main/java/org/jabref/gui/importer/actions/CheckForNewEntryTypesAction.java index c1e0208a65e..56da949dcc6 100644 --- a/src/main/java/org/jabref/gui/importer/actions/CheckForNewEntryTypesAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/CheckForNewEntryTypesAction.java @@ -5,14 +5,11 @@ import org.jabref.gui.DialogService; import org.jabref.gui.Globals; -import org.jabref.gui.LibraryTab; import org.jabref.gui.importer.ImportCustomEntryTypesDialog; import org.jabref.logic.importer.ParserResult; import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntryType; -import com.airhacks.afterburner.injection.Injector; - /** * This action checks whether any new custom entry types were loaded from this * BIB file. If so, an offer to remember these entry types is given. @@ -25,9 +22,8 @@ public boolean isActionNecessary(ParserResult parserResult) { } @Override - public void performAction(LibraryTab libraryTab, ParserResult parserResult) { + public void performAction(ParserResult parserResult, DialogService dialogService) { BibDatabaseMode mode = getBibDatabaseModeFromParserResult(parserResult); - DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); dialogService.showCustomDialogAndWait(new ImportCustomEntryTypesDialog(mode, getListOfUnknownAndUnequalCustomizations(parserResult))); } diff --git a/src/main/java/org/jabref/gui/importer/actions/GUIPostOpenAction.java b/src/main/java/org/jabref/gui/importer/actions/GUIPostOpenAction.java index cc943956861..cc73f61c92c 100644 --- a/src/main/java/org/jabref/gui/importer/actions/GUIPostOpenAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/GUIPostOpenAction.java @@ -1,6 +1,6 @@ package org.jabref.gui.importer.actions; -import org.jabref.gui.LibraryTab; +import org.jabref.gui.DialogService; import org.jabref.logic.importer.ParserResult; /** @@ -31,8 +31,7 @@ public interface GUIPostOpenAction { * important that all implementations of this method do not return * until the operation is finished. * - * @param panel The BasePanel where the database is shown. * @param pr The result of the BIB parse operation. */ - void performAction(LibraryTab panel, ParserResult pr); + void performAction(ParserResult pr, DialogService dialogService); } diff --git a/src/main/java/org/jabref/gui/importer/actions/MergeReviewIntoCommentAction.java b/src/main/java/org/jabref/gui/importer/actions/MergeReviewIntoCommentAction.java index a8bb0a453f1..638692e9d1a 100644 --- a/src/main/java/org/jabref/gui/importer/actions/MergeReviewIntoCommentAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/MergeReviewIntoCommentAction.java @@ -2,7 +2,7 @@ import java.util.List; -import org.jabref.gui.LibraryTab; +import org.jabref.gui.DialogService; import org.jabref.logic.importer.ParserResult; import org.jabref.migrations.MergeReviewIntoCommentMigration; import org.jabref.model.entry.BibEntry; @@ -15,12 +15,12 @@ public boolean isActionNecessary(ParserResult parserResult) { } @Override - public void performAction(LibraryTab libraryTab, ParserResult parserResult) { + public void performAction(ParserResult parserResult, DialogService dialogService) { MergeReviewIntoCommentMigration migration = new MergeReviewIntoCommentMigration(); migration.performMigration(parserResult); List conflicts = MergeReviewIntoCommentMigration.collectConflicts(parserResult); - if (!conflicts.isEmpty() && new MergeReviewIntoCommentConfirmationDialog(libraryTab.frame().getDialogService()).askUserForMerge(conflicts)) { + if (!conflicts.isEmpty() && new MergeReviewIntoCommentConfirmationDialog(dialogService).askUserForMerge(conflicts)) { migration.performConflictingMigration(parserResult); } } diff --git a/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java b/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java index 4e2854ba764..af295f03a19 100644 --- a/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java @@ -14,8 +14,8 @@ import javax.swing.undo.UndoManager; import org.jabref.gui.DialogService; -import org.jabref.gui.JabRefFrame; import org.jabref.gui.LibraryTab; +import org.jabref.gui.LibraryTabContainer; import org.jabref.gui.StateManager; import org.jabref.gui.Telemetry; import org.jabref.gui.actions.SimpleCommand; @@ -56,7 +56,7 @@ public class OpenDatabaseAction extends SimpleCommand { // Check for new custom entry types loaded from the BIB file: new CheckForNewEntryTypesAction()); - private final JabRefFrame frame; + private final LibraryTabContainer tabContainer; private final PreferencesService preferencesService; private final StateManager stateManager; private final FileUpdateMonitor fileUpdateMonitor; @@ -65,7 +65,7 @@ public class OpenDatabaseAction extends SimpleCommand { private final CountingUndoManager undoManager; private final TaskExecutor taskExecutor; - public OpenDatabaseAction(JabRefFrame frame, + public OpenDatabaseAction(LibraryTabContainer tabContainer, PreferencesService preferencesService, DialogService dialogService, StateManager stateManager, @@ -73,7 +73,7 @@ public OpenDatabaseAction(JabRefFrame frame, BibEntryTypesManager entryTypesManager, CountingUndoManager undoManager, TaskExecutor taskExecutor) { - this.frame = frame; + this.tabContainer = tabContainer; this.preferencesService = preferencesService; this.dialogService = dialogService; this.stateManager = stateManager; @@ -86,14 +86,12 @@ public OpenDatabaseAction(JabRefFrame frame, /** * Go through the list of post open actions, and perform those that need to be performed. * - * @param libraryTab The BasePanel where the database is shown. * @param result The result of the BIB file parse operation. */ - public static void performPostOpenActions(LibraryTab libraryTab, ParserResult result) { + public static void performPostOpenActions(ParserResult result, DialogService dialogService) { for (GUIPostOpenAction action : OpenDatabaseAction.POST_OPEN_ACTIONS) { if (action.isActionNecessary(result)) { - action.performAction(libraryTab, result); - libraryTab.frame().showLibraryTab(libraryTab); + action.performAction(result, dialogService); } } } @@ -114,10 +112,10 @@ public void execute() { * @return Path of current panel database directory or the working directory */ private Path getInitialDirectory() { - if (frame.getLibraryTabs().isEmpty()) { + if (tabContainer.getLibraryTabs().isEmpty()) { return preferencesService.getFilePreferences().getWorkingDirectory(); } else { - Optional databasePath = frame.getCurrentLibraryTab().getBibDatabaseContext().getDatabasePath(); + Optional databasePath = tabContainer.getCurrentLibraryTab().getBibDatabaseContext().getDatabasePath(); return databasePath.map(Path::getParent).orElse(preferencesService.getFilePreferences().getWorkingDirectory()); } } @@ -146,8 +144,7 @@ public void openFiles(List filesToOpen) { // Check if any of the files are already open: for (Iterator iterator = filesToOpen.iterator(); iterator.hasNext(); ) { Path file = iterator.next(); - for (int i = 0; i < frame.getLibraryTabs().size(); i++) { - LibraryTab libraryTab = frame.getLibraryTabAt(i); + for (LibraryTab libraryTab : tabContainer.getLibraryTabs()) { if ((libraryTab.getBibDatabaseContext().getDatabasePath().isPresent()) && libraryTab.getBibDatabaseContext().getDatabasePath().get().equals(file)) { iterator.remove(); @@ -175,7 +172,7 @@ public void openFiles(List filesToOpen) { } else if (toRaise != null) { // If no files are remaining to open, this could mean that a file was // already open. If so, we may have to raise the correct tab: - frame.showLibraryTab(toRaise); + tabContainer.showLibraryTab(toRaise); } } @@ -198,7 +195,7 @@ private void openTheFile(Path file) { dialogService, preferencesService, stateManager, - frame, + tabContainer, fileUpdateMonitor, entryTypesManager, undoManager, @@ -244,7 +241,7 @@ private ParserResult loadDatabase(Path file) throws Exception { if (parserResult.getDatabase().isShared()) { openSharedDatabase( parserResult, - frame, + tabContainer, dialogService, preferencesService, stateManager, @@ -264,7 +261,7 @@ private void trackOpenNewDatabase(LibraryTab libraryTab) { } public static void openSharedDatabase(ParserResult parserResult, - JabRefFrame frame, + LibraryTabContainer tabContainer, DialogService dialogService, PreferencesService preferencesService, StateManager stateManager, @@ -275,7 +272,7 @@ public static void openSharedDatabase(ParserResult parserResult, throws SQLException, DatabaseNotSupportedException, InvalidDBMSConnectionPropertiesException, NotASharedDatabaseException { try { new SharedDatabaseUIManager( - frame, + tabContainer, dialogService, preferencesService, stateManager, diff --git a/src/main/java/org/jabref/gui/importer/fetcher/LookupIdentifierAction.java b/src/main/java/org/jabref/gui/importer/fetcher/LookupIdentifierAction.java index 745006517fa..f3a0242c915 100644 --- a/src/main/java/org/jabref/gui/importer/fetcher/LookupIdentifierAction.java +++ b/src/main/java/org/jabref/gui/importer/fetcher/LookupIdentifierAction.java @@ -5,7 +5,7 @@ import javax.swing.undo.UndoManager; -import org.jabref.gui.JabRefFrame; +import org.jabref.gui.DialogService; import org.jabref.gui.StateManager; import org.jabref.gui.actions.Action; import org.jabref.gui.actions.SimpleCommand; @@ -32,22 +32,21 @@ public class LookupIdentifierAction extends SimpleCommand private static final Logger LOGGER = LoggerFactory.getLogger(LookupIdentifierAction.class); - private final JabRefFrame frame; - private final IdFetcher fetcher; private final StateManager stateManager; private final UndoManager undoManager; + private final DialogService dialogService; private final TaskExecutor taskExecutor; - public LookupIdentifierAction(JabRefFrame frame, - IdFetcher fetcher, + public LookupIdentifierAction(IdFetcher fetcher, StateManager stateManager, UndoManager undoManager, + DialogService dialogService, TaskExecutor taskExecutor) { - this.frame = frame; this.fetcher = fetcher; this.stateManager = stateManager; this.undoManager = undoManager; + this.dialogService = dialogService; this.taskExecutor = taskExecutor; this.executable.bind(needsDatabase(this.stateManager).and(needsEntriesSelected(this.stateManager))); @@ -58,7 +57,7 @@ public LookupIdentifierAction(JabRefFrame frame, public void execute() { try { BackgroundTask.wrap(() -> lookupIdentifiers(stateManager.getSelectedEntries())) - .onSuccess(frame.getDialogService()::notify) + .onSuccess(dialogService::notify) .executeWith(taskExecutor); } catch (Exception e) { LOGGER.error("Problem running ID Worker", e); @@ -78,7 +77,7 @@ private String lookupIdentifiers(List bibEntries) { count++; final String statusMessage = Localization.lang("Looking up %0... - entry %1 out of %2 - found %3", fetcher.getIdentifierName(), Integer.toString(count), totalCount, Integer.toString(foundCount)); - DefaultTaskExecutor.runInJavaFXThread(() -> frame.getDialogService().notify(statusMessage)); + DefaultTaskExecutor.runInJavaFXThread(() -> dialogService.notify(statusMessage)); Optional identifier = Optional.empty(); try { identifier = fetcher.findIdentifier(bibEntry); @@ -92,7 +91,7 @@ private String lookupIdentifiers(List bibEntries) { foundCount++; final String nextStatusMessage = Localization.lang("Looking up %0... - entry %1 out of %2 - found %3", fetcher.getIdentifierName(), Integer.toString(count), totalCount, Integer.toString(foundCount)); - DefaultTaskExecutor.runInJavaFXThread(() -> frame.getDialogService().notify(nextStatusMessage)); + DefaultTaskExecutor.runInJavaFXThread(() -> dialogService.notify(nextStatusMessage)); } } } diff --git a/src/main/java/org/jabref/gui/integrity/IntegrityCheckAction.java b/src/main/java/org/jabref/gui/integrity/IntegrityCheckAction.java index 0acf35de17a..472efce865e 100644 --- a/src/main/java/org/jabref/gui/integrity/IntegrityCheckAction.java +++ b/src/main/java/org/jabref/gui/integrity/IntegrityCheckAction.java @@ -2,12 +2,13 @@ import java.util.ArrayList; import java.util.List; +import java.util.function.Supplier; import javafx.collections.ObservableList; import javafx.concurrent.Task; import org.jabref.gui.DialogService; -import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTab; import org.jabref.gui.StateManager; import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.util.TaskExecutor; @@ -26,20 +27,20 @@ public class IntegrityCheckAction extends SimpleCommand { private final TaskExecutor taskExecutor; private final DialogService dialogService; - private final JabRefFrame frame; + private final Supplier tabSupplier; private final PreferencesService preferencesService; private final StateManager stateManager; private final JournalAbbreviationRepository abbreviationRepository; private final PredatoryJournalRepository predatoryJournalRepository; - public IntegrityCheckAction(JabRefFrame frame, + public IntegrityCheckAction(Supplier tabSupplier, PreferencesService preferencesService, DialogService dialogService, StateManager stateManager, TaskExecutor taskExecutor, JournalAbbreviationRepository abbreviationRepository, PredatoryJournalRepository predatoryJournalRepository) { - this.frame = frame; + this.tabSupplier = tabSupplier; this.stateManager = stateManager; this.taskExecutor = taskExecutor; this.preferencesService = preferencesService; @@ -83,7 +84,7 @@ protected List call() { if (messages.isEmpty()) { dialogService.notify(Localization.lang("No problems found.")); } else { - dialogService.showCustomDialogAndWait(new IntegrityCheckDialog(messages, frame.getCurrentLibraryTab())); + dialogService.showCustomDialogAndWait(new IntegrityCheckDialog(messages, tabSupplier.get())); } }); task.setOnFailed(event -> dialogService.showErrorDialogAndWait("Integrity check failed.", task.getException())); diff --git a/src/main/java/org/jabref/gui/journals/AbbreviateAction.java b/src/main/java/org/jabref/gui/journals/AbbreviateAction.java index a1a723287d9..c876418fc4e 100644 --- a/src/main/java/org/jabref/gui/journals/AbbreviateAction.java +++ b/src/main/java/org/jabref/gui/journals/AbbreviateAction.java @@ -5,12 +5,15 @@ import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; +import java.util.function.Supplier; import java.util.stream.Collectors; +import javax.swing.undo.UndoManager; + import org.jabref.gui.DialogService; import org.jabref.gui.Globals; import org.jabref.gui.JabRefExecutorService; -import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTab; import org.jabref.gui.StateManager; import org.jabref.gui.actions.ActionHelper; import org.jabref.gui.actions.SimpleCommand; @@ -36,29 +39,32 @@ public class AbbreviateAction extends SimpleCommand { private static final Logger LOGGER = LoggerFactory.getLogger(AbbreviateAction.class); private final StandardActions action; - private final JabRefFrame frame; + private final Supplier tabSupplier; private final DialogService dialogService; private final StateManager stateManager; private final JournalAbbreviationPreferences journalAbbreviationPreferences; private final JournalAbbreviationRepository abbreviationRepository; private final TaskExecutor taskExecutor; + private final UndoManager undoManager; private AbbreviationType abbreviationType; public AbbreviateAction(StandardActions action, - JabRefFrame frame, + Supplier tabSupplier, DialogService dialogService, StateManager stateManager, JournalAbbreviationPreferences abbreviationPreferences, JournalAbbreviationRepository abbreviationRepository, - TaskExecutor taskExecutor) { + TaskExecutor taskExecutor, + UndoManager undoManager) { this.action = action; - this.frame = frame; + this.tabSupplier = tabSupplier; this.dialogService = dialogService; this.stateManager = stateManager; this.journalAbbreviationPreferences = abbreviationPreferences; this.abbreviationRepository = abbreviationRepository; this.taskExecutor = taskExecutor; + this.undoManager = undoManager; switch (action) { case ABBREVIATE_DEFAULT -> abbreviationType = AbbreviationType.DEFAULT; @@ -123,8 +129,8 @@ private String abbreviate(BibDatabaseContext databaseContext, List ent } ce.end(); - frame.getUndoManager().addEdit(ce); - frame.getCurrentLibraryTab().markBaseChanged(); + undoManager.addEdit(ce); + tabSupplier.get().markBaseChanged(); return Localization.lang("Abbreviated %0 journal names.", String.valueOf(count)); } @@ -140,8 +146,8 @@ private String unabbreviate(BibDatabaseContext databaseContext, List e } ce.end(); - frame.getUndoManager().addEdit(ce); - frame.getCurrentLibraryTab().markBaseChanged(); + undoManager.addEdit(ce); + tabSupplier.get().markBaseChanged(); return Localization.lang("Unabbreviated %0 journal names.", String.valueOf(count)); } } diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 6ff70140fc7..439146b78a6 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -29,6 +29,7 @@ import org.jabref.gui.DragAndDropDataFormats; import org.jabref.gui.Globals; import org.jabref.gui.LibraryTab; +import org.jabref.gui.LibraryTabContainer; import org.jabref.gui.StateManager; import org.jabref.gui.actions.StandardActions; import org.jabref.gui.edit.EditAction; @@ -72,11 +73,13 @@ public class MainTable extends TableView { private final ClipBoardManager clipBoardManager; private final BibEntryTypesManager entryTypesManager; private final TaskExecutor taskExecutor; + private final UndoManager undoManager; private long lastKeyPressTime; private String columnSearchTerm; public MainTable(MainTableDataModel model, LibraryTab libraryTab, + LibraryTabContainer tabContainer, BibDatabaseContext database, PreferencesService preferencesService, DialogService dialogService, @@ -96,7 +99,7 @@ public MainTable(MainTableDataModel model, this.clipBoardManager = clipBoardManager; this.entryTypesManager = entryTypesManager; this.taskExecutor = taskExecutor; - UndoManager undoManager = libraryTab.getUndoManager(); + this.undoManager = libraryTab.getUndoManager(); MainTablePreferences mainTablePreferences = preferencesService.getMainTablePreferences(); importHandler = new ImportHandler( @@ -118,7 +121,7 @@ public MainTable(MainTableDataModel model, database, preferencesService, preferencesService.getMainTableColumnPreferences(), - libraryTab.getUndoManager(), + undoManager, dialogService, stateManager, taskExecutor).createColumns()); @@ -192,13 +195,13 @@ public MainTable(MainTableDataModel model, database, preferencesService, preferencesService.getMainTableColumnPreferences(), - libraryTab.getUndoManager(), + undoManager, dialogService, stateManager, taskExecutor); // Enable the header right-click menu. - new MainTableHeaderContextMenu(this, rightClickMenuFactory, this.libraryTab.frame(), keyBindingRepository).show(true); + new MainTableHeaderContextMenu(this, rightClickMenuFactory, tabContainer, keyBindingRepository, dialogService).show(true); } /** @@ -265,10 +268,10 @@ public void cut() { } private void setupKeyBindings(KeyBindingRepository keyBindings) { - EditAction pasteAction = new EditAction(StandardActions.PASTE, libraryTab.frame(), stateManager); - EditAction copyAction = new EditAction(StandardActions.COPY, libraryTab.frame(), stateManager); - EditAction cutAction = new EditAction(StandardActions.CUT, libraryTab.frame(), stateManager); - EditAction deleteAction = new EditAction(StandardActions.DELETE_ENTRY, libraryTab.frame(), stateManager); + EditAction pasteAction = new EditAction(StandardActions.PASTE, () -> libraryTab, stateManager, undoManager); + EditAction copyAction = new EditAction(StandardActions.COPY, () -> libraryTab, stateManager, undoManager); + EditAction cutAction = new EditAction(StandardActions.CUT, () -> libraryTab, stateManager, undoManager); + EditAction deleteAction = new EditAction(StandardActions.DELETE_ENTRY, () -> libraryTab, stateManager, undoManager); this.addEventFilter(KeyEvent.KEY_PRESSED, event -> { if (event.getCode() == KeyCode.ENTER) { diff --git a/src/main/java/org/jabref/gui/maintable/MainTableHeaderContextMenu.java b/src/main/java/org/jabref/gui/maintable/MainTableHeaderContextMenu.java index 7bf82372c10..2b2c1376dbc 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableHeaderContextMenu.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableHeaderContextMenu.java @@ -11,7 +11,8 @@ import javafx.scene.control.TableColumn; import javafx.scene.layout.StackPane; -import org.jabref.gui.JabRefFrame; +import org.jabref.gui.DialogService; +import org.jabref.gui.LibraryTabContainer; import org.jabref.gui.actions.ActionFactory; import org.jabref.gui.actions.StandardActions; import org.jabref.gui.keyboard.KeyBindingRepository; @@ -25,23 +26,23 @@ public class MainTableHeaderContextMenu extends ContextMenu { private static final int OUT_OF_BOUNDS = -1; MainTable mainTable; MainTableColumnFactory factory; - private final JabRefFrame frame; + private final LibraryTabContainer tabContainer; private final KeyBindingRepository keyBindingRepository; + private final DialogService dialogService; - /** - * Constructor for the right click menu - * - */ public MainTableHeaderContextMenu(MainTable mainTable, MainTableColumnFactory factory, - JabRefFrame frame, - KeyBindingRepository keyBindingRepository) { + LibraryTabContainer tabContainer, + KeyBindingRepository keyBindingRepository, + DialogService dialogService) { super(); - this.frame = frame; + this.tabContainer = tabContainer; this.mainTable = mainTable; this.factory = factory; this.keyBindingRepository = keyBindingRepository; - constructItems(mainTable); + this.dialogService = dialogService; + + constructItems(); } /** @@ -63,7 +64,7 @@ public void show(boolean show) { /** * Constructs the items for the list and places them in the menu. */ - private void constructItems(MainTable mainTable) { + private void constructItems() { // Reset the right-click menu this.getItems().clear(); List> commonColumns = commonColumns(); @@ -75,9 +76,9 @@ private void constructItems(MainTable mainTable) { this.getItems().add(itemToAdd); // Remove from remaining common columns pool - MainTableColumn searchCol = (MainTableColumn) column; + MainTableColumn searchCol = (MainTableColumn) column; if (isACommonColumn(searchCol)) { - commonColumns.removeIf(tableCol -> ((MainTableColumn) tableCol).getModel().equals(searchCol.getModel())); + commonColumns.removeIf(tableCol -> ((MainTableColumn) tableCol).getModel().equals(searchCol.getModel())); } } @@ -95,31 +96,28 @@ private void constructItems(MainTable mainTable) { ActionFactory actionfactory = new ActionFactory(this.keyBindingRepository); MenuItem showMoreItem = actionfactory.createMenuItem( StandardActions.SHOW_PREFS.withText(Localization.lang("More options...")), - new ShowPreferencesAction(frame, TableTab.class)); + new ShowPreferencesAction(tabContainer, TableTab.class, dialogService)); this.getItems().add(showMoreItem); } /** * Creates an item for the menu constructed with the name/visibility of the table column. - * */ - @SuppressWarnings("rawtypes") private RightClickMenuItem createMenuItem(TableColumn column, boolean isDisplaying) { // Gets display name and constructs Radio Menu Item. - MainTableColumn tableColumn = (MainTableColumn) column; + MainTableColumn tableColumn = (MainTableColumn) column; String displayName = tableColumn.getDisplayName(); return new RightClickMenuItem(displayName, tableColumn, isDisplaying); } /** * Returns the current position of the inputted column in the table (index). - * */ - private int obtainIndexOfColumn(MainTableColumn searchColumn) { + private int obtainIndexOfColumn(MainTableColumn searchColumn) { ObservableList> columns = mainTable.getColumns(); for (int i = 0; i < columns.size(); i++) { TableColumn column = columns.get(i); - MainTableColumnModel model = ((MainTableColumn) column).getModel(); + MainTableColumnModel model = ((MainTableColumn) column).getModel(); if (model.equals(searchColumn.getModel())) { return i; } @@ -130,8 +128,7 @@ private int obtainIndexOfColumn(MainTableColumn searchColumn) { /** * Adds the column into the MainTable for display. */ - @SuppressWarnings("rawtypes") - private void addColumn(MainTableColumn tableColumn, int index) { + private void addColumn(MainTableColumn tableColumn, int index) { if ((index <= OUT_OF_BOUNDS) || (index >= mainTable.getColumns().size())) { mainTable.getColumns().add(tableColumn); } else { @@ -142,25 +139,24 @@ private void addColumn(MainTableColumn tableColumn, int index) { /** * Removes the column from the MainTable to remove visibility. */ - @SuppressWarnings("rawtypes") - private void removeColumn(MainTableColumn tableColumn) { - mainTable.getColumns().removeIf(tableCol -> ((MainTableColumn) tableCol).getModel().equals(tableColumn.getModel())); + private void removeColumn(MainTableColumn tableColumn) { + mainTable.getColumns().removeIf(tableCol -> ((MainTableColumn) tableCol).getModel().equals(tableColumn.getModel())); } /** * Checks if a column is one of the commonly used columns. */ - private boolean isACommonColumn(MainTableColumn tableColumn) { + private boolean isACommonColumn(MainTableColumn tableColumn) { return isColumnInList(tableColumn, commonColumns()); } /** * Determines if a list of TableColumns contains the searched column. */ - private boolean isColumnInList(MainTableColumn searchColumn, List> tableColumns) { + private boolean isColumnInList(MainTableColumn searchColumn, List> tableColumns) { for (TableColumn column: tableColumns) { - MainTableColumnModel model = ((MainTableColumn) column).getModel(); + MainTableColumnModel model = ((MainTableColumn) column).getModel(); if (model.equals(searchColumn.getModel())) { return true; } @@ -207,13 +203,12 @@ private boolean isColumnInList(MainTableColumn searchColumn, List column, boolean isVisible) { super(displayName); setVisibleInTable(isVisible); // Flag item as selected if the item is already in the main table. diff --git a/src/main/java/org/jabref/gui/maintable/RightClickMenu.java b/src/main/java/org/jabref/gui/maintable/RightClickMenu.java index 42686574b3e..6e65da6ab13 100644 --- a/src/main/java/org/jabref/gui/maintable/RightClickMenu.java +++ b/src/main/java/org/jabref/gui/maintable/RightClickMenu.java @@ -51,23 +51,23 @@ public static ContextMenu create(BibEntryTableViewModel entry, ContextMenu contextMenu = new ContextMenu(); contextMenu.getItems().addAll( - factory.createMenuItem(StandardActions.COPY, new EditAction(StandardActions.COPY, libraryTab.frame(), stateManager)), + factory.createMenuItem(StandardActions.COPY, new EditAction(StandardActions.COPY, () -> libraryTab, stateManager, undoManager)), createCopySubMenu(factory, dialogService, stateManager, preferencesService, clipBoardManager, abbreviationRepository, taskExecutor), - factory.createMenuItem(StandardActions.PASTE, new EditAction(StandardActions.PASTE, libraryTab.frame(), stateManager)), - factory.createMenuItem(StandardActions.CUT, new EditAction(StandardActions.CUT, libraryTab.frame(), stateManager)), + factory.createMenuItem(StandardActions.PASTE, new EditAction(StandardActions.PASTE, () -> libraryTab, stateManager, undoManager)), + factory.createMenuItem(StandardActions.CUT, new EditAction(StandardActions.CUT, () -> libraryTab, stateManager, undoManager)), factory.createMenuItem(StandardActions.MERGE_ENTRIES, new MergeEntriesAction(dialogService, stateManager, preferencesService)), - factory.createMenuItem(StandardActions.DELETE_ENTRY, new EditAction(StandardActions.DELETE_ENTRY, libraryTab.frame(), stateManager)), + factory.createMenuItem(StandardActions.DELETE_ENTRY, new EditAction(StandardActions.DELETE_ENTRY, () -> libraryTab, stateManager, undoManager)), new SeparatorMenuItem(), createSendSubMenu(factory, dialogService, stateManager, preferencesService, entryTypesManager, taskExecutor), - SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.RANKING, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager), - SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.RELEVANCE, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager), - SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.QUALITY, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager), - SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.PRINTED, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager), - SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.PRIORITY, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager), - SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.READ_STATUS, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager), + SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.RANKING, factory, () -> libraryTab, dialogService, preferencesService, undoManager, stateManager), + SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.RELEVANCE, factory, () -> libraryTab, dialogService, preferencesService, undoManager, stateManager), + SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.QUALITY, factory, () -> libraryTab, dialogService, preferencesService, undoManager, stateManager), + SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.PRINTED, factory, () -> libraryTab, dialogService, preferencesService, undoManager, stateManager), + SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.PRIORITY, factory, () -> libraryTab, dialogService, preferencesService, undoManager, stateManager), + SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.READ_STATUS, factory, () -> libraryTab, dialogService, preferencesService, undoManager, stateManager), new SeparatorMenuItem(), diff --git a/src/main/java/org/jabref/gui/preferences/ShowPreferencesAction.java b/src/main/java/org/jabref/gui/preferences/ShowPreferencesAction.java index 08eec1e610c..ca1d59c6f8a 100644 --- a/src/main/java/org/jabref/gui/preferences/ShowPreferencesAction.java +++ b/src/main/java/org/jabref/gui/preferences/ShowPreferencesAction.java @@ -1,33 +1,29 @@ package org.jabref.gui.preferences; import org.jabref.gui.DialogService; -import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTabContainer; import org.jabref.gui.actions.SimpleCommand; -import com.airhacks.afterburner.injection.Injector; - public class ShowPreferencesAction extends SimpleCommand { - private final JabRefFrame jabRefFrame; + private final LibraryTabContainer tabContainer; private final Class preferencesTabToSelectClass; - public ShowPreferencesAction(JabRefFrame jabRefFrame) { - this(jabRefFrame, null); + private final DialogService dialogService; + + public ShowPreferencesAction(LibraryTabContainer tabContainer, DialogService dialogService) { + this(tabContainer, null, dialogService); } - public ShowPreferencesAction(JabRefFrame jabRefFrame, Class preferencesTabToSelectClass) { - this.jabRefFrame = jabRefFrame; + public ShowPreferencesAction(LibraryTabContainer tabContainer, Class preferencesTabToSelectClass, DialogService dialogService) { + this.tabContainer = tabContainer; this.preferencesTabToSelectClass = preferencesTabToSelectClass; + this.dialogService = dialogService; } @Override public void execute() { - DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); dialogService.showCustomDialog(new PreferencesDialogView(preferencesTabToSelectClass)); - - // Refresh frame and tables - jabRefFrame.getGlobalSearchBar().updateHintVisibility(); - jabRefFrame.setupAllTables(); - jabRefFrame.getLibraryTabs().forEach(panel -> panel.getMainTable().getTableModel().refresh()); + tabContainer.refresh(); } } diff --git a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java index e419c97b827..8f0ce5a4a17 100644 --- a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java +++ b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java @@ -43,7 +43,7 @@ import org.jabref.gui.ClipBoardManager; import org.jabref.gui.DialogService; -import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTabContainer; import org.jabref.gui.StateManager; import org.jabref.gui.autocompleter.AppendPersonNamesStrategy; import org.jabref.gui.autocompleter.AutoCompleteFirstNameMode; @@ -109,7 +109,11 @@ public class GlobalSearchBar extends HBox { private final BooleanProperty globalSearchActive = new SimpleBooleanProperty(false); private GlobalSearchResultDialog globalSearchResultDialog; - public GlobalSearchBar(JabRefFrame frame, StateManager stateManager, PreferencesService preferencesService, CountingUndoManager undoManager, DialogService dialogService) { + public GlobalSearchBar(LibraryTabContainer tabContainer, + StateManager stateManager, + PreferencesService preferencesService, + CountingUndoManager undoManager, + DialogService dialogService) { super(); this.stateManager = stateManager; this.preferencesService = preferencesService; @@ -119,7 +123,7 @@ public GlobalSearchBar(JabRefFrame frame, StateManager stateManager, Preferences searchField.disableProperty().bind(needsDatabase(stateManager).not()); - // fits the standard "found x entries"-message thus hinders the searchbar to jump around while searching if the frame width is too small + // fits the standard "found x entries"-message thus hinders the searchbar to jump around while searching if the tabContainer width is too small currentResults.setPrefWidth(150); searchField.setTooltip(searchFieldTooltip); @@ -134,7 +138,7 @@ public GlobalSearchBar(JabRefFrame frame, StateManager stateManager, Preferences if (keyBinding.get() == KeyBinding.CLOSE) { // Clear search and select first entry, if available searchField.setText(""); - frame.getCurrentLibraryTab().getMainTable().getSelectionModel().selectFirst(); + tabContainer.getCurrentLibraryTab().getMainTable().getSelectionModel().selectFirst(); event.consume(); } } @@ -144,7 +148,8 @@ public GlobalSearchBar(JabRefFrame frame, StateManager stateManager, Preferences keyBindingRepository, stateManager, searchField, - frame)); + tabContainer, + undoManager)); ObservableList search = stateManager.getWholeSearchHistory(); search.addListener((ListChangeListener.Change change) -> { @@ -152,7 +157,8 @@ public GlobalSearchBar(JabRefFrame frame, StateManager stateManager, Preferences keyBindingRepository, stateManager, searchField, - frame)); + tabContainer, + undoManager)); }); ClipBoardManager.addX11Support(searchField); diff --git a/src/main/java/org/jabref/gui/search/SearchFieldRightClickMenu.java b/src/main/java/org/jabref/gui/search/SearchFieldRightClickMenu.java index 5839619b881..68b5f58e6d3 100644 --- a/src/main/java/org/jabref/gui/search/SearchFieldRightClickMenu.java +++ b/src/main/java/org/jabref/gui/search/SearchFieldRightClickMenu.java @@ -1,11 +1,13 @@ package org.jabref.gui.search; +import javax.swing.undo.UndoManager; + import javafx.scene.control.ContextMenu; import javafx.scene.control.Menu; import javafx.scene.control.MenuItem; import javafx.scene.control.SeparatorMenuItem; -import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTabContainer; import org.jabref.gui.StateManager; import org.jabref.gui.actions.ActionFactory; import org.jabref.gui.actions.SimpleCommand; @@ -20,21 +22,22 @@ public class SearchFieldRightClickMenu { public static ContextMenu create(KeyBindingRepository keyBindingRepository, StateManager stateManager, CustomTextField searchField, - JabRefFrame frame) { + LibraryTabContainer tabContainer, + UndoManager undoManager) { ActionFactory factory = new ActionFactory(keyBindingRepository); ContextMenu contextMenu = new ContextMenu(); contextMenu.getItems().addAll( - factory.createMenuItem(StandardActions.UNDO, new EditAction(StandardActions.UNDO, frame, stateManager)), - factory.createMenuItem(StandardActions.REDO, new EditAction(StandardActions.REDO, frame, stateManager)), - factory.createMenuItem(StandardActions.CUT, new EditAction(StandardActions.CUT, frame, stateManager)), - factory.createMenuItem(StandardActions.COPY, new EditAction(StandardActions.COPY, frame, stateManager)), - factory.createMenuItem(StandardActions.PASTE, new EditAction(StandardActions.PASTE, frame, stateManager)), - factory.createMenuItem(StandardActions.DELETE, new EditAction(StandardActions.DELETE, frame, stateManager)), + factory.createMenuItem(StandardActions.UNDO, new EditAction(StandardActions.UNDO, tabContainer::getCurrentLibraryTab, stateManager, undoManager)), + factory.createMenuItem(StandardActions.REDO, new EditAction(StandardActions.REDO, tabContainer::getCurrentLibraryTab, stateManager, undoManager)), + factory.createMenuItem(StandardActions.CUT, new EditAction(StandardActions.CUT, tabContainer::getCurrentLibraryTab, stateManager, undoManager)), + factory.createMenuItem(StandardActions.COPY, new EditAction(StandardActions.COPY, tabContainer::getCurrentLibraryTab, stateManager, undoManager)), + factory.createMenuItem(StandardActions.PASTE, new EditAction(StandardActions.PASTE, tabContainer::getCurrentLibraryTab, stateManager, undoManager)), + factory.createMenuItem(StandardActions.DELETE, new EditAction(StandardActions.DELETE, tabContainer::getCurrentLibraryTab, stateManager, undoManager)), new SeparatorMenuItem(), - factory.createMenuItem(StandardActions.SELECT_ALL, new EditAction(StandardActions.SELECT_ALL, null, stateManager)), + factory.createMenuItem(StandardActions.SELECT_ALL, new EditAction(StandardActions.SELECT_ALL, null, stateManager, undoManager)), createSearchFromHistorySubMenu(factory, stateManager, searchField) ); diff --git a/src/main/java/org/jabref/gui/shared/ConnectToSharedDatabaseCommand.java b/src/main/java/org/jabref/gui/shared/ConnectToSharedDatabaseCommand.java index 9a79e714a65..16b11a60cae 100644 --- a/src/main/java/org/jabref/gui/shared/ConnectToSharedDatabaseCommand.java +++ b/src/main/java/org/jabref/gui/shared/ConnectToSharedDatabaseCommand.java @@ -1,25 +1,24 @@ package org.jabref.gui.shared; import org.jabref.gui.DialogService; -import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTabContainer; import org.jabref.gui.actions.SimpleCommand; -import com.airhacks.afterburner.injection.Injector; - /** * Opens a shared database. */ public class ConnectToSharedDatabaseCommand extends SimpleCommand { - private final JabRefFrame jabRefFrame; + private final LibraryTabContainer tabContainer; + private final DialogService dialogService; - public ConnectToSharedDatabaseCommand(JabRefFrame jabRefFrame) { - this.jabRefFrame = jabRefFrame; + public ConnectToSharedDatabaseCommand(LibraryTabContainer tabContainer, DialogService dialogService) { + this.tabContainer = tabContainer; + this.dialogService = dialogService; } @Override public void execute() { - DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); - dialogService.showCustomDialogAndWait(new SharedDatabaseLoginDialogView(jabRefFrame)); + dialogService.showCustomDialogAndWait(new SharedDatabaseLoginDialogView(tabContainer)); } } diff --git a/src/main/java/org/jabref/gui/shared/SharedDatabaseLoginDialogView.java b/src/main/java/org/jabref/gui/shared/SharedDatabaseLoginDialogView.java index a3307e7dad4..b43c748cfc0 100644 --- a/src/main/java/org/jabref/gui/shared/SharedDatabaseLoginDialogView.java +++ b/src/main/java/org/jabref/gui/shared/SharedDatabaseLoginDialogView.java @@ -13,7 +13,7 @@ import javafx.scene.control.TextField; import org.jabref.gui.DialogService; -import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTabContainer; import org.jabref.gui.StateManager; import org.jabref.gui.util.BaseDialog; import org.jabref.gui.util.ControlHelper; @@ -56,12 +56,12 @@ public class SharedDatabaseLoginDialogView extends BaseDialog { @Inject private UndoManager undoManager; @Inject private TaskExecutor taskExecutor; - private final JabRefFrame frame; + private final LibraryTabContainer tabContainer; private SharedDatabaseLoginDialogViewModel viewModel; private final ControlsFxVisualizer visualizer = new ControlsFxVisualizer(); - public SharedDatabaseLoginDialogView(JabRefFrame frame) { - this.frame = frame; + public SharedDatabaseLoginDialogView(LibraryTabContainer tabContainer) { + this.tabContainer = tabContainer; this.setTitle(Localization.lang("Connect to shared database")); ViewLoader.view(this) @@ -89,7 +89,7 @@ private void initialize() { visualizer.setDecoration(new IconValidationDecorator()); viewModel = new SharedDatabaseLoginDialogViewModel( - frame, + tabContainer, dialogService, preferencesService, stateManager, diff --git a/src/main/java/org/jabref/gui/shared/SharedDatabaseLoginDialogViewModel.java b/src/main/java/org/jabref/gui/shared/SharedDatabaseLoginDialogViewModel.java index 0e13f6bd2a4..6505d7ca028 100644 --- a/src/main/java/org/jabref/gui/shared/SharedDatabaseLoginDialogViewModel.java +++ b/src/main/java/org/jabref/gui/shared/SharedDatabaseLoginDialogViewModel.java @@ -24,8 +24,8 @@ import org.jabref.gui.AbstractViewModel; import org.jabref.gui.DialogService; import org.jabref.gui.Globals; -import org.jabref.gui.JabRefFrame; import org.jabref.gui.LibraryTab; +import org.jabref.gui.LibraryTabContainer; import org.jabref.gui.StateManager; import org.jabref.gui.exporter.SaveDatabaseAction; import org.jabref.gui.help.HelpAction; @@ -77,7 +77,7 @@ public class SharedDatabaseLoginDialogViewModel extends AbstractViewModel { private final StringProperty keyStorePasswordProperty = new SimpleStringProperty(""); private final StringProperty serverTimezone = new SimpleStringProperty(""); - private final JabRefFrame frame; + private final LibraryTabContainer tabContainer; private final DialogService dialogService; private final PreferencesService preferencesService; private final SharedDatabasePreferences sharedDatabasePreferences = new SharedDatabasePreferences(); @@ -95,7 +95,7 @@ public class SharedDatabaseLoginDialogViewModel extends AbstractViewModel { private final Validator keystoreValidator; private final CompositeValidator formValidator; - public SharedDatabaseLoginDialogViewModel(JabRefFrame frame, + public SharedDatabaseLoginDialogViewModel(LibraryTabContainer tabContainer, DialogService dialogService, PreferencesService preferencesService, StateManager stateManager, @@ -103,7 +103,7 @@ public SharedDatabaseLoginDialogViewModel(JabRefFrame frame, FileUpdateMonitor fileUpdateMonitor, UndoManager undoManager, TaskExecutor taskExecutor) { - this.frame = frame; + this.tabContainer = tabContainer; this.dialogService = dialogService; this.preferencesService = preferencesService; this.stateManager = stateManager; @@ -181,7 +181,7 @@ private boolean openSharedDatabase(DBMSConnectionProperties connectionProperties try { SharedDatabaseUIManager manager = new SharedDatabaseUIManager( - frame, + tabContainer, dialogService, preferencesService, stateManager, @@ -290,7 +290,7 @@ private void applyPreferences() { } private boolean isSharedDatabaseAlreadyPresent(DBMSConnectionProperties connectionProperties) { - List libraryTabs = frame.getLibraryTabs(); + List libraryTabs = tabContainer.getLibraryTabs(); return libraryTabs.parallelStream().anyMatch(panel -> { BibDatabaseContext context = panel.getBibDatabaseContext(); diff --git a/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java b/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java index 44d92e9c216..387b165f158 100644 --- a/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java +++ b/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java @@ -12,8 +12,8 @@ import javafx.scene.control.ButtonType; import org.jabref.gui.DialogService; -import org.jabref.gui.JabRefFrame; import org.jabref.gui.LibraryTab; +import org.jabref.gui.LibraryTabContainer; import org.jabref.gui.StateManager; import org.jabref.gui.entryeditor.EntryEditor; import org.jabref.gui.exporter.SaveDatabaseAction; @@ -44,7 +44,7 @@ public class SharedDatabaseUIManager { - private final JabRefFrame frame; + private final LibraryTabContainer tabContainer; private DatabaseSynchronizer dbmsSynchronizer; private final DialogService dialogService; private final PreferencesService preferencesService; @@ -54,7 +54,7 @@ public class SharedDatabaseUIManager { private final UndoManager undoManager; private final TaskExecutor taskExecutor; - public SharedDatabaseUIManager(JabRefFrame frame, + public SharedDatabaseUIManager(LibraryTabContainer tabContainer, DialogService dialogService, PreferencesService preferencesService, StateManager stateManager, @@ -62,7 +62,7 @@ public SharedDatabaseUIManager(JabRefFrame frame, FileUpdateMonitor fileUpdateMonitor, UndoManager undoManager, TaskExecutor taskExecutor) { - this.frame = frame; + this.tabContainer = tabContainer; this.dialogService = dialogService; this.preferencesService = preferencesService; this.stateManager = stateManager; @@ -87,15 +87,15 @@ public void listen(ConnectionLostEvent connectionLostEvent) { if (answer.isPresent()) { if (answer.get().equals(reconnect)) { - frame.closeCurrentTab(); - dialogService.showCustomDialogAndWait(new SharedDatabaseLoginDialogView(frame)); + tabContainer.closeCurrentTab(); + dialogService.showCustomDialogAndWait(new SharedDatabaseLoginDialogView(tabContainer)); } else if (answer.get().equals(workOffline)) { connectionLostEvent.getBibDatabaseContext().convertToLocalDatabase(); - frame.getLibraryTabs().forEach(tab -> tab.updateTabTitle(tab.isModified())); + tabContainer.getLibraryTabs().forEach(tab -> tab.updateTabTitle(tab.isModified())); dialogService.notify(Localization.lang("Working offline.")); } } else { - frame.closeCurrentTab(); + tabContainer.closeCurrentTab(); } } @@ -134,7 +134,7 @@ public void listen(UpdateRefusedEvent updateRefusedEvent) { @Subscribe public void listen(SharedEntriesNotPresentEvent event) { - LibraryTab libraryTab = frame.getCurrentLibraryTab(); + LibraryTab libraryTab = tabContainer.getCurrentLibraryTab(); EntryEditor entryEditor = libraryTab.getEntryEditor(); libraryTab.getUndoManager().addEdit(new UndoableRemoveEntries(libraryTab.getDatabase(), event.getBibEntries())); @@ -173,7 +173,7 @@ public LibraryTab openNewSharedDatabaseTab(DBMSConnectionProperties dbmsConnecti LibraryTab libraryTab = LibraryTab.createLibraryTab( bibDatabaseContext, - frame, + tabContainer, dialogService, preferencesService, stateManager, @@ -181,7 +181,7 @@ public LibraryTab openNewSharedDatabaseTab(DBMSConnectionProperties dbmsConnecti entryTypesManager, undoManager, taskExecutor); - frame.addTab(libraryTab, true); + tabContainer.addTab(libraryTab, true); return libraryTab; } diff --git a/src/main/java/org/jabref/gui/slr/ExistingStudySearchAction.java b/src/main/java/org/jabref/gui/slr/ExistingStudySearchAction.java index 827a25edc25..2d174f724a3 100644 --- a/src/main/java/org/jabref/gui/slr/ExistingStudySearchAction.java +++ b/src/main/java/org/jabref/gui/slr/ExistingStudySearchAction.java @@ -4,7 +4,7 @@ import java.nio.file.Path; import org.jabref.gui.DialogService; -import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTabContainer; import org.jabref.gui.StateManager; import org.jabref.gui.actions.ActionHelper; import org.jabref.gui.actions.SimpleCommand; @@ -35,22 +35,22 @@ public class ExistingStudySearchAction extends SimpleCommand { private final FileUpdateMonitor fileUpdateMonitor; private final TaskExecutor taskExecutor; - private final JabRefFrame frame; + private final LibraryTabContainer tabContainer; private final OpenDatabaseAction openDatabaseAction; /** - * @param frame Required to close the tab before the study is updated + * @param tabContainer Required to close the tab before the study is updated * @param openDatabaseAction Required to open the tab after the study is exectued */ public ExistingStudySearchAction( - JabRefFrame frame, + LibraryTabContainer tabContainer, OpenDatabaseAction openDatabaseAction, DialogService dialogService, FileUpdateMonitor fileUpdateMonitor, TaskExecutor taskExecutor, PreferencesService preferencesService, StateManager stateManager) { - this(frame, + this(tabContainer, openDatabaseAction, dialogService, fileUpdateMonitor, @@ -61,7 +61,7 @@ public ExistingStudySearchAction( } protected ExistingStudySearchAction( - JabRefFrame frame, + LibraryTabContainer tabContainer, OpenDatabaseAction openDatabaseAction, DialogService dialogService, FileUpdateMonitor fileUpdateMonitor, @@ -69,7 +69,7 @@ protected ExistingStudySearchAction( PreferencesService preferencesService, StateManager stateManager, boolean isNew) { - this.frame = frame; + this.tabContainer = tabContainer; this.openDatabaseAction = openDatabaseAction; this.dialogService = dialogService; this.fileUpdateMonitor = fileUpdateMonitor; @@ -146,6 +146,6 @@ protected void crawlPreparation(Path studyRepositoryRoot) throws IOException, Gi // The user focused an SLR // We hard close the tab // Future work: Properly close the tab (with saving, ...) - frame.closeCurrentTab(); + tabContainer.closeCurrentTab(); } } diff --git a/src/main/java/org/jabref/gui/slr/StartNewStudyAction.java b/src/main/java/org/jabref/gui/slr/StartNewStudyAction.java index 848d36d4cb5..a356c144989 100644 --- a/src/main/java/org/jabref/gui/slr/StartNewStudyAction.java +++ b/src/main/java/org/jabref/gui/slr/StartNewStudyAction.java @@ -3,9 +3,12 @@ import java.io.IOException; import java.nio.file.Path; import java.util.Optional; +import java.util.function.Supplier; -import org.jabref.gui.JabRefFrame; +import org.jabref.gui.DialogService; +import org.jabref.gui.LibraryTabContainer; import org.jabref.gui.StateManager; +import org.jabref.gui.importer.actions.OpenDatabaseAction; import org.jabref.gui.util.TaskExecutor; import org.jabref.logic.crawler.StudyRepository; import org.jabref.logic.crawler.StudyYamlParser; @@ -35,14 +38,16 @@ public class StartNewStudyAction extends ExistingStudySearchAction { Study newStudy; - public StartNewStudyAction(JabRefFrame frame, + public StartNewStudyAction(LibraryTabContainer tabContainer, + Supplier openDatabaseActionSupplier, FileUpdateMonitor fileUpdateMonitor, TaskExecutor taskExecutor, PreferencesService preferencesService, - StateManager stateManager) { - super(frame, - frame.getOpenDatabaseAction(), - frame.getDialogService(), + StateManager stateManager, + DialogService dialogService) { + super(tabContainer, + openDatabaseActionSupplier.get(), + dialogService, fileUpdateMonitor, taskExecutor, preferencesService, diff --git a/src/main/java/org/jabref/gui/specialfields/SpecialFieldAction.java b/src/main/java/org/jabref/gui/specialfields/SpecialFieldAction.java index d95cff66d47..fc256c69b56 100644 --- a/src/main/java/org/jabref/gui/specialfields/SpecialFieldAction.java +++ b/src/main/java/org/jabref/gui/specialfields/SpecialFieldAction.java @@ -4,11 +4,12 @@ import java.util.List; import java.util.Objects; import java.util.Optional; +import java.util.function.Supplier; import javax.swing.undo.UndoManager; import org.jabref.gui.DialogService; -import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTab; import org.jabref.gui.StateManager; import org.jabref.gui.actions.ActionHelper; import org.jabref.gui.actions.SimpleCommand; @@ -27,7 +28,7 @@ public class SpecialFieldAction extends SimpleCommand { private static final Logger LOGGER = LoggerFactory.getLogger(SpecialFieldAction.class); - private final JabRefFrame frame; + private final Supplier tabSupplier; private final SpecialField specialField; private final String value; private final boolean nullFieldIfValueIsTheSame; @@ -40,7 +41,7 @@ public class SpecialFieldAction extends SimpleCommand { /** * @param nullFieldIfValueIsTheSame - false also causes that doneTextPattern has two place holders %0 for the value and %1 for the sum of entries */ - public SpecialFieldAction(JabRefFrame frame, + public SpecialFieldAction(Supplier tabSupplier, SpecialField specialField, String value, boolean nullFieldIfValueIsTheSame, @@ -49,7 +50,7 @@ public SpecialFieldAction(JabRefFrame frame, PreferencesService preferencesService, UndoManager undoManager, StateManager stateManager) { - this.frame = frame; + this.tabSupplier = tabSupplier; this.specialField = specialField; this.value = value; this.nullFieldIfValueIsTheSame = nullFieldIfValueIsTheSame; @@ -79,9 +80,9 @@ public void execute() { } ce.end(); if (ce.hasEdits()) { - frame.getCurrentLibraryTab().getUndoManager().addEdit(ce); - frame.getCurrentLibraryTab().markBaseChanged(); - frame.getCurrentLibraryTab().updateEntryEditorIfShowing(); + undoManager.addEdit(ce); + tabSupplier.get().markBaseChanged(); + tabSupplier.get().updateEntryEditorIfShowing(); String outText; if (nullFieldIfValueIsTheSame || value == null) { outText = getTextDone(specialField, Integer.toString(bes.size())); diff --git a/src/main/java/org/jabref/gui/specialfields/SpecialFieldMenuItemFactory.java b/src/main/java/org/jabref/gui/specialfields/SpecialFieldMenuItemFactory.java index 2fa0a404799..47ec0ac27e4 100644 --- a/src/main/java/org/jabref/gui/specialfields/SpecialFieldMenuItemFactory.java +++ b/src/main/java/org/jabref/gui/specialfields/SpecialFieldMenuItemFactory.java @@ -1,6 +1,7 @@ package org.jabref.gui.specialfields; import java.util.function.Function; +import java.util.function.Supplier; import javax.swing.undo.UndoManager; @@ -8,7 +9,7 @@ import javafx.scene.control.MenuItem; import org.jabref.gui.DialogService; -import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTab; import org.jabref.gui.StateManager; import org.jabref.gui.actions.ActionFactory; import org.jabref.model.entry.field.SpecialField; @@ -20,22 +21,22 @@ public class SpecialFieldMenuItemFactory { public static MenuItem getSpecialFieldSingleItem(SpecialField field, ActionFactory factory, - JabRefFrame frame, + Supplier tabSupplier, DialogService dialogService, PreferencesService preferencesService, UndoManager undoManager, StateManager stateManager) { - SpecialFieldValueViewModel specialField = new SpecialFieldValueViewModel(field.getValues().get(0)); + SpecialFieldValueViewModel specialField = new SpecialFieldValueViewModel(field.getValues().getFirst()); MenuItem menuItem = factory.createMenuItem(specialField.getAction(), new SpecialFieldViewModel(field, preferencesService, undoManager) - .getSpecialFieldAction(field.getValues().get(0), frame, dialogService, stateManager)); + .getSpecialFieldAction(field.getValues().getFirst(), tabSupplier, dialogService, stateManager)); menuItem.visibleProperty().bind(preferencesService.getSpecialFieldsPreferences().specialFieldsEnabledProperty()); return menuItem; } public static Menu createSpecialFieldMenu(SpecialField field, ActionFactory factory, - JabRefFrame frame, + Supplier tabSupplier, DialogService dialogService, PreferencesService preferencesService, UndoManager undoManager, @@ -43,7 +44,7 @@ public static Menu createSpecialFieldMenu(SpecialField field, return createSpecialFieldMenu(field, factory, preferencesService, undoManager, specialField -> new SpecialFieldViewModel(field, preferencesService, undoManager) - .getSpecialFieldAction(specialField.getValue(), frame, dialogService, stateManager)); + .getSpecialFieldAction(specialField.getValue(), tabSupplier, dialogService, stateManager)); } public static Menu createSpecialFieldMenu(SpecialField field, diff --git a/src/main/java/org/jabref/gui/specialfields/SpecialFieldViewModel.java b/src/main/java/org/jabref/gui/specialfields/SpecialFieldViewModel.java index 596b1848a5a..f7cdb6fb971 100644 --- a/src/main/java/org/jabref/gui/specialfields/SpecialFieldViewModel.java +++ b/src/main/java/org/jabref/gui/specialfields/SpecialFieldViewModel.java @@ -3,12 +3,13 @@ import java.util.List; import java.util.Objects; import java.util.Optional; +import java.util.function.Supplier; import java.util.stream.Collectors; import javax.swing.undo.UndoManager; import org.jabref.gui.DialogService; -import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTab; import org.jabref.gui.StateManager; import org.jabref.gui.actions.Action; import org.jabref.gui.actions.StandardActions; @@ -38,11 +39,11 @@ public SpecialField getField() { } public SpecialFieldAction getSpecialFieldAction(SpecialFieldValue value, - JabRefFrame frame, + Supplier tabSupplier, DialogService dialogService, StateManager stateManager) { return new SpecialFieldAction( - frame, + tabSupplier, field, value.getFieldValue().orElse(null), // if field contains only one value, it has to be nulled, as another setting does not empty the field diff --git a/src/main/java/org/jabref/gui/undo/UndoRedoAction.java b/src/main/java/org/jabref/gui/undo/UndoRedoAction.java index 9515bda0654..53b68628221 100644 --- a/src/main/java/org/jabref/gui/undo/UndoRedoAction.java +++ b/src/main/java/org/jabref/gui/undo/UndoRedoAction.java @@ -1,10 +1,11 @@ package org.jabref.gui.undo; +import java.util.function.Supplier; + import javax.swing.undo.CannotRedoException; import javax.swing.undo.CannotUndoException; import org.jabref.gui.DialogService; -import org.jabref.gui.JabRefFrame; import org.jabref.gui.LibraryTab; import org.jabref.gui.StateManager; import org.jabref.gui.actions.ActionHelper; @@ -20,12 +21,12 @@ public class UndoRedoAction extends SimpleCommand { private static final Logger LOGGER = LoggerFactory.getLogger(UndoRedoAction.class); private final StandardActions action; - private final JabRefFrame frame; - private DialogService dialogService; + private final Supplier tabSupplier; + private final DialogService dialogService; - public UndoRedoAction(StandardActions action, JabRefFrame frame, DialogService dialogService, StateManager stateManager) { + public UndoRedoAction(StandardActions action, Supplier tabSupplier, DialogService dialogService, StateManager stateManager) { this.action = action; - this.frame = frame; + this.tabSupplier = tabSupplier; this.dialogService = dialogService; // ToDo: Rework the UndoManager to something like the following, if it had a property. @@ -35,7 +36,7 @@ public UndoRedoAction(StandardActions action, JabRefFrame frame, DialogService d @Override public void execute() { - LibraryTab libraryTab = frame.getCurrentLibraryTab(); + LibraryTab libraryTab = this.tabSupplier.get(); if (action == StandardActions.UNDO) { try { libraryTab.getUndoManager().undo(); @@ -44,7 +45,7 @@ public void execute() { } catch (CannotUndoException ex) { dialogService.notify(Localization.lang("Nothing to undo") + '.'); } - frame.getCurrentLibraryTab().markChangedOrUnChanged(); + this.tabSupplier.get().markChangedOrUnChanged(); } else if (action == StandardActions.REDO) { try { libraryTab.getUndoManager().redo(); diff --git a/src/test/java/org/jabref/gui/exporter/SaveDatabaseActionTest.java b/src/test/java/org/jabref/gui/exporter/SaveDatabaseActionTest.java index 5752fc7afa7..9b36a5a712b 100644 --- a/src/test/java/org/jabref/gui/exporter/SaveDatabaseActionTest.java +++ b/src/test/java/org/jabref/gui/exporter/SaveDatabaseActionTest.java @@ -11,7 +11,6 @@ import javafx.collections.FXCollections; import org.jabref.gui.DialogService; -import org.jabref.gui.JabRefFrame; import org.jabref.gui.LibraryTab; import org.jabref.gui.undo.CountingUndoManager; import org.jabref.gui.util.FileDialogConfiguration; @@ -54,18 +53,15 @@ class SaveDatabaseActionTest { private final FilePreferences filePreferences = mock(FilePreferences.class); private final JabRefPreferences preferences = mock(JabRefPreferences.class); private LibraryTab libraryTab = mock(LibraryTab.class); - private final JabRefFrame jabRefFrame = mock(JabRefFrame.class); private BibDatabaseContext dbContext = spy(BibDatabaseContext.class); private SaveDatabaseAction saveDatabaseAction; @BeforeEach public void setUp() { - when(libraryTab.frame()).thenReturn(jabRefFrame); when(libraryTab.getBibDatabaseContext()).thenReturn(dbContext); when(filePreferences.getWorkingDirectory()).thenReturn(Path.of(TEST_BIBTEX_LIBRARY_LOCATION)); when(preferences.getFilePreferences()).thenReturn(filePreferences); when(preferences.getExportPreferences()).thenReturn(mock(ExportPreferences.class)); - when(jabRefFrame.getDialogService()).thenReturn(dialogService); saveDatabaseAction = spy(new SaveDatabaseAction(libraryTab, dialogService, preferences, mock(BibEntryTypesManager.class))); } @@ -127,7 +123,6 @@ private SaveDatabaseAction createSaveDatabaseActionForBibDatabase(BibDatabase da when(preferences.getCitationKeyPatternPreferences().getKeyPattern()).thenReturn(emptyGlobalCitationKeyPattern); when(preferences.getFieldPreferences().getNonWrappableFields()).thenReturn(FXCollections.emptyObservableList()); when(preferences.getLibraryPreferences()).thenReturn(mock(LibraryPreferences.class)); - when(libraryTab.frame()).thenReturn(jabRefFrame); when(libraryTab.getBibDatabaseContext()).thenReturn(dbContext); when(libraryTab.getUndoManager()).thenReturn(mock(CountingUndoManager.class)); when(libraryTab.getBibDatabaseContext()).thenReturn(dbContext); diff --git a/src/test/java/org/jabref/gui/importer/NewEntryActionTest.java b/src/test/java/org/jabref/gui/importer/NewEntryActionTest.java index 079bb6c1388..12e36236576 100644 --- a/src/test/java/org/jabref/gui/importer/NewEntryActionTest.java +++ b/src/test/java/org/jabref/gui/importer/NewEntryActionTest.java @@ -1,9 +1,10 @@ package org.jabref.gui.importer; +import java.util.List; + import org.jabref.gui.DialogService; -import org.jabref.gui.EntryTypeView; -import org.jabref.gui.JabRefFrame; import org.jabref.gui.LibraryTab; +import org.jabref.gui.LibraryTabContainer; import org.jabref.gui.StateManager; import org.jabref.gui.util.OptionalObjectProperty; import org.jabref.model.entry.BibEntry; @@ -14,7 +15,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.mockito.Mockito.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; @@ -24,33 +24,23 @@ public class NewEntryActionTest { private NewEntryAction newEntryAction; - private LibraryTab libraryTab = mock(LibraryTab.class); - private JabRefFrame jabRefFrame = mock(JabRefFrame.class); - private DialogService dialogService = spy(DialogService.class); - private PreferencesService preferencesService = mock(PreferencesService.class); - private StateManager stateManager = mock(StateManager.class); + private final LibraryTab libraryTab = mock(LibraryTab.class); + private final LibraryTabContainer tabContainer = mock(LibraryTabContainer.class); + private final DialogService dialogService = spy(DialogService.class); + private final PreferencesService preferencesService = mock(PreferencesService.class); + private final StateManager stateManager = mock(StateManager.class); @BeforeEach public void setUp() { - when(jabRefFrame.getCurrentLibraryTab()).thenReturn(libraryTab); when(stateManager.activeDatabaseProperty()).thenReturn(OptionalObjectProperty.empty()); - newEntryAction = new NewEntryAction(jabRefFrame, dialogService, preferencesService, stateManager); - } - - @Test - public void testExecuteIfNoBasePanel() { - when(jabRefFrame.getBasePanelCount()).thenReturn(0); - - newEntryAction.execute(); - verify(libraryTab, times(0)).insertEntry(any(BibEntry.class)); - verify(dialogService, times(0)).showCustomDialogAndWait(any(EntryTypeView.class)); + newEntryAction = new NewEntryAction(() -> libraryTab, dialogService, preferencesService, stateManager); } @Test public void testExecuteOnSuccessWithFixedType() { EntryType type = StandardEntryType.Article; - newEntryAction = new NewEntryAction(jabRefFrame, type, dialogService, preferencesService, stateManager); - when(jabRefFrame.getBasePanelCount()).thenReturn(1); + newEntryAction = new NewEntryAction(() -> libraryTab, type, dialogService, preferencesService, stateManager); + when(tabContainer.getLibraryTabs()).thenReturn(List.of(libraryTab)); newEntryAction.execute(); verify(libraryTab, times(1)).insertEntry(new BibEntry(type)); diff --git a/src/test/java/org/jabref/gui/search/GlobalSearchBarTest.java b/src/test/java/org/jabref/gui/search/GlobalSearchBarTest.java index b702ec57e2d..4a3b9819cb9 100644 --- a/src/test/java/org/jabref/gui/search/GlobalSearchBarTest.java +++ b/src/test/java/org/jabref/gui/search/GlobalSearchBarTest.java @@ -9,7 +9,7 @@ import javafx.stage.Stage; import org.jabref.gui.DialogService; -import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTabContainer; import org.jabref.gui.StateManager; import org.jabref.gui.undo.CountingUndoManager; import org.jabref.gui.util.DefaultTaskExecutor; @@ -34,11 +34,8 @@ @GUITest @ExtendWith(ApplicationExtension.class) public class GlobalSearchBarTest { - private Stage stage; - private Scene scene; private HBox hBox; - private GlobalSearchBar searchBar; private StateManager stateManager; @Start @@ -53,8 +50,8 @@ public void onStart(Stage stage) { stateManager.setActiveDatabase(new BibDatabaseContext()); // Instantiate GlobalSearchBar class, so the change listener is registered - searchBar = new GlobalSearchBar( - mock(JabRefFrame.class), + GlobalSearchBar searchBar = new GlobalSearchBar( + mock(LibraryTabContainer.class), stateManager, prefs, mock(CountingUndoManager.class), @@ -63,8 +60,7 @@ public void onStart(Stage stage) { hBox = new HBox(searchBar); - scene = new Scene(hBox, 400, 400); - this.stage = stage; + Scene scene = new Scene(hBox, 400, 400); stage.setScene(scene); stage.show();