Verified Owner
Top Description Inners Fields Constructors Methods
org.jabref.gui.exporter

public Class SaveDatabaseAction

extends Object
Class Inheritance
Imports
java.io.IOException, java.nio.charset.Charset, .StandardCharsets, .UnsupportedCharsetException, java.nio.file.Files, .Path, java.util.List, .Optional, .Set, java.util.concurrent.CompletionException, .ExecutionException, java.util.stream.Collectors, javafx.scene.control.ButtonBar, .ButtonType, .DialogPane, .TableColumn, javafx.scene.layout.VBox, javafx.scene.text.Text, org.jabref.gui.DialogService, .LibraryTab, .StateManager, org.jabref.gui.autosaveandbackup.AutosaveManager, .BackupManager, org.jabref.gui.git.GitAutoSync, .GitPullScheduler, org.jabref.gui.maintable.BibEntryTableViewModel, org.jabref.gui.maintable.columns.MainTableColumn, org.jabref.gui.preferences.GuiPreferences, org.jabref.gui.util.FileDialogConfiguration, .UiTaskExecutor, org.jabref.logic.exporter.AtomicFileWriter, .BibDatabaseWriter, .BibWriter, .FileChangedException, .SaveException, .SelfContainedSaveConfiguration, org.jabref.logic.git.util.GitHandlerRegistry, org.jabref.logic.journals.JournalAbbreviationRepository, org.jabref.logic.l10n.Localization, org.jabref.logic.os.OS, org.jabref.logic.shared.DatabaseLocation, org.jabref.logic.shared.prefs.SharedDatabasePreferences, org.jabref.logic.util.StandardFileType, .TaskExecutor, org.jabref.logic.util.io.FileSnapshot, org.jabref.model.database.BibDatabaseContext, org.jabref.model.database.event.ChangePropagation, org.jabref.model.entry.BibEntryTypesManager, org.jabref.model.metadata.SaveOrder, .SelfContainedSaveOrder, com.airhacks.afterburner.injection.Injector, org.jspecify.annotations.Nullable, org.slf4j.Logger, .LoggerFactory

Action for the "Save" and "Save as" operations called from BasePanel. This class is also used for save operations when closing a database or quitting the applications.

The save operation is loaded off of the GUI thread using org.jabref.logic.util.BackgroundTask. Callers can query whether the operation was canceled, or whether it was successful.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
public static enum
SaveDatabaseAction.SaveResult

ALREADY_SAVING reports that another thread is writing the very same library: nothing was written by this call, and the file on disk is not yet the state the user sees.

Field Summary

Modifier and TypeField and Description
private final DialogService
private final BibEntryTypesManager
private final GitHandlerRegistry
private final JournalAbbreviationRepository
private final LibraryTab
private static final Logger
private final GuiPreferences
private final StateManager
private final TaskExecutor

Constructor Summary

AccessConstructor and Description
public
SaveDatabaseAction(LibraryTab libraryTab, DialogService dialogService, GuiPreferences preferences, BibEntryTypesManager entryTypesManager, StateManager stateManager, JournalAbbreviationRepository journalAbbreviationRepository)

public
SaveDatabaseAction(LibraryTab libraryTab, DialogService dialogService, GuiPreferences preferences, BibEntryTypesManager entryTypesManager, StateManager stateManager, JournalAbbreviationRepository journalAbbreviationRepository, GitHandlerRegistry gitHandlerRegistry, TaskExecutor taskExecutor)

Method Summary

Modifier and TypeMethod and Description
private Optional<Path>

Returns:

the path set by the user
askForSavePath
()

Asks the user for the path to save to.

private void
commitToGit(Path targetPath)

private static AtomicFileWriter
createFileWriter(Path file, Charset encoding, boolean keepBackup, @Nullable FileSnapshot expectedState)

private SelfContainedSaveOrder
private static void
public SaveDatabaseAction.SaveResult
save()

