Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove preferences and globals from tests #2768

Merged
merged 7 commits into from
Apr 20, 2017
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/main/java/org/jabref/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.jabref.collab.FileUpdateMonitor;
import org.jabref.gui.GlobalFocusListener;
import org.jabref.gui.StateManager;
import org.jabref.gui.keyboard.KeyBindingPreferences;
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.importer.ImportFormatReader;
Expand Down Expand Up @@ -48,7 +48,7 @@ public class Globals {
*/
public static StateManager stateManager = new StateManager();
// Key binding preferences
private static KeyBindingPreferences keyPrefs;
private static KeyBindingRepository keyBindingRepository;
// Background tasks
private static GlobalFocusListener focusListener;
private static FileUpdateMonitor fileUpdateMonitor;
Expand All @@ -58,11 +58,11 @@ private Globals() {
}

// Key binding preferences
public static KeyBindingPreferences getKeyPrefs() {
if (keyPrefs == null) {
keyPrefs = new KeyBindingPreferences(prefs);
public static KeyBindingRepository getKeyPrefs() {
if (keyBindingRepository == null) {
keyBindingRepository = prefs.getKeyBindingRepository();
}
return keyPrefs;
return keyBindingRepository;
}


Expand Down
7 changes: 5 additions & 2 deletions src/main/java/org/jabref/gui/DefaultInjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import java.util.function.Function;

import org.jabref.Globals;
import org.jabref.gui.keyboard.KeyBindingPreferences;
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.preferences.JabRefPreferences;

import com.airhacks.afterburner.injection.Injector;
Expand All @@ -28,8 +29,10 @@ private static Object createDependency(Class<?> clazz) {
return Globals.taskExecutor;
} else if (clazz == JabRefPreferences.class) {
return Globals.prefs;
} else if (clazz == KeyBindingPreferences.class) {
} else if (clazz == KeyBindingRepository.class) {
return Globals.getKeyPrefs();
} else if (clazz == JournalAbbreviationLoader.class) {
return Globals.journalAbbreviationLoader;
} else if (clazz == StateManager.class) {
return Globals.stateManager;
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/jabref/gui/FXDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.jabref.Globals;
import org.jabref.JabRefGUI;
import org.jabref.gui.keyboard.KeyBinding;
import org.jabref.gui.keyboard.KeyBindingPreferences;
import org.jabref.gui.keyboard.KeyBindingRepository;

/**
* This class provides a super class for all dialogs implemented in JavaFX.
Expand Down Expand Up @@ -101,9 +101,9 @@ public FXDialog(AlertType type, boolean isModal) {

dialogWindow.setOnCloseRequest(evt -> this.close());

dialogWindow.getScene().setOnKeyPressed(evt -> {
KeyBindingPreferences keyPreferences = Globals.getKeyPrefs();
if (keyPreferences.checkKeyCombinationEquality(KeyBinding.CLOSE_DIALOG, evt)) {
dialogWindow.getScene().setOnKeyPressed(event -> {
KeyBindingRepository keyBindingRepository = Globals.getKeyPrefs();
if (keyBindingRepository.checkKeyCombinationEquality(KeyBinding.CLOSE_DIALOG, event)) {
dialogWindow.close();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.jabref.gui.DialogService;
import org.jabref.gui.IconTheme;
import org.jabref.gui.keyboard.KeyBinding;
import org.jabref.gui.keyboard.KeyBindingPreferences;
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.logic.util.BuildInfo;

public class ErrorConsoleController extends AbstractController<ErrorConsoleViewModel> {
Expand All @@ -36,7 +36,7 @@ public class ErrorConsoleController extends AbstractController<ErrorConsoleViewM
@Inject private DialogService dialogService;
@Inject private ClipBoardManager clipBoardManager;
@Inject private BuildInfo buildInfo;
@Inject private KeyBindingPreferences keyBindingPreferences;
@Inject private KeyBindingRepository keyBindingRepository;

@FXML
private void initialize() {
Expand Down Expand Up @@ -94,7 +94,7 @@ public void updateItem(LogEventViewModel event, boolean empty) {

@FXML
private void copySelectedLogEntries(KeyEvent event) {
if (keyBindingPreferences.checkKeyCombinationEquality(KeyBinding.COPY, event)) {
if (keyBindingRepository.checkKeyCombinationEquality(KeyBinding.COPY, event)) {
ObservableList<LogEventViewModel> selectedEntries = messagesListView.getSelectionModel().getSelectedItems();
viewModel.copyLog(selectedEntries);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.jabref.logic.importer.ParseException;
import org.jabref.logic.importer.fileformat.BibtexParser;
import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.logic.journals.JournalAbbreviationPreferences;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.net.URLDownload;
import org.jabref.model.entry.BibEntry;
Expand Down Expand Up @@ -67,9 +68,8 @@ public class IEEEXploreFetcher implements EntryFetcher {
private final UnitsToLatexFormatter unitsToLatexFormatter = new UnitsToLatexFormatter();
private final HtmlToLatexFormatter htmlToLatexFormatter = new HtmlToLatexFormatter();
private final JCheckBox absCheckBox = new JCheckBox(Localization.lang("Include abstracts"), false);

private boolean shouldContinue;
private final JournalAbbreviationLoader abbreviationLoader;
private boolean shouldContinue;


public IEEEXploreFetcher(JournalAbbreviationLoader abbreviationLoader) {
Expand Down Expand Up @@ -406,9 +406,10 @@ private BibEntry cleanup(BibEntry entry) {
fullName = fullName.replace(" - ", "-"); //IEE Proceedings-

fullName = fullName.trim();
if (Globals.prefs.getBoolean(JabRefPreferences.USE_IEEE_ABRV)) {
JournalAbbreviationPreferences journalAbbreviationPreferences = Globals.prefs.getJournalAbbreviationPreferences();
if (journalAbbreviationPreferences.useIEEEAbbreviations()) {
fullName = abbreviationLoader
.getRepository(Globals.prefs.getJournalAbbreviationPreferences())
.getRepository(journalAbbreviationPreferences)
.getMedlineAbbreviation(fullName)
.orElse(fullName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
import org.jabref.gui.IconTheme;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.gui.util.ValueTableCellFactory;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.preferences.PreferencesService;

public class ManageJournalAbbreviationsController extends AbstractController<ManageJournalAbbreviationsViewModel> {

@FXML public Label loadingLabel;
@FXML public ProgressIndicator progressIndicator;
@FXML private TableView<AbbreviationViewModel> journalAbbreviationsTable;
@FXML private TableColumn<AbbreviationViewModel, String> journalTableNameColumn;
@FXML private TableColumn<AbbreviationViewModel, String> journalTableAbbreviationColumn;
Expand All @@ -34,17 +37,14 @@ public class ManageJournalAbbreviationsController extends AbstractController<Man
@FXML private Button addJournalFileButton;
@FXML private Button addNewJournalFileButton;
@FXML private Button removeJournalAbbreviationsButton;
@FXML public Label loadingLabel;
@FXML public ProgressIndicator progressIndicator;


@Inject private JabRefPreferences preferences;
@Inject private PreferencesService preferences;
@Inject private DialogService dialogService;
@Inject private TaskExecutor taskExecutor;
@Inject private JournalAbbreviationLoader journalAbbreviationLoader;

@FXML
private void initialize() {
viewModel = new ManageJournalAbbreviationsViewModel(preferences, dialogService, taskExecutor);
viewModel = new ManageJournalAbbreviationsViewModel(preferences, dialogService, taskExecutor, journalAbbreviationLoader);

setUpTable();
setBindings();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@
import org.jabref.logic.journals.JournalAbbreviationPreferences;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.FileExtensions;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.preferences.PreferencesService;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import static org.jabref.Globals.journalAbbreviationLoader;

/**
* This class provides a model for managing journal abbreviation lists.
* It provides all necessary methods to create, modify or delete journal
Expand All @@ -51,14 +49,18 @@ public class ManageJournalAbbreviationsViewModel extends AbstractViewModel {
private final SimpleBooleanProperty isLoadingBuiltIn = new SimpleBooleanProperty(false);
private final SimpleBooleanProperty isLoadingIeee = new SimpleBooleanProperty(false);
private final SimpleBooleanProperty isAbbreviationEditableAndRemovable = new SimpleBooleanProperty();
private final JabRefPreferences preferences;
private final PreferencesService preferences;
private final DialogService dialogService;
private final TaskExecutor taskExecutor;
private final JournalAbbreviationPreferences abbreviationsPreferences;
private final JournalAbbreviationLoader journalAbbreviationLoader;

public ManageJournalAbbreviationsViewModel(JabRefPreferences preferences, DialogService dialogService, TaskExecutor taskExecutor) {
public ManageJournalAbbreviationsViewModel(PreferencesService preferences, DialogService dialogService, TaskExecutor taskExecutor, JournalAbbreviationLoader journalAbbreviationLoader) {
this.preferences = Objects.requireNonNull(preferences);
this.dialogService = Objects.requireNonNull(dialogService);
this.taskExecutor = Objects.requireNonNull(taskExecutor);
this.journalAbbreviationLoader = Objects.requireNonNull(journalAbbreviationLoader);
this.abbreviationsPreferences = preferences.getJournalAbbreviationPreferences();

abbreviationsCount.bind(abbreviations.sizeProperty());
currentAbbreviation.addListener((observable, oldvalue, newvalue) -> {
Expand Down Expand Up @@ -124,7 +126,7 @@ void addBuiltInLists() {

BackgroundTask
.wrap(() -> {
if (preferences.getBoolean(JabRefPreferences.USE_IEEE_ABRV)) {
if (abbreviationsPreferences.useIEEEAbbreviations()) {
return JournalAbbreviationLoader.getOfficialIEEEAbbreviations();
} else {
return JournalAbbreviationLoader.getStandardIEEEAbbreviations();
Expand All @@ -150,7 +152,7 @@ private void addList(String name, List<Abbreviation> abbreviations) {
* Read all saved file paths and read their abbreviations
*/
public void createFileObjects() {
List<String> externalFiles = preferences.getStringList(JabRefPreferences.EXTERNAL_JOURNAL_LISTS);
List<String> externalFiles = abbreviationsPreferences.getExternalJournalLists();
externalFiles.forEach(name -> openFile(Paths.get(name)));
}

Expand Down Expand Up @@ -316,14 +318,14 @@ public void saveJournalAbbreviationFiles() {
* This method stores all file paths of the files in the journalFiles property
* to the global JabRef preferences. Pseudo abbreviation files will not be stored.
*/
public void saveExternalFilesList() {
private void saveExternalFilesList() {
List<String> extFiles = new ArrayList<>();
journalFiles.forEach(file -> {
if (!file.isBuiltInListProperty().get()) {
file.getAbsolutePath().ifPresent(path -> extFiles.add(path.toAbsolutePath().toString()));
}
});
preferences.putStringList(JabRefPreferences.EXTERNAL_JOURNAL_LISTS, extFiles);
abbreviationsPreferences.setExternalJournalLists(extFiles);
}

/**
Expand All @@ -346,8 +348,11 @@ public void selectLastJournalFile() {
public void saveEverythingAndUpdateAutoCompleter() {
saveExternalFilesList();
saveJournalAbbreviationFiles();

// Update journal abbreviation loader
journalAbbreviationLoader.update(JournalAbbreviationPreferences.fromPreferences(preferences));
journalAbbreviationLoader.update(abbreviationsPreferences);

preferences.storeJournalAbbreviationPreferences(abbreviationsPreferences);
}

public SimpleListProperty<AbbreviationsFileViewModel> journalFilesProperty() {
Expand Down
Loading