Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExternalFileTypes singleton refactor #9044

Merged
merged 14 commits into from
Aug 12, 2022
4 changes: 1 addition & 3 deletions src/main/java/org/jabref/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import org.jabref.gui.Globals;
import org.jabref.gui.externalfiles.AutoSetFileLinksUtil;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.undo.NamedCompound;
import org.jabref.logic.JabRefException;
import org.jabref.logic.bibtex.FieldWriterPreferences;
Expand Down Expand Up @@ -640,8 +639,7 @@ private void automaticallySetFileLinks(List<ParserResult> loaded) {
AutoSetFileLinksUtil util = new AutoSetFileLinksUtil(
parserResult.getDatabaseContext(),
preferencesService.getFilePreferences(),
preferencesService.getAutoLinkPreferences(),
ExternalFileTypes.getInstance());
preferencesService.getAutoLinkPreferences());
util.linkAssociatedFiles(database.getEntries(), new NamedCompound(""));
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/org/jabref/gui/EntryTypeViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import javafx.concurrent.Worker;

import org.jabref.gui.externalfiles.ImportHandler;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.importer.NewEntryAction;
import org.jabref.logic.importer.FetcherClientException;
import org.jabref.logic.importer.FetcherException;
Expand Down Expand Up @@ -169,7 +168,6 @@ public void runFetcherWorker() {

ImportHandler handler = new ImportHandler(
libraryTab.getBibDatabaseContext(),
ExternalFileTypes.getInstance(),
preferencesService,
Globals.getFileUpdateMonitor(),
libraryTab.getUndoManager(),
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
import org.jabref.gui.externalfiles.AutoLinkFilesAction;
import org.jabref.gui.externalfiles.DownloadFullTextAction;
import org.jabref.gui.externalfiles.FindUnlinkedFilesAction;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.help.AboutAction;
import org.jabref.gui.help.ErrorConsoleAction;
import org.jabref.gui.help.HelpAction;
Expand Down Expand Up @@ -1143,7 +1142,7 @@ private void trackOpenNewDatabase(LibraryTab libraryTab) {
public LibraryTab addTab(BibDatabaseContext databaseContext, boolean raisePanel) {
Objects.requireNonNull(databaseContext);

LibraryTab libraryTab = new LibraryTab(this, prefs, stateManager, themeManager, databaseContext, ExternalFileTypes.getInstance(), importFormatReader);
LibraryTab libraryTab = new LibraryTab(this, prefs, stateManager, themeManager, databaseContext, importFormatReader);
addTab(libraryTab, raisePanel);
return libraryTab;
}
Expand Down
11 changes: 3 additions & 8 deletions src/main/java/org/jabref/gui/LibraryTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.jabref.gui.collab.DatabaseChangeMonitor;
import org.jabref.gui.dialogs.AutosaveUiManager;
import org.jabref.gui.entryeditor.EntryEditor;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.importer.actions.OpenDatabaseAction;
import org.jabref.gui.maintable.MainTable;
import org.jabref.gui.maintable.MainTableDataModel;
Expand Down Expand Up @@ -84,7 +83,6 @@ public class LibraryTab extends Tab {
private static final Logger LOGGER = LoggerFactory.getLogger(LibraryTab.class);
private final JabRefFrame frame;
private final CountingUndoManager undoManager;
private final ExternalFileTypes externalFileTypes;
private final DialogService dialogService;
private final PreferencesService preferencesService;
private final StateManager stateManager;
Expand Down Expand Up @@ -122,11 +120,9 @@ public LibraryTab(JabRefFrame frame,
StateManager stateManager,
ThemeManager themeManager,
BibDatabaseContext bibDatabaseContext,
ExternalFileTypes externalFileTypes,
ImportFormatReader importFormatReader) {
this.frame = Objects.requireNonNull(frame);
this.bibDatabaseContext = Objects.requireNonNull(bibDatabaseContext);
this.externalFileTypes = Objects.requireNonNull(externalFileTypes);
this.undoManager = frame.getUndoManager();
this.dialogService = frame.getDialogService();
this.preferencesService = Objects.requireNonNull(preferencesService);
Expand Down Expand Up @@ -156,7 +152,7 @@ public LibraryTab(JabRefFrame frame,

this.getDatabase().registerListener(new UpdateTimestampListener(preferencesService));

this.entryEditor = new EntryEditor(this, externalFileTypes);
this.entryEditor = new EntryEditor(this);

// set LibraryTab ID for drag'n'drop
// ID content doesn't matter, we only need different tabs to have different ID
Expand Down Expand Up @@ -257,7 +253,7 @@ public void feedData(BibDatabaseContext bibDatabaseContext) {

this.getDatabase().registerListener(new UpdateTimestampListener(preferencesService));

this.entryEditor = new EntryEditor(this, externalFileTypes);
this.entryEditor = new EntryEditor(this);

Platform.runLater(() -> {
EasyBind.subscribe(changedProperty, this::updateTabTitle);
Expand Down Expand Up @@ -488,7 +484,6 @@ private void createMainTable() {
preferencesService,
dialogService,
stateManager,
externalFileTypes,
Globals.getKeyPrefs(),
Globals.getClipboardManager(),
Globals.IMPORT_FORMAT_READER);
Expand Down Expand Up @@ -808,7 +803,7 @@ public LibraryTab createLibraryTab(JabRefFrame frame, PreferencesService prefere
BibDatabaseContext context = new BibDatabaseContext();
context.setDatabasePath(file);

LibraryTab newTab = new LibraryTab(frame, preferencesService, stateManager, themeManager, context, ExternalFileTypes.getInstance(), importFormatReader);
LibraryTab newTab = new LibraryTab(frame, preferencesService, stateManager, themeManager, context, importFormatReader);
newTab.setDataLoadingTask(dataLoadingTask);

dataLoadingTask.onRunning(newTab::onDatabaseLoadingStarted)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.jabref.gui.Globals;
import org.jabref.gui.StateManager;
import org.jabref.gui.externalfiles.ImportHandler;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.util.BackgroundTask;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.importer.FetcherException;
Expand Down Expand Up @@ -52,7 +51,6 @@ public BibtexExtractorViewModel(BibDatabaseContext bibdatabaseContext,
this.taskExecutor = taskExecutor;
this.importHandler = new ImportHandler(
bibdatabaseContext,
ExternalFileTypes.getInstance(),
preferencesService,
fileUpdateMonitor,
undoManager,
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/desktop/JabRefDesktop.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public static void openFolderAndSelectFile(Path fileLink, PreferencesService pre
* @param url the URL to open
*/
public static void openBrowser(String url) throws IOException {
Optional<ExternalFileType> fileType = ExternalFileTypes.getInstance().getExternalFileTypeByExt("html");
Optional<ExternalFileType> fileType = ExternalFileTypes.getExternalFileTypeByExt("html", Globals.prefs.getFilePreferences());
openExternalFilePlatformIndependent(fileType, url);
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/gui/desktop/os/Linux.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import org.jabref.architecture.AllowedToUseAwt;
import org.jabref.gui.DialogService;
import org.jabref.gui.Globals;
import org.jabref.gui.JabRefExecutorService;
import org.jabref.gui.externalfiletype.ExternalFileType;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
Expand Down Expand Up @@ -48,7 +49,7 @@ private void nativeOpenFile(String filePath) {

@Override
public void openFile(String filePath, String fileType) throws IOException {
Optional<ExternalFileType> type = ExternalFileTypes.getInstance().getExternalFileTypeByExt(fileType);
Optional<ExternalFileType> type = ExternalFileTypes.getExternalFileTypeByExt(fileType, Globals.prefs.getFilePreferences());
String viewer;

if (type.isPresent() && !type.get().getOpenWithApplication().isEmpty()) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/gui/desktop/os/OSX.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import org.jabref.architecture.AllowedToUseAwt;
import org.jabref.gui.DialogService;
import org.jabref.gui.Globals;
import org.jabref.gui.externalfiletype.ExternalFileType;
import org.jabref.gui.externalfiletype.ExternalFileTypes;

Expand All @@ -14,7 +15,7 @@ public class OSX implements NativeDesktop {

@Override
public void openFile(String filePath, String fileType) throws IOException {
Optional<ExternalFileType> type = ExternalFileTypes.getInstance().getExternalFileTypeByExt(fileType);
Optional<ExternalFileType> type = ExternalFileTypes.getExternalFileTypeByExt(fileType, Globals.prefs.getFilePreferences());
if (type.isPresent() && !type.get().getOpenWithApplication().isEmpty()) {
openFileWithApplication(filePath, type.get().getOpenWithApplication());
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/gui/desktop/os/Windows.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Optional;

import org.jabref.gui.DialogService;
import org.jabref.gui.Globals;
import org.jabref.gui.externalfiletype.ExternalFileType;
import org.jabref.gui.externalfiletype.ExternalFileTypes;

Expand All @@ -15,7 +16,7 @@ public class Windows implements NativeDesktop {

@Override
public void openFile(String filePath, String fileType) throws IOException {
Optional<ExternalFileType> type = ExternalFileTypes.getInstance().getExternalFileTypeByExt(fileType);
Optional<ExternalFileType> type = ExternalFileTypes.getExternalFileTypeByExt(fileType, Globals.prefs.getFilePreferences());

if (type.isPresent() && !type.get().getOpenWithApplication().isEmpty()) {
openFileWithApplication(filePath, type.get().getOpenWithApplication());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.jabref.gui.DialogService;
import org.jabref.gui.StateManager;
import org.jabref.gui.autocompleter.SuggestionProviders;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.theme.ThemeManager;
import org.jabref.gui.util.TaskExecutor;
Expand All @@ -39,10 +38,9 @@ public DeprecatedFieldsTab(BibDatabaseContext databaseContext,
ThemeManager themeManager,
IndexingTaskManager indexingTaskManager,
BibEntryTypesManager entryTypesManager,
ExternalFileTypes externalFileTypes,
TaskExecutor taskExecutor,
JournalAbbreviationRepository journalAbbreviationRepository) {
super(false, databaseContext, suggestionProviders, undoManager, dialogService, preferences, stateManager, themeManager, externalFileTypes, taskExecutor, journalAbbreviationRepository, indexingTaskManager);
super(false, databaseContext, suggestionProviders, undoManager, dialogService, preferences, stateManager, themeManager, taskExecutor, journalAbbreviationRepository, indexingTaskManager);
this.entryTypesManager = entryTypesManager;

setText(Localization.lang("Deprecated fields"));
Expand Down
20 changes: 9 additions & 11 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.jabref.gui.entryeditor.fileannotationtab.FileAnnotationTab;
import org.jabref.gui.entryeditor.fileannotationtab.FulltextSearchResultsTab;
import org.jabref.gui.externalfiles.ExternalFilesEntryLinker;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.help.HelpAction;
import org.jabref.gui.importer.GrobidOptInDialogHelper;
import org.jabref.gui.keyboard.KeyBinding;
Expand Down Expand Up @@ -113,7 +112,7 @@ public class EntryEditor extends BorderPane {

private final List<EntryEditorTab> entryEditorTabs = new LinkedList<>();

public EntryEditor(LibraryTab libraryTab, ExternalFileTypes externalFileTypes) {
public EntryEditor(LibraryTab libraryTab) {
this.libraryTab = libraryTab;
this.databaseContext = libraryTab.getBibDatabaseContext();

Expand All @@ -122,8 +121,7 @@ public EntryEditor(LibraryTab libraryTab, ExternalFileTypes externalFileTypes) {
.load();

this.entryEditorPreferences = preferencesService.getEntryEditorPreferences();
this.fileLinker = new ExternalFilesEntryLinker(externalFileTypes, preferencesService.getFilePreferences(),
databaseContext);
this.fileLinker = new ExternalFilesEntryLinker(preferencesService.getFilePreferences(), databaseContext);

EasyBind.subscribe(tabbed.getSelectionModel().selectedItemProperty(), tab -> {
EntryEditorTab activeTab = (EntryEditorTab) tab;
Expand Down Expand Up @@ -242,22 +240,22 @@ private void navigateToNextEntry() {

private List<EntryEditorTab> createTabs() {
// Preview tab
entryEditorTabs.add(new PreviewTab(databaseContext, dialogService, preferencesService, stateManager, themeManager, libraryTab.getIndexingTaskManager(), ExternalFileTypes.getInstance()));
entryEditorTabs.add(new PreviewTab(databaseContext, dialogService, preferencesService, stateManager, themeManager, libraryTab.getIndexingTaskManager()));

// Required fields
entryEditorTabs.add(new RequiredFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, themeManager, libraryTab.getIndexingTaskManager(), bibEntryTypesManager, ExternalFileTypes.getInstance(), taskExecutor, journalAbbreviationRepository));
entryEditorTabs.add(new RequiredFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, themeManager, libraryTab.getIndexingTaskManager(), bibEntryTypesManager, taskExecutor, journalAbbreviationRepository));

// Optional fields
entryEditorTabs.add(new OptionalFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, themeManager, libraryTab.getIndexingTaskManager(), bibEntryTypesManager, ExternalFileTypes.getInstance(), taskExecutor, journalAbbreviationRepository));
entryEditorTabs.add(new OptionalFields2Tab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, themeManager, libraryTab.getIndexingTaskManager(), bibEntryTypesManager, ExternalFileTypes.getInstance(), taskExecutor, journalAbbreviationRepository));
entryEditorTabs.add(new DeprecatedFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, themeManager, libraryTab.getIndexingTaskManager(), bibEntryTypesManager, ExternalFileTypes.getInstance(), taskExecutor, journalAbbreviationRepository));
entryEditorTabs.add(new OptionalFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, themeManager, libraryTab.getIndexingTaskManager(), bibEntryTypesManager, taskExecutor, journalAbbreviationRepository));
entryEditorTabs.add(new OptionalFields2Tab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, themeManager, libraryTab.getIndexingTaskManager(), bibEntryTypesManager, taskExecutor, journalAbbreviationRepository));
entryEditorTabs.add(new DeprecatedFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, themeManager, libraryTab.getIndexingTaskManager(), bibEntryTypesManager, taskExecutor, journalAbbreviationRepository));

// Other fields
entryEditorTabs.add(new OtherFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, themeManager, libraryTab.getIndexingTaskManager(), bibEntryTypesManager, ExternalFileTypes.getInstance(), taskExecutor, journalAbbreviationRepository));
entryEditorTabs.add(new OtherFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, themeManager, libraryTab.getIndexingTaskManager(), bibEntryTypesManager, taskExecutor, journalAbbreviationRepository));

// General fields from preferences
for (Map.Entry<String, Set<Field>> tab : entryEditorPreferences.getEntryEditorTabList().entrySet()) {
entryEditorTabs.add(new UserDefinedFieldsTab(tab.getKey(), tab.getValue(), databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, themeManager, libraryTab.getIndexingTaskManager(), bibEntryTypesManager, ExternalFileTypes.getInstance(), taskExecutor, journalAbbreviationRepository));
entryEditorTabs.add(new UserDefinedFieldsTab(tab.getKey(), tab.getValue(), databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, themeManager, libraryTab.getIndexingTaskManager(), taskExecutor, journalAbbreviationRepository));
}

// Special tabs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.jabref.gui.DialogService;
import org.jabref.gui.StateManager;
import org.jabref.gui.autocompleter.SuggestionProviders;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.fieldeditors.FieldEditorFX;
import org.jabref.gui.fieldeditors.FieldEditors;
import org.jabref.gui.fieldeditors.FieldNameLabel;
Expand All @@ -53,7 +52,6 @@ abstract class FieldsEditorTab extends EntryEditorTab {
private final DialogService dialogService;
private final PreferencesService preferences;
private final ThemeManager themeManager;
private final ExternalFileTypes externalFileTypes;
private final TaskExecutor taskExecutor;
private final JournalAbbreviationRepository journalAbbreviationRepository;
private final StateManager stateManager;
Expand All @@ -71,7 +69,6 @@ public FieldsEditorTab(boolean compressed,
PreferencesService preferences,
StateManager stateManager,
ThemeManager themeManager,
ExternalFileTypes externalFileTypes,
TaskExecutor taskExecutor,
JournalAbbreviationRepository journalAbbreviationRepository,
IndexingTaskManager indexingTaskManager) {
Expand All @@ -82,7 +79,6 @@ public FieldsEditorTab(boolean compressed,
this.dialogService = Objects.requireNonNull(dialogService);
this.preferences = Objects.requireNonNull(preferences);
this.themeManager = themeManager;
this.externalFileTypes = Objects.requireNonNull(externalFileTypes);
this.taskExecutor = Objects.requireNonNull(taskExecutor);
this.journalAbbreviationRepository = Objects.requireNonNull(journalAbbreviationRepository);
this.stateManager = stateManager;
Expand Down Expand Up @@ -246,7 +242,7 @@ private void initPanel() {
scrollPane.setFitToHeight(true);

SplitPane container = new SplitPane(scrollPane);
previewPanel = new PreviewPanel(databaseContext, dialogService, externalFileTypes, preferences.getKeyBindingRepository(), preferences, stateManager, themeManager, indexingTaskManager);
previewPanel = new PreviewPanel(databaseContext, dialogService, preferences.getKeyBindingRepository(), preferences, stateManager, themeManager, indexingTaskManager);
EasyBind.subscribe(preferences.getPreviewPreferences().showPreviewAsExtraTabProperty(), show -> {
if (show) {
container.getItems().remove(previewPanel);
Expand Down
Loading