public SaveDatabaseAction.SaveResult
private SaveDatabaseAction.SaveResult
save(BibDatabaseContext bibDatabaseContext, SaveDatabaseAction.SaveDatabaseMode mode, boolean mayAutoCommit)

private SaveDatabaseAction.SaveResult
save(Path targetPath, SaveDatabaseAction.SaveDatabaseMode mode, boolean mayAutoCommit)

public void
saveAs()

Asks the user for the path and saves afterward

public boolean
saveAs(Path file)

pack-priv boolean
pack-priv boolean
saveAs(Path
the new file name to save the database to. This is stored in the database context of the panel upon successful save.
file
,
SaveDatabaseAction.SaveDatabaseMode mode, boolean mayAutoCommit)

Returns: true on successful save

private @Nullable FileSnapshot
saveDatabase(Path file, boolean selectedOnly, Charset encoding, SaveType saveType, SelfContainedSaveOrder saveOrder, @Nullable FileSnapshot expectedState)

Returns: the state of the file as committed by this save (or by its encoding retry), null when unreadable

public void
private @Nullable FileSnapshot
saveWithDifferentEncoding(Path file, boolean selectedOnly, Charset encoding, Set<Character> encodingProblems, SaveType saveType, SelfContainedSaveOrder saveOrder, @Nullable FileSnapshot committedState)

Returns: the state committed by the retry, or null when no retry happened and the first write stands

public SaveDatabaseAction.SaveResult
saveWithoutGitAutoCommit(SaveDatabaseAction.SaveDatabaseMode mode)

Saves the library without triggering the automatic Git commit configured in the library properties.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dialogServiceback to summary
private final DialogService dialogService
entryTypesManagerback to summary
private final BibEntryTypesManager entryTypesManager
gitHandlerRegistryback to summary
private final GitHandlerRegistry gitHandlerRegistry
journalAbbreviationRepositoryback to summary
private final JournalAbbreviationRepository journalAbbreviationRepository
libraryTabback to summary
private final LibraryTab libraryTab
LOGGERback to summary
private static final Logger LOGGER
preferencesback to summary
private final GuiPreferences preferences
stateManagerback to summary
private final StateManager stateManager
taskExecutorback to summary
private final TaskExecutor taskExecutor

Constructor Detail

SaveDatabaseActionback to summary
public SaveDatabaseAction(LibraryTab libraryTab, DialogService dialogService, GuiPreferences preferences, BibEntryTypesManager entryTypesManager, StateManager stateManager, JournalAbbreviationRepository journalAbbreviationRepository)
SaveDatabaseActionback to summary
public SaveDatabaseAction(LibraryTab libraryTab, DialogService dialogService, GuiPreferences preferences, BibEntryTypesManager entryTypesManager, StateManager stateManager, JournalAbbreviationRepository journalAbbreviationRepository, GitHandlerRegistry gitHandlerRegistry, TaskExecutor taskExecutor)

Method Detail

askForSavePathback to summary
private Optional<Path> askForSavePath()

Asks the user for the path to save to. Stores the directory to the preferences, which is used next time when opening the dialog.

Returns:Optional<Path>

the path set by the user

commitToGitback to summary
private void commitToGit(Path targetPath)
createFileWriterback to summary
private static AtomicFileWriter createFileWriter(Path file, Charset encoding, boolean keepBackup, @Nullable FileSnapshot expectedState) throws org.jabref.logic.exporter.SaveException
getSaveOrderback to summary
private SelfContainedSaveOrder getSaveOrder()
runSaveMutationback to summary
private static void runSaveMutation(Runnable mutation)
saveback to summary
public SaveDatabaseAction.SaveResult save()
saveback to summary
public SaveDatabaseAction.SaveResult save(SaveDatabaseAction.SaveDatabaseMode mode)
saveback to summary
private SaveDatabaseAction.SaveResult save(BibDatabaseContext bibDatabaseContext, SaveDatabaseAction.SaveDatabaseMode mode, boolean mayAutoCommit)
saveback to summary
private SaveDatabaseAction.SaveResult save(Path targetPath, SaveDatabaseAction.SaveDatabaseMode mode, boolean mayAutoCommit)
saveAsback to summary
public void saveAs()

