Skip to content

Commit

Permalink
fix build, remove layout prefs, pass journal abbrev loader and prefs …
Browse files Browse the repository at this point in the history
…where necessary
  • Loading branch information
Siedlerchr committed Mar 18, 2018
1 parent ad8bfd4 commit a93ed9b
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 123 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);
return new LinkedFilesEditor(fieldName, dialogService, databaseContext, taskExecutor, suggestionProvider, fieldCheckers, preferences, journalAbbreviationLoader);
} else if (fieldExtras.contains(FieldProperty.YES_NO)) {
return new OptionEditor<>(new YesNoEditorViewModel(fieldName, suggestionProvider, fieldCheckers));
} else if (fieldExtras.contains(FieldProperty.MONTH)) {
Expand Down
129 changes: 61 additions & 68 deletions src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
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 @@ -51,8 +52,10 @@ public class LinkedFilesEditor extends HBox implements FieldEditorFX {
@FXML private final LinkedFilesEditorViewModel viewModel;
@FXML private ListView<LinkedFileViewModel> listView;

public LinkedFilesEditor(String fieldName, DialogService dialogService, BibDatabaseContext databaseContext, TaskExecutor taskExecutor, AutoCompleteSuggestionProvider<?> suggestionProvider, FieldCheckers fieldCheckers, JabRefPreferences preferences) {
this.viewModel = new LinkedFilesEditorViewModel(fieldName, suggestionProvider, dialogService, databaseContext, taskExecutor, fieldCheckers, preferences);
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);

ControlHelper.loadFXMLForControl(this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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 @@ -47,14 +48,22 @@ public class LinkedFilesEditorViewModel extends AbstractEditorViewModel {
private final BibDatabaseContext databaseContext;
private final TaskExecutor taskExecutor;
private final JabRefPreferences preferences;

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

public LinkedFilesEditorViewModel(String fieldName, AutoCompleteSuggestionProvider<?> suggestionProvider,
DialogService dialogService,
BibDatabaseContext databaseContext,
TaskExecutor taskExecutor,
FieldCheckers fieldCheckers,
JabRefPreferences preferences,
JournalAbbreviationLoader journalAbbreviationLoader) {
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 @@ -92,7 +101,7 @@ public LinkedFileViewModel fromFile(Path file) {
List<Path> fileDirectories = databaseContext.getFileDirectoriesAsPaths(preferences.getFileDirectoryPreferences());

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

}

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

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

Expand All @@ -127,10 +136,9 @@ public void addNewFile() {
.build();

List<Path> fileDirectories = databaseContext.getFileDirectoriesAsPaths(preferences.getFileDirectoryPreferences());
dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(
newFile -> {
LinkedFile newLinkedFile = fromFile(newFile, fileDirectories);
files.add(new LinkedFileViewModel(newLinkedFile, entry, databaseContext, dialogService, taskExecutor));
dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(newFile -> {
LinkedFile newLinkedFile = fromFile(newFile, fileDirectories);
files.add(new LinkedFileViewModel(newLinkedFile, entry, databaseContext, taskExecutor, dialogService, preferences, journalAbbreviationLoader));
});
}

Expand All @@ -156,7 +164,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, dialogService, taskExecutor);
LinkedFileViewModel newLinkedFile = new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences, journalAbbreviationLoader);
newLinkedFile.markAsAutomaticallyFound();
result.add(newLinkedFile);
}
Expand Down Expand Up @@ -199,8 +207,8 @@ public void addFromURL() {
}

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

MenuItem menuItem = new MenuItem(linkedFileViewModel.getDescriptionAndLink(), linkedFileViewModel.getTypeIcon().getGraphicNode());
menuItem.setOnAction(event -> linkedFileViewModel.open());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/logic/cleanup/CleanupWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ private List<CleanupJob> determineCleanupActions(CleanupPreset preset) {
jobs.add(new FileLinksCleanup());
}
if (preset.isMovePDF()) {
jobs.add(new MoveFilesCleanup(databaseContext, fileDirPattern, fileDirectoryPreferences, layoutPrefs));
jobs.add(new MoveFilesCleanup(databaseContext, fileDirPattern, fileDirectoryPreferences));
}
if (preset.isMakePathsRelative()) {
jobs.add(new RelativePathsCleanup(databaseContext, fileDirectoryPreferences));
}
if (preset.isRenamePDF()) {
RenamePdfCleanup cleaner = new RenamePdfCleanup(preset.isRenamePdfOnlyRelativePaths(), databaseContext,
fileNamePattern, layoutPrefs, fileDirectoryPreferences);
fileNamePattern, fileDirectoryPreferences);
jobs.add(cleaner);
unsuccessfulRenames += cleaner.getUnsuccessfulRenames();
}
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/org/jabref/logic/cleanup/MoveFilesCleanup.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.util.Optional;
import java.util.stream.Collectors;

import org.jabref.logic.layout.LayoutFormatterPreferences;
import org.jabref.logic.util.io.FileUtil;
import org.jabref.model.FieldChange;
import org.jabref.model.cleanup.CleanupJob;
Expand All @@ -35,19 +34,17 @@ public class MoveFilesCleanup implements CleanupJob {

private LinkedFile singleFileFieldCleanup;

// FIXME: remove unused parameter 'layoutPrefs' later S.G.
public MoveFilesCleanup(BibDatabaseContext databaseContext, String fileDirPattern,
FileDirectoryPreferences fileDirectoryPreferences, LayoutFormatterPreferences layoutPrefs) {
FileDirectoryPreferences fileDirectoryPreferences) {
this.databaseContext = Objects.requireNonNull(databaseContext);
this.fileDirPattern = Objects.requireNonNull(fileDirPattern);
this.fileDirectoryPreferences = Objects.requireNonNull(fileDirectoryPreferences);
}

public MoveFilesCleanup(BibDatabaseContext databaseContext, String fileDirPattern,
FileDirectoryPreferences fileDirectoryPreferences, LayoutFormatterPreferences prefs,
LinkedFile field) {
FileDirectoryPreferences fileDirectoryPreferences, LinkedFile field) {

this(databaseContext, fileDirPattern, fileDirectoryPreferences, prefs);
this(databaseContext, fileDirPattern, fileDirectoryPreferences);
this.singleFileFieldCleanup = field;
}

Expand Down
9 changes: 2 additions & 7 deletions src/main/java/org/jabref/logic/cleanup/RenamePdfCleanup.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.jabref.logic.layout.LayoutFormatterPreferences;
import org.jabref.logic.util.io.FileUtil;
import org.jabref.model.FieldChange;
import org.jabref.model.cleanup.CleanupJob;
Expand All @@ -37,10 +36,8 @@ public class RenamePdfCleanup implements CleanupJob {
private int unsuccessfulRenames;
private LinkedFile singleFieldCleanup;

// FIXME: (S.G.) remove unused constructor argument 'layoutPreferences' later; for now,
// however, the argument is retained in order not to change the class interface:

public RenamePdfCleanup(boolean onlyRelativePaths, BibDatabaseContext databaseContext, String fileNamePattern,
LayoutFormatterPreferences layoutPreferences,
FileDirectoryPreferences fileDirectoryPreferences) {
this.databaseContext = Objects.requireNonNull(databaseContext);
this.onlyRelativePaths = onlyRelativePaths;
Expand All @@ -49,11 +46,9 @@ public RenamePdfCleanup(boolean onlyRelativePaths, BibDatabaseContext databaseCo
}

public RenamePdfCleanup(boolean onlyRelativePaths, BibDatabaseContext databaseContext, String fileNamePattern,
LayoutFormatterPreferences layoutPreferences,
FileDirectoryPreferences fileDirectoryPreferences, LinkedFile singleField) {

this(onlyRelativePaths, databaseContext, fileNamePattern, layoutPreferences,
fileDirectoryPreferences);
this(onlyRelativePaths, databaseContext, fileNamePattern, fileDirectoryPreferences);
this.singleFieldCleanup = singleField;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ public class TestArchitectureTests {
private static final String CLASS_ORG_JABREF_PREFERENCES_TEST = "JabRefPreferencesTest";
private static final String CLASS_ORG_JABREF_PREFERENCES_MIGRATIONS_TEST = "PreferencesMigrationsTest";
private static final String CLASS_ORG_JABREF_UPDATE_TIMESTAMP_LISTENER_TEST = "UpdateTimestampListenerTest";
private static final String CLASS_ORG_JABREF_ENTRY_EDITOR_TEST = "SourceTabTest";
private static final String CLASS_ORG_JABREF_ENTRY_EDITOR_TEST = "EntryEditorTest";
private static final String CLASS_ORG_JABREF_LINKED_FILE_VIEW_MODEL_TEST = "LinkedFileViewModelTest";

private final String forbiddenPackage;

private List<String> exceptions;
private final List<String> exceptions;

public TestArchitectureTests(String forbiddenPackage) {
this.forbiddenPackage = forbiddenPackage;
Expand Down
19 changes: 8 additions & 11 deletions src/test/java/org/jabref/logic/cleanup/MoveFilesCleanupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.Arrays;
import java.util.Optional;

import org.jabref.logic.layout.LayoutFormatterPreferences;
import org.jabref.model.Defaults;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.database.BibDatabaseContext;
Expand Down Expand Up @@ -62,8 +61,8 @@ public void movesFileFromSubfolder() throws IOException {

LinkedFile fileField = new LinkedFile("", fileBefore.getAbsolutePath(), "");
entry.setField("file", FileFieldWriter.getStringRepresentation(fileField));
cleanup = new MoveFilesCleanup(databaseContext, "", fileDirPrefs,
mock(LayoutFormatterPreferences.class));
cleanup = new MoveFilesCleanup(databaseContext, "", fileDirPrefs);

cleanup.cleanup(entry);

assertFalse(fileBefore.exists());
Expand All @@ -85,8 +84,7 @@ public void movesFileFromSubfolderMultiple() throws IOException {
entry.setField("file", FileFieldWriter.getStringRepresentation(
Arrays.asList(new LinkedFile("", "", ""), fileField, new LinkedFile("", "", ""))));

cleanup = new MoveFilesCleanup(databaseContext, "", fileDirPrefs,
mock(LayoutFormatterPreferences.class));
cleanup = new MoveFilesCleanup(databaseContext, "", fileDirPrefs);
cleanup.cleanup(entry);

assertFalse(fileBefore.exists());
Expand All @@ -109,8 +107,8 @@ public void movesFileFromSubfolderWithFileDirPattern() throws IOException {
LinkedFile fileField = new LinkedFile("", fileBefore.getAbsolutePath(), "");
entry.setField("file", FileFieldWriter.getStringRepresentation(fileField));

cleanup = new MoveFilesCleanup(databaseContext, "[entrytype]", fileDirPrefs,
mock(LayoutFormatterPreferences.class));
cleanup = new MoveFilesCleanup(databaseContext, "[entrytype]", fileDirPrefs);

cleanup.cleanup(entry);

assertFalse(fileBefore.exists());
Expand All @@ -136,8 +134,7 @@ public void movesFileFromSubfolderWithSubdirPattern() throws IOException {
LinkedFile fileField = new LinkedFile("", fileBefore.getAbsolutePath(), "");
local_entry.setField("file", FileFieldWriter.getStringRepresentation(fileField));

cleanup = new MoveFilesCleanup(databaseContext, "[year]", fileDirPrefs,
mock(LayoutFormatterPreferences.class));
cleanup = new MoveFilesCleanup(databaseContext, "[year]", fileDirPrefs);
cleanup.cleanup(local_entry);

assertFalse(fileBefore.exists());
Expand All @@ -164,8 +161,8 @@ public void movesFileFromSubfolderWithDeepSubdirPattern() throws IOException {
LinkedFile fileField = new LinkedFile("", fileBefore.getAbsolutePath(), "");
local_entry.setField("file", FileFieldWriter.getStringRepresentation(fileField));

cleanup = new MoveFilesCleanup(databaseContext, "[entrytype]/[year]/[auth]", fileDirPrefs,
mock(LayoutFormatterPreferences.class));
cleanup = new MoveFilesCleanup(databaseContext, "[entrytype]/[year]/[auth]", fileDirPrefs);

cleanup.cleanup(local_entry);

assertFalse(fileBefore.exists());
Expand Down
Loading

0 comments on commit a93ed9b

Please sign in to comment.