Verified Owner
Top Fields Constructors Methods
org.jabref.gui.frame

public Class JabRefFrameViewModel

extends Object
Class Inheritance
Imports
java.io.IOException, .Reader, .UncheckedIOException, java.nio.file.Files, .Path, java.util.ArrayList, .Comparator, .HashSet, .LinkedHashMap, .List, .Objects, .Optional, .SequencedMap, .Set, java.util.concurrent.CompletableFuture, java.util.function.Supplier, java.util.stream.Collectors, javafx.beans.value.ChangeListener, .ObservableBooleanValue, javafx.scene.control.ButtonType, org.jabref.cli.CliImportHelper, org.jabref.gui.DialogService, .LibraryTab, .LibraryTabContainer, .StateManager, org.jabref.gui.clipboard.ClipBoardManager, org.jabref.gui.externalfiles.ImportHandler, org.jabref.gui.importer.ImportEntriesDialog, org.jabref.gui.importer.actions.OpenDatabaseAction, org.jabref.gui.preferences.GuiPreferences, org.jabref.gui.util.UiTaskExecutor, org.jabref.logic.UiCommand, org.jabref.logic.ai.AiService, org.jabref.logic.groups.GroupsHelper, org.jabref.logic.importer.ImportCleanup, .ImportException, .ImportFormatReader, .OpenDatabase, .ParseException, .ParserResult, org.jabref.logic.importer.fileformat.BibtexParser, org.jabref.logic.l10n.Localization, org.jabref.logic.os.OS, org.jabref.logic.shared.DatabaseConnectionProperties, .DatabaseLocation, .SharedDatabaseSessionService, org.jabref.logic.util.BackgroundTask, .TaskExecutor, org.jabref.logic.util.io.FileUtil, org.jabref.logic.util.strings.StringUtil, org.jabref.model.database.BibDatabaseContext, org.jabref.model.entry.BibEntry, .BibEntryTypesManager, org.jabref.model.util.FileUpdateMonitor, com.google.common.annotations.VisibleForTesting, org.jooq.lambda.Unchecked, org.jspecify.annotations.NullMarked, .Nullable, org.slf4j.Logger, .LoggerFactory

Field Summary

Modifier and TypeField and Description
private final AiService
private final ClipBoardManager
private final DialogService
private final BibEntryTypesManager
private final FileUpdateMonitor
private static final Logger
private final Supplier<OpenDatabaseAction>
private final GuiPreferences
private final StateManager
private final LibraryTabContainer
private final TaskExecutor

Constructor Summary

AccessConstructor and Description
public
JabRefFrameViewModel(GuiPreferences preferences, AiService aiService, StateManager stateManager, DialogService dialogService, LibraryTabContainer tabContainer, Supplier<OpenDatabaseAction> openDatabaseAction, BibEntryTypesManager entryTypesManager, FileUpdateMonitor fileUpdateMonitor, ClipBoardManager clipBoardManager, TaskExecutor taskExecutor)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
pack-priv void
addParserResult(ParserResult parserResult, @Nullable String
optional group the imported entries are assigned to (e.g. the REST ?group= parameter). It pre-selects/falls back to that group in the import dialog, which creates it (top-level) on confirm if missing. An explicit pick in the dialog overrides it; cancelling imports nothing.
targetGroup
)

private void
appendToCurrentLibrary(List<Path> libraries)

Supports both BibTeX and non-BibTeX

private void
appendToCurrentLibrary(Reader library)

Imports a single library, BibTeX and non-BibTeX

Similar code as org.jabref.gui.importer.actions.ImportCommand

private void
public boolean

Returns:

true if the user chose to quit; false otherwise
close
()

Quit JabRef

private static SequencedMap<String, DatabaseConnectionProperties>
collectSharedDatabases(List<LibraryTab> tabs)

Shared databases that are backed by a local file are reopened through that file (it carries the shared database id).

private void
directImportEntries(ParserResult parserResult, @Nullable String targetGroup)

private Optional<Path>
firstBibFile()

Use case: User starts JabRef.bat or JabRef.exe.

public void
handleUiCommands(List<UiCommand>
to be handled
uiCommands
)

Handles commands submitted by the command line or by the remote host to be executed in the ui Needs to run in a certain order.

private void
importBibtexStringAndOpen(String importStr, @Nullable String targetGroup)
Deprecated used by the browser extension only

private void
importFromFileAndOpen(String location)
Deprecated used by the browser extension only

private ImportHandler
private ParserResult
private void
private void
selectLibraryTab(Optional<Path> library)

Selects the tab whose library lives at library so that the subsequent append targets it instead of the previously active tab.

pack-priv void
storeLastOpenedFiles(List<Path> filenames, Path focusedDatabase, List<String> sharedDatabaseIds)

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

