diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index e29aa474ff3..3f7cf981ff6 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -11,6 +11,8 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; +import java.util.function.Consumer; +import java.util.function.Supplier; import java.util.stream.Collectors; import javax.swing.undo.CannotRedoException; @@ -49,6 +51,7 @@ import org.jabref.gui.journals.AbbreviateAction; import org.jabref.gui.journals.AbbreviationType; import org.jabref.gui.journals.UnabbreviateAction; +import org.jabref.gui.maintable.ColumnPreferences; import org.jabref.gui.maintable.MainTable; import org.jabref.gui.maintable.MainTableDataModel; import org.jabref.gui.mergeentries.MergeEntriesAction; @@ -66,12 +69,15 @@ import org.jabref.gui.worker.SendAsEMailAction; import org.jabref.logic.citationstyle.CitationStyleCache; import org.jabref.logic.citationstyle.CitationStyleOutputFormat; +import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.l10n.Localization; import org.jabref.logic.layout.Layout; import org.jabref.logic.layout.LayoutHelper; import org.jabref.logic.pdf.FileAnnotationCache; +import org.jabref.logic.preferences.TimestampPreferences; import org.jabref.logic.search.SearchQuery; import org.jabref.logic.util.UpdateField; +import org.jabref.logic.util.UpdateFieldPreferences; import org.jabref.logic.util.io.FileFinder; import org.jabref.logic.util.io.FileFinders; import org.jabref.logic.util.io.FileUtil; @@ -96,6 +102,7 @@ import org.jabref.model.entry.field.SpecialFieldValue; import org.jabref.model.entry.field.StandardField; import org.jabref.model.metadata.FilePreferences; +import org.jabref.model.util.FileUpdateMonitor; import org.jabref.preferences.JabRefPreferences; import com.google.common.eventbus.Subscribe; @@ -127,7 +134,7 @@ public class BasePanel extends StackPane { private final EntryEditor entryEditor; private final DialogService dialogService; private MainTable mainTable; - private BasePanelPreferences preferences; + private BasePanelPreferences basePanelPreferences; // To contain instantiated entry editors. This is to save time // As most enums, this must not be null private BasePanelMode mode = BasePanelMode.SHOWING_NOTHING; @@ -147,8 +154,8 @@ public class BasePanel extends StackPane { private Optional changeMonitor = Optional.empty(); private JabRefExecutorService executorService; - public BasePanel(JabRefFrame frame, BasePanelPreferences preferences, BibDatabaseContext bibDatabaseContext, ExternalFileTypes externalFileTypes, GroupViewMode groupViewMode, FilePreferences filePreferences) { - this.preferences = Objects.requireNonNull(preferences); + public BasePanel(JabRefFrame frame, BasePanelPreferences basePanelPreferences, BibDatabaseContext bibDatabaseContext, ExternalFileTypes externalFileTypes, GroupViewMode groupViewMode, FilePreferences filePreferences, ImportFormatPreferences importFormatPreferences, UpdateFieldPreferences updateFieldPreferences, FileUpdateMonitor fileUpdateMonitor, StateManager stateManager, Consumer updateColumnPreferences, Supplier timestampPreferencesSupplier) { + this.basePanelPreferences = Objects.requireNonNull(basePanelPreferences); this.frame = Objects.requireNonNull(frame); this.executorService = JabRefExecutorService.INSTANCE; this.bibDatabaseContext = Objects.requireNonNull(bibDatabaseContext); @@ -165,7 +172,7 @@ public BasePanel(JabRefFrame frame, BasePanelPreferences preferences, BibDatabas citationStyleCache = new CitationStyleCache(bibDatabaseContext); annotationCache = new FileAnnotationCache(bibDatabaseContext, filePreferences); - setupMainPanel(); + setupMainPanel(filePreferences, importFormatPreferences, updateFieldPreferences, fileUpdateMonitor, stateManager, updateColumnPreferences, basePanelPreferences); setupActions(); @@ -177,7 +184,7 @@ public BasePanel(JabRefFrame frame, BasePanelPreferences preferences, BibDatabas // ensure that all entry changes mark the panel as changed this.bibDatabaseContext.getDatabase().registerListener(this); - this.getDatabase().registerListener(new UpdateTimestampListener(Globals.prefs)); + this.getDatabase().registerListener(new UpdateTimestampListener(timestampPreferencesSupplier)); this.entryEditor = new EntryEditor(this, externalFileTypes); // Open entry editor for first entry on start up. @@ -647,10 +654,23 @@ public void updateTableFont() { mainTable.updateFont(); } - private void createMainTable() { + private void createMainTable(FilePreferences filePreferences, ImportFormatPreferences importFormatPreferences, UpdateFieldPreferences updateFieldPreferences, FileUpdateMonitor fileUpdateMonitor, StateManager stateManager, Consumer updateColumnPreferences) { bibDatabaseContext.getDatabase().registerListener(SpecialFieldDatabaseChangeListener.INSTANCE); - mainTable = new MainTable(tableModel, frame, this, bibDatabaseContext, preferences.getTablePreferences(), externalFileTypes, preferences.getKeyBindings()); + mainTable = new MainTable( + tableModel, + frame, + this, + bibDatabaseContext, + basePanelPreferences.getTablePreferences(), + externalFileTypes, + basePanelPreferences.getKeyBindings(), + filePreferences, + importFormatPreferences, + updateFieldPreferences, + fileUpdateMonitor, + stateManager, + updateColumnPreferences); mainTable.updateFont(); @@ -728,14 +748,14 @@ public void actionPerformed(ActionEvent e) { */ } - public void setupMainPanel() { - preferences = BasePanelPreferences.from(Globals.prefs); + public void setupMainPanel(FilePreferences filePreferences, ImportFormatPreferences importFormatPreferences, UpdateFieldPreferences updateFieldPreferences, FileUpdateMonitor fileUpdateMonitor, StateManager stateManager, Consumer updateColumnPreferences, BasePanelPreferences basePanelPreferences) { + this.basePanelPreferences = basePanelPreferences; splitPane = new SplitPane(); splitPane.setOrientation(Orientation.VERTICAL); adjustSplitter(); // restore last splitting state (before mainTable is created as creation affects the stored size of the entryEditors) - createMainTable(); + createMainTable(filePreferences, importFormatPreferences, updateFieldPreferences, fileUpdateMonitor, stateManager, updateColumnPreferences); splitPane.getItems().add(mainTable); @@ -771,7 +791,7 @@ public void setupMainPanel() { * Set up auto completion for this database */ private void setupAutoCompletion() { - AutoCompletePreferences autoCompletePreferences = preferences.getAutoCompletePreferences(); + AutoCompletePreferences autoCompletePreferences = basePanelPreferences.getAutoCompletePreferences(); if (autoCompletePreferences.shouldAutoComplete()) { suggestionProviders = new SuggestionProviders(autoCompletePreferences, Globals.journalAbbreviationLoader); suggestionProviders.indexDatabase(getDatabase()); @@ -797,7 +817,7 @@ private void instantiateSearchAutoCompleter() { private void adjustSplitter() { if (mode == BasePanelMode.SHOWING_EDITOR) { - splitPane.setDividerPositions(preferences.getEntryEditorDividerPosition()); + splitPane.setDividerPositions(basePanelPreferences.getEntryEditorDividerPosition()); } } @@ -968,7 +988,7 @@ private void saveDividerLocation(Number position) { } if (mode == BasePanelMode.SHOWING_EDITOR) { - preferences.setEntryEditorDividerPosition(position.doubleValue()); + basePanelPreferences.setEntryEditorDividerPosition(position.doubleValue()); } } diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 85d43cc045a..2d0dabe5426 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -922,7 +922,7 @@ public void setupAllTables() { // Update tables: if (bf.getDatabase() != null) { - DefaultTaskExecutor.runInJavaFXThread(bf::setupMainPanel); + DefaultTaskExecutor.runInJavaFXThread(() -> bf.setupMainPanel(Globals.prefs.getFilePreferences(), Globals.prefs.getImportFormatPreferences(), Globals.prefs.getUpdateFieldPreferences(), Globals.getFileUpdateMonitor(), Globals.stateManager, columnPreferences -> Globals.prefs.storeColumnPreferences(columnPreferences), BasePanelPreferences.from(Globals.prefs))); } } } @@ -1016,7 +1016,7 @@ private void trackOpenNewDatabase(BasePanel basePanel) { public BasePanel addTab(BibDatabaseContext databaseContext, boolean raisePanel) { Objects.requireNonNull(databaseContext); - BasePanel bp = new BasePanel(this, BasePanelPreferences.from(Globals.prefs), databaseContext, ExternalFileTypes.getInstance(), Globals.prefs.getGroupViewMode(), Globals.prefs.getFilePreferences()); + BasePanel bp = new BasePanel(this, BasePanelPreferences.from(Globals.prefs), databaseContext, ExternalFileTypes.getInstance(), Globals.prefs.getGroupViewMode(), Globals.prefs.getFilePreferences(), Globals.prefs.getImportFormatPreferences(), Globals.prefs.getUpdateFieldPreferences(), Globals.getFileUpdateMonitor(), Globals.stateManager, columnPreferences -> Globals.prefs.storeColumnPreferences(columnPreferences), () -> Globals.prefs.getTimestampPreferences()); addTab(bp, raisePanel); return bp; } diff --git a/src/main/java/org/jabref/gui/UpdateTimestampListener.java b/src/main/java/org/jabref/gui/UpdateTimestampListener.java index f3f559252fa..a61a35c8038 100644 --- a/src/main/java/org/jabref/gui/UpdateTimestampListener.java +++ b/src/main/java/org/jabref/gui/UpdateTimestampListener.java @@ -1,7 +1,9 @@ package org.jabref.gui; +import java.util.function.Supplier; + +import org.jabref.logic.preferences.TimestampPreferences; import org.jabref.model.entry.event.EntryChangedEvent; -import org.jabref.preferences.JabRefPreferences; import com.google.common.eventbus.Subscribe; @@ -9,24 +11,22 @@ * Updates the timestamp of changed entries if the feature is enabled */ class UpdateTimestampListener { - private final JabRefPreferences jabRefPreferences; + private final Supplier timestampPreferencesSupplier; /** - * The jabRefPreferences are required, because they are queried at each call. The user can change the preferences - * and this listener behaves differently. This implementation seems to be less complex then re-registering this - * listener or reconfiguring this listener if the preferences changed. - * - * @param jabRefPreferences the global JabRef preferences. + * The timestampPreferencesSupplier is required, because timestampPreferences are queried at each call. The user can + * change the preferences and this listener behaves differently. This implementation seems to be less complex then + * re-registering this listener or reconfiguring this listener if the preferences changed. */ - UpdateTimestampListener(JabRefPreferences jabRefPreferences) { - this.jabRefPreferences = jabRefPreferences; + UpdateTimestampListener(Supplier timestampPreferencesSupplier) { + this.timestampPreferencesSupplier = timestampPreferencesSupplier; } @Subscribe public void listen(EntryChangedEvent event) { - if (jabRefPreferences.getTimestampPreferences().includeTimestamps()) { - event.getBibEntry().setField(jabRefPreferences.getTimestampPreferences().getTimestampField(), - jabRefPreferences.getTimestampPreferences().now()); + TimestampPreferences timestampPreferences = timestampPreferencesSupplier.get(); + if (timestampPreferences.includeTimestamps()) { + event.getBibEntry().setField(timestampPreferences.getTimestampField(), timestampPreferences.now()); } } } diff --git a/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java b/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java index bdb93aa7ad0..be02cf8b64b 100644 --- a/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java +++ b/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java @@ -60,7 +60,7 @@ public FromAuxDialog(JabRefFrame frame) { setResultConverter(button -> { if (button == generateButtonType) { Defaults defaults = new Defaults(Globals.prefs.getDefaultBibDatabaseMode()); - BasePanel bp = new BasePanel(frame, BasePanelPreferences.from(Globals.prefs), new BibDatabaseContext(auxParserResult.getGeneratedBibDatabase(), defaults), ExternalFileTypes.getInstance(), Globals.prefs.getGroupViewMode(), Globals.prefs.getFilePreferences()); + BasePanel bp = new BasePanel(frame, BasePanelPreferences.from(Globals.prefs), new BibDatabaseContext(auxParserResult.getGeneratedBibDatabase(), defaults), ExternalFileTypes.getInstance(), Globals.prefs.getGroupViewMode(), Globals.prefs.getFilePreferences(), Globals.prefs.getImportFormatPreferences(), Globals.prefs.getUpdateFieldPreferences(), Globals.getFileUpdateMonitor(), Globals.stateManager, columnPreferences -> Globals.prefs.storeColumnPreferences(columnPreferences), () -> Globals.prefs.getTimestampPreferences()); frame.addTab(bp, true); } return null; diff --git a/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialogViewModel.java b/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialogViewModel.java index 7d10d5841e2..27604d3b60a 100644 --- a/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialogViewModel.java +++ b/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialogViewModel.java @@ -19,8 +19,10 @@ import javafx.beans.property.StringProperty; import javafx.collections.FXCollections; +import org.jabref.Globals; import org.jabref.gui.AbstractViewModel; import org.jabref.gui.BasePanel; +import org.jabref.gui.BasePanelPreferences; import org.jabref.gui.DialogService; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.field.Field; @@ -177,7 +179,7 @@ void saveChanges() { List fieldNamesToRemove = filterFieldsToRemove(); fieldNamesToRemove.forEach(metaData::clearContentSelectors); - basePanel.setupMainPanel(); + basePanel.setupMainPanel(Globals.prefs.getFilePreferences(), Globals.prefs.getImportFormatPreferences(), Globals.prefs.getUpdateFieldPreferences(), Globals.getFileUpdateMonitor(), Globals.stateManager, columnPreferences -> Globals.prefs.storeColumnPreferences(columnPreferences), BasePanelPreferences.from(Globals.prefs)); basePanel.markNonUndoableBaseChanged(); } 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 cbcb1208bd8..b5276b1a227 100644 --- a/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java @@ -235,7 +235,7 @@ private BasePanel addNewDatabase(ParserResult result, final Path file, boolean r ParserResultWarningDialog.showParserResultWarningDialog(result, frame); } - BasePanel basePanel = new BasePanel(frame, BasePanelPreferences.from(Globals.prefs), result.getDatabaseContext(), ExternalFileTypes.getInstance(), Globals.prefs.getGroupViewMode(), Globals.prefs.getFilePreferences()); + BasePanel basePanel = new BasePanel(frame, BasePanelPreferences.from(Globals.prefs), result.getDatabaseContext(), ExternalFileTypes.getInstance(), Globals.prefs.getGroupViewMode(), Globals.prefs.getFilePreferences(), Globals.prefs.getImportFormatPreferences(), Globals.prefs.getUpdateFieldPreferences(), Globals.getFileUpdateMonitor(), Globals.stateManager, columnPreferences -> Globals.prefs.storeColumnPreferences(columnPreferences), () -> Globals.prefs.getTimestampPreferences()); frame.addTab(basePanel, raisePanel); return basePanel; diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 5eb3b3704fa..d127018ee87 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -6,6 +6,9 @@ import java.util.List; import java.util.Objects; import java.util.Optional; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Supplier; import java.util.stream.Collectors; import javax.swing.undo.UndoManager; @@ -28,6 +31,7 @@ import org.jabref.gui.DragAndDropDataFormats; import org.jabref.gui.GUIGlobals; import org.jabref.gui.JabRefFrame; +import org.jabref.gui.StateManager; import org.jabref.gui.externalfiles.ImportHandler; import org.jabref.gui.externalfiletype.ExternalFileTypes; import org.jabref.gui.keyboard.KeyBinding; @@ -38,11 +42,15 @@ import org.jabref.gui.util.CustomLocalDragboard; import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.gui.util.ViewModelTableRowFactory; +import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.UpdateField; +import org.jabref.logic.util.UpdateFieldPreferences; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.event.AllInsertsFinishedEvent; import org.jabref.model.entry.BibEntry; +import org.jabref.model.metadata.FilePreferences; +import org.jabref.model.util.FileUpdateMonitor; import org.jabref.preferences.JabRefPreferences; import com.google.common.eventbus.Subscribe; @@ -64,7 +72,15 @@ public class MainTable extends TableView { public MainTable(MainTableDataModel model, JabRefFrame frame, BasePanel panel, BibDatabaseContext database, - MainTablePreferences preferences, ExternalFileTypes externalFileTypes, KeyBindingRepository keyBindingRepository) { + MainTablePreferences preferences, + ExternalFileTypes externalFileTypes, + KeyBindingRepository keyBindingRepository, + FilePreferences filePreferences, + ImportFormatPreferences importFormatPreferences, + UpdateFieldPreferences updateFieldPreferences, + FileUpdateMonitor fileUpdateMonitor, + StateManager stateManager, + Consumer storeColumnPreferences) { super(); this.model = model; @@ -74,21 +90,21 @@ public MainTable(MainTableDataModel model, JabRefFrame frame, importHandler = new ImportHandler( frame.getDialogService(), database, externalFileTypes, - Globals.prefs.getFilePreferences(), - Globals.prefs.getImportFormatPreferences(), - Globals.prefs.getUpdateFieldPreferences(), - Globals.getFileUpdateMonitor(), + filePreferences, + importFormatPreferences, + updateFieldPreferences, + fileUpdateMonitor, undoManager, - Globals.stateManager); + stateManager); this.getColumns().addAll(new MainTableColumnFactory(database, preferences.getColumnPreferences(), externalFileTypes, panel.getUndoManager(), frame.getDialogService()).createColumns()); new ViewModelTableRowFactory() .withOnMouseClickedEvent((entry, event) -> { - if (event.getClickCount() == 2) { - panel.showAndEdit(entry.getEntry()); - } - }) + if (event.getClickCount() == 2) { + panel.showAndEdit(entry.getEntry()); + } + }) .withContextMenu(entry -> RightClickMenu.create(entry, keyBindingRepository, panel, frame.getDialogService())) .setOnDragDetected(this::handleOnDragDetected) .setOnDragDropped(this::handleOnDragDropped) @@ -100,10 +116,10 @@ public MainTable(MainTableDataModel model, JabRefFrame frame, this.getSortOrder().clear(); preferences.getColumnPreferences().getColumnSortOrder().forEach(columnModel -> this.getColumns().stream() - .map(column -> (MainTableColumn) column) - .filter(column -> column.getModel().equals(columnModel)) - .findFirst() - .ifPresent(column -> this.getSortOrder().add(column))); + .map(column -> (MainTableColumn) column) + .filter(column -> column.getModel().equals(columnModel)) + .findFirst() + .ifPresent(column -> this.getSortOrder().add(column))); if (preferences.getResizeColumnsToFit()) { this.setColumnResizePolicy(new SmartConstrainedResizePolicy()); @@ -119,7 +135,7 @@ public MainTable(MainTableDataModel model, JabRefFrame frame, this.getStylesheets().add(MainTable.class.getResource("MainTable.css").toExternalForm()); // Store visual state - new PersistenceVisualStateTable(this, Globals.prefs); + new PersistenceVisualStateTable(this, storeColumnPreferences); // TODO: Float marked entries //model.updateMarkingState(Globals.prefs.getBoolean(JabRefPreferences.FLOAT_MARKED_ENTRIES)); @@ -337,10 +353,10 @@ public BibEntry getEntryAt(int row) { public List getSelectedEntries() { return getSelectionModel() - .getSelectedItems() - .stream() - .map(BibEntryTableViewModel::getEntry) - .collect(Collectors.toList()); + .getSelectedItems() + .stream() + .map(BibEntryTableViewModel::getEntry) + .collect(Collectors.toList()); } private Optional findEntry(BibEntry entry) { diff --git a/src/main/java/org/jabref/gui/maintable/PersistenceVisualStateTable.java b/src/main/java/org/jabref/gui/maintable/PersistenceVisualStateTable.java index 03caa77521f..27fd6451852 100644 --- a/src/main/java/org/jabref/gui/maintable/PersistenceVisualStateTable.java +++ b/src/main/java/org/jabref/gui/maintable/PersistenceVisualStateTable.java @@ -1,22 +1,21 @@ package org.jabref.gui.maintable; +import java.util.function.Consumer; import java.util.stream.Collectors; import javafx.beans.InvalidationListener; -import org.jabref.preferences.JabRefPreferences; - /** * Keep track of changes made to the columns (reordering, resorting, resizing). */ public class PersistenceVisualStateTable { private final MainTable mainTable; - private final JabRefPreferences preferences; + private final Consumer storeColumnPreferences; - public PersistenceVisualStateTable(final MainTable mainTable, JabRefPreferences preferences) { + public PersistenceVisualStateTable(final MainTable mainTable, final Consumer storeColumnPreferences) { this.mainTable = mainTable; - this.preferences = preferences; + this.storeColumnPreferences = storeColumnPreferences; mainTable.getColumns().addListener((InvalidationListener) obs -> updateColumnPreferences()); mainTable.getSortOrder().addListener((InvalidationListener) obs -> updateColumnPreferences()); @@ -33,13 +32,14 @@ public PersistenceVisualStateTable(final MainTable mainTable, JabRefPreferences * Store shown columns, their width and their sortType in preferences. */ private void updateColumnPreferences() { - preferences.storeColumnPreferences(new ColumnPreferences( - mainTable.getColumns().stream() - .map(column -> ((MainTableColumn) column).getModel()) - .collect(Collectors.toList()), - mainTable.getSortOrder().stream() - .map(column -> ((MainTableColumn) column).getModel()) - .collect(Collectors.toList()) - )); + storeColumnPreferences.accept( + new ColumnPreferences( + mainTable.getColumns().stream() + .map(column -> ((MainTableColumn) column).getModel()) + .collect(Collectors.toList()), + mainTable.getSortOrder().stream() + .map(column -> ((MainTableColumn) column).getModel()) + .collect(Collectors.toList()) + )); } } diff --git a/src/test/java/org/jabref/gui/BasePanelTest.java b/src/test/java/org/jabref/gui/BasePanelTest.java index b5086d43071..21136666861 100644 --- a/src/test/java/org/jabref/gui/BasePanelTest.java +++ b/src/test/java/org/jabref/gui/BasePanelTest.java @@ -1,23 +1,26 @@ package org.jabref.gui; +import java.util.Collections; + import javafx.scene.Scene; import javafx.scene.control.SplitPane; import javafx.stage.Stage; -import org.jabref.Globals; +import org.jabref.JabRefGUI; import org.jabref.gui.autocompleter.AutoCompletePreferences; import org.jabref.gui.entryeditor.EntryEditorPreferences; import org.jabref.gui.externalfiletype.ExternalFileTypes; import org.jabref.gui.groups.GroupViewMode; import org.jabref.gui.keyboard.KeyBindingRepository; import org.jabref.gui.maintable.MainTablePreferences; +import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.preferences.TimestampPreferences; +import org.jabref.logic.util.UpdateFieldPreferences; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.InternalField; -import org.jabref.model.entry.field.StandardField; import org.jabref.model.metadata.FilePreferences; -import org.jabref.preferences.JabRefPreferences; +import org.jabref.model.util.DummyFileUpdateMonitor; import org.jabref.preferences.PreviewPreferences; import org.jabref.testutils.category.GUITest; @@ -38,14 +41,15 @@ public class BasePanelTest { private BasePanel panel; private BibDatabaseContext bibDatabaseContext; - private BasePanelPreferences preferences; + private BasePanelPreferences basePanelPreferences; @Start public void onStart(Stage stage) { + new JabRefGUI(stage, Collections.emptyList(), true); JabRefFrame frame = mock(JabRefFrame.class, RETURNS_MOCKS); ExternalFileTypes externalFileTypes = mock(ExternalFileTypes.class); bibDatabaseContext = new BibDatabaseContext(); - preferences = new BasePanelPreferences( + basePanelPreferences = new BasePanelPreferences( mock(MainTablePreferences.class, RETURNS_MOCKS), mock(AutoCompletePreferences.class, RETURNS_MOCKS), mock(EntryEditorPreferences.class, RETURNS_MOCKS), @@ -54,10 +58,25 @@ public void onStart(Stage stage) { 0.5 ); FilePreferences filePreferences = mock(FilePreferences.class); - Globals.prefs = mock(JabRefPreferences.class); + ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class); + when(importFormatPreferences.getKeywordSeparator()).thenReturn(','); + UpdateFieldPreferences updateFieldPreferences = mock(UpdateFieldPreferences.class); + StateManager stateManager = mock(StateManager.class); TimestampPreferences timestampPreferences = new TimestampPreferences(false, false, InternalField.TIMESTAMP, "yyyy-MM-dd-HH-mm-ss", false); - when(Globals.prefs.getTimestampPreferences()).thenReturn(timestampPreferences); - panel = new BasePanel(frame, preferences, bibDatabaseContext, externalFileTypes, GroupViewMode.UNION, filePreferences); + panel = new BasePanel( + frame, + basePanelPreferences, + bibDatabaseContext, + externalFileTypes, + GroupViewMode.UNION, + filePreferences, + importFormatPreferences, + updateFieldPreferences, + new DummyFileUpdateMonitor(), + stateManager, + columnPreferences -> { + }, + () -> timestampPreferences); stage.setScene(new Scene(panel)); stage.show(); diff --git a/src/test/java/org/jabref/gui/UpdateTimestampListenerTest.java b/src/test/java/org/jabref/gui/UpdateTimestampListenerTest.java index c8a9e226acf..5eec81c55e7 100644 --- a/src/test/java/org/jabref/gui/UpdateTimestampListenerTest.java +++ b/src/test/java/org/jabref/gui/UpdateTimestampListenerTest.java @@ -54,7 +54,7 @@ void updateTimestampEnabled() { assertEquals(Optional.of(baseDate), bibEntry.getField(timestampField), "Initial timestamp not set correctly"); - database.registerListener(new UpdateTimestampListener(preferencesMock)); + database.registerListener(new UpdateTimestampListener(() -> timestampPreferencesMock)); bibEntry.setField(new UnknownField("test"), "some value"); @@ -77,7 +77,7 @@ void updateTimestampDisabled() { assertEquals(Optional.of(baseDate), bibEntry.getField(timestampField), "Initial timestamp not set correctly"); - database.registerListener(new UpdateTimestampListener(preferencesMock)); + database.registerListener(new UpdateTimestampListener(() -> timestampPreferencesMock)); bibEntry.setField(new UnknownField("test"), "some value");