Skip to content

Commit

Permalink
Get rid of journal abbrev loader in linkedFiles (#3862)
Browse files Browse the repository at this point in the history
  • Loading branch information
Siedlerchr authored Mar 18, 2018
1 parent a93ed9b commit 4b76989
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static FieldEditorFX getForField(String fieldName, TaskExecutor taskExecu
} else if (fieldExtras.contains(FieldProperty.OWNER)) {
return new OwnerEditor(fieldName, preferences, suggestionProvider, fieldCheckers);
} else if (fieldExtras.contains(FieldProperty.FILE_EDITOR)) {
return new LinkedFilesEditor(fieldName, dialogService, databaseContext, taskExecutor, suggestionProvider, fieldCheckers, preferences, journalAbbreviationLoader);
return new LinkedFilesEditor(fieldName, dialogService, databaseContext, taskExecutor, suggestionProvider, fieldCheckers, preferences);
} else if (fieldExtras.contains(FieldProperty.YES_NO)) {
return new OptionEditor<>(new YesNoEditorViewModel(fieldName, suggestionProvider, fieldCheckers));
} else if (fieldExtras.contains(FieldProperty.MONTH)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.cleanup.MoveFilesCleanup;
import org.jabref.logic.cleanup.RenamePdfCleanup;
import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.net.URLDownload;
import org.jabref.logic.util.io.FileUtil;
Expand Down Expand Up @@ -76,8 +75,7 @@ public LinkedFileViewModel(LinkedFile linkedFile,
BibDatabaseContext databaseContext,
TaskExecutor taskExecutor,
DialogService dialogService,
JabRefPreferences preferences,
JournalAbbreviationLoader abbreviationLoader) {
JabRefPreferences preferences) {

this.linkedFile = linkedFile;
this.databaseContext = databaseContext;
Expand All @@ -88,7 +86,7 @@ public LinkedFileViewModel(LinkedFile linkedFile,
xmpPreferences = preferences.getXMPPreferences();
fileNamePattern = preferences.get(JabRefPreferences.IMPORT_FILENAMEPATTERN);
fileDirectoryPreferences = preferences.getFileDirectoryPreferences();
fileDirPattern = preferences.getCleanupPreferences(abbreviationLoader).getFileDirPattern();
fileDirPattern = preferences.get(JabRefPreferences.IMPORT_FILEDIRPATTERN);
downloadOngoing.bind(downloadProgress.greaterThanOrEqualTo(0).and(downloadProgress.lessThan(1)));
canWriteXMPMetadata.setValue(!linkedFile.isOnlineLink() && linkedFile.getFileType().equalsIgnoreCase("pdf"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.jabref.gui.util.TaskExecutor;
import org.jabref.gui.util.ViewModelListCellFactory;
import org.jabref.logic.integrity.FieldCheckers;
import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
Expand All @@ -54,8 +53,8 @@ public class LinkedFilesEditor extends HBox implements FieldEditorFX {

public LinkedFilesEditor(String fieldName, DialogService dialogService, BibDatabaseContext databaseContext, TaskExecutor taskExecutor, AutoCompleteSuggestionProvider<?> suggestionProvider,
FieldCheckers fieldCheckers,
JabRefPreferences preferences, JournalAbbreviationLoader abbreviationLoader) {
this.viewModel = new LinkedFilesEditorViewModel(fieldName, suggestionProvider, dialogService, databaseContext, taskExecutor, fieldCheckers, preferences, abbreviationLoader);
JabRefPreferences preferences) {
this.viewModel = new LinkedFilesEditorViewModel(fieldName, suggestionProvider, dialogService, databaseContext, taskExecutor, fieldCheckers, preferences);

ControlHelper.loadFXMLForControl(this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.importer.FulltextFetchers;
import org.jabref.logic.integrity.FieldCheckers;
import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.io.FileUtil;
import org.jabref.model.database.BibDatabaseContext;
Expand All @@ -48,22 +47,20 @@ public class LinkedFilesEditorViewModel extends AbstractEditorViewModel {
private final BibDatabaseContext databaseContext;
private final TaskExecutor taskExecutor;
private final JabRefPreferences preferences;
private final JournalAbbreviationLoader journalAbbreviationLoader;

public LinkedFilesEditorViewModel(String fieldName, AutoCompleteSuggestionProvider<?> suggestionProvider,
DialogService dialogService,
BibDatabaseContext databaseContext,
TaskExecutor taskExecutor,
FieldCheckers fieldCheckers,
JabRefPreferences preferences,
JournalAbbreviationLoader journalAbbreviationLoader) {
JabRefPreferences preferences) {
super(fieldName, suggestionProvider, fieldCheckers);

this.dialogService = dialogService;
this.databaseContext = databaseContext;
this.taskExecutor = taskExecutor;
this.preferences = preferences;
this.journalAbbreviationLoader = journalAbbreviationLoader;


BindingsHelper.bindContentBidirectional(
files,
Expand Down Expand Up @@ -101,7 +98,7 @@ public LinkedFileViewModel fromFile(Path file) {
List<Path> fileDirectories = databaseContext.getFileDirectoriesAsPaths(preferences.getFileDirectoryPreferences());

LinkedFile linkedFile = fromFile(file, fileDirectories);
return new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences, journalAbbreviationLoader);
return new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences);

}

Expand All @@ -115,7 +112,7 @@ public BooleanProperty fulltextLookupInProgressProperty() {

private List<LinkedFileViewModel> parseToFileViewModel(String stringValue) {
return FileFieldParser.parse(stringValue).stream()
.map(linkedFile -> new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences, journalAbbreviationLoader))
.map(linkedFile -> new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences))
.collect(Collectors.toList());
}

Expand All @@ -138,7 +135,7 @@ public void addNewFile() {
List<Path> fileDirectories = databaseContext.getFileDirectoriesAsPaths(preferences.getFileDirectoryPreferences());
dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(newFile -> {
LinkedFile newLinkedFile = fromFile(newFile, fileDirectories);
files.add(new LinkedFileViewModel(newLinkedFile, entry, databaseContext, taskExecutor, dialogService, preferences, journalAbbreviationLoader));
files.add(new LinkedFileViewModel(newLinkedFile, entry, databaseContext, taskExecutor, dialogService, preferences));
});
}

Expand All @@ -164,7 +161,7 @@ private List<LinkedFileViewModel> findAssociatedNotLinkedFiles(BibEntry entry) {
try {
List<LinkedFile> linkedFiles = util.findAssociatedNotLinkedFiles(entry);
for (LinkedFile linkedFile : linkedFiles) {
LinkedFileViewModel newLinkedFile = new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences, journalAbbreviationLoader);
LinkedFileViewModel newLinkedFile = new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences);
newLinkedFile.markAsAutomaticallyFound();
result.add(newLinkedFile);
}
Expand Down Expand Up @@ -207,8 +204,7 @@ public void addFromURL() {
}

private void addFromURL(URL url) {
LinkedFileViewModel onlineFile = new LinkedFileViewModel(new LinkedFile("", url, ""),
entry, databaseContext, taskExecutor, dialogService, preferences, null);
LinkedFileViewModel onlineFile = new LinkedFileViewModel(new LinkedFile("", url, ""), entry, databaseContext, taskExecutor, dialogService, preferences);
files.add(onlineFile);
onlineFile.download();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ private TableColumn<BibEntryTableViewModel, List<LinkedFile>> createFileColumn()
.withOnMouseClickedEvent((entry, linkedFiles) -> event -> {
if ((event.getButton() == MouseButton.PRIMARY) && (linkedFiles.size() == 1)) {
// Only one linked file -> open directly
LinkedFileViewModel linkedFileViewModel = new LinkedFileViewModel(linkedFiles.get(0), entry.getEntry(), database, Globals.TASK_EXECUTOR, dialogService, Globals.prefs, Globals.journalAbbreviationLoader);
LinkedFileViewModel linkedFileViewModel = new LinkedFileViewModel(linkedFiles.get(0), entry.getEntry(), database, Globals.TASK_EXECUTOR, dialogService, Globals.prefs);
linkedFileViewModel.open();
}
})
Expand All @@ -258,7 +258,7 @@ private ContextMenu createFileMenu(BibEntryTableViewModel entry, List<LinkedFile
ContextMenu contextMenu = new ContextMenu();

for (LinkedFile linkedFile : linkedFiles) {
LinkedFileViewModel linkedFileViewModel = new LinkedFileViewModel(linkedFile, entry.getEntry(), database, Globals.TASK_EXECUTOR, dialogService, Globals.prefs, Globals.journalAbbreviationLoader);
LinkedFileViewModel linkedFileViewModel = new LinkedFileViewModel(linkedFile, entry.getEntry(), database, Globals.TASK_EXECUTOR, dialogService, Globals.prefs);

MenuItem menuItem = new MenuItem(linkedFileViewModel.getDescriptionAndLink(), linkedFileViewModel.getTypeIcon().getGraphicNode());
menuItem.setOnAction(event -> linkedFileViewModel.open());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void deleteWhenFilePathNotPresentReturnsTrue() {
linkedFile = spy(new LinkedFile("", "nonexistent file", ""));
doReturn(Optional.empty()).when(linkedFile).findIn(any(BibDatabaseContext.class), any(FileDirectoryPreferences.class));

LinkedFileViewModel viewModel = new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences, abbreviationLoader);
LinkedFileViewModel viewModel = new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences);
boolean removed = viewModel.delete(fileDirectoryPreferences);

assertTrue(removed);
Expand All @@ -78,7 +78,7 @@ public void deleteWhenRemoveChosenReturnsTrue() throws IOException {
any(ButtonType.class),
any(ButtonType.class))).thenAnswer(invocation -> Optional.of(invocation.getArgument(3))); // first vararg - remove button

LinkedFileViewModel viewModel = new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences, abbreviationLoader);
LinkedFileViewModel viewModel = new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences);
boolean removed = viewModel.delete(fileDirectoryPreferences);

assertTrue(removed);
Expand All @@ -97,7 +97,7 @@ public void deleteWhenDeleteChosenReturnsTrueAndDeletesFile() throws IOException
any(ButtonType.class),
any(ButtonType.class))).thenAnswer(invocation -> Optional.of(invocation.getArgument(4))); // second vararg - delete button

LinkedFileViewModel viewModel = new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences, abbreviationLoader);
LinkedFileViewModel viewModel = new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences);
boolean removed = viewModel.delete(fileDirectoryPreferences);

assertTrue(removed);
Expand All @@ -115,7 +115,7 @@ public void deleteWhenDeleteChosenAndFileMissingReturnsFalse() throws IOExceptio
any(ButtonType.class),
any(ButtonType.class))).thenAnswer(invocation -> Optional.of(invocation.getArgument(4))); // second vararg - delete button

LinkedFileViewModel viewModel = new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences, abbreviationLoader);
LinkedFileViewModel viewModel = new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences);
boolean removed = viewModel.delete(fileDirectoryPreferences);

verify(dialogService).showErrorDialogAndWait(anyString(), anyString());
Expand All @@ -134,7 +134,7 @@ public void deleteWhenDialogCancelledReturnsFalse() throws IOException {
any(ButtonType.class),
any(ButtonType.class))).thenAnswer(invocation -> Optional.of(invocation.getArgument(5))); // third vararg - cancel button

LinkedFileViewModel viewModel = new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences, abbreviationLoader);
LinkedFileViewModel viewModel = new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences);
boolean removed = viewModel.delete(fileDirectoryPreferences);

assertFalse(removed);
Expand Down

0 comments on commit 4b76989

Please sign in to comment.