aiServiceback to summary
private final AiService aiService
clipBoardManagerback to summary
private final ClipBoardManager clipBoardManager
dialogServiceback to summary
private final DialogService dialogService
entryTypesManagerback to summary
private final BibEntryTypesManager entryTypesManager
fileUpdateMonitorback to summary
private final FileUpdateMonitor fileUpdateMonitor
LOGGERback to summary
private static final Logger LOGGER
openDatabaseActionback to summary
private final Supplier<OpenDatabaseAction> openDatabaseAction
preferencesback to summary
private final GuiPreferences preferences
stateManagerback to summary
private final StateManager stateManager
tabContainerback to summary
private final LibraryTabContainer tabContainer
taskExecutorback to summary
private final TaskExecutor taskExecutor

Constructor Detail

JabRefFrameViewModelback to summary
public JabRefFrameViewModel(GuiPreferences preferences, AiService aiService, StateManager stateManager, DialogService dialogService, LibraryTabContainer tabContainer, Supplier<OpenDatabaseAction> openDatabaseAction, BibEntryTypesManager entryTypesManager, FileUpdateMonitor fileUpdateMonitor, ClipBoardManager clipBoardManager, TaskExecutor taskExecutor)

Method Detail

addParserResultback to summary
pack-priv void addParserResult(ParserResult parserResult)
Annotations
@VisibleForTesting
addParserResultback to summary
pack-priv void addParserResult(ParserResult parserResult, @Nullable String targetGroup)
Parameters
targetGroup:@Nullable String

optional group the imported entries are assigned to (e.g. the REST ?group= parameter). It pre-selects/falls back to that group in the import dialog, which creates it (top-level) on confirm if missing. An explicit pick in the dialog overrides it; cancelling imports nothing.

appendToCurrentLibraryback to summary
private void appendToCurrentLibrary(List<Path> libraries)

Supports both BibTeX and non-BibTeX

appendToCurrentLibraryback to summary
private void appendToCurrentLibrary(Reader library)

Imports a single library, BibTeX and non-BibTeX

Similar code as org.jabref.gui.importer.actions.ImportCommand

checkForBibInUpperDirback to summary
private void checkForBibInUpperDir()
closeback to summary
public boolean close()

Quit JabRef

Returns:boolean

true if the user chose to quit; false otherwise

collectSharedDatabasesback to summary
private static SequencedMap<String, DatabaseConnectionProperties> collectSharedDatabases(List<LibraryTab> tabs)

Shared databases that are backed by a local file are reopened through that file (it carries the shared database id). The others only live in the connection, so their connection properties are collected here, keyed by a generated id. Nothing is written yet: the user may still cancel the quit, and a credential must not land in the keyring for a database that then stays open.

directImportEntriesback to summary
private void directImportEntries(ParserResult parserResult, @Nullable String targetGroup)
firstBibFileback to summary
private Optional<Path> firstBibFile()

Use case: User starts JabRef.bat or JabRef.exe. JabRef should open a "close by" bib file. By "close by" a .bib file in the current folder or one level up of JabRef.exeis meant.

Paths:

  • ...\{example-dir}\JabRef\JabRef.exe (Windows)
  • .../{example-dir}/JabRef/bin/JabRef (Linux)
  • ...\{example-dir}\JabRef\runtime\bin\JabRef.bat (Windows)

In the example, ...\{example-dir}\example.bib should be found.

We do NOT go up another level (i.e., everything in ... is not found)

handleUiCommandsback to summary
public void handleUiCommands(List<UiCommand> uiCommands)

Handles commands submitted by the command line or by the remote host to be executed in the ui Needs to run in a certain order. E.g. databases have to be loaded before selecting an entry.

Does NOT handle focus - this is done in JabRefFrame

Parameters
uiCommands:List<UiCommand>

to be handled

importBibtexStringAndOpenback to summary
private void importBibtexStringAndOpen(String importStr, @Nullable String targetGroup)

Deprecated

used by the browser extension only

importFromFileAndOpenback to summary
private void importFromFileAndOpen(String location)

Deprecated

used by the browser extension only

newImportHandlerback to summary
private ImportHandler newImportHandler(BibDatabaseContext databaseContext)
parseBibtexEntriesback to summary
private ParserResult parseBibtexEntries(String importStr) throws org.jabref.logic.importer.ParseException
selectEntriesback to summary
private void selectEntries(List<String> entryKeys)
Annotations
@NullMarked
selectLibraryTabback to summary
private void selectLibraryTab(Optional<Path> library)

Selects the tab whose library lives at library so that the subsequent append targets it instead of the previously active tab. An empty Optional leaves the current tab unchanged. If the library is not open yet, it is opened in a new (raised) tab; the actual loading happens in the background, so callers must run the append via waitForLoadingFinished(Runnable) to let the new tab finish loading first. A path that does not exist (or is not a .bib file) is silently ignored by OpenDatabaseAction#openFile(Path) and the current tab is kept (the server side already rejects unknown ids with 404, so this is only a defensive fallback).

storeLastOpenedFilesback to summary
pack-priv void storeLastOpenedFiles(List<Path> filenames, Path focusedDatabase, List<String> sharedDatabaseIds)
waitForLoadingFinishedback to summary
private void waitForLoadingFinished(Runnable runnable)