Skip to content

Commit

Permalink
Refactored FilePreferences to immutable class
Browse files Browse the repository at this point in the history
  • Loading branch information
calixtus committed Aug 23, 2020
1 parent 1fb6e7a commit 4147133
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
19 changes: 13 additions & 6 deletions src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,14 @@ public class ImportEntriesViewModel extends AbstractViewModel {
* @param databaseContext the database to import into
* @param task the task executed for parsing the selected files(s).
*/
public ImportEntriesViewModel(BackgroundTask<ParserResult> task, TaskExecutor taskExecutor, BibDatabaseContext databaseContext, DialogService dialogService, UndoManager undoManager, PreferencesService preferences, StateManager stateManager, FileUpdateMonitor fileUpdateMonitor) {
public ImportEntriesViewModel(BackgroundTask<ParserResult> task,
TaskExecutor taskExecutor,
BibDatabaseContext databaseContext,
DialogService dialogService,
UndoManager undoManager,
PreferencesService preferences,
StateManager stateManager,
FileUpdateMonitor fileUpdateMonitor) {
this.taskExecutor = taskExecutor;
this.databaseContext = databaseContext;
this.dialogService = dialogService;
Expand Down Expand Up @@ -94,9 +101,9 @@ public ObservableList<BibEntry> getEntries() {
}

public boolean hasDuplicate(BibEntry entry) {
return findInternalDuplicate(entry).isPresent()
||
new DuplicateCheck(Globals.entryTypesManager).containsDuplicate(databaseContext.getDatabase(), entry, databaseContext.getMode()).isPresent();
return findInternalDuplicate(entry).isPresent() ||
new DuplicateCheck(Globals.entryTypesManager)
.containsDuplicate(databaseContext.getDatabase(), entry, databaseContext.getMode()).isPresent();
}

/**
Expand Down Expand Up @@ -132,8 +139,8 @@ public void importEntries(List<BibEntry> entriesToImport, boolean shouldDownload
}

// Remember the selection in the dialog
FilePreferences filePreferences = preferences.getFilePreferences();
filePreferences.setShouldDownloadLinkedFiles(shouldDownloadFiles);
FilePreferences filePreferences = preferences.getFilePreferences()
.withShouldDownloadLinkedFiles(shouldDownloadFiles);
preferences.storeFilePreferences(filePreferences);

if (shouldDownloadFiles) {
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/org/jabref/model/metadata/FilePreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class FilePreferences {
private final boolean bibLocationAsPrimary;
private final String fileNamePattern;
private final String fileDirPattern;
private boolean shouldDownloadLinkedFiles;
private final boolean shouldDownloadLinkedFiles;

public FilePreferences(String user,
String mainFileDirectory,
Expand Down Expand Up @@ -56,7 +56,13 @@ public boolean shouldDownloadLinkedFiles() {
return shouldDownloadLinkedFiles;
}

public void setShouldDownloadLinkedFiles(boolean shouldDownloadLinkedFiles) {
this.shouldDownloadLinkedFiles = shouldDownloadLinkedFiles;
public FilePreferences withShouldDownloadLinkedFiles(boolean newShouldDownloadLinkedFiles) {
return new FilePreferences(
this.user,
this.mainFileDirectory,
this.bibLocationAsPrimary,
this.fileNamePattern,
this.fileDirPattern,
newShouldDownloadLinkedFiles);
}
}

0 comments on commit 4147133

Please sign in to comment.