Asks the user for the path and saves afterward

saveAsback to summary
public boolean saveAs(Path file)
saveAsback to summary
pack-priv boolean saveAs(Path file, SaveDatabaseAction.SaveDatabaseMode mode)
saveAsback to summary
pack-priv boolean saveAs(Path file, SaveDatabaseAction.SaveDatabaseMode mode, boolean mayAutoCommit)
Parameters
file:Path

the new file name to save the database to. This is stored in the database context of the panel upon successful save.

Returns:boolean

true on successful save

saveDatabaseback to summary
private @Nullable FileSnapshot saveDatabase(Path file, boolean selectedOnly, Charset encoding, SaveType saveType, SelfContainedSaveOrder saveOrder, @Nullable FileSnapshot expectedState) throws org.jabref.logic.exporter.SaveException
Returns:@Nullable FileSnapshot

the state of the file as committed by this save (or by its encoding retry), null when unreadable

saveSelectedAsPlainback to summary
public void saveSelectedAsPlain()
saveWithDifferentEncodingback to summary
private @Nullable FileSnapshot saveWithDifferentEncoding(Path file, boolean selectedOnly, Charset encoding, Set<Character> encodingProblems, SaveType saveType, SelfContainedSaveOrder saveOrder, @Nullable FileSnapshot committedState) throws org.jabref.logic.exporter.SaveException
Returns:@Nullable FileSnapshot

the state committed by the retry, or null when no retry happened and the first write stands

saveWithoutGitAutoCommitback to summary
public SaveDatabaseAction.SaveResult saveWithoutGitAutoCommit(SaveDatabaseAction.SaveDatabaseMode mode)

Saves the library without triggering the automatic Git commit configured in the library properties.

org.jabref.gui.exporter back to summary

public final Enum SaveDatabaseAction.SaveDatabaseMode

extends Enum<SaveDatabaseAction.SaveDatabaseMode>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final SaveDatabaseAction.SaveDatabaseMode
public static final SaveDatabaseAction.SaveDatabaseMode

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static SaveDatabaseAction.SaveDatabaseMode
public static SaveDatabaseAction.SaveDatabaseMode[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

NORMALback to summary
public static final SaveDatabaseAction.SaveDatabaseMode NORMAL
SILENTback to summary
public static final SaveDatabaseAction.SaveDatabaseMode SILENT

Constructor Detail

SaveDatabaseModeback to summary
private SaveDatabaseMode()

Method Detail

valueOfback to summary
public static SaveDatabaseAction.SaveDatabaseMode valueOf(String name)
valuesback to summary
public static SaveDatabaseAction.SaveDatabaseMode[] values()
org.jabref.gui.exporter back to summary

public final Enum SaveDatabaseAction.SaveResult

extends Enum<SaveDatabaseAction.SaveResult>
Class Inheritance

ALREADY_SAVING reports that another thread is writing the very same library: nothing was written by this call, and the file on disk is not yet the state the user sees.

Field Summary

Modifier and TypeField and Description
public static final SaveDatabaseAction.SaveResult
public static final SaveDatabaseAction.SaveResult
public static final SaveDatabaseAction.SaveResult

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static SaveDatabaseAction.SaveResult
public static SaveDatabaseAction.SaveResult[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

ALREADY_SAVINGback to summary
public static final SaveDatabaseAction.SaveResult ALREADY_SAVING
FAILUREback to summary
public static final SaveDatabaseAction.SaveResult FAILURE
SUCCESSback to summary
public static final SaveDatabaseAction.SaveResult SUCCESS

Constructor Detail

SaveResultback to summary
private SaveResult()

Method Detail

valueOfback to summary
public static SaveDatabaseAction.SaveResult valueOf(String name)
valuesback to summary
public static SaveDatabaseAction.SaveResult[] values()