From f326b088d7a9990b855b0e6b5bceb28398ce3248 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Tue, 27 Jun 2017 17:18:12 +0200 Subject: [PATCH 01/10] Works in principle --- .../gui/actions/ManageKeywordsAction.java | 37 +-- .../jabref/gui/entryeditor/EntryEditor.java | 5 +- .../gui/entryeditor/FieldsEditorTab.java | 5 +- .../fieldeditors/AbstractEditorViewModel.java | 20 +- .../jabref/gui/fieldeditors/DateEditor.java | 9 +- .../gui/fieldeditors/DateEditorViewModel.java | 4 +- .../EditorTypeEditorViewModel.java | 5 +- .../jabref/gui/fieldeditors/FieldEditors.java | 35 +-- .../fieldeditors/GenderEditorViewModel.java | 5 +- .../gui/fieldeditors/IdentifierEditor.java | 9 +- .../IdentifierEditorViewModel.java | 7 +- .../gui/fieldeditors/JournalEditor.java | 9 +- .../fieldeditors/JournalEditorViewModel.java | 5 +- .../gui/fieldeditors/LinkedEntriesEditor.java | 9 +- .../LinkedEntriesEditorViewModel.java | 5 +- .../gui/fieldeditors/LinkedFileViewModel.java | 4 +- .../gui/fieldeditors/LinkedFilesEditor.java | 9 +- .../LinkedFilesEditorViewModel.java | 9 +- .../fieldeditors/MapBasedEditorViewModel.java | 6 + .../fieldeditors/MonthEditorViewModel.java | 4 +- .../jabref/gui/fieldeditors/OptionEditor.java | 4 +- .../fieldeditors/OptionEditorViewModel.java | 6 + .../jabref/gui/fieldeditors/OwnerEditor.java | 13 +- .../fieldeditors/OwnerEditorViewModel.java | 4 +- .../PaginationEditorViewModel.java | 5 +- .../PatentTypeEditorViewModel.java | 5 +- .../jabref/gui/fieldeditors/SimpleEditor.java | 12 +- .../fieldeditors/SimpleEditorViewModel.java | 6 + .../gui/fieldeditors/TypeEditorViewModel.java | 5 +- .../jabref/gui/fieldeditors/UrlEditor.java | 13 +- .../gui/fieldeditors/UrlEditorViewModel.java | 4 +- .../fieldeditors/YesNoEditorViewModel.java | 6 +- .../util/AutoCompletionTextInputBinding.java | 172 ++++++++++++++ .../AutoCompleteSuggestionProvider.java | 13 ++ .../autocompleter/AutoCompleterFactory.java | 24 +- .../logic/autocompleter/AutoCompleters.java | 10 +- .../BibEntrySuggestionProvider.java | 37 +++ .../autocompleter/BibtexKeyAutoCompleter.java | 38 --- .../autocompleter/ContentAutoCompleters.java | 9 +- .../EntireFieldAutoCompleter.java | 43 ---- .../FieldValueSuggestionProvider.java | 26 +++ .../autocompleter/JournalAutoCompleter.java | 37 --- .../JournalsSuggestionProvider.java | 24 ++ ...java => PersonNameSuggestionProvider.java} | 14 +- .../StringSuggestionProvider.java | 27 +++ ...leter.java => WordSuggestionProvider.java} | 25 +- .../IdentifierEditorViewModelTest.java | 3 +- .../AutoCompleterFactoryTest.java | 14 +- .../autocompleter/AutoCompleterTestUtil.java | 19 ++ .../BibtexKeyAutoCompleterTest.java | 98 +++----- .../DefaultAutoCompleterTest.java | 139 ++++------- .../EntireFieldAutoCompleterTest.java | 220 ------------------ .../FieldValueSuggestionProviderTest.java | 164 +++++++++++++ ... => PersonNameSuggestionProviderTest.java} | 56 ++--- 54 files changed, 780 insertions(+), 716 deletions(-) create mode 100644 src/main/java/org/jabref/gui/util/AutoCompletionTextInputBinding.java create mode 100644 src/main/java/org/jabref/logic/autocompleter/AutoCompleteSuggestionProvider.java create mode 100644 src/main/java/org/jabref/logic/autocompleter/BibEntrySuggestionProvider.java delete mode 100644 src/main/java/org/jabref/logic/autocompleter/BibtexKeyAutoCompleter.java delete mode 100644 src/main/java/org/jabref/logic/autocompleter/EntireFieldAutoCompleter.java create mode 100644 src/main/java/org/jabref/logic/autocompleter/FieldValueSuggestionProvider.java delete mode 100644 src/main/java/org/jabref/logic/autocompleter/JournalAutoCompleter.java create mode 100644 src/main/java/org/jabref/logic/autocompleter/JournalsSuggestionProvider.java rename src/main/java/org/jabref/logic/autocompleter/{NameFieldAutoCompleter.java => PersonNameSuggestionProvider.java} (91%) create mode 100644 src/main/java/org/jabref/logic/autocompleter/StringSuggestionProvider.java rename src/main/java/org/jabref/logic/autocompleter/{DefaultAutoCompleter.java => WordSuggestionProvider.java} (53%) create mode 100644 src/test/java/org/jabref/logic/autocompleter/AutoCompleterTestUtil.java delete mode 100644 src/test/java/org/jabref/logic/autocompleter/EntireFieldAutoCompleterTest.java create mode 100644 src/test/java/org/jabref/logic/autocompleter/FieldValueSuggestionProviderTest.java rename src/test/java/org/jabref/logic/autocompleter/{NameFieldAutoCompleterTest.java => PersonNameSuggestionProviderTest.java} (80%) diff --git a/src/main/java/org/jabref/gui/actions/ManageKeywordsAction.java b/src/main/java/org/jabref/gui/actions/ManageKeywordsAction.java index ba7f6b8db2f..a55f13f56d2 100644 --- a/src/main/java/org/jabref/gui/actions/ManageKeywordsAction.java +++ b/src/main/java/org/jabref/gui/actions/ManageKeywordsAction.java @@ -25,19 +25,15 @@ import javax.swing.JTextField; import org.jabref.Globals; -import org.jabref.JabRefGUI; import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefFrame; -import org.jabref.gui.autocompleter.AutoCompleteListener; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.gui.undo.NamedCompound; import org.jabref.gui.undo.UndoableFieldChange; -import org.jabref.logic.autocompleter.AutoCompleter; import org.jabref.logic.l10n.Localization; import org.jabref.logic.specialfields.SpecialFieldsUtils; import org.jabref.model.FieldChange; import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.FieldName; import org.jabref.model.entry.Keyword; import org.jabref.model.entry.KeywordList; import org.jabref.model.strings.StringUtil; @@ -53,19 +49,13 @@ public class ManageKeywordsAction extends MnemonicAwareAction { private final JabRefFrame frame; - + private final KeywordList sortedKeywordsOfAllEntriesBeforeUpdateByUser = new KeywordList(); private JDialog diag; - - private DefaultListModel keywordListModel; - private JRadioButton intersectKeywords; private JRadioButton mergeKeywords; - private boolean canceled; - private final KeywordList sortedKeywordsOfAllEntriesBeforeUpdateByUser = new KeywordList(); - public ManageKeywordsAction(JabRefFrame frame) { putValue(Action.NAME, Localization.menuTitle("Manage keywords")); @@ -171,31 +161,6 @@ public void keyPressed(KeyEvent arg0) { } }); - AutoCompleter autoComp = JabRefGUI.getMainFrame().getCurrentBasePanel().getAutoCompleters() - .get(FieldName.KEYWORDS); - AutoCompleteListener acl = new AutoCompleteListener(autoComp); - keyword.addKeyListener(acl); - keyword.addFocusListener(acl); - keyword.addKeyListener(new KeyListener() { - - @Override - public void keyTyped(KeyEvent e) { - // Do nothing - } - - @Override - public void keyReleased(KeyEvent e) { - // Do nothing - } - - @Override - public void keyPressed(KeyEvent e) { - if (e.getKeyCode() == KeyEvent.VK_ENTER) { - addActionListener.actionPerformed(null); - } - } - }); - // Key bindings: ActionMap am = builder.getPanel().getActionMap(); InputMap im = builder.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index 0b3503f5515..85699fd20e8 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -64,7 +64,6 @@ import org.jabref.gui.util.component.CheckBoxMessage; import org.jabref.gui.util.component.VerticalLabelUI; import org.jabref.logic.TypedBibEntry; -import org.jabref.logic.autocompleter.AutoCompleter; import org.jabref.logic.bibtex.InvalidFieldValueException; import org.jabref.logic.bibtex.LatexFieldFormatter; import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; @@ -687,11 +686,13 @@ public void actionPerformed(ActionEvent event) { fieldEditor.setValidBackgroundColor(); - // See if we need to update an AutoCompleter instance: + //TODO: See if we need to update an AutoCompleter instance: + /* AutoCompleter aComp = panel.getAutoCompleters().get(fieldEditor.getFieldName()); if (aComp != null) { aComp.addBibtexEntry(entry); } + */ // Add an UndoableFieldChange to the baseframe's undoManager. UndoableFieldChange undoableFieldChange = new UndoableFieldChange(entry, diff --git a/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java b/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java index e2663763b23..e4d62da39ea 100644 --- a/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java @@ -45,8 +45,8 @@ class FieldsEditorTab extends EntryEditorTab { private final Map editors = new LinkedHashMap<>(); private final JabRefFrame frame; private final BasePanel basePanel; - private FieldEditorFX activeField; private final BibEntry entry; + private FieldEditorFX activeField; public FieldsEditorTab(JabRefFrame frame, BasePanel basePanel, List fields, EntryEditor parent, boolean addKeyField, boolean compressed, BibEntry entry) { this.entry = Objects.requireNonNull(entry); @@ -123,7 +123,8 @@ private Region setupPanel(JabRefFrame frame, BasePanel bPanel, boolean compresse FieldEditorFX fieldEditor = FieldEditors.getForField(fieldName, Globals.taskExecutor, new FXDialogService(), Globals.journalAbbreviationLoader, Globals.prefs.getJournalAbbreviationPreferences(), Globals.prefs, - bPanel.getBibDatabaseContext(), entry.getType()); + bPanel.getBibDatabaseContext(), entry.getType(), + bPanel.getAutoCompleters()); fieldEditor.bindToEntry(entry); editors.put(fieldName, fieldEditor); diff --git a/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java index 046e47de7f7..0ffbace3503 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java @@ -1,21 +1,34 @@ package org.jabref.gui.fieldeditors; +import java.util.Collection; + import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import org.jabref.gui.AbstractViewModel; import org.jabref.gui.util.BindingsHelper; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; +import org.jabref.logic.autocompleter.ContentAutoCompleters; import org.jabref.model.entry.BibEntry; +import org.controlsfx.control.textfield.AutoCompletionBinding; + public class AbstractEditorViewModel extends AbstractViewModel { + protected final String fieldName; protected StringProperty text = new SimpleStringProperty(""); protected BibEntry entry; + private final ContentAutoCompleters autoCompleter; + + public AbstractEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter) { + this.fieldName = fieldName; + this.autoCompleter = autoCompleter; + } public StringProperty textProperty() { return text; } - public void bindToEntry(String fieldName, BibEntry entry) { + public void bindToEntry(BibEntry entry) { this.entry = entry; BindingsHelper.bindBidirectional( this.textProperty(), @@ -26,4 +39,9 @@ public void bindToEntry(String fieldName, BibEntry entry) { } }); } + + public Collection complete(AutoCompletionBinding.ISuggestionRequest request) { + AutoCompleteSuggestionProvider suggestionProvider = autoCompleter.get(fieldName); + return suggestionProvider.call(request); + } } diff --git a/src/main/java/org/jabref/gui/fieldeditors/DateEditor.java b/src/main/java/org/jabref/gui/fieldeditors/DateEditor.java index 6f7abfe4145..63a0c53d243 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/DateEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/DateEditor.java @@ -8,17 +8,16 @@ import org.jabref.gui.util.ControlHelper; import org.jabref.gui.util.component.TemporalAccessorPicker; +import org.jabref.logic.autocompleter.ContentAutoCompleters; import org.jabref.model.entry.BibEntry; public class DateEditor extends HBox implements FieldEditorFX { - private final String fieldName; @FXML private DateEditorViewModel viewModel; @FXML private TemporalAccessorPicker datePicker; - public DateEditor(String fieldName, DateTimeFormatter dateFormatter) { - this.fieldName = fieldName; - this.viewModel = new DateEditorViewModel(dateFormatter); + public DateEditor(String fieldName, DateTimeFormatter dateFormatter, ContentAutoCompleters autoCompleter) { + this.viewModel = new DateEditorViewModel(fieldName, autoCompleter, dateFormatter); ControlHelper.loadFXMLForControl(this); @@ -32,7 +31,7 @@ public DateEditorViewModel getViewModel() { @Override public void bindToEntry(BibEntry entry) { - viewModel.bindToEntry(fieldName, entry); + viewModel.bindToEntry(entry); } @Override diff --git a/src/main/java/org/jabref/gui/fieldeditors/DateEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/DateEditorViewModel.java index 9763b02f3ab..ab32976b9c3 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/DateEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/DateEditorViewModel.java @@ -6,13 +6,15 @@ import javafx.util.StringConverter; +import org.jabref.logic.autocompleter.ContentAutoCompleters; import org.jabref.model.entry.Date; import org.jabref.model.strings.StringUtil; public class DateEditorViewModel extends AbstractEditorViewModel { private final DateTimeFormatter dateFormatter; - public DateEditorViewModel(DateTimeFormatter dateFormatter) { + public DateEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter, DateTimeFormatter dateFormatter) { + super(fieldName, autoCompleter); this.dateFormatter = dateFormatter; } diff --git a/src/main/java/org/jabref/gui/fieldeditors/EditorTypeEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/EditorTypeEditorViewModel.java index ea05ee521ae..559f03d95f2 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/EditorTypeEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/EditorTypeEditorViewModel.java @@ -1,5 +1,6 @@ package org.jabref.gui.fieldeditors; +import org.jabref.logic.autocompleter.ContentAutoCompleters; import org.jabref.logic.l10n.Localization; import com.google.common.collect.BiMap; @@ -9,7 +10,9 @@ public class EditorTypeEditorViewModel extends MapBasedEditorViewModel { private BiMap itemMap = HashBiMap.create(7); - public EditorTypeEditorViewModel() { + public EditorTypeEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter) { + super(fieldName, autoCompleter); + itemMap.put("editor", Localization.lang("Editor")); itemMap.put("compiler", Localization.lang("Compiler")); itemMap.put("founder", Localization.lang("Founder")); diff --git a/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java b/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java index ffce18ff815..14c4727b957 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java +++ b/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java @@ -6,6 +6,7 @@ import org.jabref.Globals; import org.jabref.gui.DialogService; import org.jabref.gui.util.TaskExecutor; +import org.jabref.logic.autocompleter.ContentAutoCompleters; import org.jabref.logic.journals.JournalAbbreviationLoader; import org.jabref.logic.journals.JournalAbbreviationPreferences; import org.jabref.model.database.BibDatabaseContext; @@ -15,46 +16,46 @@ public class FieldEditors { - public static FieldEditorFX getForField(String fieldName, TaskExecutor taskExecutor, DialogService dialogService, JournalAbbreviationLoader journalAbbreviationLoader, JournalAbbreviationPreferences journalAbbreviationPreferences, JabRefPreferences preferences, BibDatabaseContext databaseContext, String entryType) { + public static FieldEditorFX getForField(String fieldName, TaskExecutor taskExecutor, DialogService dialogService, JournalAbbreviationLoader journalAbbreviationLoader, JournalAbbreviationPreferences journalAbbreviationPreferences, JabRefPreferences preferences, BibDatabaseContext databaseContext, String entryType, ContentAutoCompleters autoCompleter) { final Set fieldExtras = InternalBibtexFields.getFieldProperties(fieldName); if (Globals.prefs.get(JabRefPreferences.TIME_STAMP_FIELD).equals(fieldName) || fieldExtras.contains(FieldProperty.DATE)) { if (fieldExtras.contains(FieldProperty.ISO_DATE)) { - return new DateEditor(fieldName, DateTimeFormatter.ofPattern("[uuuu][-MM][-dd]")); + return new DateEditor(fieldName, DateTimeFormatter.ofPattern("[uuuu][-MM][-dd]"), autoCompleter); } else { - return new DateEditor(fieldName, DateTimeFormatter.ofPattern(Globals.prefs.get(JabRefPreferences.TIME_STAMP_FORMAT))); + return new DateEditor(fieldName, DateTimeFormatter.ofPattern(Globals.prefs.get(JabRefPreferences.TIME_STAMP_FORMAT)), autoCompleter); } } else if (fieldExtras.contains(FieldProperty.EXTERNAL)) { - return new UrlEditor(fieldName, dialogService); + return new UrlEditor(fieldName, dialogService, autoCompleter); } else if (fieldExtras.contains(FieldProperty.JOURNAL_NAME)) { - return new JournalEditor(fieldName, journalAbbreviationLoader, journalAbbreviationPreferences); + return new JournalEditor(fieldName, journalAbbreviationLoader, journalAbbreviationPreferences, autoCompleter); } else if (fieldExtras.contains(FieldProperty.DOI) || fieldExtras.contains(FieldProperty.EPRINT) || fieldExtras.contains(FieldProperty.ISBN)) { - return new IdentifierEditor(fieldName, taskExecutor, dialogService); + return new IdentifierEditor(fieldName, taskExecutor, dialogService, autoCompleter); } else if (fieldExtras.contains(FieldProperty.OWNER)) { - return new OwnerEditor(fieldName, preferences); + return new OwnerEditor(fieldName, preferences, autoCompleter); } else if (fieldExtras.contains(FieldProperty.FILE_EDITOR)) { - return new LinkedFilesEditor(fieldName, dialogService, databaseContext, taskExecutor); + return new LinkedFilesEditor(fieldName, dialogService, databaseContext, taskExecutor, autoCompleter); } else if (fieldExtras.contains(FieldProperty.YES_NO)) { - return new OptionEditor<>(fieldName, new YesNoEditorViewModel()); + return new OptionEditor<>(fieldName, new YesNoEditorViewModel(fieldName, autoCompleter)); } else if (fieldExtras.contains(FieldProperty.MONTH)) { - return new OptionEditor<>(fieldName, new MonthEditorViewModel(databaseContext.getMode())); + return new OptionEditor<>(fieldName, new MonthEditorViewModel(fieldName, autoCompleter, databaseContext.getMode())); } else if (fieldExtras.contains(FieldProperty.GENDER)) { - return new OptionEditor<>(fieldName, new GenderEditorViewModel()); + return new OptionEditor<>(fieldName, new GenderEditorViewModel(fieldName, autoCompleter)); } else if (fieldExtras.contains(FieldProperty.EDITOR_TYPE)) { - return new OptionEditor<>(fieldName, new EditorTypeEditorViewModel()); + return new OptionEditor<>(fieldName, new EditorTypeEditorViewModel(fieldName, autoCompleter)); } else if (fieldExtras.contains(FieldProperty.PAGINATION)) { - return new OptionEditor<>(fieldName, new PaginationEditorViewModel()); + return new OptionEditor<>(fieldName, new PaginationEditorViewModel(fieldName, autoCompleter)); } else if (fieldExtras.contains(FieldProperty.TYPE)) { if ("patent".equalsIgnoreCase(entryType)) { - return new OptionEditor<>(fieldName, new PatentTypeEditorViewModel()); + return new OptionEditor<>(fieldName, new PatentTypeEditorViewModel(fieldName, autoCompleter)); } else { - return new OptionEditor<>(fieldName, new TypeEditorViewModel()); + return new OptionEditor<>(fieldName, new TypeEditorViewModel(fieldName, autoCompleter)); } } else if (fieldExtras.contains(FieldProperty.SINGLE_ENTRY_LINK) || fieldExtras.contains(FieldProperty.MULTIPLE_ENTRY_LINK)) { - return new LinkedEntriesEditor(fieldName, databaseContext); + return new LinkedEntriesEditor(fieldName, databaseContext, autoCompleter); } // default - return new SimpleEditor(fieldName); + return new SimpleEditor(fieldName, autoCompleter); } } diff --git a/src/main/java/org/jabref/gui/fieldeditors/GenderEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/GenderEditorViewModel.java index 7df18b82bb7..9eae4272585 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/GenderEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/GenderEditorViewModel.java @@ -1,5 +1,6 @@ package org.jabref.gui.fieldeditors; +import org.jabref.logic.autocompleter.ContentAutoCompleters; import org.jabref.logic.l10n.Localization; import com.google.common.collect.BiMap; @@ -9,7 +10,9 @@ public class GenderEditorViewModel extends MapBasedEditorViewModel { private BiMap itemMap = HashBiMap.create(7); - public GenderEditorViewModel() { + public GenderEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter) { + super(fieldName, autoCompleter); + itemMap.put("sf", Localization.lang("Female name")); itemMap.put("sm", Localization.lang("Male name")); itemMap.put("sn", Localization.lang("Neuter name")); diff --git a/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditor.java b/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditor.java index 69bd79aa4a4..9267704d6e9 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditor.java @@ -16,22 +16,21 @@ import org.jabref.gui.fieldeditors.contextmenu.EditorMenus; import org.jabref.gui.util.ControlHelper; import org.jabref.gui.util.TaskExecutor; +import org.jabref.logic.autocompleter.ContentAutoCompleters; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.FieldName; public class IdentifierEditor extends HBox implements FieldEditorFX { - private final String fieldName; @FXML private IdentifierEditorViewModel viewModel; @FXML private EditorTextArea textArea; @FXML private Button fetchInformationByIdentifierButton; @FXML private Button lookupIdentifierButton; private Optional entry; - public IdentifierEditor(String fieldName, TaskExecutor taskExecutor, DialogService dialogService) { - this.fieldName = fieldName; - this.viewModel = new IdentifierEditorViewModel(fieldName, taskExecutor, dialogService); + public IdentifierEditor(String fieldName, TaskExecutor taskExecutor, DialogService dialogService, ContentAutoCompleters autoCompleter) { + this.viewModel = new IdentifierEditorViewModel(fieldName, autoCompleter, taskExecutor, dialogService); ControlHelper.loadFXMLForControl(this); @@ -57,7 +56,7 @@ public IdentifierEditorViewModel getViewModel() { @Override public void bindToEntry(BibEntry entry) { this.entry = Optional.of(entry); - viewModel.bindToEntry(fieldName, entry); + viewModel.bindToEntry(entry); } @Override diff --git a/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java index 3c3fefe9aa8..e60057a49d9 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java @@ -13,6 +13,7 @@ import org.jabref.gui.mergeentries.FetchAndMergeEntry; import org.jabref.gui.util.BackgroundTask; import org.jabref.gui.util.TaskExecutor; +import org.jabref.logic.autocompleter.ContentAutoCompleters; import org.jabref.logic.importer.WebFetchers; import org.jabref.logic.importer.util.IdentifierParser; import org.jabref.logic.l10n.Localization; @@ -23,7 +24,6 @@ import org.fxmisc.easybind.EasyBind; public class IdentifierEditorViewModel extends AbstractEditorViewModel { - private final String fieldName; private BooleanProperty validIdentifierIsNotPresent = new SimpleBooleanProperty(true); private BooleanProperty identifierLookupInProgress = new SimpleBooleanProperty(false); private BooleanProperty idFetcherAvailable = new SimpleBooleanProperty(true); @@ -31,8 +31,9 @@ public class IdentifierEditorViewModel extends AbstractEditorViewModel { private TaskExecutor taskExecutor; private DialogService dialogService; - public IdentifierEditorViewModel(String fieldName, TaskExecutor taskExecutor, DialogService dialogService) { - this.fieldName = fieldName; + public IdentifierEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter, TaskExecutor taskExecutor, DialogService dialogService) { + super(fieldName, autoCompleter); + this.taskExecutor = taskExecutor; this.dialogService = dialogService; diff --git a/src/main/java/org/jabref/gui/fieldeditors/JournalEditor.java b/src/main/java/org/jabref/gui/fieldeditors/JournalEditor.java index 920d8a403f3..4c517e153a9 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/JournalEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/JournalEditor.java @@ -9,20 +9,19 @@ import org.jabref.gui.fieldeditors.contextmenu.EditorMenus; import org.jabref.gui.util.ControlHelper; +import org.jabref.logic.autocompleter.ContentAutoCompleters; import org.jabref.logic.journals.JournalAbbreviationLoader; import org.jabref.logic.journals.JournalAbbreviationPreferences; import org.jabref.model.entry.BibEntry; public class JournalEditor extends HBox implements FieldEditorFX { - private final String fieldName; @FXML private JournalEditorViewModel viewModel; @FXML private EditorTextArea textArea; private Optional entry; - public JournalEditor(String fieldName, JournalAbbreviationLoader journalAbbreviationLoader, JournalAbbreviationPreferences journalAbbreviationPreferences) { - this.fieldName = fieldName; - this.viewModel = new JournalEditorViewModel(journalAbbreviationLoader, journalAbbreviationPreferences); + public JournalEditor(String fieldName, JournalAbbreviationLoader journalAbbreviationLoader, JournalAbbreviationPreferences journalAbbreviationPreferences, ContentAutoCompleters autoCompleter) { + this.viewModel = new JournalEditorViewModel(fieldName, autoCompleter, journalAbbreviationLoader, journalAbbreviationPreferences); ControlHelper.loadFXMLForControl(this); @@ -38,7 +37,7 @@ public JournalEditorViewModel getViewModel() { @Override public void bindToEntry(BibEntry entry) { this.entry = Optional.of(entry); - viewModel.bindToEntry(fieldName, entry); + viewModel.bindToEntry(entry); } @Override diff --git a/src/main/java/org/jabref/gui/fieldeditors/JournalEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/JournalEditorViewModel.java index 18cff62a6f5..759f9901fb8 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/JournalEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/JournalEditorViewModel.java @@ -2,6 +2,7 @@ import java.util.Optional; +import org.jabref.logic.autocompleter.ContentAutoCompleters; import org.jabref.logic.journals.JournalAbbreviationLoader; import org.jabref.logic.journals.JournalAbbreviationPreferences; import org.jabref.logic.journals.JournalAbbreviationRepository; @@ -11,7 +12,9 @@ public class JournalEditorViewModel extends AbstractEditorViewModel { private final JournalAbbreviationLoader journalAbbreviationLoader; private final JournalAbbreviationPreferences journalAbbreviationPreferences; - public JournalEditorViewModel(JournalAbbreviationLoader journalAbbreviationLoader, JournalAbbreviationPreferences journalAbbreviationPreferences) { + public JournalEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter, JournalAbbreviationLoader journalAbbreviationLoader, JournalAbbreviationPreferences journalAbbreviationPreferences) { + super(fieldName, autoCompleter); + this.journalAbbreviationLoader = journalAbbreviationLoader; this.journalAbbreviationPreferences = journalAbbreviationPreferences; } diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditor.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditor.java index 1954199372b..7b665ac2d5b 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditor.java @@ -7,19 +7,18 @@ import org.jabref.gui.util.ControlHelper; import org.jabref.gui.util.component.TagBar; +import org.jabref.logic.autocompleter.ContentAutoCompleters; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.ParsedEntryLink; public class LinkedEntriesEditor extends HBox implements FieldEditorFX { - private final String fieldName; @FXML private LinkedEntriesEditorViewModel viewModel; @FXML private TagBar linkedEntriesBar; - public LinkedEntriesEditor(String fieldName, BibDatabaseContext databaseContext) { - this.fieldName = fieldName; - this.viewModel = new LinkedEntriesEditorViewModel(databaseContext); + public LinkedEntriesEditor(String fieldName, BibDatabaseContext databaseContext, ContentAutoCompleters autoCompleter) { + this.viewModel = new LinkedEntriesEditorViewModel(fieldName, autoCompleter, databaseContext); ControlHelper.loadFXMLForControl(this); @@ -34,7 +33,7 @@ public LinkedEntriesEditorViewModel getViewModel() { @Override public void bindToEntry(BibEntry entry) { - viewModel.bindToEntry(fieldName, entry); + viewModel.bindToEntry(entry); } @Override diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditorViewModel.java index 32d6d06315c..2f33a9ce7b4 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditorViewModel.java @@ -6,6 +6,7 @@ import javafx.util.StringConverter; import org.jabref.gui.util.BindingsHelper; +import org.jabref.logic.autocompleter.ContentAutoCompleters; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.EntryLinkList; import org.jabref.model.entry.ParsedEntryLink; @@ -15,7 +16,9 @@ public class LinkedEntriesEditorViewModel extends AbstractEditorViewModel { private final BibDatabaseContext databaseContext; private final ListProperty linkedEntries; - public LinkedEntriesEditorViewModel(BibDatabaseContext databaseContext) { + public LinkedEntriesEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter, BibDatabaseContext databaseContext) { + super(fieldName, autoCompleter); + this.databaseContext = databaseContext; linkedEntries = new SimpleListProperty<>(FXCollections.observableArrayList()); BindingsHelper.bindContentBidirectional( diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java index 0cfb0983330..425734e8663 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java @@ -14,6 +14,7 @@ import javafx.beans.property.SimpleDoubleProperty; import org.jabref.Globals; +import org.jabref.gui.AbstractViewModel; import org.jabref.gui.DialogService; import org.jabref.gui.FXDialogService; import org.jabref.gui.desktop.JabRefDesktop; @@ -32,7 +33,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -public class LinkedFileViewModel extends AbstractEditorViewModel { +public class LinkedFileViewModel extends AbstractViewModel { private static final Log LOGGER = LogFactory.getLog(LinkedFileViewModel.class); private final LinkedFile linkedFile; @@ -42,6 +43,7 @@ public class LinkedFileViewModel extends AbstractEditorViewModel { private final BooleanProperty isAutomaticallyFound = new SimpleBooleanProperty(false); private final DialogService dialogService = new FXDialogService(); + private final BibEntry entry; public LinkedFileViewModel(LinkedFile linkedFile, BibEntry entry, BibDatabaseContext databaseContext) { this.linkedFile = linkedFile; diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java index cda3e3383cb..0d76f0402bc 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java @@ -26,6 +26,7 @@ import org.jabref.gui.util.ControlHelper; import org.jabref.gui.util.TaskExecutor; import org.jabref.gui.util.ViewModelListCellFactory; +import org.jabref.logic.autocompleter.ContentAutoCompleters; import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; @@ -35,13 +36,11 @@ public class LinkedFilesEditor extends HBox implements FieldEditorFX { - private final String fieldName; @FXML private LinkedFilesEditorViewModel viewModel; @FXML private ListView listView; - public LinkedFilesEditor(String fieldName, DialogService dialogService, BibDatabaseContext databaseContext, TaskExecutor taskExecutor) { - this.fieldName = fieldName; - this.viewModel = new LinkedFilesEditorViewModel(dialogService, databaseContext, taskExecutor); + public LinkedFilesEditor(String fieldName, DialogService dialogService, BibDatabaseContext databaseContext, TaskExecutor taskExecutor, ContentAutoCompleters autoCompleter) { + this.viewModel = new LinkedFilesEditorViewModel(fieldName, autoCompleter, dialogService, databaseContext, taskExecutor); ControlHelper.loadFXMLForControl(this); @@ -99,7 +98,7 @@ public LinkedFilesEditorViewModel getViewModel() { @Override public void bindToEntry(BibEntry entry) { - viewModel.bindToEntry(fieldName, entry); + viewModel.bindToEntry(entry); } @Override diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java index c5864940515..b4f4a4bfcbb 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java @@ -28,6 +28,7 @@ import org.jabref.gui.util.BindingsHelper; import org.jabref.gui.util.FileDialogConfiguration; import org.jabref.gui.util.TaskExecutor; +import org.jabref.logic.autocompleter.ContentAutoCompleters; import org.jabref.logic.importer.FulltextFetchers; import org.jabref.logic.l10n.Localization; import org.jabref.logic.net.URLDownload; @@ -55,7 +56,9 @@ public class LinkedFilesEditorViewModel extends AbstractEditorViewModel { private BibDatabaseContext databaseContext; private TaskExecutor taskExecutor; - public LinkedFilesEditorViewModel(DialogService dialogService, BibDatabaseContext databaseContext, TaskExecutor taskExecutor) { + public LinkedFilesEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter, DialogService dialogService, BibDatabaseContext databaseContext, TaskExecutor taskExecutor) { + super(fieldName, autoCompleter); + this.dialogService = dialogService; this.databaseContext = databaseContext; this.taskExecutor = taskExecutor; @@ -131,8 +134,8 @@ public void addNewFile() { } @Override - public void bindToEntry(String fieldName, BibEntry entry) { - super.bindToEntry(fieldName, entry); + public void bindToEntry(BibEntry entry) { + super.bindToEntry(entry); if (entry != null) { BackgroundTask> findAssociatedNotLinkedFiles = BackgroundTask diff --git a/src/main/java/org/jabref/gui/fieldeditors/MapBasedEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/MapBasedEditorViewModel.java index 0dd82a758f1..b18eb1474db 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/MapBasedEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/MapBasedEditorViewModel.java @@ -5,6 +5,8 @@ import javafx.util.StringConverter; +import org.jabref.logic.autocompleter.ContentAutoCompleters; + import com.google.common.collect.BiMap; /** @@ -12,6 +14,10 @@ */ public abstract class MapBasedEditorViewModel extends OptionEditorViewModel { + public MapBasedEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter) { + super(fieldName, autoCompleter); + } + protected abstract BiMap getItemMap(); @Override diff --git a/src/main/java/org/jabref/gui/fieldeditors/MonthEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/MonthEditorViewModel.java index a9c0b3563f1..23c5b807ba4 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/MonthEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/MonthEditorViewModel.java @@ -5,6 +5,7 @@ import javafx.util.StringConverter; +import org.jabref.logic.autocompleter.ContentAutoCompleters; import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.Month; import org.jabref.model.strings.StringUtil; @@ -12,7 +13,8 @@ public class MonthEditorViewModel extends OptionEditorViewModel { private BibDatabaseMode databaseMode; - public MonthEditorViewModel(BibDatabaseMode databaseMode) { + public MonthEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter, BibDatabaseMode databaseMode) { + super(fieldName, autoCompleter); this.databaseMode = databaseMode; } diff --git a/src/main/java/org/jabref/gui/fieldeditors/OptionEditor.java b/src/main/java/org/jabref/gui/fieldeditors/OptionEditor.java index 8718d4b1c49..1b97d7be35f 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/OptionEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/OptionEditor.java @@ -14,12 +14,10 @@ */ public class OptionEditor extends HBox implements FieldEditorFX { - private final String fieldName; @FXML private OptionEditorViewModel viewModel; @FXML private ComboBox comboBox; public OptionEditor(String fieldName, OptionEditorViewModel viewModel) { - this.fieldName = fieldName; this.viewModel = viewModel; ControlHelper.loadFXMLForControl(this); @@ -36,7 +34,7 @@ public OptionEditorViewModel getViewModel() { @Override public void bindToEntry(BibEntry entry) { - viewModel.bindToEntry(fieldName, entry); + viewModel.bindToEntry(entry); } @Override diff --git a/src/main/java/org/jabref/gui/fieldeditors/OptionEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/OptionEditorViewModel.java index e899a541d20..7aed491b68b 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/OptionEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/OptionEditorViewModel.java @@ -4,8 +4,14 @@ import javafx.util.StringConverter; +import org.jabref.logic.autocompleter.ContentAutoCompleters; + public abstract class OptionEditorViewModel extends AbstractEditorViewModel { + public OptionEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter) { + super(fieldName, autoCompleter); + } + public abstract StringConverter getStringConverter(); public abstract List getItems(); diff --git a/src/main/java/org/jabref/gui/fieldeditors/OwnerEditor.java b/src/main/java/org/jabref/gui/fieldeditors/OwnerEditor.java index a89355c07f3..2083b630a95 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/OwnerEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/OwnerEditor.java @@ -1,26 +1,22 @@ package org.jabref.gui.fieldeditors; -import java.util.Optional; - import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.Parent; import javafx.scene.layout.HBox; import org.jabref.gui.util.ControlHelper; +import org.jabref.logic.autocompleter.ContentAutoCompleters; import org.jabref.model.entry.BibEntry; import org.jabref.preferences.JabRefPreferences; public class OwnerEditor extends HBox implements FieldEditorFX { - private final String fieldName; @FXML private OwnerEditorViewModel viewModel; @FXML private EditorTextArea textArea; - private Optional entry; - public OwnerEditor(String fieldName, JabRefPreferences preferences) { - this.fieldName = fieldName; - this.viewModel = new OwnerEditorViewModel(preferences); + public OwnerEditor(String fieldName, JabRefPreferences preferences, ContentAutoCompleters autoCompleter) { + this.viewModel = new OwnerEditorViewModel(fieldName, autoCompleter, preferences); ControlHelper.loadFXMLForControl(this); @@ -33,8 +29,7 @@ public OwnerEditorViewModel getViewModel() { @Override public void bindToEntry(BibEntry entry) { - this.entry = Optional.of(entry); - viewModel.bindToEntry(fieldName, entry); + viewModel.bindToEntry(entry); } @Override diff --git a/src/main/java/org/jabref/gui/fieldeditors/OwnerEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/OwnerEditorViewModel.java index 321e3e0011f..8cd4856597d 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/OwnerEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/OwnerEditorViewModel.java @@ -1,11 +1,13 @@ package org.jabref.gui.fieldeditors; +import org.jabref.logic.autocompleter.ContentAutoCompleters; import org.jabref.preferences.JabRefPreferences; public class OwnerEditorViewModel extends AbstractEditorViewModel { private final JabRefPreferences preferences; - public OwnerEditorViewModel(JabRefPreferences preferences) { + public OwnerEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter, JabRefPreferences preferences) { + super(fieldName, autoCompleter); this.preferences = preferences; } diff --git a/src/main/java/org/jabref/gui/fieldeditors/PaginationEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/PaginationEditorViewModel.java index c30333c2fb9..b92e3b83ba2 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/PaginationEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/PaginationEditorViewModel.java @@ -1,5 +1,6 @@ package org.jabref.gui.fieldeditors; +import org.jabref.logic.autocompleter.ContentAutoCompleters; import org.jabref.logic.l10n.Localization; import com.google.common.collect.BiMap; @@ -9,7 +10,9 @@ public class PaginationEditorViewModel extends MapBasedEditorViewModel { private BiMap itemMap = HashBiMap.create(7); - public PaginationEditorViewModel() { + public PaginationEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter) { + super(fieldName, autoCompleter); + itemMap.put("page", Localization.lang("Page")); itemMap.put("column", Localization.lang("Column")); itemMap.put("line", Localization.lang("Line")); diff --git a/src/main/java/org/jabref/gui/fieldeditors/PatentTypeEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/PatentTypeEditorViewModel.java index 8cc3c0a1df0..2894dbcb7ea 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/PatentTypeEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/PatentTypeEditorViewModel.java @@ -1,5 +1,6 @@ package org.jabref.gui.fieldeditors; +import org.jabref.logic.autocompleter.ContentAutoCompleters; import org.jabref.logic.l10n.Localization; import com.google.common.collect.BiMap; @@ -9,7 +10,9 @@ public class PatentTypeEditorViewModel extends MapBasedEditorViewModel { private BiMap itemMap = HashBiMap.create(12); - public PatentTypeEditorViewModel() { + public PatentTypeEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter) { + super(fieldName, autoCompleter); + itemMap.put("patent", Localization.lang("Patent")); itemMap.put("patentde", Localization.lang("German patent")); itemMap.put("patenteu", Localization.lang("European patent")); diff --git a/src/main/java/org/jabref/gui/fieldeditors/SimpleEditor.java b/src/main/java/org/jabref/gui/fieldeditors/SimpleEditor.java index 4554a22dd27..c74688cc8fa 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/SimpleEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/SimpleEditor.java @@ -6,27 +6,29 @@ import javafx.scene.layout.Priority; import org.jabref.gui.fieldeditors.contextmenu.EditorMenus; +import org.jabref.gui.util.AutoCompletionTextInputBinding; +import org.jabref.logic.autocompleter.ContentAutoCompleters; import org.jabref.model.entry.BibEntry; public class SimpleEditor extends HBox implements FieldEditorFX { - protected final String fieldName; @FXML private final SimpleEditorViewModel viewModel; - public SimpleEditor(String fieldName) { - this.fieldName = fieldName; - this.viewModel = new SimpleEditorViewModel(); + public SimpleEditor(String fieldName, ContentAutoCompleters autoCompleters) { + this.viewModel = new SimpleEditorViewModel(fieldName, autoCompleters); EditorTextArea textArea = new EditorTextArea(); HBox.setHgrow(textArea, Priority.ALWAYS); textArea.textProperty().bindBidirectional(viewModel.textProperty()); textArea.addToContextMenu(EditorMenus.getDefaultMenu(textArea)); this.getChildren().add(textArea); + + AutoCompletionTextInputBinding.autoComplete(textArea, viewModel::complete); } @Override public void bindToEntry(BibEntry entry) { - viewModel.bindToEntry(fieldName, entry); + viewModel.bindToEntry(entry); } @Override diff --git a/src/main/java/org/jabref/gui/fieldeditors/SimpleEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/SimpleEditorViewModel.java index 2892b5ac730..b043ec61f04 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/SimpleEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/SimpleEditorViewModel.java @@ -1,4 +1,10 @@ package org.jabref.gui.fieldeditors; +import org.jabref.logic.autocompleter.ContentAutoCompleters; + public class SimpleEditorViewModel extends AbstractEditorViewModel { + + public SimpleEditorViewModel(String fieldName, ContentAutoCompleters autoCompleters) { + super(fieldName, autoCompleters); + } } diff --git a/src/main/java/org/jabref/gui/fieldeditors/TypeEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/TypeEditorViewModel.java index 852c8c97c9b..a3b54194083 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/TypeEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/TypeEditorViewModel.java @@ -1,5 +1,6 @@ package org.jabref.gui.fieldeditors; +import org.jabref.logic.autocompleter.ContentAutoCompleters; import org.jabref.logic.l10n.Localization; import com.google.common.collect.BiMap; @@ -9,7 +10,9 @@ public class TypeEditorViewModel extends MapBasedEditorViewModel { private BiMap itemMap = HashBiMap.create(8); - public TypeEditorViewModel() { + public TypeEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter) { + super(fieldName, autoCompleter); + itemMap.put("mathesis", Localization.lang("Master's thesis")); itemMap.put("phdthesis", Localization.lang("PhD thesis")); itemMap.put("candthesis", Localization.lang("Candidate thesis")); diff --git a/src/main/java/org/jabref/gui/fieldeditors/UrlEditor.java b/src/main/java/org/jabref/gui/fieldeditors/UrlEditor.java index 9b75b39d9f5..adc4b12327b 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/UrlEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/UrlEditor.java @@ -1,7 +1,5 @@ package org.jabref.gui.fieldeditors; -import java.util.Optional; - import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.Parent; @@ -9,18 +7,16 @@ import org.jabref.gui.DialogService; import org.jabref.gui.util.ControlHelper; +import org.jabref.logic.autocompleter.ContentAutoCompleters; import org.jabref.model.entry.BibEntry; public class UrlEditor extends HBox implements FieldEditorFX { - private final String fieldName; @FXML private UrlEditorViewModel viewModel; @FXML private EditorTextArea textArea; - private Optional entry; - public UrlEditor(String fieldName, DialogService dialogService) { - this.fieldName = fieldName; - this.viewModel = new UrlEditorViewModel(dialogService); + public UrlEditor(String fieldName, DialogService dialogService, ContentAutoCompleters autoCompleter) { + this.viewModel = new UrlEditorViewModel(fieldName, autoCompleter, dialogService); ControlHelper.loadFXMLForControl(this); @@ -33,8 +29,7 @@ public UrlEditorViewModel getViewModel() { @Override public void bindToEntry(BibEntry entry) { - this.entry = Optional.of(entry); - viewModel.bindToEntry(fieldName, entry); + viewModel.bindToEntry(entry); } @Override diff --git a/src/main/java/org/jabref/gui/fieldeditors/UrlEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/UrlEditorViewModel.java index 61394dbe8c0..24aa1aef0ca 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/UrlEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/UrlEditorViewModel.java @@ -7,6 +7,7 @@ import org.jabref.gui.DialogService; import org.jabref.gui.desktop.JabRefDesktop; +import org.jabref.logic.autocompleter.ContentAutoCompleters; import org.jabref.logic.l10n.Localization; import org.jabref.logic.net.URLUtil; import org.jabref.model.strings.StringUtil; @@ -17,7 +18,8 @@ public class UrlEditorViewModel extends AbstractEditorViewModel { private DialogService dialogService; private BooleanProperty validUrlIsNotPresent = new SimpleBooleanProperty(true); - public UrlEditorViewModel(DialogService dialogService) { + public UrlEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter, DialogService dialogService) { + super(fieldName, autoCompleter); this.dialogService = dialogService; validUrlIsNotPresent.bind( diff --git a/src/main/java/org/jabref/gui/fieldeditors/YesNoEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/YesNoEditorViewModel.java index 3220231982d..72f2759229f 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/YesNoEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/YesNoEditorViewModel.java @@ -1,5 +1,7 @@ package org.jabref.gui.fieldeditors; +import org.jabref.logic.autocompleter.ContentAutoCompleters; + import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; @@ -7,7 +9,9 @@ public class YesNoEditorViewModel extends MapBasedEditorViewModel { private BiMap itemMap = HashBiMap.create(2); - public YesNoEditorViewModel() { + public YesNoEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter) { + super(fieldName, autoCompleter); + itemMap.put("yes", "Yes"); itemMap.put("no", "No"); } diff --git a/src/main/java/org/jabref/gui/util/AutoCompletionTextInputBinding.java b/src/main/java/org/jabref/gui/util/AutoCompletionTextInputBinding.java new file mode 100644 index 00000000000..1afdebb5ed2 --- /dev/null +++ b/src/main/java/org/jabref/gui/util/AutoCompletionTextInputBinding.java @@ -0,0 +1,172 @@ +/** + * Copyright (c) 2014, 2015, ControlsFX + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of ControlsFX, any associated website, nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL CONTROLSFX BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.jabref.gui.util; + +import java.util.Collection; + +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.scene.control.TextInputControl; +import javafx.util.Callback; +import javafx.util.StringConverter; + +import org.controlsfx.control.textfield.AutoCompletionBinding; + +/** + * Represents a binding between a text input control and a auto-completion popup + * This class is a slightly modified version of {@link impl.org.controlsfx.autocompletion.AutoCompletionTextFieldBinding} + * that works with general text input controls instead of just text fields. + * @param + * + */ +public class AutoCompletionTextInputBinding extends AutoCompletionBinding { + + /*************************************************************************** + * * + * Event Listeners * + * * + **************************************************************************/ + + + private final ChangeListener textChangeListener = new ChangeListener() { + @Override + public void changed(ObservableValue obs, String oldText, String newText) { + if (getCompletionTarget().isFocused()) { + setUserInput(newText); + } + } + }; + + /*************************************************************************** + * * + * Private fields * + * * + **************************************************************************/ + private final ChangeListener focusChangedListener = new ChangeListener() { + @Override + public void changed(ObservableValue obs, Boolean oldFocused, Boolean newFocused) { + if (newFocused == false) + hidePopup(); + } + }; + + + /*************************************************************************** + * * + * Constructors * + * * + **************************************************************************/ + /** + * String converter to be used to convert suggestions to strings. + */ + private StringConverter converter; + + /** + * Creates a new auto-completion binding between the given textInputControl + * and the given suggestion provider. + * + * @param textInputControl + * @param suggestionProvider + */ + public AutoCompletionTextInputBinding(final TextInputControl textInputControl, + Callback> suggestionProvider) { + + this(textInputControl, suggestionProvider, AutoCompletionTextInputBinding + .defaultStringConverter()); + } + + + /*************************************************************************** + * * + * Public API * + * * + **************************************************************************/ + + /** + * Creates a new auto-completion binding between the given textInputControl + * and the given suggestion provider. + * + * @param textInputControl + * @param suggestionProvider + */ + public AutoCompletionTextInputBinding(final TextInputControl textInputControl, + Callback> suggestionProvider, + final StringConverter converter) { + + super(textInputControl, suggestionProvider, converter); + this.converter = converter; + + getCompletionTarget().textProperty().addListener(textChangeListener); + getCompletionTarget().focusedProperty().addListener(focusChangedListener); + } + + /*************************************************************************** + * * + * Static properties and methods * + * * + **************************************************************************/ + + private static StringConverter defaultStringConverter() { + return new StringConverter() { + @Override + public String toString(T t) { + return t == null ? null : t.toString(); + } + + @SuppressWarnings("unchecked") + @Override + public T fromString(String string) { + return (T) string; + } + }; + } + + public static void autoComplete(TextInputControl textArea, Callback> suggestionProvider) { + new AutoCompletionTextInputBinding<>(textArea, suggestionProvider); + } + + /** {@inheritDoc} */ + @Override + public TextInputControl getCompletionTarget() { + return (TextInputControl) super.getCompletionTarget(); + } + + /** {@inheritDoc} */ + @Override + public void dispose() { + getCompletionTarget().textProperty().removeListener(textChangeListener); + getCompletionTarget().focusedProperty().removeListener(focusChangedListener); + } + + /** {@inheritDoc} */ + @Override + protected void completeUserInput(T completion) { + String newText = converter.toString(completion); + getCompletionTarget().setText(newText); + getCompletionTarget().positionCaret(newText.length()); + } +} diff --git a/src/main/java/org/jabref/logic/autocompleter/AutoCompleteSuggestionProvider.java b/src/main/java/org/jabref/logic/autocompleter/AutoCompleteSuggestionProvider.java new file mode 100644 index 00000000000..05ea92926c3 --- /dev/null +++ b/src/main/java/org/jabref/logic/autocompleter/AutoCompleteSuggestionProvider.java @@ -0,0 +1,13 @@ +package org.jabref.logic.autocompleter; + +import java.util.Collection; + +import javafx.util.Callback; + +import org.jabref.model.entry.BibEntry; + +import org.controlsfx.control.textfield.AutoCompletionBinding; + +public interface AutoCompleteSuggestionProvider extends Callback> { + void indexBibtexEntry(BibEntry entry); +} diff --git a/src/main/java/org/jabref/logic/autocompleter/AutoCompleterFactory.java b/src/main/java/org/jabref/logic/autocompleter/AutoCompleterFactory.java index 6fec0fad4ea..2d16a1ba75f 100644 --- a/src/main/java/org/jabref/logic/autocompleter/AutoCompleterFactory.java +++ b/src/main/java/org/jabref/logic/autocompleter/AutoCompleterFactory.java @@ -27,19 +27,27 @@ public AutoCompleter getFor(String fieldName) { Objects.requireNonNull(fieldName); if (InternalBibtexFields.getFieldProperties(fieldName).contains(FieldProperty.PERSON_NAMES)) { - return new NameFieldAutoCompleter(fieldName, preferences); - } else if (InternalBibtexFields.getFieldProperties(fieldName).contains(FieldProperty.SINGLE_ENTRY_LINK)) { - return new BibtexKeyAutoCompleter(preferences); - } else if (InternalBibtexFields.getFieldProperties(fieldName).contains(FieldProperty.JOURNAL_NAME) - || FieldName.PUBLISHER.equals(fieldName)) { - return new JournalAutoCompleter(fieldName, preferences, abbreviationLoader); + return new PersonNameSuggestionProvider(fieldName, preferences); } else { - return new DefaultAutoCompleter(fieldName, preferences); + return null; } } public AutoCompleter getPersonAutoCompleter() { - return new NameFieldAutoCompleter(InternalBibtexFields.getPersonNameFields(), true, preferences); + return new PersonNameSuggestionProvider(InternalBibtexFields.getPersonNameFields(), true, preferences); } + public AutoCompleteSuggestionProvider getForField(String fieldName) { + //if (InternalBibtexFields.getFieldProperties(fieldName).contains(FieldProperty.PERSON_NAMES)) { + // return new NameFieldAutoCompleter(fieldName, preferences); + //} else + if (InternalBibtexFields.getFieldProperties(fieldName).contains(FieldProperty.SINGLE_ENTRY_LINK)) { + return new BibEntrySuggestionProvider(); + } else if (InternalBibtexFields.getFieldProperties(fieldName).contains(FieldProperty.JOURNAL_NAME) + || FieldName.PUBLISHER.equals(fieldName)) { + return new JournalsSuggestionProvider(fieldName, preferences, abbreviationLoader); + } else { + return new WordSuggestionProvider(fieldName); + } + } } diff --git a/src/main/java/org/jabref/logic/autocompleter/AutoCompleters.java b/src/main/java/org/jabref/logic/autocompleter/AutoCompleters.java index 93857a84f4c..da1799cdd35 100644 --- a/src/main/java/org/jabref/logic/autocompleter/AutoCompleters.java +++ b/src/main/java/org/jabref/logic/autocompleter/AutoCompleters.java @@ -8,11 +8,11 @@ class AutoCompleters { - protected final Map> autoCompleters = new HashMap<>(); + protected final Map> autoCompleters = new HashMap<>(); // Hashtable that holds as keys the names of the fields where // autocomplete is active, and references to the autocompleter objects. - public AutoCompleter get(String fieldName) { + public AutoCompleteSuggestionProvider get(String fieldName) { return autoCompleters.get(fieldName); } @@ -27,12 +27,12 @@ protected void addDatabase(BibDatabase database) { * respective Completers, if any. */ public void addEntry(BibEntry bibEntry) { - for (AutoCompleter autoCompleter : autoCompleters.values()) { - autoCompleter.addBibtexEntry(bibEntry); + for (AutoCompleteSuggestionProvider autoCompleter : autoCompleters.values()) { + autoCompleter.indexBibtexEntry(bibEntry); } } - protected void put(String field, AutoCompleter autoCompleter) { + protected void put(String field, AutoCompleteSuggestionProvider autoCompleter) { autoCompleters.put(field, autoCompleter); } diff --git a/src/main/java/org/jabref/logic/autocompleter/BibEntrySuggestionProvider.java b/src/main/java/org/jabref/logic/autocompleter/BibEntrySuggestionProvider.java new file mode 100644 index 00000000000..909e1e5b692 --- /dev/null +++ b/src/main/java/org/jabref/logic/autocompleter/BibEntrySuggestionProvider.java @@ -0,0 +1,37 @@ +package org.jabref.logic.autocompleter; + +import java.util.Comparator; + +import org.jabref.logic.bibtex.comparator.EntryComparator; +import org.jabref.model.entry.BibEntry; + +import impl.org.controlsfx.autocompletion.SuggestionProvider; +import org.controlsfx.control.textfield.AutoCompletionBinding; + +/** + * Delivers possible completions as a list of {@link BibEntry} based on their cite key. + */ +class BibEntrySuggestionProvider extends SuggestionProvider implements AutoCompleteSuggestionProvider { + + @Override + public void indexBibtexEntry(BibEntry entry) { + if (entry == null) { + return; + } + + addPossibleSuggestions(entry); + } + + @Override + protected Comparator getComparator() { + return new EntryComparator(false, true, BibEntry.KEY_FIELD); + } + + @Override + protected boolean isMatch(BibEntry suggestion, AutoCompletionBinding.ISuggestionRequest request) { + String userTextLower = request.getUserText().toLowerCase(); + return suggestion.getCiteKeyOptional() + .map(key -> key.toLowerCase().contains(userTextLower)) + .orElse(false); + } +} diff --git a/src/main/java/org/jabref/logic/autocompleter/BibtexKeyAutoCompleter.java b/src/main/java/org/jabref/logic/autocompleter/BibtexKeyAutoCompleter.java deleted file mode 100644 index 5cad7403180..00000000000 --- a/src/main/java/org/jabref/logic/autocompleter/BibtexKeyAutoCompleter.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.jabref.logic.autocompleter; - -import org.jabref.model.entry.BibEntry; - -/** - * Delivers possible completions for a given string based on the key fields of the added items. - * - * @author kahlert, cordes - */ -class BibtexKeyAutoCompleter extends AbstractAutoCompleter { - - public BibtexKeyAutoCompleter(AutoCompletePreferences preferences) { - super(preferences); - } - - @Override - public boolean isSingleUnitField() { - return false; - } - - /** - * {@inheritDoc} - * The bibtex key of the entry will be added to the index. - */ - @Override - public void addBibtexEntry(BibEntry entry) { - if (entry == null) { - return; - } - - entry.getCiteKeyOptional().ifPresent(key -> addItemToIndex(key.trim())); - } - - @Override - protected int getLengthOfShortestWordToAdd() { - return 1; - } -} diff --git a/src/main/java/org/jabref/logic/autocompleter/ContentAutoCompleters.java b/src/main/java/org/jabref/logic/autocompleter/ContentAutoCompleters.java index 93ddfaff663..5bcd2cce20a 100644 --- a/src/main/java/org/jabref/logic/autocompleter/ContentAutoCompleters.java +++ b/src/main/java/org/jabref/logic/autocompleter/ContentAutoCompleters.java @@ -1,7 +1,6 @@ package org.jabref.logic.autocompleter; import java.util.List; -import java.util.Map; import java.util.Objects; import org.jabref.logic.journals.JournalAbbreviationLoader; @@ -20,7 +19,7 @@ public ContentAutoCompleters(BibDatabase database, MetaData metaData, AutoComple AutoCompleterFactory autoCompleterFactory = new AutoCompleterFactory(preferences, abbreviationLoader); List completeFields = preferences.getCompleteNames(); for (String field : completeFields) { - AutoCompleter autoCompleter = autoCompleterFactory.getFor(field); + AutoCompleteSuggestionProvider autoCompleter = autoCompleterFactory.getForField(field); put(field, autoCompleter); } addContentSelectorValuesToAutoCompleters(metaData); @@ -33,9 +32,11 @@ public ContentAutoCompleters(BibDatabase database, MetaData metaData, AutoComple * values to the autocompleter list: */ public void addContentSelectorValuesToAutoCompleters(MetaData metaData) { - for (Map.Entry> entry : this.autoCompleters.entrySet()) { - AutoCompleter ac = entry.getValue(); + /* + for (Map.Entry> entry : this.autoCompleters.entrySet()) { + AutoCompleteSuggestionProvider ac = entry.getValue(); metaData.getContentSelectorValuesForField(entry.getKey()).forEach(ac::addItemToIndex); } + */ } } diff --git a/src/main/java/org/jabref/logic/autocompleter/EntireFieldAutoCompleter.java b/src/main/java/org/jabref/logic/autocompleter/EntireFieldAutoCompleter.java deleted file mode 100644 index 8ef05855e6b..00000000000 --- a/src/main/java/org/jabref/logic/autocompleter/EntireFieldAutoCompleter.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.jabref.logic.autocompleter; - -import java.util.Objects; - -import org.jabref.model.entry.BibEntry; - -/** - * Delivers possible completions for a given string. - * Stores the full original value of one field of the given BibtexEntries. - * - * @author kahlert, cordes - */ -class EntireFieldAutoCompleter extends AbstractAutoCompleter { - - private final String fieldName; - - /** - * @see AutoCompleterFactory - */ - EntireFieldAutoCompleter(String fieldName, AutoCompletePreferences preferences) { - super(preferences); - - this.fieldName = Objects.requireNonNull(fieldName); - } - - @Override - public boolean isSingleUnitField() { - return true; - } - - /** - * {@inheritDoc} - * Stores the full original value of the given field. - */ - @Override - public void addBibtexEntry(BibEntry entry) { - if (entry == null) { - return; - } - - entry.getField(fieldName).ifPresent(fieldValue -> addItemToIndex(fieldValue.trim())); - } -} diff --git a/src/main/java/org/jabref/logic/autocompleter/FieldValueSuggestionProvider.java b/src/main/java/org/jabref/logic/autocompleter/FieldValueSuggestionProvider.java new file mode 100644 index 00000000000..2ebc07b5356 --- /dev/null +++ b/src/main/java/org/jabref/logic/autocompleter/FieldValueSuggestionProvider.java @@ -0,0 +1,26 @@ +package org.jabref.logic.autocompleter; + +import java.util.Objects; + +import org.jabref.model.entry.BibEntry; + +/** + * Stores the full content of one field. + */ +class FieldValueSuggestionProvider extends StringSuggestionProvider implements AutoCompleteSuggestionProvider { + + private final String fieldName; + + FieldValueSuggestionProvider(String fieldName) { + this.fieldName = Objects.requireNonNull(fieldName); + } + + @Override + public void indexBibtexEntry(BibEntry entry) { + if (entry == null) { + return; + } + + entry.getField(fieldName).ifPresent(fieldValue -> addPossibleSuggestions(fieldValue.trim())); + } +} diff --git a/src/main/java/org/jabref/logic/autocompleter/JournalAutoCompleter.java b/src/main/java/org/jabref/logic/autocompleter/JournalAutoCompleter.java deleted file mode 100644 index 20cee610ea3..00000000000 --- a/src/main/java/org/jabref/logic/autocompleter/JournalAutoCompleter.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.jabref.logic.autocompleter; - -import java.util.List; -import java.util.Objects; - -import org.jabref.logic.journals.Abbreviation; -import org.jabref.logic.journals.JournalAbbreviationLoader; -import org.jabref.logic.journals.JournalAbbreviationPreferences; - -public class JournalAutoCompleter extends EntireFieldAutoCompleter { - - private final JournalAbbreviationLoader abbreviationLoader; - private final JournalAbbreviationPreferences journalAbbreviationPreferences; - - - JournalAutoCompleter(String fieldName, AutoCompletePreferences preferences, - JournalAbbreviationLoader abbreviationLoader) { - super(fieldName, preferences); - this.abbreviationLoader = Objects.requireNonNull(abbreviationLoader); - this.journalAbbreviationPreferences = preferences.getJournalAbbreviationPreferences(); - } - - @Override - public List complete(String toComplete) { - List completions = super.complete(toComplete); - - // Also return journal names in the journal abbreviation list - for (Abbreviation abbreviation : abbreviationLoader - .getRepository(journalAbbreviationPreferences).getAbbreviations()) { - if (abbreviation.getName().startsWith(toComplete)) { - completions.add(abbreviation.getName()); - } - } - - return completions; - } -} diff --git a/src/main/java/org/jabref/logic/autocompleter/JournalsSuggestionProvider.java b/src/main/java/org/jabref/logic/autocompleter/JournalsSuggestionProvider.java new file mode 100644 index 00000000000..a6ce494c597 --- /dev/null +++ b/src/main/java/org/jabref/logic/autocompleter/JournalsSuggestionProvider.java @@ -0,0 +1,24 @@ +package org.jabref.logic.autocompleter; + +import java.util.List; +import java.util.stream.Collectors; + +import org.jabref.logic.journals.Abbreviation; +import org.jabref.logic.journals.JournalAbbreviationLoader; +import org.jabref.logic.journals.JournalAbbreviationPreferences; + +public class JournalsSuggestionProvider extends FieldValueSuggestionProvider { + + + JournalsSuggestionProvider(String fieldName, AutoCompletePreferences preferences, + JournalAbbreviationLoader abbreviationLoader) { + super(fieldName); + + JournalAbbreviationPreferences journalAbbreviationPreferences = preferences.getJournalAbbreviationPreferences(); + List journals = abbreviationLoader.getRepository(journalAbbreviationPreferences) + .getAbbreviations().stream() + .map(Abbreviation::getName) + .collect(Collectors.toList()); + addPossibleSuggestions(journals); + } +} diff --git a/src/main/java/org/jabref/logic/autocompleter/NameFieldAutoCompleter.java b/src/main/java/org/jabref/logic/autocompleter/PersonNameSuggestionProvider.java similarity index 91% rename from src/main/java/org/jabref/logic/autocompleter/NameFieldAutoCompleter.java rename to src/main/java/org/jabref/logic/autocompleter/PersonNameSuggestionProvider.java index 95b4ecb09e1..7137bcdc666 100644 --- a/src/main/java/org/jabref/logic/autocompleter/NameFieldAutoCompleter.java +++ b/src/main/java/org/jabref/logic/autocompleter/PersonNameSuggestionProvider.java @@ -11,13 +11,9 @@ import org.jabref.model.entry.BibEntry; /** - * Delivers possible completions for a given string. - * Interprets the given values as names and stores them in different - * permutations so we can complete by beginning with last name or first name. - * - * @author kahlert, cordes + * Delivers possible completions as a list of {@link Author}s. */ -class NameFieldAutoCompleter extends AbstractAutoCompleter { +class PersonNameSuggestionProvider extends AbstractAutoCompleter { private final List fieldNames; /** @@ -34,12 +30,12 @@ class NameFieldAutoCompleter extends AbstractAutoCompleter { /** * @see AutoCompleterFactory */ - NameFieldAutoCompleter(String fieldName, AutoCompletePreferences preferences) { + PersonNameSuggestionProvider(String fieldName, AutoCompletePreferences preferences) { this(Collections.singletonList(Objects.requireNonNull(fieldName)), false, preferences); } - public NameFieldAutoCompleter(List fieldNames, boolean lastNameOnlyAndSeparationBySpace, - AutoCompletePreferences preferences) { + public PersonNameSuggestionProvider(List fieldNames, boolean lastNameOnlyAndSeparationBySpace, + AutoCompletePreferences preferences) { super(preferences); this.fieldNames = Objects.requireNonNull(fieldNames); diff --git a/src/main/java/org/jabref/logic/autocompleter/StringSuggestionProvider.java b/src/main/java/org/jabref/logic/autocompleter/StringSuggestionProvider.java new file mode 100644 index 00000000000..093161dbe63 --- /dev/null +++ b/src/main/java/org/jabref/logic/autocompleter/StringSuggestionProvider.java @@ -0,0 +1,27 @@ +package org.jabref.logic.autocompleter; + +import java.util.Comparator; + +import impl.org.controlsfx.autocompletion.SuggestionProvider; +import org.controlsfx.control.textfield.AutoCompletionBinding; + +class StringSuggestionProvider extends SuggestionProvider { + + private final Comparator stringComparator = Comparator.naturalOrder(); + + public StringSuggestionProvider() { + + } + + @Override + protected Comparator getComparator() { + return stringComparator; + } + + @Override + protected boolean isMatch(String suggestion, AutoCompletionBinding.ISuggestionRequest request) { + String userTextLower = request.getUserText().toLowerCase(); + String suggestionStr = suggestion.toLowerCase(); + return suggestionStr.contains(userTextLower); + } +} diff --git a/src/main/java/org/jabref/logic/autocompleter/DefaultAutoCompleter.java b/src/main/java/org/jabref/logic/autocompleter/WordSuggestionProvider.java similarity index 53% rename from src/main/java/org/jabref/logic/autocompleter/DefaultAutoCompleter.java rename to src/main/java/org/jabref/logic/autocompleter/WordSuggestionProvider.java index 319f573edce..9140b6dc7ff 100644 --- a/src/main/java/org/jabref/logic/autocompleter/DefaultAutoCompleter.java +++ b/src/main/java/org/jabref/logic/autocompleter/WordSuggestionProvider.java @@ -6,37 +6,20 @@ import org.jabref.model.entry.BibEntry; /** - * Delivers possible completions for a given string. * Stores all words in the given field which are separated by SEPARATING_CHARS. - * - * @author kahlert, cordes */ -class DefaultAutoCompleter extends AbstractAutoCompleter { +class WordSuggestionProvider extends StringSuggestionProvider implements AutoCompleteSuggestionProvider { private static final String SEPARATING_CHARS = ";,\n "; private final String fieldName; - /** - * @see AutoCompleterFactory - */ - DefaultAutoCompleter(String fieldName, AutoCompletePreferences preferences) { - super(preferences); - + WordSuggestionProvider(String fieldName) { this.fieldName = Objects.requireNonNull(fieldName); } @Override - public boolean isSingleUnitField() { - return false; - } - - /** - * {@inheritDoc} - * Stores all words in the given field which are separated by SEPARATING_CHARS. - */ - @Override - public void addBibtexEntry(BibEntry entry) { + public void indexBibtexEntry(BibEntry entry) { if (entry == null) { return; } @@ -44,7 +27,7 @@ public void addBibtexEntry(BibEntry entry) { entry.getField(fieldName).ifPresent(fieldValue -> { StringTokenizer tok = new StringTokenizer(fieldValue, SEPARATING_CHARS); while (tok.hasMoreTokens()) { - addItemToIndex(tok.nextToken()); + addPossibleSuggestions(tok.nextToken()); } }); } diff --git a/src/test/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModelTest.java b/src/test/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModelTest.java index 3caee9cc192..460ddaad223 100644 --- a/src/test/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModelTest.java +++ b/src/test/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModelTest.java @@ -2,6 +2,7 @@ import org.jabref.gui.DialogService; import org.jabref.gui.util.CurrentThreadTaskExecutor; +import org.jabref.logic.autocompleter.ContentAutoCompleters; import org.junit.Before; import org.junit.Test; @@ -15,7 +16,7 @@ public class IdentifierEditorViewModelTest { @Before public void setUp() throws Exception { - viewModel = new IdentifierEditorViewModel("DOI", new CurrentThreadTaskExecutor(), mock(DialogService.class)); + viewModel = new IdentifierEditorViewModel("DOI", new ContentAutoCompleters(), new CurrentThreadTaskExecutor(), mock(DialogService.class)); } @Test diff --git a/src/test/java/org/jabref/logic/autocompleter/AutoCompleterFactoryTest.java b/src/test/java/org/jabref/logic/autocompleter/AutoCompleterFactoryTest.java index 7da50b60fc1..e01faba37ae 100644 --- a/src/test/java/org/jabref/logic/autocompleter/AutoCompleterFactoryTest.java +++ b/src/test/java/org/jabref/logic/autocompleter/AutoCompleterFactoryTest.java @@ -28,7 +28,7 @@ public void initFactoryWithNullPreferenceThrowsException() { @Test public void getForUnknownFieldReturnsDefaultAutoCompleter() { AutoCompleter autoCompleter = autoCompleterFactory.getFor("unknownField"); - Assert.assertTrue(autoCompleter instanceof DefaultAutoCompleter); + Assert.assertTrue(autoCompleter != null); } @Test(expected = NullPointerException.class) @@ -39,36 +39,36 @@ public void getForNullThrowsException() { @Test public void getForAuthorReturnsNameFieldAutoCompleter() { AutoCompleter autoCompleter = autoCompleterFactory.getFor("author"); - Assert.assertTrue(autoCompleter instanceof NameFieldAutoCompleter); + Assert.assertTrue(autoCompleter instanceof PersonNameSuggestionProvider); } @Test public void getForEditorReturnsNameFieldAutoCompleter() { AutoCompleter autoCompleter = autoCompleterFactory.getFor("editor"); - Assert.assertTrue(autoCompleter instanceof NameFieldAutoCompleter); + Assert.assertTrue(autoCompleter instanceof PersonNameSuggestionProvider); } @Test public void getForCrossrefReturnsBibtexKeyAutoCompleter() { AutoCompleter autoCompleter = autoCompleterFactory.getFor("crossref"); - Assert.assertTrue(autoCompleter instanceof BibtexKeyAutoCompleter); + Assert.assertTrue(autoCompleter instanceof BibEntrySuggestionProvider); } @Test public void getForJournalReturnsEntireFieldAutoCompleter() { AutoCompleter autoCompleter = autoCompleterFactory.getFor("journal"); - Assert.assertTrue(autoCompleter instanceof EntireFieldAutoCompleter); + Assert.assertTrue(autoCompleter instanceof FieldValueSuggestionProvider); } @Test public void getForPublisherReturnsEntireFieldAutoCompleter() { AutoCompleter autoCompleter = autoCompleterFactory.getFor("publisher"); - Assert.assertTrue(autoCompleter instanceof EntireFieldAutoCompleter); + Assert.assertTrue(autoCompleter instanceof FieldValueSuggestionProvider); } @Test public void getPersonAutoCompleterReturnsNameFieldAutoCompleter() { AutoCompleter autoCompleter = autoCompleterFactory.getPersonAutoCompleter(); - Assert.assertTrue(autoCompleter instanceof NameFieldAutoCompleter); + Assert.assertTrue(autoCompleter instanceof PersonNameSuggestionProvider); } } diff --git a/src/test/java/org/jabref/logic/autocompleter/AutoCompleterTestUtil.java b/src/test/java/org/jabref/logic/autocompleter/AutoCompleterTestUtil.java new file mode 100644 index 00000000000..befdca4a8ae --- /dev/null +++ b/src/test/java/org/jabref/logic/autocompleter/AutoCompleterTestUtil.java @@ -0,0 +1,19 @@ +package org.jabref.logic.autocompleter; + +import org.controlsfx.control.textfield.AutoCompletionBinding; + +public class AutoCompleterTestUtil { + static AutoCompletionBinding.ISuggestionRequest getRequest(String text) { + return new AutoCompletionBinding.ISuggestionRequest() { + @Override + public boolean isCancelled() { + return false; + } + + @Override + public String getUserText() { + return text; + } + }; + } +} diff --git a/src/test/java/org/jabref/logic/autocompleter/BibtexKeyAutoCompleterTest.java b/src/test/java/org/jabref/logic/autocompleter/BibtexKeyAutoCompleterTest.java index 4c25f1efa99..9e327fe33a0 100644 --- a/src/test/java/org/jabref/logic/autocompleter/BibtexKeyAutoCompleterTest.java +++ b/src/test/java/org/jabref/logic/autocompleter/BibtexKeyAutoCompleterTest.java @@ -1,162 +1,118 @@ package org.jabref.logic.autocompleter; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; -import java.util.List; import org.jabref.model.entry.BibEntry; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.jabref.logic.autocompleter.AutoCompleterTestUtil.getRequest; public class BibtexKeyAutoCompleterTest { + private BibEntrySuggestionProvider autoCompleter; - @SuppressWarnings("unused") - @Test(expected = NullPointerException.class) - public void initAutoCompleterWithNullPreferenceThrowsException() { - new BibtexKeyAutoCompleter(null); + @Before + public void setUp() throws Exception { + autoCompleter = new BibEntrySuggestionProvider(); } @Test public void completeWithoutAddingAnythingReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - BibtexKeyAutoCompleter autoCompleter = new BibtexKeyAutoCompleter(preferences); - - List result = autoCompleter.complete("test"); + Collection result = autoCompleter.call(getRequest(("test"))); Assert.assertEquals(Collections.emptyList(), result); } @Test public void completeAfterAddingNullReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - BibtexKeyAutoCompleter autoCompleter = new BibtexKeyAutoCompleter(preferences); - - autoCompleter.addBibtexEntry(null); + autoCompleter.indexBibtexEntry(null); - List result = autoCompleter.complete("test"); + Collection result = autoCompleter.call(getRequest(("test"))); Assert.assertEquals(Collections.emptyList(), result); } @Test public void completeAfterAddingEmptyEntryReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - BibtexKeyAutoCompleter autoCompleter = new BibtexKeyAutoCompleter(preferences); - BibEntry entry = new BibEntry(); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexBibtexEntry(entry); - List result = autoCompleter.complete("test"); + Collection result = autoCompleter.call(getRequest(("test"))); Assert.assertEquals(Collections.emptyList(), result); } @Test public void completeKeyReturnsKey() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - BibtexKeyAutoCompleter autoCompleter = new BibtexKeyAutoCompleter(preferences); - BibEntry entry = new BibEntry(); entry.setCiteKey("testKey"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexBibtexEntry(entry); - List result = autoCompleter.complete("testKey"); + Collection result = autoCompleter.call(getRequest(("testKey"))); Assert.assertEquals(Arrays.asList("testKey"), result); } @Test public void completeBeginnigOfKeyReturnsKey() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - BibtexKeyAutoCompleter autoCompleter = new BibtexKeyAutoCompleter(preferences); - BibEntry entry = new BibEntry(); entry.setCiteKey("testKey"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexBibtexEntry(entry); - List result = autoCompleter.complete("test"); + Collection result = autoCompleter.call(getRequest(("test"))); Assert.assertEquals(Arrays.asList("testKey"), result); } @Test public void completeLowercaseKeyReturnsKey() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - BibtexKeyAutoCompleter autoCompleter = new BibtexKeyAutoCompleter(preferences); - BibEntry entry = new BibEntry(); entry.setCiteKey("testKey"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexBibtexEntry(entry); - List result = autoCompleter.complete("testkey"); + Collection result = autoCompleter.call(getRequest(("testkey"))); Assert.assertEquals(Arrays.asList("testKey"), result); } @Test public void completeNullReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - BibtexKeyAutoCompleter autoCompleter = new BibtexKeyAutoCompleter(preferences); - BibEntry entry = new BibEntry(); entry.setCiteKey("testKey"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexBibtexEntry(entry); - List result = autoCompleter.complete(null); + Collection result = autoCompleter.call(getRequest((null))); Assert.assertEquals(Collections.emptyList(), result); } @Test public void completeEmptyStringReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - BibtexKeyAutoCompleter autoCompleter = new BibtexKeyAutoCompleter(preferences); - BibEntry entry = new BibEntry(); entry.setCiteKey("testKey"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexBibtexEntry(entry); - List result = autoCompleter.complete(""); + Collection result = autoCompleter.call(getRequest((""))); Assert.assertEquals(Collections.emptyList(), result); } @Test public void completeReturnsMultipleResults() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - BibtexKeyAutoCompleter autoCompleter = new BibtexKeyAutoCompleter(preferences); - BibEntry entryOne = new BibEntry(); entryOne.setCiteKey("testKeyOne"); - autoCompleter.addBibtexEntry(entryOne); + autoCompleter.indexBibtexEntry(entryOne); BibEntry entryTwo = new BibEntry(); entryTwo.setCiteKey("testKeyTwo"); - autoCompleter.addBibtexEntry(entryTwo); + autoCompleter.indexBibtexEntry(entryTwo); - List result = autoCompleter.complete("testKey"); + Collection result = autoCompleter.call(getRequest(("testKey"))); Assert.assertEquals(Arrays.asList("testKeyOne", "testKeyTwo"), result); } @Test public void completeShortKeyReturnsKey() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - BibtexKeyAutoCompleter autoCompleter = new BibtexKeyAutoCompleter(preferences); - BibEntry entry = new BibEntry(); entry.setCiteKey("key"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexBibtexEntry(entry); - List result = autoCompleter.complete("k"); + Collection result = autoCompleter.call(getRequest(("k"))); Assert.assertEquals(Arrays.asList("key"), result); } - - @Test - public void completeTooShortInputReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - when(preferences.getShortestLengthToComplete()).thenReturn(100); - BibtexKeyAutoCompleter autoCompleter = new BibtexKeyAutoCompleter(preferences); - - BibEntry entry = new BibEntry(); - entry.setCiteKey("testKey"); - autoCompleter.addBibtexEntry(entry); - - List result = autoCompleter.complete("test"); - Assert.assertEquals(Collections.emptyList(), result); - } } diff --git a/src/test/java/org/jabref/logic/autocompleter/DefaultAutoCompleterTest.java b/src/test/java/org/jabref/logic/autocompleter/DefaultAutoCompleterTest.java index 95299367cc3..6538a79da42 100644 --- a/src/test/java/org/jabref/logic/autocompleter/DefaultAutoCompleterTest.java +++ b/src/test/java/org/jabref/logic/autocompleter/DefaultAutoCompleterTest.java @@ -1,207 +1,154 @@ package org.jabref.logic.autocompleter; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; -import java.util.List; import org.jabref.model.entry.BibEntry; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.jabref.logic.autocompleter.AutoCompleterTestUtil.getRequest; public class DefaultAutoCompleterTest { - @SuppressWarnings("unused") - @Test(expected = NullPointerException.class) - public void initAutoCompleterWithNullPreferenceThrowsException() { - new DefaultAutoCompleter("field", null); - } + private WordSuggestionProvider autoCompleter; @SuppressWarnings("unused") @Test(expected = NullPointerException.class) public void initAutoCompleterWithNullFieldThrowsException() { - new DefaultAutoCompleter(null, mock(AutoCompletePreferences.class)); + new WordSuggestionProvider(null); + } + + @Before + public void setUp() throws Exception { + autoCompleter = new WordSuggestionProvider("field"); } @Test public void completeWithoutAddingAnythingReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - DefaultAutoCompleter autoCompleter = new DefaultAutoCompleter("field", preferences); - - List result = autoCompleter.complete("test"); + Collection result = autoCompleter.call(getRequest(("test"))); Assert.assertEquals(Collections.emptyList(), result); } @Test public void completeAfterAddingNullReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - DefaultAutoCompleter autoCompleter = new DefaultAutoCompleter("field", preferences); + autoCompleter.indexBibtexEntry(null); - autoCompleter.addBibtexEntry(null); - - List result = autoCompleter.complete("test"); + Collection result = autoCompleter.call(getRequest(("test"))); Assert.assertEquals(Collections.emptyList(), result); } @Test public void completeAfterAddingEmptyEntryReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - DefaultAutoCompleter autoCompleter = new DefaultAutoCompleter("field", preferences); - BibEntry entry = new BibEntry(); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexBibtexEntry(entry); - List result = autoCompleter.complete("test"); + Collection result = autoCompleter.call(getRequest(("test"))); Assert.assertEquals(Collections.emptyList(), result); } @Test public void completeAfterAddingEntryWithoutFieldReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - DefaultAutoCompleter autoCompleter = new DefaultAutoCompleter("field", preferences); - BibEntry entry = new BibEntry(); entry.setField("title", "testTitle"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexBibtexEntry(entry); - List result = autoCompleter.complete("test"); + Collection result = autoCompleter.call(getRequest(("test"))); Assert.assertEquals(Collections.emptyList(), result); } @Test public void completeValueReturnsValue() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - DefaultAutoCompleter autoCompleter = new DefaultAutoCompleter("field", preferences); - BibEntry entry = new BibEntry(); entry.setField("field", "testValue"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexBibtexEntry(entry); - List result = autoCompleter.complete("testValue"); + Collection result = autoCompleter.call(getRequest(("testValue"))); Assert.assertEquals(Arrays.asList("testValue"), result); } @Test public void completeBeginnigOfValueReturnsValue() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - DefaultAutoCompleter autoCompleter = new DefaultAutoCompleter("field", preferences); - BibEntry entry = new BibEntry(); entry.setField("field", "testValue"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexBibtexEntry(entry); - List result = autoCompleter.complete("test"); + Collection result = autoCompleter.call(getRequest(("test"))); Assert.assertEquals(Arrays.asList("testValue"), result); } @Test public void completeLowercaseValueReturnsValue() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - DefaultAutoCompleter autoCompleter = new DefaultAutoCompleter("field", preferences); - BibEntry entry = new BibEntry(); entry.setField("field", "testValue"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexBibtexEntry(entry); - List result = autoCompleter.complete("testvalue"); + Collection result = autoCompleter.call(getRequest(("testvalue"))); Assert.assertEquals(Arrays.asList("testValue"), result); } - @Test - public void completeNullReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - DefaultAutoCompleter autoCompleter = new DefaultAutoCompleter("field", preferences); - + @Test(expected = NullPointerException.class) + public void completeNullThrowsException() { BibEntry entry = new BibEntry(); entry.setField("field", "testKey"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexBibtexEntry(entry); - List result = autoCompleter.complete(null); - Assert.assertEquals(Collections.emptyList(), result); + autoCompleter.call(getRequest((null))); } @Test public void completeEmptyStringReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - DefaultAutoCompleter autoCompleter = new DefaultAutoCompleter("field", preferences); - BibEntry entry = new BibEntry(); entry.setField("field", "testKey"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexBibtexEntry(entry); - List result = autoCompleter.complete(""); + Collection result = autoCompleter.call(getRequest((""))); Assert.assertEquals(Collections.emptyList(), result); } @Test public void completeReturnsMultipleResults() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - DefaultAutoCompleter autoCompleter = new DefaultAutoCompleter("field", preferences); - BibEntry entryOne = new BibEntry(); entryOne.setField("field", "testValueOne"); - autoCompleter.addBibtexEntry(entryOne); + autoCompleter.indexBibtexEntry(entryOne); BibEntry entryTwo = new BibEntry(); entryTwo.setField("field", "testValueTwo"); - autoCompleter.addBibtexEntry(entryTwo); + autoCompleter.indexBibtexEntry(entryTwo); - List result = autoCompleter.complete("testValue"); + Collection result = autoCompleter.call(getRequest(("testValue"))); Assert.assertEquals(Arrays.asList("testValueOne", "testValueTwo"), result); } @Test - public void completeShortStringReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - DefaultAutoCompleter autoCompleter = new DefaultAutoCompleter("field", preferences); - + public void completeShortStringReturnsValue() { BibEntry entry = new BibEntry(); entry.setField("field", "val"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexBibtexEntry(entry); - List result = autoCompleter.complete("va"); - Assert.assertEquals(Collections.emptyList(), result); - } - - @Test - public void completeTooShortInputReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - when(preferences.getShortestLengthToComplete()).thenReturn(100); - DefaultAutoCompleter autoCompleter = new DefaultAutoCompleter("field", preferences); - - BibEntry entry = new BibEntry(); - entry.setField("field", "testValue"); - autoCompleter.addBibtexEntry(entry); - - List result = autoCompleter.complete("test"); - Assert.assertEquals(Collections.emptyList(), result); + Collection result = autoCompleter.call(getRequest(("va"))); + Assert.assertEquals(Collections.singletonList("val"), result); } @Test public void completeBeginnigOfSecondWordReturnsWord() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - DefaultAutoCompleter autoCompleter = new DefaultAutoCompleter("field", preferences); - BibEntry entry = new BibEntry(); entry.setField("field", "test value"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexBibtexEntry(entry); - List result = autoCompleter.complete("val"); - Assert.assertEquals(Arrays.asList("value"), result); + Collection result = autoCompleter.call(getRequest(("val"))); + Assert.assertEquals(Collections.singletonList("value"), result); } @Test - public void completePartOfWordReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - DefaultAutoCompleter autoCompleter = new DefaultAutoCompleter("field", preferences); - + public void completePartOfWordReturnsValue() { BibEntry entry = new BibEntry(); entry.setField("field", "test value"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexBibtexEntry(entry); - List result = autoCompleter.complete("lue"); - Assert.assertEquals(Collections.emptyList(), result); + Collection result = autoCompleter.call(getRequest(("lue"))); + Assert.assertEquals(Collections.singletonList("value"), result); } } diff --git a/src/test/java/org/jabref/logic/autocompleter/EntireFieldAutoCompleterTest.java b/src/test/java/org/jabref/logic/autocompleter/EntireFieldAutoCompleterTest.java deleted file mode 100644 index 5209d0b0764..00000000000 --- a/src/test/java/org/jabref/logic/autocompleter/EntireFieldAutoCompleterTest.java +++ /dev/null @@ -1,220 +0,0 @@ -package org.jabref.logic.autocompleter; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import org.jabref.model.entry.BibEntry; - -import org.junit.Assert; -import org.junit.Test; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class EntireFieldAutoCompleterTest { - - @SuppressWarnings("unused") - @Test(expected = NullPointerException.class) - public void initAutoCompleterWithNullPreferenceThrowsException() { - new EntireFieldAutoCompleter("field", null); - } - - @SuppressWarnings("unused") - @Test(expected = NullPointerException.class) - public void initAutoCompleterWithNullFieldThrowsException() { - new EntireFieldAutoCompleter(null, mock(AutoCompletePreferences.class)); - } - - @Test - public void completeWithoutAddingAnythingReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - EntireFieldAutoCompleter autoCompleter = new EntireFieldAutoCompleter("field", preferences); - - List result = autoCompleter.complete("test"); - Assert.assertEquals(Collections.emptyList(), result); - } - - @Test - public void completeAfterAddingNullReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - EntireFieldAutoCompleter autoCompleter = new EntireFieldAutoCompleter("field", preferences); - - autoCompleter.addBibtexEntry(null); - - List result = autoCompleter.complete("test"); - Assert.assertEquals(Collections.emptyList(), result); - } - - @Test - public void completeAfterAddingEmptyEntryReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - EntireFieldAutoCompleter autoCompleter = new EntireFieldAutoCompleter("field", preferences); - - BibEntry entry = new BibEntry(); - autoCompleter.addBibtexEntry(entry); - - List result = autoCompleter.complete("test"); - Assert.assertEquals(Collections.emptyList(), result); - } - - @Test - public void completeAfterAddingEntryWithoutFieldReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - EntireFieldAutoCompleter autoCompleter = new EntireFieldAutoCompleter("field", preferences); - - BibEntry entry = new BibEntry(); - entry.setField("title", "testTitle"); - autoCompleter.addBibtexEntry(entry); - - List result = autoCompleter.complete("test"); - Assert.assertEquals(Collections.emptyList(), result); - } - - @Test - public void completeValueReturnsValue() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - EntireFieldAutoCompleter autoCompleter = new EntireFieldAutoCompleter("field", preferences); - - BibEntry entry = new BibEntry(); - entry.setField("field", "testValue"); - autoCompleter.addBibtexEntry(entry); - - List result = autoCompleter.complete("testValue"); - Assert.assertEquals(Arrays.asList("testValue"), result); - } - - @Test - public void completeBeginnigOfValueReturnsValue() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - EntireFieldAutoCompleter autoCompleter = new EntireFieldAutoCompleter("field", preferences); - - BibEntry entry = new BibEntry(); - entry.setField("field", "testValue"); - autoCompleter.addBibtexEntry(entry); - - List result = autoCompleter.complete("test"); - Assert.assertEquals(Arrays.asList("testValue"), result); - } - - @Test - public void completeLowercaseValueReturnsValue() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - EntireFieldAutoCompleter autoCompleter = new EntireFieldAutoCompleter("field", preferences); - - BibEntry entry = new BibEntry(); - entry.setField("field", "testValue"); - autoCompleter.addBibtexEntry(entry); - - List result = autoCompleter.complete("testvalue"); - Assert.assertEquals(Arrays.asList("testValue"), result); - } - - @Test - public void completeNullReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - EntireFieldAutoCompleter autoCompleter = new EntireFieldAutoCompleter("field", preferences); - - BibEntry entry = new BibEntry(); - entry.setField("field", "testKey"); - autoCompleter.addBibtexEntry(entry); - - List result = autoCompleter.complete(null); - Assert.assertEquals(Collections.emptyList(), result); - } - - @Test - public void completeEmptyStringReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - EntireFieldAutoCompleter autoCompleter = new EntireFieldAutoCompleter("field", preferences); - - BibEntry entry = new BibEntry(); - entry.setField("field", "testKey"); - autoCompleter.addBibtexEntry(entry); - - List result = autoCompleter.complete(""); - Assert.assertEquals(Collections.emptyList(), result); - } - - @Test - public void completeReturnsMultipleResults() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - EntireFieldAutoCompleter autoCompleter = new EntireFieldAutoCompleter("field", preferences); - - BibEntry entryOne = new BibEntry(); - entryOne.setField("field", "testValueOne"); - autoCompleter.addBibtexEntry(entryOne); - BibEntry entryTwo = new BibEntry(); - entryTwo.setField("field", "testValueTwo"); - autoCompleter.addBibtexEntry(entryTwo); - - List result = autoCompleter.complete("testValue"); - Assert.assertEquals(Arrays.asList("testValueOne", "testValueTwo"), result); - } - - @Test - public void completeShortStringReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - EntireFieldAutoCompleter autoCompleter = new EntireFieldAutoCompleter("field", preferences); - - BibEntry entry = new BibEntry(); - entry.setField("field", "val"); - autoCompleter.addBibtexEntry(entry); - - List result = autoCompleter.complete("va"); - Assert.assertEquals(Collections.emptyList(), result); - } - - @Test - public void completeTooShortInputReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - when(preferences.getShortestLengthToComplete()).thenReturn(100); - EntireFieldAutoCompleter autoCompleter = new EntireFieldAutoCompleter("field", preferences); - - BibEntry entry = new BibEntry(); - entry.setField("field", "testValue"); - autoCompleter.addBibtexEntry(entry); - - List result = autoCompleter.complete("test"); - Assert.assertEquals(Collections.emptyList(), result); - } - - @Test - public void completeBeginnigOfSecondWordReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - EntireFieldAutoCompleter autoCompleter = new EntireFieldAutoCompleter("field", preferences); - - BibEntry entry = new BibEntry(); - entry.setField("field", "test value"); - autoCompleter.addBibtexEntry(entry); - - List result = autoCompleter.complete("val"); - Assert.assertEquals(Collections.emptyList(), result); - } - - @Test - public void completePartOfWordReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - EntireFieldAutoCompleter autoCompleter = new EntireFieldAutoCompleter("field", preferences); - - BibEntry entry = new BibEntry(); - entry.setField("field", "test value"); - autoCompleter.addBibtexEntry(entry); - - List result = autoCompleter.complete("lue"); - Assert.assertEquals(Collections.emptyList(), result); - } - - @Test - public void completeReturnsWholeFieldValue() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - EntireFieldAutoCompleter autoCompleter = new EntireFieldAutoCompleter("field", preferences); - - BibEntry entry = new BibEntry(); - entry.setField("field", "test value"); - autoCompleter.addBibtexEntry(entry); - - List result = autoCompleter.complete("te"); - Assert.assertEquals(Arrays.asList("test value"), result); - } -} diff --git a/src/test/java/org/jabref/logic/autocompleter/FieldValueSuggestionProviderTest.java b/src/test/java/org/jabref/logic/autocompleter/FieldValueSuggestionProviderTest.java new file mode 100644 index 00000000000..7af7cab5ee1 --- /dev/null +++ b/src/test/java/org/jabref/logic/autocompleter/FieldValueSuggestionProviderTest.java @@ -0,0 +1,164 @@ +package org.jabref.logic.autocompleter; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; + +import org.jabref.model.entry.BibEntry; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import static org.jabref.logic.autocompleter.AutoCompleterTestUtil.getRequest; + +public class FieldValueSuggestionProviderTest { + private FieldValueSuggestionProvider autoCompleter; + + @Before + public void setUp() throws Exception { + autoCompleter = new FieldValueSuggestionProvider("field"); + } + + @SuppressWarnings("unused") + @Test(expected = NullPointerException.class) + public void initAutoCompleterWithNullFieldThrowsException() { + new FieldValueSuggestionProvider(null); + } + + @Test + public void completeWithoutAddingAnythingReturnsNothing() { + Collection result = autoCompleter.call(getRequest(("test"))); + Assert.assertEquals(Collections.emptyList(), result); + } + + @Test + public void completeAfterAddingNullReturnsNothing() { + autoCompleter.indexBibtexEntry(null); + + Collection result = autoCompleter.call(getRequest(("test"))); + Assert.assertEquals(Collections.emptyList(), result); + } + + @Test + public void completeAfterAddingEmptyEntryReturnsNothing() { + BibEntry entry = new BibEntry(); + autoCompleter.indexBibtexEntry(entry); + + Collection result = autoCompleter.call(getRequest(("test"))); + Assert.assertEquals(Collections.emptyList(), result); + } + + @Test + public void completeAfterAddingEntryWithoutFieldReturnsNothing() { + BibEntry entry = new BibEntry(); + entry.setField("title", "testTitle"); + autoCompleter.indexBibtexEntry(entry); + + Collection result = autoCompleter.call(getRequest(("test"))); + Assert.assertEquals(Collections.emptyList(), result); + } + + @Test + public void completeValueReturnsValue() { + BibEntry entry = new BibEntry(); + entry.setField("field", "testValue"); + autoCompleter.indexBibtexEntry(entry); + + Collection result = autoCompleter.call(getRequest(("testValue"))); + Assert.assertEquals(Arrays.asList("testValue"), result); + } + + @Test + public void completeBeginnigOfValueReturnsValue() { + BibEntry entry = new BibEntry(); + entry.setField("field", "testValue"); + autoCompleter.indexBibtexEntry(entry); + + Collection result = autoCompleter.call(getRequest(("test"))); + Assert.assertEquals(Arrays.asList("testValue"), result); + } + + @Test + public void completeLowercaseValueReturnsValue() { + BibEntry entry = new BibEntry(); + entry.setField("field", "testValue"); + autoCompleter.indexBibtexEntry(entry); + + Collection result = autoCompleter.call(getRequest(("testvalue"))); + Assert.assertEquals(Arrays.asList("testValue"), result); + } + + @Test + public void completeNullReturnsNothing() { + BibEntry entry = new BibEntry(); + entry.setField("field", "testKey"); + autoCompleter.indexBibtexEntry(entry); + + Collection result = autoCompleter.call(getRequest((null))); + Assert.assertEquals(Collections.emptyList(), result); + } + + @Test + public void completeEmptyStringReturnsNothing() { + BibEntry entry = new BibEntry(); + entry.setField("field", "testKey"); + autoCompleter.indexBibtexEntry(entry); + + Collection result = autoCompleter.call(getRequest((""))); + Assert.assertEquals(Collections.emptyList(), result); + } + + @Test + public void completeReturnsMultipleResults() { + BibEntry entryOne = new BibEntry(); + entryOne.setField("field", "testValueOne"); + autoCompleter.indexBibtexEntry(entryOne); + BibEntry entryTwo = new BibEntry(); + entryTwo.setField("field", "testValueTwo"); + autoCompleter.indexBibtexEntry(entryTwo); + + Collection result = autoCompleter.call(getRequest(("testValue"))); + Assert.assertEquals(Arrays.asList("testValueOne", "testValueTwo"), result); + } + + @Test + public void completeShortStringReturnsNothing() { + BibEntry entry = new BibEntry(); + entry.setField("field", "val"); + autoCompleter.indexBibtexEntry(entry); + + Collection result = autoCompleter.call(getRequest(("va"))); + Assert.assertEquals(Collections.emptyList(), result); + } + + @Test + public void completeBeginnigOfSecondWordReturnsNothing() { + BibEntry entry = new BibEntry(); + entry.setField("field", "test value"); + autoCompleter.indexBibtexEntry(entry); + + Collection result = autoCompleter.call(getRequest(("val"))); + Assert.assertEquals(Collections.emptyList(), result); + } + + @Test + public void completePartOfWordReturnsNothing() { + BibEntry entry = new BibEntry(); + entry.setField("field", "test value"); + autoCompleter.indexBibtexEntry(entry); + + Collection result = autoCompleter.call(getRequest(("lue"))); + Assert.assertEquals(Collections.emptyList(), result); + } + + @Test + public void completeReturnsWholeFieldValue() { + BibEntry entry = new BibEntry(); + entry.setField("field", "test value"); + autoCompleter.indexBibtexEntry(entry); + + Collection result = autoCompleter.call(getRequest(("te"))); + Assert.assertEquals(Arrays.asList("test value"), result); + } +} diff --git a/src/test/java/org/jabref/logic/autocompleter/NameFieldAutoCompleterTest.java b/src/test/java/org/jabref/logic/autocompleter/PersonNameSuggestionProviderTest.java similarity index 80% rename from src/test/java/org/jabref/logic/autocompleter/NameFieldAutoCompleterTest.java rename to src/test/java/org/jabref/logic/autocompleter/PersonNameSuggestionProviderTest.java index 4c7fcb5ab13..323ec1ba12d 100644 --- a/src/test/java/org/jabref/logic/autocompleter/NameFieldAutoCompleterTest.java +++ b/src/test/java/org/jabref/logic/autocompleter/PersonNameSuggestionProviderTest.java @@ -12,24 +12,24 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class NameFieldAutoCompleterTest { +public class PersonNameSuggestionProviderTest { @SuppressWarnings("unused") @Test(expected = NullPointerException.class) public void initAutoCompleterWithNullPreferenceThrowsException() { - new NameFieldAutoCompleter("field", null); + new PersonNameSuggestionProvider("field", null); } @SuppressWarnings("unused") @Test(expected = NullPointerException.class) public void initAutoCompleterWithNullFieldThrowsException() { - new NameFieldAutoCompleter(null, mock(AutoCompletePreferences.class)); + new PersonNameSuggestionProvider(null, mock(AutoCompletePreferences.class)); } @Test public void completeWithoutAddingAnythingReturnsNothing() { AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - NameFieldAutoCompleter autoCompleter = new NameFieldAutoCompleter("field", preferences); + PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); List result = autoCompleter.complete("test"); Assert.assertEquals(Collections.emptyList(), result); @@ -38,7 +38,7 @@ public void completeWithoutAddingAnythingReturnsNothing() { @Test public void completeAfterAddingNullReturnsNothing() { AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - NameFieldAutoCompleter autoCompleter = new NameFieldAutoCompleter("field", preferences); + PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); autoCompleter.addBibtexEntry(null); @@ -49,7 +49,7 @@ public void completeAfterAddingNullReturnsNothing() { @Test public void completeAfterAddingEmptyEntryReturnsNothing() { AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - NameFieldAutoCompleter autoCompleter = new NameFieldAutoCompleter("field", preferences); + PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); BibEntry entry = new BibEntry(); autoCompleter.addBibtexEntry(entry); @@ -61,7 +61,7 @@ public void completeAfterAddingEmptyEntryReturnsNothing() { @Test public void completeAfterAddingEntryWithoutFieldReturnsNothing() { AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - NameFieldAutoCompleter autoCompleter = new NameFieldAutoCompleter("field", preferences); + PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); BibEntry entry = new BibEntry(); entry.setField("title", "testTitle"); @@ -74,7 +74,7 @@ public void completeAfterAddingEntryWithoutFieldReturnsNothing() { @Test public void completeNameReturnsName() { AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - NameFieldAutoCompleter autoCompleter = new NameFieldAutoCompleter("field", preferences); + PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); BibEntry entry = new BibEntry(); entry.setField("field", "Testname"); @@ -87,7 +87,7 @@ public void completeNameReturnsName() { @Test public void completeBeginnigOfNameReturnsName() { AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - NameFieldAutoCompleter autoCompleter = new NameFieldAutoCompleter("field", preferences); + PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); BibEntry entry = new BibEntry(); entry.setField("field", "Testname"); @@ -100,7 +100,7 @@ public void completeBeginnigOfNameReturnsName() { @Test public void completeLowercaseNameReturnsName() { AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - NameFieldAutoCompleter autoCompleter = new NameFieldAutoCompleter("field", preferences); + PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); BibEntry entry = new BibEntry(); entry.setField("field", "Testname"); @@ -113,7 +113,7 @@ public void completeLowercaseNameReturnsName() { @Test public void completeNullReturnsNothing() { AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - NameFieldAutoCompleter autoCompleter = new NameFieldAutoCompleter("field", preferences); + PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); BibEntry entry = new BibEntry(); entry.setField("field", "testKey"); @@ -126,7 +126,7 @@ public void completeNullReturnsNothing() { @Test public void completeEmptyStringReturnsNothing() { AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - NameFieldAutoCompleter autoCompleter = new NameFieldAutoCompleter("field", preferences); + PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); BibEntry entry = new BibEntry(); entry.setField("field", "testKey"); @@ -139,7 +139,7 @@ public void completeEmptyStringReturnsNothing() { @Test public void completeReturnsMultipleResults() { AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - NameFieldAutoCompleter autoCompleter = new NameFieldAutoCompleter("field", preferences); + PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); BibEntry entryOne = new BibEntry(); entryOne.setField("field", "testNameOne"); @@ -156,7 +156,7 @@ public void completeReturnsMultipleResults() { public void completeTooShortInputReturnsNothing() { AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); when(preferences.getShortestLengthToComplete()).thenReturn(100); - NameFieldAutoCompleter autoCompleter = new NameFieldAutoCompleter("field", preferences); + PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); BibEntry entry = new BibEntry(); entry.setField("field", "Testname"); @@ -169,7 +169,7 @@ public void completeTooShortInputReturnsNothing() { @Test public void completePartOfNameReturnsNothing() { AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - NameFieldAutoCompleter autoCompleter = new NameFieldAutoCompleter("field", preferences); + PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); BibEntry entry = new BibEntry(); entry.setField("field", "Vassilis Kostakos"); @@ -182,7 +182,7 @@ public void completePartOfNameReturnsNothing() { @Test public void completeBeginningOfFirstNameReturnsCompleteName() { AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - NameFieldAutoCompleter autoCompleter = new NameFieldAutoCompleter("field", preferences); + PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); BibEntry entry = new BibEntry(); entry.setField("field", "Vassilis Kostakos"); @@ -195,7 +195,7 @@ public void completeBeginningOfFirstNameReturnsCompleteName() { @Test public void completeBeginningOfFirstNameReturnsCompleteNameWithJr() { AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - NameFieldAutoCompleter autoCompleter = new NameFieldAutoCompleter("field", preferences); + PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); BibEntry entry = new BibEntry(); entry.setField("field", "Reagle, Jr., Joseph M."); @@ -208,7 +208,7 @@ public void completeBeginningOfFirstNameReturnsCompleteNameWithJr() { @Test public void completeBeginningOfFirstNameReturnsCompleteNameWithVon() { AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - NameFieldAutoCompleter autoCompleter = new NameFieldAutoCompleter("field", preferences); + PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); BibEntry entry = new BibEntry(); entry.setField("field", "Eric von Hippel"); @@ -222,7 +222,7 @@ public void completeBeginningOfFirstNameReturnsCompleteNameWithVon() { public void completeBeginningOfLastNameReturnsNameWithUmlauts() { AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); when(preferences.getFirstnameMode()).thenReturn(AutoCompleteFirstNameMode.ONLY_FULL); - NameFieldAutoCompleter autoCompleter = new NameFieldAutoCompleter("field", preferences); + PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); BibEntry entry = new BibEntry(); entry.setField("field", "Honig Bär"); @@ -235,7 +235,7 @@ public void completeBeginningOfLastNameReturnsNameWithUmlauts() { @Test public void completeBeginningOfLastNameReturnsNameAndNameWithInitialFirstname() { AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - NameFieldAutoCompleter autoCompleter = new NameFieldAutoCompleter("field", preferences); + PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); BibEntry entry = new BibEntry(); entry.setField("field", "Vassilis Kostakos"); @@ -249,7 +249,7 @@ public void completeBeginningOfLastNameReturnsNameAndNameWithInitialFirstname() public void completeBeginningOfLastNameReturnsNameIfPref() { AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); when(preferences.getFirstnameMode()).thenReturn(AutoCompleteFirstNameMode.ONLY_FULL); - NameFieldAutoCompleter autoCompleter = new NameFieldAutoCompleter("field", preferences); + PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); BibEntry entry = new BibEntry(); entry.setField("field", "Vassilis Kostakos"); @@ -263,7 +263,7 @@ public void completeBeginningOfLastNameReturnsNameIfPref() { public void completeBeginningOfLastNameReturnsNameWithJrIfPref() { AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); when(preferences.getFirstnameMode()).thenReturn(AutoCompleteFirstNameMode.ONLY_ABBREVIATED); - NameFieldAutoCompleter autoCompleter = new NameFieldAutoCompleter("field", preferences); + PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); BibEntry entry = new BibEntry(); entry.setField("field", "Reagle, Jr., Joseph M."); @@ -277,7 +277,7 @@ public void completeBeginningOfLastNameReturnsNameWithJrIfPref() { public void completeBeginningOfLastNameReturnsNameWithInitialFirstnameIfPref() { AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); when(preferences.getFirstnameMode()).thenReturn(AutoCompleteFirstNameMode.ONLY_ABBREVIATED); - NameFieldAutoCompleter autoCompleter = new NameFieldAutoCompleter("field", preferences); + PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); BibEntry entry = new BibEntry(); entry.setField("field", "Vassilis Kostakos"); @@ -291,7 +291,7 @@ public void completeBeginningOfLastNameReturnsNameWithInitialFirstnameIfPref() { public void completeVonReturnsNameWithInitialFirstnameIfPref() { AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); when(preferences.getFirstnameMode()).thenReturn(AutoCompleteFirstNameMode.ONLY_ABBREVIATED); - NameFieldAutoCompleter autoCompleter = new NameFieldAutoCompleter("field", preferences); + PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); BibEntry entry = new BibEntry(); entry.setField("field", "Eric von Hippel"); @@ -304,7 +304,7 @@ public void completeVonReturnsNameWithInitialFirstnameIfPref() { @Test public void completeBeginningOfNameReturnsCompleteName() { AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - NameFieldAutoCompleter autoCompleter = new NameFieldAutoCompleter("field", preferences); + PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); BibEntry entry = new BibEntry(); entry.setField("field", "Vassilis Kostakos"); @@ -318,7 +318,7 @@ public void completeBeginningOfNameReturnsCompleteName() { public void completeBeginningOfLastNameReturnsNothingIfPref() { AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); when(preferences.getOnlyCompleteFirstLast()).thenReturn(true); - NameFieldAutoCompleter autoCompleter = new NameFieldAutoCompleter("field", preferences); + PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); BibEntry entry = new BibEntry(); entry.setField("field", "Vassilis Kostakos"); @@ -332,7 +332,7 @@ public void completeBeginningOfLastNameReturnsNothingIfPref() { public void completeBeginningOfFirstNameReturnsNothingIfPref() { AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); when(preferences.getOnlyCompleteLastFirst()).thenReturn(true); - NameFieldAutoCompleter autoCompleter = new NameFieldAutoCompleter("field", preferences); + PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); BibEntry entry = new BibEntry(); entry.setField("field", "Vassilis Kostakos"); @@ -345,7 +345,7 @@ public void completeBeginningOfFirstNameReturnsNothingIfPref() { @Test public void completeShortNameReturnsName() { AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - NameFieldAutoCompleter autoCompleter = new NameFieldAutoCompleter("field", preferences); + PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); BibEntry entry = new BibEntry(); entry.setField("field", "nam"); From 6ee387e58edef5f96820f4a1c584f210336da341 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Mon, 3 Jul 2017 18:10:15 +0200 Subject: [PATCH 02/10] Code cleanup --- src/main/java/org/jabref/gui/BasePanel.java | 58 ++++++++----------- .../ContentSelectorDialog.java | 7 +-- .../jabref/gui/entryeditor/EntryEditor.java | 2 +- .../gui/entryeditor/FieldsEditorTab.java | 4 +- .../fieldeditors/AbstractEditorViewModel.java | 8 +-- .../jabref/gui/fieldeditors/DateEditor.java | 6 +- .../gui/fieldeditors/DateEditorViewModel.java | 6 +- .../EditorTypeEditorViewModel.java | 6 +- .../jabref/gui/fieldeditors/FieldEditors.java | 39 +++++++------ .../fieldeditors/GenderEditorViewModel.java | 6 +- .../gui/fieldeditors/IdentifierEditor.java | 6 +- .../IdentifierEditorViewModel.java | 6 +- .../gui/fieldeditors/JournalEditor.java | 6 +- .../fieldeditors/JournalEditorViewModel.java | 6 +- .../gui/fieldeditors/LinkedEntriesEditor.java | 6 +- .../LinkedEntriesEditorViewModel.java | 6 +- .../gui/fieldeditors/LinkedFilesEditor.java | 6 +- .../LinkedFilesEditorViewModel.java | 6 +- .../fieldeditors/MapBasedEditorViewModel.java | 6 +- .../fieldeditors/MonthEditorViewModel.java | 6 +- .../fieldeditors/OptionEditorViewModel.java | 6 +- .../jabref/gui/fieldeditors/OwnerEditor.java | 6 +- .../fieldeditors/OwnerEditorViewModel.java | 6 +- .../PaginationEditorViewModel.java | 6 +- .../PatentTypeEditorViewModel.java | 6 +- .../jabref/gui/fieldeditors/SimpleEditor.java | 6 +- .../fieldeditors/SimpleEditorViewModel.java | 6 +- .../gui/fieldeditors/TypeEditorViewModel.java | 6 +- .../jabref/gui/fieldeditors/UrlEditor.java | 6 +- .../gui/fieldeditors/UrlEditorViewModel.java | 6 +- .../fieldeditors/YesNoEditorViewModel.java | 6 +- .../autocompleter/AutoCompleteListener.java | 28 +++++++++ .../AutoCompleteSuggestionProvider.java | 2 +- .../logic/autocompleter/AutoCompleters.java | 39 ------------- .../BibEntrySuggestionProvider.java | 2 +- .../autocompleter/ContentAutoCompleters.java | 42 -------------- .../ContentSelectorSuggestionProvider.java | 33 +++++++++++ .../FieldValueSuggestionProvider.java | 2 +- .../autocompleter/SuggestionProviders.java | 56 ++++++++++++++++++ .../autocompleter/WordSuggestionProvider.java | 2 +- 40 files changed, 250 insertions(+), 224 deletions(-) create mode 100644 src/main/java/org/jabref/logic/autocompleter/AutoCompleteListener.java delete mode 100644 src/main/java/org/jabref/logic/autocompleter/AutoCompleters.java delete mode 100644 src/main/java/org/jabref/logic/autocompleter/ContentAutoCompleters.java create mode 100644 src/main/java/org/jabref/logic/autocompleter/ContentSelectorSuggestionProvider.java create mode 100644 src/main/java/org/jabref/logic/autocompleter/SuggestionProviders.java diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 5690497c24a..e433e35990f 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -96,10 +96,11 @@ import org.jabref.gui.worker.CitationStyleToClipboardWorker; import org.jabref.gui.worker.MarkEntriesAction; import org.jabref.gui.worker.SendAsEMailAction; +import org.jabref.logic.autocompleter.AutoCompleteListener; import org.jabref.logic.autocompleter.AutoCompletePreferences; import org.jabref.logic.autocompleter.AutoCompleter; import org.jabref.logic.autocompleter.AutoCompleterFactory; -import org.jabref.logic.autocompleter.ContentAutoCompleters; +import org.jabref.logic.autocompleter.SuggestionProviders; import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; import org.jabref.logic.citationstyle.CitationStyleCache; import org.jabref.logic.citationstyle.CitationStyleOutputFormat; @@ -193,7 +194,7 @@ public class BasePanel extends JPanel implements ClipboardOwner, FileUpdateListe private PreambleEditor preambleEditor; // Keeps track of the preamble dialog if it is open. private StringDialog stringDialog; - private ContentAutoCompleters autoCompleters; + private SuggestionProviders suggestionProviders; /** the query the user searches when this basepanel is active */ private Optional currentSearchQuery = Optional.empty(); @@ -258,9 +259,11 @@ public static void runWorker(AbstractWorker worker) throws Exception { clb.update(); // Runs the update() method on the EDT. } - // Returns a collection of AutoCompleters, which are populated from the current library - public ContentAutoCompleters getAutoCompleters() { - return autoCompleters; + /** + * Returns a collection of suggestion providers, which are populated from the current library. + */ + public SuggestionProviders getSuggestionProviders() { + return suggestionProviders; } public String getTabTitle() { @@ -1364,17 +1367,7 @@ public void setupMainPanel() { instantiateSearchAutoCompleter(); this.getDatabase().registerListener(new SearchAutoCompleteListener()); - AutoCompletePreferences autoCompletePreferences = new AutoCompletePreferences(Globals.prefs); - // Set up AutoCompleters for this panel: - if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_COMPLETE)) { - autoCompleters = new ContentAutoCompleters(getDatabase(), bibDatabaseContext.getMetaData(), - autoCompletePreferences, Globals.journalAbbreviationLoader); - // ensure that the autocompleters are in sync with entries - this.getDatabase().registerListener(new AutoCompleteListener()); - } else { - // create empty ContentAutoCompleters() if autoCompletion is deactivated - autoCompleters = new ContentAutoCompleters(); - } + setupAutoCompletion(); // restore floating search result // (needed if preferences have been changed which causes a recreation of the main table) @@ -1390,6 +1383,22 @@ public void setupMainPanel() { splitPane.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, event -> saveDividerLocation()); } + /** + * Set up auto completion for this database + */ + private void setupAutoCompletion() { + AutoCompletePreferences autoCompletePreferences = new AutoCompletePreferences(Globals.prefs); + if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_COMPLETE)) { + suggestionProviders = new SuggestionProviders(autoCompletePreferences, Globals.journalAbbreviationLoader); + suggestionProviders.indexDatabase(getDatabase()); + // Ensure that the suggestion providers are in sync with entries + this.getDatabase().registerListener(new AutoCompleteListener(suggestionProviders)); + } else { + // Create empty suggestion providers if auto completion is deactivated + suggestionProviders = new SuggestionProviders(); + } + } + public void updateSearchManager() { frame.getGlobalSearchBar().setAutoCompleter(searchAutoCompleter); } @@ -2116,23 +2125,6 @@ public void listen(EntryChangedEvent entryChangedEvent) { } } - /** - * Ensures that auto completers are up to date when entries are changed AKA Let the auto completer, if any, harvest - * words from the entry - */ - private class AutoCompleteListener { - - @Subscribe - public void listen(EntryAddedEvent addedEntryEvent) { - BasePanel.this.autoCompleters.addEntry(addedEntryEvent.getBibEntry()); - } - - @Subscribe - public void listen(EntryChangedEvent entryChangedEvent) { - BasePanel.this.autoCompleters.addEntry(entryChangedEvent.getBibEntry()); - } - } - /** * Ensures that the results of the current search are updated when a new entry is inserted into the database */ diff --git a/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialog.java b/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialog.java index 80cc81deef9..160fa128ba5 100644 --- a/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialog.java +++ b/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialog.java @@ -73,10 +73,10 @@ public class ContentSelectorDialog extends JabRefDialog { private final JTextField wordEditField = new JTextField("", 20); private final JScrollPane fPane = new JScrollPane(fieldList); private final Map> wordListModels = new HashMap<>(); - private DefaultListModel wordListModel = new DefaultListModel<>(); - private final JList wordList = new JList<>(wordListModel); private final JScrollPane wPane = new JScrollPane(wordList); private final List removedFields = new ArrayList<>(); + private DefaultListModel wordListModel = new DefaultListModel<>(); + private final JList wordList = new JList<>(wordListModel); private String currentField; @@ -320,9 +320,6 @@ private void applyChanges() { // Mark the database updated so changes are not lost panel.markNonUndoableBaseChanged(); } - - panel.getAutoCompleters().addContentSelectorValuesToAutoCompleters(panel.getBibDatabaseContext().getMetaData()); - } /** diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index 85699fd20e8..a4ed8839214 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -688,7 +688,7 @@ public void actionPerformed(ActionEvent event) { //TODO: See if we need to update an AutoCompleter instance: /* - AutoCompleter aComp = panel.getAutoCompleters().get(fieldEditor.getFieldName()); + AutoCompleter aComp = panel.getSuggestionProviders().get(fieldEditor.getFieldName()); if (aComp != null) { aComp.addBibtexEntry(entry); } diff --git a/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java b/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java index e4d62da39ea..ebcb8ee8944 100644 --- a/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java @@ -112,7 +112,7 @@ private Region setupPanel(JabRefFrame frame, BasePanel bPanel, boolean compresse // Add autocompleter listener, if required for this field: /* - AutoCompleter autoCompleter = bPanel.getAutoCompleters().get(field); + AutoCompleter autoCompleter = bPanel.getSuggestionProviders().get(field); AutoCompleteListener autoCompleteListener = null; if (autoCompleter != null) { autoCompleteListener = new AutoCompleteListener(autoCompleter); @@ -124,7 +124,7 @@ private Region setupPanel(JabRefFrame frame, BasePanel bPanel, boolean compresse FieldEditorFX fieldEditor = FieldEditors.getForField(fieldName, Globals.taskExecutor, new FXDialogService(), Globals.journalAbbreviationLoader, Globals.prefs.getJournalAbbreviationPreferences(), Globals.prefs, bPanel.getBibDatabaseContext(), entry.getType(), - bPanel.getAutoCompleters()); + bPanel.getSuggestionProviders()); fieldEditor.bindToEntry(entry); editors.put(fieldName, fieldEditor); diff --git a/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java index 0ffbace3503..1aa4aa66e1d 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java @@ -8,7 +8,6 @@ import org.jabref.gui.AbstractViewModel; import org.jabref.gui.util.BindingsHelper; import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; -import org.jabref.logic.autocompleter.ContentAutoCompleters; import org.jabref.model.entry.BibEntry; import org.controlsfx.control.textfield.AutoCompletionBinding; @@ -17,11 +16,11 @@ public class AbstractEditorViewModel extends AbstractViewModel { protected final String fieldName; protected StringProperty text = new SimpleStringProperty(""); protected BibEntry entry; - private final ContentAutoCompleters autoCompleter; + private final AutoCompleteSuggestionProvider suggestionProvider; - public AbstractEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter) { + public AbstractEditorViewModel(String fieldName, AutoCompleteSuggestionProvider suggestionProvider) { this.fieldName = fieldName; - this.autoCompleter = autoCompleter; + this.suggestionProvider = suggestionProvider; } public StringProperty textProperty() { @@ -41,7 +40,6 @@ public void bindToEntry(BibEntry entry) { } public Collection complete(AutoCompletionBinding.ISuggestionRequest request) { - AutoCompleteSuggestionProvider suggestionProvider = autoCompleter.get(fieldName); return suggestionProvider.call(request); } } diff --git a/src/main/java/org/jabref/gui/fieldeditors/DateEditor.java b/src/main/java/org/jabref/gui/fieldeditors/DateEditor.java index 63a0c53d243..e2ce259b3ad 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/DateEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/DateEditor.java @@ -8,7 +8,7 @@ import org.jabref.gui.util.ControlHelper; import org.jabref.gui.util.component.TemporalAccessorPicker; -import org.jabref.logic.autocompleter.ContentAutoCompleters; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.model.entry.BibEntry; public class DateEditor extends HBox implements FieldEditorFX { @@ -16,8 +16,8 @@ public class DateEditor extends HBox implements FieldEditorFX { @FXML private DateEditorViewModel viewModel; @FXML private TemporalAccessorPicker datePicker; - public DateEditor(String fieldName, DateTimeFormatter dateFormatter, ContentAutoCompleters autoCompleter) { - this.viewModel = new DateEditorViewModel(fieldName, autoCompleter, dateFormatter); + public DateEditor(String fieldName, DateTimeFormatter dateFormatter, AutoCompleteSuggestionProvider suggestionProvider) { + this.viewModel = new DateEditorViewModel(fieldName, suggestionProvider, dateFormatter); ControlHelper.loadFXMLForControl(this); diff --git a/src/main/java/org/jabref/gui/fieldeditors/DateEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/DateEditorViewModel.java index ab32976b9c3..fec3f7a0687 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/DateEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/DateEditorViewModel.java @@ -6,15 +6,15 @@ import javafx.util.StringConverter; -import org.jabref.logic.autocompleter.ContentAutoCompleters; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.model.entry.Date; import org.jabref.model.strings.StringUtil; public class DateEditorViewModel extends AbstractEditorViewModel { private final DateTimeFormatter dateFormatter; - public DateEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter, DateTimeFormatter dateFormatter) { - super(fieldName, autoCompleter); + public DateEditorViewModel(String fieldName, AutoCompleteSuggestionProvider suggestionProvider, DateTimeFormatter dateFormatter) { + super(fieldName, suggestionProvider); this.dateFormatter = dateFormatter; } diff --git a/src/main/java/org/jabref/gui/fieldeditors/EditorTypeEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/EditorTypeEditorViewModel.java index 559f03d95f2..00413673d5c 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/EditorTypeEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/EditorTypeEditorViewModel.java @@ -1,6 +1,6 @@ package org.jabref.gui.fieldeditors; -import org.jabref.logic.autocompleter.ContentAutoCompleters; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.logic.l10n.Localization; import com.google.common.collect.BiMap; @@ -10,8 +10,8 @@ public class EditorTypeEditorViewModel extends MapBasedEditorViewModel { private BiMap itemMap = HashBiMap.create(7); - public EditorTypeEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter) { - super(fieldName, autoCompleter); + public EditorTypeEditorViewModel(String fieldName, AutoCompleteSuggestionProvider suggestionProvider) { + super(fieldName, suggestionProvider); itemMap.put("editor", Localization.lang("Editor")); itemMap.put("compiler", Localization.lang("Compiler")); diff --git a/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java b/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java index 14c4727b957..8b323d56380 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java +++ b/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java @@ -6,7 +6,8 @@ import org.jabref.Globals; import org.jabref.gui.DialogService; import org.jabref.gui.util.TaskExecutor; -import org.jabref.logic.autocompleter.ContentAutoCompleters; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; +import org.jabref.logic.autocompleter.SuggestionProviders; import org.jabref.logic.journals.JournalAbbreviationLoader; import org.jabref.logic.journals.JournalAbbreviationPreferences; import org.jabref.model.database.BibDatabaseContext; @@ -16,46 +17,48 @@ public class FieldEditors { - public static FieldEditorFX getForField(String fieldName, TaskExecutor taskExecutor, DialogService dialogService, JournalAbbreviationLoader journalAbbreviationLoader, JournalAbbreviationPreferences journalAbbreviationPreferences, JabRefPreferences preferences, BibDatabaseContext databaseContext, String entryType, ContentAutoCompleters autoCompleter) { + public static FieldEditorFX getForField(String fieldName, TaskExecutor taskExecutor, DialogService dialogService, JournalAbbreviationLoader journalAbbreviationLoader, JournalAbbreviationPreferences journalAbbreviationPreferences, JabRefPreferences preferences, BibDatabaseContext databaseContext, String entryType, SuggestionProviders suggestionProviders) { final Set fieldExtras = InternalBibtexFields.getFieldProperties(fieldName); + AutoCompleteSuggestionProvider suggestionProvider = suggestionProviders.getForField(fieldName); + if (Globals.prefs.get(JabRefPreferences.TIME_STAMP_FIELD).equals(fieldName) || fieldExtras.contains(FieldProperty.DATE)) { if (fieldExtras.contains(FieldProperty.ISO_DATE)) { - return new DateEditor(fieldName, DateTimeFormatter.ofPattern("[uuuu][-MM][-dd]"), autoCompleter); + return new DateEditor(fieldName, DateTimeFormatter.ofPattern("[uuuu][-MM][-dd]"), suggestionProvider); } else { - return new DateEditor(fieldName, DateTimeFormatter.ofPattern(Globals.prefs.get(JabRefPreferences.TIME_STAMP_FORMAT)), autoCompleter); + return new DateEditor(fieldName, DateTimeFormatter.ofPattern(Globals.prefs.get(JabRefPreferences.TIME_STAMP_FORMAT)), suggestionProvider); } } else if (fieldExtras.contains(FieldProperty.EXTERNAL)) { - return new UrlEditor(fieldName, dialogService, autoCompleter); + return new UrlEditor(fieldName, dialogService, suggestionProvider); } else if (fieldExtras.contains(FieldProperty.JOURNAL_NAME)) { - return new JournalEditor(fieldName, journalAbbreviationLoader, journalAbbreviationPreferences, autoCompleter); + return new JournalEditor(fieldName, journalAbbreviationLoader, journalAbbreviationPreferences, suggestionProvider); } else if (fieldExtras.contains(FieldProperty.DOI) || fieldExtras.contains(FieldProperty.EPRINT) || fieldExtras.contains(FieldProperty.ISBN)) { - return new IdentifierEditor(fieldName, taskExecutor, dialogService, autoCompleter); + return new IdentifierEditor(fieldName, taskExecutor, dialogService, suggestionProvider); } else if (fieldExtras.contains(FieldProperty.OWNER)) { - return new OwnerEditor(fieldName, preferences, autoCompleter); + return new OwnerEditor(fieldName, preferences, suggestionProvider); } else if (fieldExtras.contains(FieldProperty.FILE_EDITOR)) { - return new LinkedFilesEditor(fieldName, dialogService, databaseContext, taskExecutor, autoCompleter); + return new LinkedFilesEditor(fieldName, dialogService, databaseContext, taskExecutor, suggestionProvider); } else if (fieldExtras.contains(FieldProperty.YES_NO)) { - return new OptionEditor<>(fieldName, new YesNoEditorViewModel(fieldName, autoCompleter)); + return new OptionEditor<>(fieldName, new YesNoEditorViewModel(fieldName, suggestionProvider)); } else if (fieldExtras.contains(FieldProperty.MONTH)) { - return new OptionEditor<>(fieldName, new MonthEditorViewModel(fieldName, autoCompleter, databaseContext.getMode())); + return new OptionEditor<>(fieldName, new MonthEditorViewModel(fieldName, suggestionProvider, databaseContext.getMode())); } else if (fieldExtras.contains(FieldProperty.GENDER)) { - return new OptionEditor<>(fieldName, new GenderEditorViewModel(fieldName, autoCompleter)); + return new OptionEditor<>(fieldName, new GenderEditorViewModel(fieldName, suggestionProvider)); } else if (fieldExtras.contains(FieldProperty.EDITOR_TYPE)) { - return new OptionEditor<>(fieldName, new EditorTypeEditorViewModel(fieldName, autoCompleter)); + return new OptionEditor<>(fieldName, new EditorTypeEditorViewModel(fieldName, suggestionProvider)); } else if (fieldExtras.contains(FieldProperty.PAGINATION)) { - return new OptionEditor<>(fieldName, new PaginationEditorViewModel(fieldName, autoCompleter)); + return new OptionEditor<>(fieldName, new PaginationEditorViewModel(fieldName, suggestionProvider)); } else if (fieldExtras.contains(FieldProperty.TYPE)) { if ("patent".equalsIgnoreCase(entryType)) { - return new OptionEditor<>(fieldName, new PatentTypeEditorViewModel(fieldName, autoCompleter)); + return new OptionEditor<>(fieldName, new PatentTypeEditorViewModel(fieldName, suggestionProvider)); } else { - return new OptionEditor<>(fieldName, new TypeEditorViewModel(fieldName, autoCompleter)); + return new OptionEditor<>(fieldName, new TypeEditorViewModel(fieldName, suggestionProvider)); } } else if (fieldExtras.contains(FieldProperty.SINGLE_ENTRY_LINK) || fieldExtras.contains(FieldProperty.MULTIPLE_ENTRY_LINK)) { - return new LinkedEntriesEditor(fieldName, databaseContext, autoCompleter); + return new LinkedEntriesEditor(fieldName, databaseContext, suggestionProvider); } // default - return new SimpleEditor(fieldName, autoCompleter); + return new SimpleEditor(fieldName, suggestionProvider); } } diff --git a/src/main/java/org/jabref/gui/fieldeditors/GenderEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/GenderEditorViewModel.java index 9eae4272585..af368bed751 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/GenderEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/GenderEditorViewModel.java @@ -1,6 +1,6 @@ package org.jabref.gui.fieldeditors; -import org.jabref.logic.autocompleter.ContentAutoCompleters; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.logic.l10n.Localization; import com.google.common.collect.BiMap; @@ -10,8 +10,8 @@ public class GenderEditorViewModel extends MapBasedEditorViewModel { private BiMap itemMap = HashBiMap.create(7); - public GenderEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter) { - super(fieldName, autoCompleter); + public GenderEditorViewModel(String fieldName, AutoCompleteSuggestionProvider suggestionProvider) { + super(fieldName, suggestionProvider); itemMap.put("sf", Localization.lang("Female name")); itemMap.put("sm", Localization.lang("Male name")); diff --git a/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditor.java b/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditor.java index 9267704d6e9..12a2b14a4f8 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditor.java @@ -16,7 +16,7 @@ import org.jabref.gui.fieldeditors.contextmenu.EditorMenus; import org.jabref.gui.util.ControlHelper; import org.jabref.gui.util.TaskExecutor; -import org.jabref.logic.autocompleter.ContentAutoCompleters; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.FieldName; @@ -29,8 +29,8 @@ public class IdentifierEditor extends HBox implements FieldEditorFX { @FXML private Button lookupIdentifierButton; private Optional entry; - public IdentifierEditor(String fieldName, TaskExecutor taskExecutor, DialogService dialogService, ContentAutoCompleters autoCompleter) { - this.viewModel = new IdentifierEditorViewModel(fieldName, autoCompleter, taskExecutor, dialogService); + public IdentifierEditor(String fieldName, TaskExecutor taskExecutor, DialogService dialogService, AutoCompleteSuggestionProvider suggestionProvider) { + this.viewModel = new IdentifierEditorViewModel(fieldName, suggestionProvider, taskExecutor, dialogService); ControlHelper.loadFXMLForControl(this); diff --git a/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java index e60057a49d9..0f882c10b88 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java @@ -13,7 +13,7 @@ import org.jabref.gui.mergeentries.FetchAndMergeEntry; import org.jabref.gui.util.BackgroundTask; import org.jabref.gui.util.TaskExecutor; -import org.jabref.logic.autocompleter.ContentAutoCompleters; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.logic.importer.WebFetchers; import org.jabref.logic.importer.util.IdentifierParser; import org.jabref.logic.l10n.Localization; @@ -31,8 +31,8 @@ public class IdentifierEditorViewModel extends AbstractEditorViewModel { private TaskExecutor taskExecutor; private DialogService dialogService; - public IdentifierEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter, TaskExecutor taskExecutor, DialogService dialogService) { - super(fieldName, autoCompleter); + public IdentifierEditorViewModel(String fieldName, AutoCompleteSuggestionProvider suggestionProvider, TaskExecutor taskExecutor, DialogService dialogService) { + super(fieldName, suggestionProvider); this.taskExecutor = taskExecutor; this.dialogService = dialogService; diff --git a/src/main/java/org/jabref/gui/fieldeditors/JournalEditor.java b/src/main/java/org/jabref/gui/fieldeditors/JournalEditor.java index 4c517e153a9..153e01a3c4e 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/JournalEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/JournalEditor.java @@ -9,7 +9,7 @@ import org.jabref.gui.fieldeditors.contextmenu.EditorMenus; import org.jabref.gui.util.ControlHelper; -import org.jabref.logic.autocompleter.ContentAutoCompleters; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.logic.journals.JournalAbbreviationLoader; import org.jabref.logic.journals.JournalAbbreviationPreferences; import org.jabref.model.entry.BibEntry; @@ -20,8 +20,8 @@ public class JournalEditor extends HBox implements FieldEditorFX { @FXML private EditorTextArea textArea; private Optional entry; - public JournalEditor(String fieldName, JournalAbbreviationLoader journalAbbreviationLoader, JournalAbbreviationPreferences journalAbbreviationPreferences, ContentAutoCompleters autoCompleter) { - this.viewModel = new JournalEditorViewModel(fieldName, autoCompleter, journalAbbreviationLoader, journalAbbreviationPreferences); + public JournalEditor(String fieldName, JournalAbbreviationLoader journalAbbreviationLoader, JournalAbbreviationPreferences journalAbbreviationPreferences, AutoCompleteSuggestionProvider suggestionProvider) { + this.viewModel = new JournalEditorViewModel(fieldName, suggestionProvider, journalAbbreviationLoader, journalAbbreviationPreferences); ControlHelper.loadFXMLForControl(this); diff --git a/src/main/java/org/jabref/gui/fieldeditors/JournalEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/JournalEditorViewModel.java index 759f9901fb8..e0c20118716 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/JournalEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/JournalEditorViewModel.java @@ -2,7 +2,7 @@ import java.util.Optional; -import org.jabref.logic.autocompleter.ContentAutoCompleters; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.logic.journals.JournalAbbreviationLoader; import org.jabref.logic.journals.JournalAbbreviationPreferences; import org.jabref.logic.journals.JournalAbbreviationRepository; @@ -12,8 +12,8 @@ public class JournalEditorViewModel extends AbstractEditorViewModel { private final JournalAbbreviationLoader journalAbbreviationLoader; private final JournalAbbreviationPreferences journalAbbreviationPreferences; - public JournalEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter, JournalAbbreviationLoader journalAbbreviationLoader, JournalAbbreviationPreferences journalAbbreviationPreferences) { - super(fieldName, autoCompleter); + public JournalEditorViewModel(String fieldName, AutoCompleteSuggestionProvider suggestionProvider, JournalAbbreviationLoader journalAbbreviationLoader, JournalAbbreviationPreferences journalAbbreviationPreferences) { + super(fieldName, suggestionProvider); this.journalAbbreviationLoader = journalAbbreviationLoader; this.journalAbbreviationPreferences = journalAbbreviationPreferences; diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditor.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditor.java index 7b665ac2d5b..8356e08971b 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditor.java @@ -7,7 +7,7 @@ import org.jabref.gui.util.ControlHelper; import org.jabref.gui.util.component.TagBar; -import org.jabref.logic.autocompleter.ContentAutoCompleters; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.ParsedEntryLink; @@ -17,8 +17,8 @@ public class LinkedEntriesEditor extends HBox implements FieldEditorFX { @FXML private LinkedEntriesEditorViewModel viewModel; @FXML private TagBar linkedEntriesBar; - public LinkedEntriesEditor(String fieldName, BibDatabaseContext databaseContext, ContentAutoCompleters autoCompleter) { - this.viewModel = new LinkedEntriesEditorViewModel(fieldName, autoCompleter, databaseContext); + public LinkedEntriesEditor(String fieldName, BibDatabaseContext databaseContext, AutoCompleteSuggestionProvider suggestionProvider) { + this.viewModel = new LinkedEntriesEditorViewModel(fieldName, suggestionProvider, databaseContext); ControlHelper.loadFXMLForControl(this); diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditorViewModel.java index 2f33a9ce7b4..60b9b14a0c9 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditorViewModel.java @@ -6,7 +6,7 @@ import javafx.util.StringConverter; import org.jabref.gui.util.BindingsHelper; -import org.jabref.logic.autocompleter.ContentAutoCompleters; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.EntryLinkList; import org.jabref.model.entry.ParsedEntryLink; @@ -16,8 +16,8 @@ public class LinkedEntriesEditorViewModel extends AbstractEditorViewModel { private final BibDatabaseContext databaseContext; private final ListProperty linkedEntries; - public LinkedEntriesEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter, BibDatabaseContext databaseContext) { - super(fieldName, autoCompleter); + public LinkedEntriesEditorViewModel(String fieldName, AutoCompleteSuggestionProvider suggestionProvider, BibDatabaseContext databaseContext) { + super(fieldName, suggestionProvider); this.databaseContext = databaseContext; linkedEntries = new SimpleListProperty<>(FXCollections.observableArrayList()); diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java index 0d76f0402bc..3f4b29e679f 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java @@ -26,7 +26,7 @@ import org.jabref.gui.util.ControlHelper; import org.jabref.gui.util.TaskExecutor; import org.jabref.gui.util.ViewModelListCellFactory; -import org.jabref.logic.autocompleter.ContentAutoCompleters; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; @@ -39,8 +39,8 @@ public class LinkedFilesEditor extends HBox implements FieldEditorFX { @FXML private LinkedFilesEditorViewModel viewModel; @FXML private ListView listView; - public LinkedFilesEditor(String fieldName, DialogService dialogService, BibDatabaseContext databaseContext, TaskExecutor taskExecutor, ContentAutoCompleters autoCompleter) { - this.viewModel = new LinkedFilesEditorViewModel(fieldName, autoCompleter, dialogService, databaseContext, taskExecutor); + public LinkedFilesEditor(String fieldName, DialogService dialogService, BibDatabaseContext databaseContext, TaskExecutor taskExecutor, AutoCompleteSuggestionProvider suggestionProvider) { + this.viewModel = new LinkedFilesEditorViewModel(fieldName, suggestionProvider, dialogService, databaseContext, taskExecutor); ControlHelper.loadFXMLForControl(this); diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java index b4f4a4bfcbb..d3908ccba48 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java @@ -28,7 +28,7 @@ import org.jabref.gui.util.BindingsHelper; import org.jabref.gui.util.FileDialogConfiguration; import org.jabref.gui.util.TaskExecutor; -import org.jabref.logic.autocompleter.ContentAutoCompleters; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.logic.importer.FulltextFetchers; import org.jabref.logic.l10n.Localization; import org.jabref.logic.net.URLDownload; @@ -56,8 +56,8 @@ public class LinkedFilesEditorViewModel extends AbstractEditorViewModel { private BibDatabaseContext databaseContext; private TaskExecutor taskExecutor; - public LinkedFilesEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter, DialogService dialogService, BibDatabaseContext databaseContext, TaskExecutor taskExecutor) { - super(fieldName, autoCompleter); + public LinkedFilesEditorViewModel(String fieldName, AutoCompleteSuggestionProvider suggestionProvider, DialogService dialogService, BibDatabaseContext databaseContext, TaskExecutor taskExecutor) { + super(fieldName, suggestionProvider); this.dialogService = dialogService; this.databaseContext = databaseContext; diff --git a/src/main/java/org/jabref/gui/fieldeditors/MapBasedEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/MapBasedEditorViewModel.java index b18eb1474db..e76087268d1 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/MapBasedEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/MapBasedEditorViewModel.java @@ -5,7 +5,7 @@ import javafx.util.StringConverter; -import org.jabref.logic.autocompleter.ContentAutoCompleters; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import com.google.common.collect.BiMap; @@ -14,8 +14,8 @@ */ public abstract class MapBasedEditorViewModel extends OptionEditorViewModel { - public MapBasedEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter) { - super(fieldName, autoCompleter); + public MapBasedEditorViewModel(String fieldName, AutoCompleteSuggestionProvider suggestionProvider) { + super(fieldName, suggestionProvider); } protected abstract BiMap getItemMap(); diff --git a/src/main/java/org/jabref/gui/fieldeditors/MonthEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/MonthEditorViewModel.java index 23c5b807ba4..edf37221cbb 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/MonthEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/MonthEditorViewModel.java @@ -5,7 +5,7 @@ import javafx.util.StringConverter; -import org.jabref.logic.autocompleter.ContentAutoCompleters; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.Month; import org.jabref.model.strings.StringUtil; @@ -13,8 +13,8 @@ public class MonthEditorViewModel extends OptionEditorViewModel { private BibDatabaseMode databaseMode; - public MonthEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter, BibDatabaseMode databaseMode) { - super(fieldName, autoCompleter); + public MonthEditorViewModel(String fieldName, AutoCompleteSuggestionProvider suggestionProvider, BibDatabaseMode databaseMode) { + super(fieldName, suggestionProvider); this.databaseMode = databaseMode; } diff --git a/src/main/java/org/jabref/gui/fieldeditors/OptionEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/OptionEditorViewModel.java index 7aed491b68b..f4d7ffe50fc 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/OptionEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/OptionEditorViewModel.java @@ -4,12 +4,12 @@ import javafx.util.StringConverter; -import org.jabref.logic.autocompleter.ContentAutoCompleters; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; public abstract class OptionEditorViewModel extends AbstractEditorViewModel { - public OptionEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter) { - super(fieldName, autoCompleter); + public OptionEditorViewModel(String fieldName, AutoCompleteSuggestionProvider suggestionProvider) { + super(fieldName, suggestionProvider); } public abstract StringConverter getStringConverter(); diff --git a/src/main/java/org/jabref/gui/fieldeditors/OwnerEditor.java b/src/main/java/org/jabref/gui/fieldeditors/OwnerEditor.java index 2083b630a95..d4e8fd31aeb 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/OwnerEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/OwnerEditor.java @@ -6,7 +6,7 @@ import javafx.scene.layout.HBox; import org.jabref.gui.util.ControlHelper; -import org.jabref.logic.autocompleter.ContentAutoCompleters; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.model.entry.BibEntry; import org.jabref.preferences.JabRefPreferences; @@ -15,8 +15,8 @@ public class OwnerEditor extends HBox implements FieldEditorFX { @FXML private OwnerEditorViewModel viewModel; @FXML private EditorTextArea textArea; - public OwnerEditor(String fieldName, JabRefPreferences preferences, ContentAutoCompleters autoCompleter) { - this.viewModel = new OwnerEditorViewModel(fieldName, autoCompleter, preferences); + public OwnerEditor(String fieldName, JabRefPreferences preferences, AutoCompleteSuggestionProvider suggestionProvider) { + this.viewModel = new OwnerEditorViewModel(fieldName, suggestionProvider, preferences); ControlHelper.loadFXMLForControl(this); diff --git a/src/main/java/org/jabref/gui/fieldeditors/OwnerEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/OwnerEditorViewModel.java index 8cd4856597d..dded357ae6b 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/OwnerEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/OwnerEditorViewModel.java @@ -1,13 +1,13 @@ package org.jabref.gui.fieldeditors; -import org.jabref.logic.autocompleter.ContentAutoCompleters; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.preferences.JabRefPreferences; public class OwnerEditorViewModel extends AbstractEditorViewModel { private final JabRefPreferences preferences; - public OwnerEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter, JabRefPreferences preferences) { - super(fieldName, autoCompleter); + public OwnerEditorViewModel(String fieldName, AutoCompleteSuggestionProvider suggestionProvider, JabRefPreferences preferences) { + super(fieldName, suggestionProvider); this.preferences = preferences; } diff --git a/src/main/java/org/jabref/gui/fieldeditors/PaginationEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/PaginationEditorViewModel.java index b92e3b83ba2..9bc3db6ec56 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/PaginationEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/PaginationEditorViewModel.java @@ -1,6 +1,6 @@ package org.jabref.gui.fieldeditors; -import org.jabref.logic.autocompleter.ContentAutoCompleters; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.logic.l10n.Localization; import com.google.common.collect.BiMap; @@ -10,8 +10,8 @@ public class PaginationEditorViewModel extends MapBasedEditorViewModel { private BiMap itemMap = HashBiMap.create(7); - public PaginationEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter) { - super(fieldName, autoCompleter); + public PaginationEditorViewModel(String fieldName, AutoCompleteSuggestionProvider suggestionProvider) { + super(fieldName, suggestionProvider); itemMap.put("page", Localization.lang("Page")); itemMap.put("column", Localization.lang("Column")); diff --git a/src/main/java/org/jabref/gui/fieldeditors/PatentTypeEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/PatentTypeEditorViewModel.java index 2894dbcb7ea..e9361e77f80 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/PatentTypeEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/PatentTypeEditorViewModel.java @@ -1,6 +1,6 @@ package org.jabref.gui.fieldeditors; -import org.jabref.logic.autocompleter.ContentAutoCompleters; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.logic.l10n.Localization; import com.google.common.collect.BiMap; @@ -10,8 +10,8 @@ public class PatentTypeEditorViewModel extends MapBasedEditorViewModel { private BiMap itemMap = HashBiMap.create(12); - public PatentTypeEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter) { - super(fieldName, autoCompleter); + public PatentTypeEditorViewModel(String fieldName, AutoCompleteSuggestionProvider suggestionProvider) { + super(fieldName, suggestionProvider); itemMap.put("patent", Localization.lang("Patent")); itemMap.put("patentde", Localization.lang("German patent")); diff --git a/src/main/java/org/jabref/gui/fieldeditors/SimpleEditor.java b/src/main/java/org/jabref/gui/fieldeditors/SimpleEditor.java index c74688cc8fa..fb8da76345f 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/SimpleEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/SimpleEditor.java @@ -7,15 +7,15 @@ import org.jabref.gui.fieldeditors.contextmenu.EditorMenus; import org.jabref.gui.util.AutoCompletionTextInputBinding; -import org.jabref.logic.autocompleter.ContentAutoCompleters; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.model.entry.BibEntry; public class SimpleEditor extends HBox implements FieldEditorFX { @FXML private final SimpleEditorViewModel viewModel; - public SimpleEditor(String fieldName, ContentAutoCompleters autoCompleters) { - this.viewModel = new SimpleEditorViewModel(fieldName, autoCompleters); + public SimpleEditor(String fieldName, AutoCompleteSuggestionProvider suggestionProvider) { + this.viewModel = new SimpleEditorViewModel(fieldName, suggestionProvider); EditorTextArea textArea = new EditorTextArea(); HBox.setHgrow(textArea, Priority.ALWAYS); diff --git a/src/main/java/org/jabref/gui/fieldeditors/SimpleEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/SimpleEditorViewModel.java index b043ec61f04..2606072f330 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/SimpleEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/SimpleEditorViewModel.java @@ -1,10 +1,10 @@ package org.jabref.gui.fieldeditors; -import org.jabref.logic.autocompleter.ContentAutoCompleters; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; public class SimpleEditorViewModel extends AbstractEditorViewModel { - public SimpleEditorViewModel(String fieldName, ContentAutoCompleters autoCompleters) { - super(fieldName, autoCompleters); + public SimpleEditorViewModel(String fieldName, AutoCompleteSuggestionProvider suggestionProvider) { + super(fieldName, suggestionProvider); } } diff --git a/src/main/java/org/jabref/gui/fieldeditors/TypeEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/TypeEditorViewModel.java index a3b54194083..72c50125ec9 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/TypeEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/TypeEditorViewModel.java @@ -1,6 +1,6 @@ package org.jabref.gui.fieldeditors; -import org.jabref.logic.autocompleter.ContentAutoCompleters; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.logic.l10n.Localization; import com.google.common.collect.BiMap; @@ -10,8 +10,8 @@ public class TypeEditorViewModel extends MapBasedEditorViewModel { private BiMap itemMap = HashBiMap.create(8); - public TypeEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter) { - super(fieldName, autoCompleter); + public TypeEditorViewModel(String fieldName, AutoCompleteSuggestionProvider suggestionProvider) { + super(fieldName, suggestionProvider); itemMap.put("mathesis", Localization.lang("Master's thesis")); itemMap.put("phdthesis", Localization.lang("PhD thesis")); diff --git a/src/main/java/org/jabref/gui/fieldeditors/UrlEditor.java b/src/main/java/org/jabref/gui/fieldeditors/UrlEditor.java index adc4b12327b..6d2cb45884f 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/UrlEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/UrlEditor.java @@ -7,7 +7,7 @@ import org.jabref.gui.DialogService; import org.jabref.gui.util.ControlHelper; -import org.jabref.logic.autocompleter.ContentAutoCompleters; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.model.entry.BibEntry; public class UrlEditor extends HBox implements FieldEditorFX { @@ -15,8 +15,8 @@ public class UrlEditor extends HBox implements FieldEditorFX { @FXML private UrlEditorViewModel viewModel; @FXML private EditorTextArea textArea; - public UrlEditor(String fieldName, DialogService dialogService, ContentAutoCompleters autoCompleter) { - this.viewModel = new UrlEditorViewModel(fieldName, autoCompleter, dialogService); + public UrlEditor(String fieldName, DialogService dialogService, AutoCompleteSuggestionProvider suggestionProvider) { + this.viewModel = new UrlEditorViewModel(fieldName, suggestionProvider, dialogService); ControlHelper.loadFXMLForControl(this); diff --git a/src/main/java/org/jabref/gui/fieldeditors/UrlEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/UrlEditorViewModel.java index 24aa1aef0ca..ece78c88560 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/UrlEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/UrlEditorViewModel.java @@ -7,7 +7,7 @@ import org.jabref.gui.DialogService; import org.jabref.gui.desktop.JabRefDesktop; -import org.jabref.logic.autocompleter.ContentAutoCompleters; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.logic.l10n.Localization; import org.jabref.logic.net.URLUtil; import org.jabref.model.strings.StringUtil; @@ -18,8 +18,8 @@ public class UrlEditorViewModel extends AbstractEditorViewModel { private DialogService dialogService; private BooleanProperty validUrlIsNotPresent = new SimpleBooleanProperty(true); - public UrlEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter, DialogService dialogService) { - super(fieldName, autoCompleter); + public UrlEditorViewModel(String fieldName, AutoCompleteSuggestionProvider suggestionProvider, DialogService dialogService) { + super(fieldName, suggestionProvider); this.dialogService = dialogService; validUrlIsNotPresent.bind( diff --git a/src/main/java/org/jabref/gui/fieldeditors/YesNoEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/YesNoEditorViewModel.java index 72f2759229f..c77959ee0dd 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/YesNoEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/YesNoEditorViewModel.java @@ -1,6 +1,6 @@ package org.jabref.gui.fieldeditors; -import org.jabref.logic.autocompleter.ContentAutoCompleters; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; @@ -9,8 +9,8 @@ public class YesNoEditorViewModel extends MapBasedEditorViewModel { private BiMap itemMap = HashBiMap.create(2); - public YesNoEditorViewModel(String fieldName, ContentAutoCompleters autoCompleter) { - super(fieldName, autoCompleter); + public YesNoEditorViewModel(String fieldName, AutoCompleteSuggestionProvider suggestionProvider) { + super(fieldName, suggestionProvider); itemMap.put("yes", "Yes"); itemMap.put("no", "No"); diff --git a/src/main/java/org/jabref/logic/autocompleter/AutoCompleteListener.java b/src/main/java/org/jabref/logic/autocompleter/AutoCompleteListener.java new file mode 100644 index 00000000000..728e4545cc7 --- /dev/null +++ b/src/main/java/org/jabref/logic/autocompleter/AutoCompleteListener.java @@ -0,0 +1,28 @@ +package org.jabref.logic.autocompleter; + +import org.jabref.model.database.event.EntryAddedEvent; +import org.jabref.model.entry.event.EntryChangedEvent; + +import com.google.common.eventbus.Subscribe; + +/** + * Ensures that suggestion providers are up to date when entries are changed or added. + */ +public class AutoCompleteListener { + + private final SuggestionProviders suggestionProviders; + + public AutoCompleteListener(SuggestionProviders suggestionProviders) { + this.suggestionProviders = suggestionProviders; + } + + @Subscribe + public void listen(EntryAddedEvent addedEntryEvent) { + suggestionProviders.indexEntry(addedEntryEvent.getBibEntry()); + } + + @Subscribe + public void listen(EntryChangedEvent entryChangedEvent) { + suggestionProviders.indexEntry(entryChangedEvent.getBibEntry()); + } +} diff --git a/src/main/java/org/jabref/logic/autocompleter/AutoCompleteSuggestionProvider.java b/src/main/java/org/jabref/logic/autocompleter/AutoCompleteSuggestionProvider.java index 05ea92926c3..ea2e557a65e 100644 --- a/src/main/java/org/jabref/logic/autocompleter/AutoCompleteSuggestionProvider.java +++ b/src/main/java/org/jabref/logic/autocompleter/AutoCompleteSuggestionProvider.java @@ -9,5 +9,5 @@ import org.controlsfx.control.textfield.AutoCompletionBinding; public interface AutoCompleteSuggestionProvider extends Callback> { - void indexBibtexEntry(BibEntry entry); + void indexEntry(BibEntry entry); } diff --git a/src/main/java/org/jabref/logic/autocompleter/AutoCompleters.java b/src/main/java/org/jabref/logic/autocompleter/AutoCompleters.java deleted file mode 100644 index da1799cdd35..00000000000 --- a/src/main/java/org/jabref/logic/autocompleter/AutoCompleters.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.jabref.logic.autocompleter; - -import java.util.HashMap; -import java.util.Map; - -import org.jabref.model.database.BibDatabase; -import org.jabref.model.entry.BibEntry; - -class AutoCompleters { - - protected final Map> autoCompleters = new HashMap<>(); - // Hashtable that holds as keys the names of the fields where - // autocomplete is active, and references to the autocompleter objects. - - public AutoCompleteSuggestionProvider get(String fieldName) { - return autoCompleters.get(fieldName); - } - - protected void addDatabase(BibDatabase database) { - for (BibEntry entry : database.getEntries()) { - addEntry(entry); - } - } - - /** - * This methods assures all words in the given entry are recorded in their - * respective Completers, if any. - */ - public void addEntry(BibEntry bibEntry) { - for (AutoCompleteSuggestionProvider autoCompleter : autoCompleters.values()) { - autoCompleter.indexBibtexEntry(bibEntry); - } - } - - protected void put(String field, AutoCompleteSuggestionProvider autoCompleter) { - autoCompleters.put(field, autoCompleter); - } - -} diff --git a/src/main/java/org/jabref/logic/autocompleter/BibEntrySuggestionProvider.java b/src/main/java/org/jabref/logic/autocompleter/BibEntrySuggestionProvider.java index 909e1e5b692..0817e9639bc 100644 --- a/src/main/java/org/jabref/logic/autocompleter/BibEntrySuggestionProvider.java +++ b/src/main/java/org/jabref/logic/autocompleter/BibEntrySuggestionProvider.java @@ -14,7 +14,7 @@ class BibEntrySuggestionProvider extends SuggestionProvider implements AutoCompleteSuggestionProvider { @Override - public void indexBibtexEntry(BibEntry entry) { + public void indexEntry(BibEntry entry) { if (entry == null) { return; } diff --git a/src/main/java/org/jabref/logic/autocompleter/ContentAutoCompleters.java b/src/main/java/org/jabref/logic/autocompleter/ContentAutoCompleters.java deleted file mode 100644 index 5bcd2cce20a..00000000000 --- a/src/main/java/org/jabref/logic/autocompleter/ContentAutoCompleters.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.jabref.logic.autocompleter; - -import java.util.List; -import java.util.Objects; - -import org.jabref.logic.journals.JournalAbbreviationLoader; -import org.jabref.model.database.BibDatabase; -import org.jabref.model.metadata.MetaData; - -public class ContentAutoCompleters extends AutoCompleters { - - public ContentAutoCompleters() { - } - - public ContentAutoCompleters(BibDatabase database, MetaData metaData, AutoCompletePreferences preferences, - JournalAbbreviationLoader abbreviationLoader) { - Objects.requireNonNull(preferences); - - AutoCompleterFactory autoCompleterFactory = new AutoCompleterFactory(preferences, abbreviationLoader); - List completeFields = preferences.getCompleteNames(); - for (String field : completeFields) { - AutoCompleteSuggestionProvider autoCompleter = autoCompleterFactory.getForField(field); - put(field, autoCompleter); - } - addContentSelectorValuesToAutoCompleters(metaData); - - addDatabase(database); - } - - /** - * For all fields with both autocompletion and content selector, add content selector - * values to the autocompleter list: - */ - public void addContentSelectorValuesToAutoCompleters(MetaData metaData) { - /* - for (Map.Entry> entry : this.autoCompleters.entrySet()) { - AutoCompleteSuggestionProvider ac = entry.getValue(); - metaData.getContentSelectorValuesForField(entry.getKey()).forEach(ac::addItemToIndex); - } - */ - } -} diff --git a/src/main/java/org/jabref/logic/autocompleter/ContentSelectorSuggestionProvider.java b/src/main/java/org/jabref/logic/autocompleter/ContentSelectorSuggestionProvider.java new file mode 100644 index 00000000000..2a7bbd83724 --- /dev/null +++ b/src/main/java/org/jabref/logic/autocompleter/ContentSelectorSuggestionProvider.java @@ -0,0 +1,33 @@ +package org.jabref.logic.autocompleter; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import javafx.util.Callback; + +import org.controlsfx.control.textfield.AutoCompletionBinding; + +/** + * Enriches a suggestion provider by a given set of content selector values. + */ +public class ContentSelectorSuggestionProvider implements Callback> { + + private final AutoCompleteSuggestionProvider suggestionProvider; + private final List contentSelectorValues; + + public ContentSelectorSuggestionProvider(AutoCompleteSuggestionProvider suggestionProvider, + List contentSelectorValues) { + + this.suggestionProvider = suggestionProvider; + this.contentSelectorValues = contentSelectorValues; + } + + @Override + public Collection call(AutoCompletionBinding.ISuggestionRequest request) { + List suggestions = new ArrayList<>(); + suggestions.addAll(suggestionProvider.call(request)); + suggestions.addAll(contentSelectorValues); + return suggestions; + } +} diff --git a/src/main/java/org/jabref/logic/autocompleter/FieldValueSuggestionProvider.java b/src/main/java/org/jabref/logic/autocompleter/FieldValueSuggestionProvider.java index 2ebc07b5356..f713a101c23 100644 --- a/src/main/java/org/jabref/logic/autocompleter/FieldValueSuggestionProvider.java +++ b/src/main/java/org/jabref/logic/autocompleter/FieldValueSuggestionProvider.java @@ -16,7 +16,7 @@ class FieldValueSuggestionProvider extends StringSuggestionProvider implements A } @Override - public void indexBibtexEntry(BibEntry entry) { + public void indexEntry(BibEntry entry) { if (entry == null) { return; } diff --git a/src/main/java/org/jabref/logic/autocompleter/SuggestionProviders.java b/src/main/java/org/jabref/logic/autocompleter/SuggestionProviders.java new file mode 100644 index 00000000000..86886f036fc --- /dev/null +++ b/src/main/java/org/jabref/logic/autocompleter/SuggestionProviders.java @@ -0,0 +1,56 @@ +package org.jabref.logic.autocompleter; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +import org.jabref.logic.journals.JournalAbbreviationLoader; +import org.jabref.model.database.BibDatabase; +import org.jabref.model.entry.BibEntry; + +public class SuggestionProviders { + + /** + * key: field name + */ + private final Map> providers = new HashMap<>(); + + /** + * Empty + */ + public SuggestionProviders() { + + } + + public SuggestionProviders(AutoCompletePreferences preferences, + JournalAbbreviationLoader abbreviationLoader) { + Objects.requireNonNull(preferences); + + AutoCompleterFactory autoCompleterFactory = new AutoCompleterFactory(preferences, abbreviationLoader); + List completeFields = preferences.getCompleteNames(); + for (String field : completeFields) { + AutoCompleteSuggestionProvider autoCompleter = autoCompleterFactory.getForField(field); + providers.put(field, autoCompleter); + } + } + + public AutoCompleteSuggestionProvider getForField(String fieldName) { + return providers.get(fieldName); + } + + public void indexDatabase(BibDatabase database) { + for (BibEntry entry : database.getEntries()) { + indexEntry(entry); + } + } + + /** + * This methods assures all information in the given entry is included as suggestions. + */ + public void indexEntry(BibEntry bibEntry) { + for (AutoCompleteSuggestionProvider autoCompleter : providers.values()) { + autoCompleter.indexEntry(bibEntry); + } + } +} diff --git a/src/main/java/org/jabref/logic/autocompleter/WordSuggestionProvider.java b/src/main/java/org/jabref/logic/autocompleter/WordSuggestionProvider.java index 9140b6dc7ff..5ff7cf21dec 100644 --- a/src/main/java/org/jabref/logic/autocompleter/WordSuggestionProvider.java +++ b/src/main/java/org/jabref/logic/autocompleter/WordSuggestionProvider.java @@ -19,7 +19,7 @@ class WordSuggestionProvider extends StringSuggestionProvider implements AutoCom } @Override - public void indexBibtexEntry(BibEntry entry) { + public void indexEntry(BibEntry entry) { if (entry == null) { return; } From b7d00fd52edb70641b689417d35a0feb6eb8564b Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Mon, 3 Jul 2017 18:14:37 +0200 Subject: [PATCH 03/10] Fix build --- .../IdentifierEditorViewModelTest.java | 4 +-- .../BibtexKeyAutoCompleterTest.java | 20 ++++++------- .../DefaultAutoCompleterTest.java | 26 ++++++++--------- .../FieldValueSuggestionProviderTest.java | 28 +++++++++---------- 4 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/test/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModelTest.java b/src/test/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModelTest.java index 460ddaad223..01b5dfb6869 100644 --- a/src/test/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModelTest.java +++ b/src/test/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModelTest.java @@ -2,7 +2,7 @@ import org.jabref.gui.DialogService; import org.jabref.gui.util.CurrentThreadTaskExecutor; -import org.jabref.logic.autocompleter.ContentAutoCompleters; +import org.jabref.logic.autocompleter.WordSuggestionProvider; import org.junit.Before; import org.junit.Test; @@ -16,7 +16,7 @@ public class IdentifierEditorViewModelTest { @Before public void setUp() throws Exception { - viewModel = new IdentifierEditorViewModel("DOI", new ContentAutoCompleters(), new CurrentThreadTaskExecutor(), mock(DialogService.class)); + viewModel = new IdentifierEditorViewModel("DOI", new WordSuggestionProvider("DOI"), new CurrentThreadTaskExecutor(), mock(DialogService.class)); } @Test diff --git a/src/test/java/org/jabref/logic/autocompleter/BibtexKeyAutoCompleterTest.java b/src/test/java/org/jabref/logic/autocompleter/BibtexKeyAutoCompleterTest.java index 9e327fe33a0..a2f9e3799fa 100644 --- a/src/test/java/org/jabref/logic/autocompleter/BibtexKeyAutoCompleterTest.java +++ b/src/test/java/org/jabref/logic/autocompleter/BibtexKeyAutoCompleterTest.java @@ -28,7 +28,7 @@ public void completeWithoutAddingAnythingReturnsNothing() { @Test public void completeAfterAddingNullReturnsNothing() { - autoCompleter.indexBibtexEntry(null); + autoCompleter.indexEntry(null); Collection result = autoCompleter.call(getRequest(("test"))); Assert.assertEquals(Collections.emptyList(), result); @@ -37,7 +37,7 @@ public void completeAfterAddingNullReturnsNothing() { @Test public void completeAfterAddingEmptyEntryReturnsNothing() { BibEntry entry = new BibEntry(); - autoCompleter.indexBibtexEntry(entry); + autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("test"))); Assert.assertEquals(Collections.emptyList(), result); @@ -47,7 +47,7 @@ public void completeAfterAddingEmptyEntryReturnsNothing() { public void completeKeyReturnsKey() { BibEntry entry = new BibEntry(); entry.setCiteKey("testKey"); - autoCompleter.indexBibtexEntry(entry); + autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("testKey"))); Assert.assertEquals(Arrays.asList("testKey"), result); @@ -57,7 +57,7 @@ public void completeKeyReturnsKey() { public void completeBeginnigOfKeyReturnsKey() { BibEntry entry = new BibEntry(); entry.setCiteKey("testKey"); - autoCompleter.indexBibtexEntry(entry); + autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("test"))); Assert.assertEquals(Arrays.asList("testKey"), result); @@ -67,7 +67,7 @@ public void completeBeginnigOfKeyReturnsKey() { public void completeLowercaseKeyReturnsKey() { BibEntry entry = new BibEntry(); entry.setCiteKey("testKey"); - autoCompleter.indexBibtexEntry(entry); + autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("testkey"))); Assert.assertEquals(Arrays.asList("testKey"), result); @@ -77,7 +77,7 @@ public void completeLowercaseKeyReturnsKey() { public void completeNullReturnsNothing() { BibEntry entry = new BibEntry(); entry.setCiteKey("testKey"); - autoCompleter.indexBibtexEntry(entry); + autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest((null))); Assert.assertEquals(Collections.emptyList(), result); @@ -87,7 +87,7 @@ public void completeNullReturnsNothing() { public void completeEmptyStringReturnsNothing() { BibEntry entry = new BibEntry(); entry.setCiteKey("testKey"); - autoCompleter.indexBibtexEntry(entry); + autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest((""))); Assert.assertEquals(Collections.emptyList(), result); @@ -97,10 +97,10 @@ public void completeEmptyStringReturnsNothing() { public void completeReturnsMultipleResults() { BibEntry entryOne = new BibEntry(); entryOne.setCiteKey("testKeyOne"); - autoCompleter.indexBibtexEntry(entryOne); + autoCompleter.indexEntry(entryOne); BibEntry entryTwo = new BibEntry(); entryTwo.setCiteKey("testKeyTwo"); - autoCompleter.indexBibtexEntry(entryTwo); + autoCompleter.indexEntry(entryTwo); Collection result = autoCompleter.call(getRequest(("testKey"))); Assert.assertEquals(Arrays.asList("testKeyOne", "testKeyTwo"), result); @@ -110,7 +110,7 @@ public void completeReturnsMultipleResults() { public void completeShortKeyReturnsKey() { BibEntry entry = new BibEntry(); entry.setCiteKey("key"); - autoCompleter.indexBibtexEntry(entry); + autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("k"))); Assert.assertEquals(Arrays.asList("key"), result); diff --git a/src/test/java/org/jabref/logic/autocompleter/DefaultAutoCompleterTest.java b/src/test/java/org/jabref/logic/autocompleter/DefaultAutoCompleterTest.java index 6538a79da42..f56de4c5cc4 100644 --- a/src/test/java/org/jabref/logic/autocompleter/DefaultAutoCompleterTest.java +++ b/src/test/java/org/jabref/logic/autocompleter/DefaultAutoCompleterTest.java @@ -35,7 +35,7 @@ public void completeWithoutAddingAnythingReturnsNothing() { @Test public void completeAfterAddingNullReturnsNothing() { - autoCompleter.indexBibtexEntry(null); + autoCompleter.indexEntry(null); Collection result = autoCompleter.call(getRequest(("test"))); Assert.assertEquals(Collections.emptyList(), result); @@ -44,7 +44,7 @@ public void completeAfterAddingNullReturnsNothing() { @Test public void completeAfterAddingEmptyEntryReturnsNothing() { BibEntry entry = new BibEntry(); - autoCompleter.indexBibtexEntry(entry); + autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("test"))); Assert.assertEquals(Collections.emptyList(), result); @@ -54,7 +54,7 @@ public void completeAfterAddingEmptyEntryReturnsNothing() { public void completeAfterAddingEntryWithoutFieldReturnsNothing() { BibEntry entry = new BibEntry(); entry.setField("title", "testTitle"); - autoCompleter.indexBibtexEntry(entry); + autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("test"))); Assert.assertEquals(Collections.emptyList(), result); @@ -64,7 +64,7 @@ public void completeAfterAddingEntryWithoutFieldReturnsNothing() { public void completeValueReturnsValue() { BibEntry entry = new BibEntry(); entry.setField("field", "testValue"); - autoCompleter.indexBibtexEntry(entry); + autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("testValue"))); Assert.assertEquals(Arrays.asList("testValue"), result); @@ -74,7 +74,7 @@ public void completeValueReturnsValue() { public void completeBeginnigOfValueReturnsValue() { BibEntry entry = new BibEntry(); entry.setField("field", "testValue"); - autoCompleter.indexBibtexEntry(entry); + autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("test"))); Assert.assertEquals(Arrays.asList("testValue"), result); @@ -84,7 +84,7 @@ public void completeBeginnigOfValueReturnsValue() { public void completeLowercaseValueReturnsValue() { BibEntry entry = new BibEntry(); entry.setField("field", "testValue"); - autoCompleter.indexBibtexEntry(entry); + autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("testvalue"))); Assert.assertEquals(Arrays.asList("testValue"), result); @@ -94,7 +94,7 @@ public void completeLowercaseValueReturnsValue() { public void completeNullThrowsException() { BibEntry entry = new BibEntry(); entry.setField("field", "testKey"); - autoCompleter.indexBibtexEntry(entry); + autoCompleter.indexEntry(entry); autoCompleter.call(getRequest((null))); } @@ -103,7 +103,7 @@ public void completeNullThrowsException() { public void completeEmptyStringReturnsNothing() { BibEntry entry = new BibEntry(); entry.setField("field", "testKey"); - autoCompleter.indexBibtexEntry(entry); + autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest((""))); Assert.assertEquals(Collections.emptyList(), result); @@ -113,10 +113,10 @@ public void completeEmptyStringReturnsNothing() { public void completeReturnsMultipleResults() { BibEntry entryOne = new BibEntry(); entryOne.setField("field", "testValueOne"); - autoCompleter.indexBibtexEntry(entryOne); + autoCompleter.indexEntry(entryOne); BibEntry entryTwo = new BibEntry(); entryTwo.setField("field", "testValueTwo"); - autoCompleter.indexBibtexEntry(entryTwo); + autoCompleter.indexEntry(entryTwo); Collection result = autoCompleter.call(getRequest(("testValue"))); Assert.assertEquals(Arrays.asList("testValueOne", "testValueTwo"), result); @@ -126,7 +126,7 @@ public void completeReturnsMultipleResults() { public void completeShortStringReturnsValue() { BibEntry entry = new BibEntry(); entry.setField("field", "val"); - autoCompleter.indexBibtexEntry(entry); + autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("va"))); Assert.assertEquals(Collections.singletonList("val"), result); @@ -136,7 +136,7 @@ public void completeShortStringReturnsValue() { public void completeBeginnigOfSecondWordReturnsWord() { BibEntry entry = new BibEntry(); entry.setField("field", "test value"); - autoCompleter.indexBibtexEntry(entry); + autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("val"))); Assert.assertEquals(Collections.singletonList("value"), result); @@ -146,7 +146,7 @@ public void completeBeginnigOfSecondWordReturnsWord() { public void completePartOfWordReturnsValue() { BibEntry entry = new BibEntry(); entry.setField("field", "test value"); - autoCompleter.indexBibtexEntry(entry); + autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("lue"))); Assert.assertEquals(Collections.singletonList("value"), result); diff --git a/src/test/java/org/jabref/logic/autocompleter/FieldValueSuggestionProviderTest.java b/src/test/java/org/jabref/logic/autocompleter/FieldValueSuggestionProviderTest.java index 7af7cab5ee1..e01bc5c54a2 100644 --- a/src/test/java/org/jabref/logic/autocompleter/FieldValueSuggestionProviderTest.java +++ b/src/test/java/org/jabref/logic/autocompleter/FieldValueSuggestionProviderTest.java @@ -34,7 +34,7 @@ public void completeWithoutAddingAnythingReturnsNothing() { @Test public void completeAfterAddingNullReturnsNothing() { - autoCompleter.indexBibtexEntry(null); + autoCompleter.indexEntry(null); Collection result = autoCompleter.call(getRequest(("test"))); Assert.assertEquals(Collections.emptyList(), result); @@ -43,7 +43,7 @@ public void completeAfterAddingNullReturnsNothing() { @Test public void completeAfterAddingEmptyEntryReturnsNothing() { BibEntry entry = new BibEntry(); - autoCompleter.indexBibtexEntry(entry); + autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("test"))); Assert.assertEquals(Collections.emptyList(), result); @@ -53,7 +53,7 @@ public void completeAfterAddingEmptyEntryReturnsNothing() { public void completeAfterAddingEntryWithoutFieldReturnsNothing() { BibEntry entry = new BibEntry(); entry.setField("title", "testTitle"); - autoCompleter.indexBibtexEntry(entry); + autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("test"))); Assert.assertEquals(Collections.emptyList(), result); @@ -63,7 +63,7 @@ public void completeAfterAddingEntryWithoutFieldReturnsNothing() { public void completeValueReturnsValue() { BibEntry entry = new BibEntry(); entry.setField("field", "testValue"); - autoCompleter.indexBibtexEntry(entry); + autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("testValue"))); Assert.assertEquals(Arrays.asList("testValue"), result); @@ -73,7 +73,7 @@ public void completeValueReturnsValue() { public void completeBeginnigOfValueReturnsValue() { BibEntry entry = new BibEntry(); entry.setField("field", "testValue"); - autoCompleter.indexBibtexEntry(entry); + autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("test"))); Assert.assertEquals(Arrays.asList("testValue"), result); @@ -83,7 +83,7 @@ public void completeBeginnigOfValueReturnsValue() { public void completeLowercaseValueReturnsValue() { BibEntry entry = new BibEntry(); entry.setField("field", "testValue"); - autoCompleter.indexBibtexEntry(entry); + autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("testvalue"))); Assert.assertEquals(Arrays.asList("testValue"), result); @@ -93,7 +93,7 @@ public void completeLowercaseValueReturnsValue() { public void completeNullReturnsNothing() { BibEntry entry = new BibEntry(); entry.setField("field", "testKey"); - autoCompleter.indexBibtexEntry(entry); + autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest((null))); Assert.assertEquals(Collections.emptyList(), result); @@ -103,7 +103,7 @@ public void completeNullReturnsNothing() { public void completeEmptyStringReturnsNothing() { BibEntry entry = new BibEntry(); entry.setField("field", "testKey"); - autoCompleter.indexBibtexEntry(entry); + autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest((""))); Assert.assertEquals(Collections.emptyList(), result); @@ -113,10 +113,10 @@ public void completeEmptyStringReturnsNothing() { public void completeReturnsMultipleResults() { BibEntry entryOne = new BibEntry(); entryOne.setField("field", "testValueOne"); - autoCompleter.indexBibtexEntry(entryOne); + autoCompleter.indexEntry(entryOne); BibEntry entryTwo = new BibEntry(); entryTwo.setField("field", "testValueTwo"); - autoCompleter.indexBibtexEntry(entryTwo); + autoCompleter.indexEntry(entryTwo); Collection result = autoCompleter.call(getRequest(("testValue"))); Assert.assertEquals(Arrays.asList("testValueOne", "testValueTwo"), result); @@ -126,7 +126,7 @@ public void completeReturnsMultipleResults() { public void completeShortStringReturnsNothing() { BibEntry entry = new BibEntry(); entry.setField("field", "val"); - autoCompleter.indexBibtexEntry(entry); + autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("va"))); Assert.assertEquals(Collections.emptyList(), result); @@ -136,7 +136,7 @@ public void completeShortStringReturnsNothing() { public void completeBeginnigOfSecondWordReturnsNothing() { BibEntry entry = new BibEntry(); entry.setField("field", "test value"); - autoCompleter.indexBibtexEntry(entry); + autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("val"))); Assert.assertEquals(Collections.emptyList(), result); @@ -146,7 +146,7 @@ public void completeBeginnigOfSecondWordReturnsNothing() { public void completePartOfWordReturnsNothing() { BibEntry entry = new BibEntry(); entry.setField("field", "test value"); - autoCompleter.indexBibtexEntry(entry); + autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("lue"))); Assert.assertEquals(Collections.emptyList(), result); @@ -156,7 +156,7 @@ public void completePartOfWordReturnsNothing() { public void completeReturnsWholeFieldValue() { BibEntry entry = new BibEntry(); entry.setField("field", "test value"); - autoCompleter.indexBibtexEntry(entry); + autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("te"))); Assert.assertEquals(Arrays.asList("test value"), result); From 01efa5da2d9ae01aafe9e423e824f98601ceb7f2 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Mon, 3 Jul 2017 18:14:47 +0200 Subject: [PATCH 04/10] Fix build [cont] --- .../org/jabref/gui/contentselector/ContentSelectorDialog.java | 4 ++-- .../jabref/logic/autocompleter/WordSuggestionProvider.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialog.java b/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialog.java index 160fa128ba5..6298bd33d7a 100644 --- a/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialog.java +++ b/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialog.java @@ -72,11 +72,11 @@ public class ContentSelectorDialog extends JabRefDialog { private final JTextField fieldNameField = new JTextField("", 20); private final JTextField wordEditField = new JTextField("", 20); private final JScrollPane fPane = new JScrollPane(fieldList); + private DefaultListModel wordListModel = new DefaultListModel<>(); private final Map> wordListModels = new HashMap<>(); + private final JList wordList = new JList<>(wordListModel); private final JScrollPane wPane = new JScrollPane(wordList); private final List removedFields = new ArrayList<>(); - private DefaultListModel wordListModel = new DefaultListModel<>(); - private final JList wordList = new JList<>(wordListModel); private String currentField; diff --git a/src/main/java/org/jabref/logic/autocompleter/WordSuggestionProvider.java b/src/main/java/org/jabref/logic/autocompleter/WordSuggestionProvider.java index 5ff7cf21dec..f0e584bd84a 100644 --- a/src/main/java/org/jabref/logic/autocompleter/WordSuggestionProvider.java +++ b/src/main/java/org/jabref/logic/autocompleter/WordSuggestionProvider.java @@ -8,13 +8,13 @@ /** * Stores all words in the given field which are separated by SEPARATING_CHARS. */ -class WordSuggestionProvider extends StringSuggestionProvider implements AutoCompleteSuggestionProvider { +public class WordSuggestionProvider extends StringSuggestionProvider implements AutoCompleteSuggestionProvider { private static final String SEPARATING_CHARS = ";,\n "; private final String fieldName; - WordSuggestionProvider(String fieldName) { + public WordSuggestionProvider(String fieldName) { this.fieldName = Objects.requireNonNull(fieldName); } From 9a1e43cfda01ec7488dfc03e94df96bab0eb9e0f Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Tue, 4 Jul 2017 20:46:33 +0200 Subject: [PATCH 05/10] Properly implement person name suggestions --- src/main/java/org/jabref/gui/BasePanel.java | 17 +- .../AppendPersonNamesStrategy.java | 40 ++++ .../autocompleter/AutoCompleteListener.java | 24 +- .../autocompleter/AutoCompleteRenderer.java | 4 +- .../autocompleter/AutoCompleteSupport.java | 87 +++----- .../gui/autocompleter/AutoCompleterUtil.java} | 6 +- .../autocompleter/AutoCompletionInput.java | 19 ++ .../autocompleter/AutoCompletionStrategy.java | 6 + .../AutoCompletionTextInputBinding.java | 106 ++++----- .../ListAutoCompleteRenderer.java | 4 +- .../gui/autocompleter/ReplaceStrategy.java | 9 + .../jabref/gui/fieldeditors/FieldEditors.java | 3 + .../gui/fieldeditors/PersonsEditor.java | 39 ++++ .../fieldeditors/PersonsEditorViewModel.java | 37 +++ .../jabref/gui/fieldeditors/SimpleEditor.java | 2 +- .../jabref/gui/search/GlobalSearchBar.java | 12 +- .../autocompleter/AbstractAutoCompleter.java | 139 ------------ .../logic/autocompleter/AutoCompleter.java | 57 ----- .../autocompleter/AutoCompleterFactory.java | 53 ----- .../PersonNameStringConverter.java | 63 ++++++ .../PersonNameSuggestionProvider.java | 146 ++---------- .../autocompleter/SuggestionProviders.java | 19 +- .../AutoCompleterFactoryTest.java | 74 ------ .../BibtexKeyAutoCompleterTest.java | 2 +- .../DefaultAutoCompleterTest.java | 2 +- .../FieldValueSuggestionProviderTest.java | 2 +- .../PersonNameSuggestionProviderTest.java | 210 ++++++------------ 27 files changed, 423 insertions(+), 759 deletions(-) create mode 100644 src/main/java/org/jabref/gui/autocompleter/AppendPersonNamesStrategy.java rename src/{test/java/org/jabref/logic/autocompleter/AutoCompleterTestUtil.java => main/java/org/jabref/gui/autocompleter/AutoCompleterUtil.java} (70%) create mode 100644 src/main/java/org/jabref/gui/autocompleter/AutoCompletionInput.java create mode 100644 src/main/java/org/jabref/gui/autocompleter/AutoCompletionStrategy.java rename src/main/java/org/jabref/gui/{util => autocompleter}/AutoCompletionTextInputBinding.java (52%) create mode 100644 src/main/java/org/jabref/gui/autocompleter/ReplaceStrategy.java create mode 100644 src/main/java/org/jabref/gui/fieldeditors/PersonsEditor.java create mode 100644 src/main/java/org/jabref/gui/fieldeditors/PersonsEditorViewModel.java delete mode 100644 src/main/java/org/jabref/logic/autocompleter/AbstractAutoCompleter.java delete mode 100644 src/main/java/org/jabref/logic/autocompleter/AutoCompleter.java delete mode 100644 src/main/java/org/jabref/logic/autocompleter/AutoCompleterFactory.java create mode 100644 src/main/java/org/jabref/logic/autocompleter/PersonNameStringConverter.java delete mode 100644 src/test/java/org/jabref/logic/autocompleter/AutoCompleterFactoryTest.java diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index e433e35990f..362bd98193a 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -98,8 +98,7 @@ import org.jabref.gui.worker.SendAsEMailAction; import org.jabref.logic.autocompleter.AutoCompleteListener; import org.jabref.logic.autocompleter.AutoCompletePreferences; -import org.jabref.logic.autocompleter.AutoCompleter; -import org.jabref.logic.autocompleter.AutoCompleterFactory; +import org.jabref.logic.autocompleter.PersonNameSuggestionProvider; import org.jabref.logic.autocompleter.SuggestionProviders; import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; import org.jabref.logic.citationstyle.CitationStyleCache; @@ -132,6 +131,7 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.EntryType; import org.jabref.model.entry.FieldName; +import org.jabref.model.entry.InternalBibtexFields; import org.jabref.model.entry.event.EntryChangedEvent; import org.jabref.model.entry.event.EntryEventSource; import org.jabref.model.entry.specialfields.SpecialField; @@ -180,7 +180,7 @@ public class BasePanel extends JPanel implements ClipboardOwner, FileUpdateListe private boolean saving; private boolean updatedExternally; // AutoCompleter used in the search bar - private AutoCompleter searchAutoCompleter; + private PersonNameSuggestionProvider searchAutoCompleter; private boolean baseChanged; private boolean nonUndoableChange; // Used to track whether the base has changed since last save. @@ -1404,12 +1404,9 @@ public void updateSearchManager() { } private void instantiateSearchAutoCompleter() { - AutoCompletePreferences autoCompletePreferences = new AutoCompletePreferences(Globals.prefs); - AutoCompleterFactory autoCompleterFactory = new AutoCompleterFactory(autoCompletePreferences, - Globals.journalAbbreviationLoader); - searchAutoCompleter = autoCompleterFactory.getPersonAutoCompleter(); + searchAutoCompleter = new PersonNameSuggestionProvider(InternalBibtexFields.getPersonNameFields()); for (BibEntry entry : bibDatabaseContext.getDatabase().getEntries()) { - searchAutoCompleter.addBibtexEntry(entry); + searchAutoCompleter.indexEntry(entry); } } @@ -2116,12 +2113,12 @@ private class SearchAutoCompleteListener { @Subscribe public void listen(EntryAddedEvent addedEntryEvent) { - searchAutoCompleter.addBibtexEntry(addedEntryEvent.getBibEntry()); + searchAutoCompleter.indexEntry(addedEntryEvent.getBibEntry()); } @Subscribe public void listen(EntryChangedEvent entryChangedEvent) { - searchAutoCompleter.addBibtexEntry(entryChangedEvent.getBibEntry()); + searchAutoCompleter.indexEntry(entryChangedEvent.getBibEntry()); } } diff --git a/src/main/java/org/jabref/gui/autocompleter/AppendPersonNamesStrategy.java b/src/main/java/org/jabref/gui/autocompleter/AppendPersonNamesStrategy.java new file mode 100644 index 00000000000..32feffb25ba --- /dev/null +++ b/src/main/java/org/jabref/gui/autocompleter/AppendPersonNamesStrategy.java @@ -0,0 +1,40 @@ +package org.jabref.gui.autocompleter; + +import java.util.Locale; + +public class AppendPersonNamesStrategy implements AutoCompletionStrategy { + + /** + * true if the input should be split at a single white space instead of the usual delimiter " and " for names. + * Useful if the input consists of a list of last names. + */ + private final boolean separationBySpace; + + public AppendPersonNamesStrategy() { + this(false); + } + + public AppendPersonNamesStrategy(boolean separationBySpace) { + this.separationBySpace = separationBySpace; + } + + @Override + public AutoCompletionInput analyze(String input) { + if (this.separationBySpace) { + return determinePrefixAndReturnRemainder(input, " "); + } else { + return determinePrefixAndReturnRemainder(input, " and "); + } + } + + private AutoCompletionInput determinePrefixAndReturnRemainder(String input, String delimiter) { + int index = input.toLowerCase(Locale.ROOT).lastIndexOf(delimiter); + if (index >= 0) { + String prefix = input.substring(0, index + delimiter.length()); + String rest = input.substring(index + delimiter.length()); + return new AutoCompletionInput(prefix, rest); + } else { + return new AutoCompletionInput("", input); + } + } +} diff --git a/src/main/java/org/jabref/gui/autocompleter/AutoCompleteListener.java b/src/main/java/org/jabref/gui/autocompleter/AutoCompleteListener.java index 85567638fbe..03cfaec0b0a 100644 --- a/src/main/java/org/jabref/gui/autocompleter/AutoCompleteListener.java +++ b/src/main/java/org/jabref/gui/autocompleter/AutoCompleteListener.java @@ -5,12 +5,13 @@ import java.awt.event.InputEvent; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; +import java.util.ArrayList; import java.util.List; import javax.swing.text.BadLocationException; import javax.swing.text.JTextComponent; -import org.jabref.logic.autocompleter.AutoCompleter; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -20,7 +21,7 @@ public class AutoCompleteListener extends KeyAdapter implements FocusListener { //TODO: The logging behavior in this class is probably too fine-grained and only understandable to its original author private static final Log LOGGER = LogFactory.getLog(AutoCompleteListener.class); - private final AutoCompleter completer; + private final AutoCompleteSuggestionProvider completer; // These variables keep track of the situation from time to time. private String toSetIn; // null indicates that there are no completions available @@ -35,7 +36,7 @@ public class AutoCompleteListener extends KeyAdapter implements FocusListener { // run before the focus listener responsible for storing the current edit. private FocusListener nextFocusListener; - public AutoCompleteListener(AutoCompleter completer) { + public AutoCompleteListener(AutoCompleteSuggestionProvider completer) { // if (logger.getHandlers().length == 0) { // logger.setLevel(Level.FINEST); // ConsoleHandler ch = new ConsoleHandler(); @@ -216,7 +217,7 @@ private void startCompletion(StringBuffer currentword, KeyEvent e) { JTextComponent comp = (JTextComponent) e.getSource(); List completed = findCompletions(currentword.toString()); - String prefix = completer.getPrefix(); + String prefix = null; String cWord = (prefix != null) && (!prefix.isEmpty()) ? currentword.toString() .substring(prefix.length()) : currentword.toString(); @@ -275,7 +276,7 @@ public void keyTyped(KeyEvent e) { if ((e.getModifiers() | InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK) { // plain key or SHIFT + key is pressed, no handling of CTRL+key, META+key, ... if (Character.isLetter(ch) || Character.isDigit(ch) - || (Character.isWhitespace(ch) && completer.isSingleUnitField())) { + || (Character.isWhitespace(ch))) { JTextComponent comp = (JTextComponent) e.getSource(); @@ -377,7 +378,6 @@ public void keyTyped(KeyEvent e) { return; } else { if (Character.isWhitespace(ch)) { - assert (!completer.isSingleUnitField()); LOGGER.debug("whitespace && !singleUnitField"); // start a new search if end-of-field is reached @@ -407,7 +407,7 @@ private void resetAutoCompletion() { } private List findCompletions(String beginning) { - return completer.complete(beginning); + return new ArrayList<>(completer.call(AutoCompleterUtil.getRequest((beginning)))); } private StringBuffer getCurrentWord(JTextComponent comp) { @@ -419,8 +419,8 @@ private StringBuffer getCurrentWord(JTextComponent comp) { // We now have the text from the start of the field up to the caret position. // In most fields, we are only interested in the currently edited word, so we // seek from the caret backward to the closest space: - if (!completer.isSingleUnitField()) { - if ((comp.getCaretPosition() < comp.getText().length()) + + if ((comp.getCaretPosition() < comp.getText().length()) && Character.isWhitespace(comp.getText().charAt(comp.getCaretPosition()))) { // caret is in the middle of the text AND current character is a whitespace // that means: a new word is started and there is no current word @@ -434,11 +434,7 @@ private StringBuffer getCurrentWord(JTextComponent comp) { // piv points to whitespace char or piv is -1 // copy everything from the next char up to the end of "upToCaret" res.append(upToCaret.substring(piv + 1)); - } else { - // For fields such as "journal" it is more reasonable to try to complete on the entire - // text field content, so we skip the searching and keep the entire part up to the caret: - res.append(upToCaret); - } + LOGGER.debug("AutoCompListener: " + res); } catch (BadLocationException ignore) { // Ignored diff --git a/src/main/java/org/jabref/gui/autocompleter/AutoCompleteRenderer.java b/src/main/java/org/jabref/gui/autocompleter/AutoCompleteRenderer.java index 319a4b21ab9..47e772751f0 100644 --- a/src/main/java/org/jabref/gui/autocompleter/AutoCompleteRenderer.java +++ b/src/main/java/org/jabref/gui/autocompleter/AutoCompleteRenderer.java @@ -2,7 +2,7 @@ import java.awt.Component; import java.awt.event.ActionListener; -import java.util.List; +import java.util.Collection; /** * Renders the list of possible autocomplete items. Also takes care of the currently selected item. @@ -16,7 +16,7 @@ public abstract class AutoCompleteRenderer { * * @param items list of possible autocomplete items */ - public abstract void update(List items); + public abstract void update(Collection items); /** * Creates the control which will be shown in the autocomplete popup. diff --git a/src/main/java/org/jabref/gui/autocompleter/AutoCompleteSupport.java b/src/main/java/org/jabref/gui/autocompleter/AutoCompleteSupport.java index 7f84a264986..c40adf6571b 100644 --- a/src/main/java/org/jabref/gui/autocompleter/AutoCompleteSupport.java +++ b/src/main/java/org/jabref/gui/autocompleter/AutoCompleteSupport.java @@ -7,7 +7,7 @@ import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; import java.awt.event.KeyEvent; -import java.util.List; +import java.util.Collection; import javax.swing.AbstractAction; import javax.swing.BorderFactory; @@ -20,7 +20,7 @@ import javax.swing.event.PopupMenuListener; import javax.swing.text.JTextComponent; -import org.jabref.logic.autocompleter.AutoCompleter; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; /** * Endows a textbox with the ability to autocomplete the input. Based on code by Santhosh Kumar @@ -31,9 +31,9 @@ public class AutoCompleteSupport { private final AutoCompleteRenderer renderer; - private AutoCompleter autoCompleter; private final JTextComponent textComp; private final JPopupMenu popup = new JPopupMenu(); + private AutoCompleteSuggestionProvider autoCompleter; private boolean selectsTextOnFocusGain = true; @@ -44,8 +44,8 @@ public class AutoCompleteSupport { * @param autoCompleter the autocompleter providing the data * @param renderer the renderer displaying the popup */ - public AutoCompleteSupport(JTextComponent textComp, AutoCompleter autoCompleter, - AutoCompleteRenderer renderer) { + public AutoCompleteSupport(JTextComponent textComp, AutoCompleteSuggestionProvider autoCompleter, + AutoCompleteRenderer renderer) { this.renderer = renderer; this.textComp = textComp; this.autoCompleter = autoCompleter; @@ -63,17 +63,6 @@ public AutoCompleteSupport(JTextComponent textComp) { this(textComp, null, new ListAutoCompleteRenderer<>()); } - /** - * Constructs a new AutoCompleteSupport for the textbox using the autocompleter and a renderer. The possible - * autocomplete items are displayed as a simple list. - * - * @param textComp the textbox component for which autocompletion should be enabled - * @param autoCompleter the autocompleter providing the data - */ - public AutoCompleteSupport(JTextComponent textComp, AutoCompleter autoCompleter) { - this(textComp, autoCompleter, new ListAutoCompleteRenderer<>()); - } - /** * Inits the autocompletion popup. After this method is called, further input in the specified textbox will be * autocompleted. @@ -92,26 +81,18 @@ public void install() { return; } - String toInsert = autoCompleter.getAutoCompleteText(itemToInsert); - - // TODO: The following should be refactored. For example, the autocompleter shouldn't know whether we want to complete one word or multiple. - // In most fields, we are only interested in the currently edited word, so we - // seek from the caret backward to the closest space: - if (!autoCompleter.isSingleUnitField()) { - // Get position of last word separator (whitespace or comma) - int priv = textComp.getText().length() - 1; - while ((priv >= 0) && !Character.isWhitespace(textComp.getText().charAt(priv)) - && (textComp.getText().charAt(priv) != ',')) { - priv--; - } - // priv points to whitespace char or priv is -1 - // copy everything from the next char up to the end of "upToCaret" - textComp.setText(textComp.getText().substring(0, priv + 1) + toInsert); - } else { - // For fields such as "journal" it is more reasonable to try to complete on the entire - // text field content, so we skip the searching and keep the entire part up to the caret: - textComp.setText(toInsert); + String toInsert = itemToInsert.toString(); + + // Get position of last word separator (whitespace or comma) + int priv = textComp.getText().length() - 1; + while ((priv >= 0) && !Character.isWhitespace(textComp.getText().charAt(priv)) + && (textComp.getText().charAt(priv) != ',')) { + priv--; } + // priv points to whitespace char or priv is -1 + // copy everything from the next char up to the end of "upToCaret" + textComp.setText(textComp.getText().substring(0, priv + 1) + toInsert); + textComp.setCaretPosition(textComp.getText().length()); popup.setVisible(false); }; @@ -209,7 +190,7 @@ private void postProcessTextChange() { } String text = textComp.getText(); - List candidates = autoCompleter.complete(text); + Collection candidates = autoCompleter.call(AutoCompleterUtil.getRequest(text)); renderer.update(candidates); if (textComp.isEnabled() && (!candidates.isEmpty())) { renderer.selectItem(0); @@ -225,6 +206,22 @@ private void postProcessTextChange() { } } + /** + * Sets the autocompleter used to present autocomplete suggestions. + * + * @param autoCompleter the autocompleter providing the data + */ + public void setAutoCompleter(AutoCompleteSuggestionProvider autoCompleter) { + this.autoCompleter = autoCompleter; + } + + public boolean isVisible() { + return popup.isVisible(); + } + + public void setVisible(boolean visible) { + popup.setVisible(visible); + } /** * The action invoked by hitting the up or down arrow key. If the popup is currently shown, that the action is @@ -270,22 +267,4 @@ public void focusLost(FocusEvent e) { } } - - /** - * Sets the autocompleter used to present autocomplete suggestions. - * - * @param autoCompleter the autocompleter providing the data - */ - public void setAutoCompleter(AutoCompleter autoCompleter) { - this.autoCompleter = autoCompleter; - } - - public void setVisible(boolean visible) { - popup.setVisible(visible); - } - - public boolean isVisible() { - return popup.isVisible(); - } - } diff --git a/src/test/java/org/jabref/logic/autocompleter/AutoCompleterTestUtil.java b/src/main/java/org/jabref/gui/autocompleter/AutoCompleterUtil.java similarity index 70% rename from src/test/java/org/jabref/logic/autocompleter/AutoCompleterTestUtil.java rename to src/main/java/org/jabref/gui/autocompleter/AutoCompleterUtil.java index befdca4a8ae..c6cf7fce048 100644 --- a/src/test/java/org/jabref/logic/autocompleter/AutoCompleterTestUtil.java +++ b/src/main/java/org/jabref/gui/autocompleter/AutoCompleterUtil.java @@ -1,9 +1,9 @@ -package org.jabref.logic.autocompleter; +package org.jabref.gui.autocompleter; import org.controlsfx.control.textfield.AutoCompletionBinding; -public class AutoCompleterTestUtil { - static AutoCompletionBinding.ISuggestionRequest getRequest(String text) { +public class AutoCompleterUtil { + public static AutoCompletionBinding.ISuggestionRequest getRequest(String text) { return new AutoCompletionBinding.ISuggestionRequest() { @Override public boolean isCancelled() { diff --git a/src/main/java/org/jabref/gui/autocompleter/AutoCompletionInput.java b/src/main/java/org/jabref/gui/autocompleter/AutoCompletionInput.java new file mode 100644 index 00000000000..e5ebbdbd34e --- /dev/null +++ b/src/main/java/org/jabref/gui/autocompleter/AutoCompletionInput.java @@ -0,0 +1,19 @@ +package org.jabref.gui.autocompleter; + +public class AutoCompletionInput { + private String unfinishedPart; + private String prefix; + + public AutoCompletionInput(String prefix, String unfinishedPart) { + this.prefix = prefix; + this.unfinishedPart = unfinishedPart; + } + + public String getUnfinishedPart() { + return unfinishedPart; + } + + public String getPrefix() { + return prefix; + } +} diff --git a/src/main/java/org/jabref/gui/autocompleter/AutoCompletionStrategy.java b/src/main/java/org/jabref/gui/autocompleter/AutoCompletionStrategy.java new file mode 100644 index 00000000000..50e835a3a9f --- /dev/null +++ b/src/main/java/org/jabref/gui/autocompleter/AutoCompletionStrategy.java @@ -0,0 +1,6 @@ +package org.jabref.gui.autocompleter; + +public interface AutoCompletionStrategy { + + public AutoCompletionInput analyze(String input); +} diff --git a/src/main/java/org/jabref/gui/util/AutoCompletionTextInputBinding.java b/src/main/java/org/jabref/gui/autocompleter/AutoCompletionTextInputBinding.java similarity index 52% rename from src/main/java/org/jabref/gui/util/AutoCompletionTextInputBinding.java rename to src/main/java/org/jabref/gui/autocompleter/AutoCompletionTextInputBinding.java index 1afdebb5ed2..384d5067ec3 100644 --- a/src/main/java/org/jabref/gui/util/AutoCompletionTextInputBinding.java +++ b/src/main/java/org/jabref/gui/autocompleter/AutoCompletionTextInputBinding.java @@ -24,12 +24,11 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.jabref.gui.util; +package org.jabref.gui.autocompleter; import java.util.Collection; import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; import javafx.scene.control.TextInputControl; import javafx.util.Callback; import javafx.util.StringConverter; @@ -45,90 +44,56 @@ */ public class AutoCompletionTextInputBinding extends AutoCompletionBinding { - /*************************************************************************** - * * - * Event Listeners * - * * - **************************************************************************/ - - - private final ChangeListener textChangeListener = new ChangeListener() { - @Override - public void changed(ObservableValue obs, String oldText, String newText) { - if (getCompletionTarget().isFocused()) { - setUserInput(newText); - } - } - }; - - /*************************************************************************** - * * - * Private fields * - * * - **************************************************************************/ - private final ChangeListener focusChangedListener = new ChangeListener() { - @Override - public void changed(ObservableValue obs, Boolean oldFocused, Boolean newFocused) { - if (newFocused == false) - hidePopup(); + private final ChangeListener focusChangedListener = (obs, oldFocused, newFocused) -> { + if (!newFocused) { + hidePopup(); } }; - - - /*************************************************************************** - * * - * Constructors * - * * - **************************************************************************/ /** * String converter to be used to convert suggestions to strings. */ private StringConverter converter; + private AutoCompletionStrategy inputAnalyzer; + private final ChangeListener textChangeListener = (obs, oldText, newText) -> { + if (getCompletionTarget().isFocused()) { + AutoCompletionInput input = inputAnalyzer.analyze(newText); + setUserInput(input.getUnfinishedPart()); + } + }; + /** * Creates a new auto-completion binding between the given textInputControl * and the given suggestion provider. - * - * @param textInputControl - * @param suggestionProvider */ - public AutoCompletionTextInputBinding(final TextInputControl textInputControl, - Callback> suggestionProvider) { + private AutoCompletionTextInputBinding(final TextInputControl textInputControl, + Callback> suggestionProvider) { - this(textInputControl, suggestionProvider, AutoCompletionTextInputBinding - .defaultStringConverter()); + this(textInputControl, + suggestionProvider, + AutoCompletionTextInputBinding.defaultStringConverter(), + new ReplaceStrategy()); } + private AutoCompletionTextInputBinding(final TextInputControl textInputControl, + final Callback> suggestionProvider, + final StringConverter converter) { + this(textInputControl, suggestionProvider, converter, new ReplaceStrategy()); + } - /*************************************************************************** - * * - * Public API * - * * - **************************************************************************/ - - /** - * Creates a new auto-completion binding between the given textInputControl - * and the given suggestion provider. - * - * @param textInputControl - * @param suggestionProvider - */ - public AutoCompletionTextInputBinding(final TextInputControl textInputControl, - Callback> suggestionProvider, - final StringConverter converter) { + private AutoCompletionTextInputBinding(final TextInputControl textInputControl, + final Callback> suggestionProvider, + final StringConverter converter, + final AutoCompletionStrategy inputAnalyzer) { super(textInputControl, suggestionProvider, converter); this.converter = converter; + this.inputAnalyzer = inputAnalyzer; getCompletionTarget().textProperty().addListener(textChangeListener); getCompletionTarget().focusedProperty().addListener(focusChangedListener); } - /*************************************************************************** - * * - * Static properties and methods * - * * - **************************************************************************/ private static StringConverter defaultStringConverter() { return new StringConverter() { @@ -149,23 +114,30 @@ public static void autoComplete(TextInputControl textArea, Callback(textArea, suggestionProvider); } - /** {@inheritDoc} */ + public static void autoComplete(TextInputControl textArea, Callback> suggestionProvider, StringConverter converter) { + new AutoCompletionTextInputBinding<>(textArea, suggestionProvider, converter); + } + + public static void autoComplete(TextInputControl textArea, Callback> suggestionProvider, StringConverter converter, AutoCompletionStrategy inputAnalyzer) { + new AutoCompletionTextInputBinding<>(textArea, suggestionProvider, converter, inputAnalyzer); + } + @Override public TextInputControl getCompletionTarget() { return (TextInputControl) super.getCompletionTarget(); } - /** {@inheritDoc} */ @Override public void dispose() { getCompletionTarget().textProperty().removeListener(textChangeListener); getCompletionTarget().focusedProperty().removeListener(focusChangedListener); } - /** {@inheritDoc} */ @Override protected void completeUserInput(T completion) { - String newText = converter.toString(completion); + String completionText = converter.toString(completion); + AutoCompletionInput input = inputAnalyzer.analyze(getCompletionTarget().getText()); + String newText = input.getPrefix() + completionText; getCompletionTarget().setText(newText); getCompletionTarget().positionCaret(newText.length()); } diff --git a/src/main/java/org/jabref/gui/autocompleter/ListAutoCompleteRenderer.java b/src/main/java/org/jabref/gui/autocompleter/ListAutoCompleteRenderer.java index 968ba47190b..48018dd7a0e 100644 --- a/src/main/java/org/jabref/gui/autocompleter/ListAutoCompleteRenderer.java +++ b/src/main/java/org/jabref/gui/autocompleter/ListAutoCompleteRenderer.java @@ -3,7 +3,7 @@ import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.util.List; +import java.util.Collection; import java.util.Vector; import javax.swing.BorderFactory; @@ -30,7 +30,7 @@ public class ListAutoCompleteRenderer extends AutoCompleteRenderer { private Boolean interpretSelectionChangeAsAccept = true; @Override - public void update(List autoCompletions) { + public void update(Collection autoCompletions) { if (autoCompletions == null) { model.removeAllElements(); } else { diff --git a/src/main/java/org/jabref/gui/autocompleter/ReplaceStrategy.java b/src/main/java/org/jabref/gui/autocompleter/ReplaceStrategy.java new file mode 100644 index 00000000000..1ba900201b2 --- /dev/null +++ b/src/main/java/org/jabref/gui/autocompleter/ReplaceStrategy.java @@ -0,0 +1,9 @@ +package org.jabref.gui.autocompleter; + +public class ReplaceStrategy implements AutoCompletionStrategy { + + @Override + public AutoCompletionInput analyze(String input) { + return new AutoCompletionInput("", input); + } +} diff --git a/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java b/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java index 8b323d56380..f8827c4a748 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java +++ b/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java @@ -6,6 +6,7 @@ import org.jabref.Globals; import org.jabref.gui.DialogService; import org.jabref.gui.util.TaskExecutor; +import org.jabref.logic.autocompleter.AutoCompletePreferences; import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.logic.autocompleter.SuggestionProviders; import org.jabref.logic.journals.JournalAbbreviationLoader; @@ -56,6 +57,8 @@ public static FieldEditorFX getForField(String fieldName, TaskExecutor taskExecu } } else if (fieldExtras.contains(FieldProperty.SINGLE_ENTRY_LINK) || fieldExtras.contains(FieldProperty.MULTIPLE_ENTRY_LINK)) { return new LinkedEntriesEditor(fieldName, databaseContext, suggestionProvider); + } else if (fieldExtras.contains(FieldProperty.PERSON_NAMES)) { + return new PersonsEditor(fieldName, suggestionProvider, new AutoCompletePreferences(preferences)); } // default diff --git a/src/main/java/org/jabref/gui/fieldeditors/PersonsEditor.java b/src/main/java/org/jabref/gui/fieldeditors/PersonsEditor.java new file mode 100644 index 00000000000..bc438c16aed --- /dev/null +++ b/src/main/java/org/jabref/gui/fieldeditors/PersonsEditor.java @@ -0,0 +1,39 @@ +package org.jabref.gui.fieldeditors; + +import javafx.fxml.FXML; +import javafx.scene.Parent; +import javafx.scene.layout.HBox; +import javafx.scene.layout.Priority; + +import org.jabref.gui.autocompleter.AutoCompletionTextInputBinding; +import org.jabref.gui.fieldeditors.contextmenu.EditorMenus; +import org.jabref.logic.autocompleter.AutoCompletePreferences; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; +import org.jabref.model.entry.BibEntry; + +public class PersonsEditor extends HBox implements FieldEditorFX { + + @FXML private final PersonsEditorViewModel viewModel; + + public PersonsEditor(String fieldName, AutoCompleteSuggestionProvider suggestionProvider, AutoCompletePreferences autoCompletePreferences) { + this.viewModel = new PersonsEditorViewModel(fieldName, suggestionProvider, autoCompletePreferences); + + EditorTextArea textArea = new EditorTextArea(); + HBox.setHgrow(textArea, Priority.ALWAYS); + textArea.textProperty().bindBidirectional(viewModel.textProperty()); + textArea.addToContextMenu(EditorMenus.getDefaultMenu(textArea)); + this.getChildren().add(textArea); + + AutoCompletionTextInputBinding.autoComplete(textArea, viewModel::complete, viewModel.getAutoCompletionConverter(), viewModel.getAutoCompletionStrategy()); + } + + @Override + public void bindToEntry(BibEntry entry) { + viewModel.bindToEntry(entry); + } + + @Override + public Parent getNode() { + return this; + } +} diff --git a/src/main/java/org/jabref/gui/fieldeditors/PersonsEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/PersonsEditorViewModel.java new file mode 100644 index 00000000000..79747169244 --- /dev/null +++ b/src/main/java/org/jabref/gui/fieldeditors/PersonsEditorViewModel.java @@ -0,0 +1,37 @@ +package org.jabref.gui.fieldeditors; + +import java.util.Collection; + +import javafx.util.StringConverter; + +import org.jabref.gui.autocompleter.AppendPersonNamesStrategy; +import org.jabref.gui.autocompleter.AutoCompletionStrategy; +import org.jabref.logic.autocompleter.AutoCompletePreferences; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; +import org.jabref.logic.autocompleter.PersonNameStringConverter; +import org.jabref.model.entry.Author; + +import org.controlsfx.control.textfield.AutoCompletionBinding; + +public class PersonsEditorViewModel extends AbstractEditorViewModel { + + private final AutoCompletePreferences preferences; + + public PersonsEditorViewModel(String fieldName, AutoCompleteSuggestionProvider suggestionProvider, AutoCompletePreferences preferences) { + super(fieldName, suggestionProvider); + this.preferences = preferences; + } + + public StringConverter getAutoCompletionConverter() { + return new PersonNameStringConverter(preferences); + } + + @SuppressWarnings("unchecked") + public Collection complete(AutoCompletionBinding.ISuggestionRequest request) { + return (Collection) super.complete(request); + } + + public AutoCompletionStrategy getAutoCompletionStrategy() { + return new AppendPersonNamesStrategy(); + } +} diff --git a/src/main/java/org/jabref/gui/fieldeditors/SimpleEditor.java b/src/main/java/org/jabref/gui/fieldeditors/SimpleEditor.java index fb8da76345f..deb799f4862 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/SimpleEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/SimpleEditor.java @@ -5,8 +5,8 @@ import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; +import org.jabref.gui.autocompleter.AutoCompletionTextInputBinding; import org.jabref.gui.fieldeditors.contextmenu.EditorMenus; -import org.jabref.gui.util.AutoCompletionTextInputBinding; import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.model.entry.BibEntry; diff --git a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java index 53ba13620b0..d57af4ba9fa 100644 --- a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java +++ b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java @@ -31,12 +31,13 @@ import org.jabref.gui.maintable.MainTable; import org.jabref.gui.maintable.MainTableDataModel; import org.jabref.gui.util.component.JTextFieldWithPlaceholder; -import org.jabref.logic.autocompleter.AutoCompleter; +import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.logic.help.HelpFile; import org.jabref.logic.l10n.Localization; import org.jabref.logic.search.SearchQuery; import org.jabref.logic.search.SearchQueryHighlightObservable; import org.jabref.logic.util.OS; +import org.jabref.model.entry.Author; import org.jabref.model.entry.BibEntry; import org.jabref.preferences.SearchPreferences; @@ -51,16 +52,13 @@ public class GlobalSearchBar extends JPanel { private final JLabel searchIcon = new JLabel(IconTheme.JabRefIcon.SEARCH.getSmallIcon()); private final JTextFieldWithPlaceholder searchField = new JTextFieldWithPlaceholder(Localization.lang("Search") + "..."); - private JButton openCurrentResultsInDialog = new JButton(IconTheme.JabRefIcon.OPEN_IN_NEW_WINDOW.getSmallIcon()); - private final JToggleButton caseSensitive; private final JToggleButton regularExp; private final JButton searchModeButton = new JButton(); private final JLabel currentResults = new JLabel(""); - - private AutoCompleteSupport autoCompleteSupport = new AutoCompleteSupport<>(searchField); private final SearchQueryHighlightObservable searchQueryHighlightObservable = new SearchQueryHighlightObservable(); - + private JButton openCurrentResultsInDialog = new JButton(IconTheme.JabRefIcon.OPEN_IN_NEW_WINDOW.getSmallIcon()); + private AutoCompleteSupport autoCompleteSupport = new AutoCompleteSupport<>(searchField); private SearchWorker searchWorker; private GlobalSearchWorker globalSearchWorker; @@ -355,7 +353,7 @@ private void informUserAboutInvalidSearchQuery() { openCurrentResultsInDialog.setEnabled(false); } - public void setAutoCompleter(AutoCompleter searchCompleter) { + public void setAutoCompleter(AutoCompleteSuggestionProvider searchCompleter) { this.autoCompleteSupport.setAutoCompleter(searchCompleter); } diff --git a/src/main/java/org/jabref/logic/autocompleter/AbstractAutoCompleter.java b/src/main/java/org/jabref/logic/autocompleter/AbstractAutoCompleter.java deleted file mode 100644 index 4f4f26ba910..00000000000 --- a/src/main/java/org/jabref/logic/autocompleter/AbstractAutoCompleter.java +++ /dev/null @@ -1,139 +0,0 @@ -package org.jabref.logic.autocompleter; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.jabref.logic.layout.format.LatexToUnicodeFormatter; - -/** - * Delivers possible completions for a given string. - * - * @author kahlert, cordes, olly98 - * @see AutoCompleterFactory - */ -public abstract class AbstractAutoCompleter implements AutoCompleter { - - private static final int SHORTEST_WORD_TO_ADD = 4; - private final AutoCompletePreferences preferences; - - /** - * Stores the strings as is. - */ - private final TreeSet indexCaseSensitive = new TreeSet<>(); - - /** - * Stores strings in lowercase. - */ - private final TreeSet indexCaseInsensitive = new TreeSet<>(); - - /** - * Stores for a lowercase string the possible expanded strings. - */ - private final Map> possibleStringsForSearchString = new HashMap<>(); - - - public AbstractAutoCompleter(AutoCompletePreferences preferences) { - this.preferences = Objects.requireNonNull(preferences); - } - - /** - * {@inheritDoc} - * The completion is case sensitive if the string contains upper case letters. - * Otherwise the completion is case insensitive. - */ - @Override - public List complete(String toComplete) { - if (toComplete == null) { - return new ArrayList<>(); - } - if (isTooShortToComplete(toComplete)) { - return new ArrayList<>(); - } - String lowerCase = toComplete.toLowerCase(Locale.ROOT); - - if (lowerCase.equals(toComplete)) { - // user typed in lower case word -> we do an case-insensitive search - String ender = AbstractAutoCompleter.incrementLastCharacter(lowerCase); - SortedSet subset = indexCaseInsensitive.subSet(lowerCase, ender); - - // As subset only contains lower case strings, - // we have to to determine possible strings for each hit - List result = new ArrayList<>(); - for (String s : subset) { - result.addAll(possibleStringsForSearchString.get(s)); - } - return result; - } else { - // user typed in a mix of upper case and lower case, - // we assume user wants to have exact search - String ender = AbstractAutoCompleter.incrementLastCharacter(toComplete); - SortedSet subset = indexCaseSensitive.subSet(toComplete, ender); - return new ArrayList<>(subset); - } - } - - /** - * Increments the last character of a string. - * - * Example: incrementLastCharacter("abc") returns "abd". - */ - private static String incrementLastCharacter(String toIncrement) { - if (toIncrement.isEmpty()) { - return ""; - } - - char lastChar = toIncrement.charAt(toIncrement.length() - 1); - return toIncrement.substring(0, toIncrement.length() - 1) + Character.toString((char) (lastChar + 1)); - } - - /** - * Returns whether the string is to short to be completed. - */ - private boolean isTooShortToComplete(String toCheck) { - return toCheck.length() < preferences.getShortestLengthToComplete(); - } - - @Override - public void addItemToIndex(String word) { - if (word.length() < getLengthOfShortestWordToAdd()) { - return; - } - - word = new LatexToUnicodeFormatter().format(word); - - indexCaseSensitive.add(word); - - // insensitive treatment - // first, add the lower cased word to search index - // second, add a mapping from the lower cased word to the real word - String lowerCase = word.toLowerCase(Locale.ROOT); - indexCaseInsensitive.add(lowerCase); - Set set = possibleStringsForSearchString.get(lowerCase); - if (set == null) { - set = new TreeSet<>(); - } - set.add(word); - possibleStringsForSearchString.put(lowerCase, set); - } - - @Override - public String getPrefix() { - return ""; - } - - @Override - public String getAutoCompleteText(String item) { - return item; - } - - protected int getLengthOfShortestWordToAdd() { - return AbstractAutoCompleter.SHORTEST_WORD_TO_ADD; - } -} diff --git a/src/main/java/org/jabref/logic/autocompleter/AutoCompleter.java b/src/main/java/org/jabref/logic/autocompleter/AutoCompleter.java deleted file mode 100644 index ef7f0fc1cf6..00000000000 --- a/src/main/java/org/jabref/logic/autocompleter/AutoCompleter.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.jabref.logic.autocompleter; - -import java.util.List; - -import org.jabref.model.entry.BibEntry; - -/** - * Delivers possible completions for a given string. - */ -public interface AutoCompleter { - - /** - * Formats the specified item. This method is called when an item is selected by the user and we need to determine - * the text to be inserted in the textbox. - * - * @param item the item to format - * @return formated string representation of the item - */ - String getAutoCompleteText(E item); - - /** - * Add a BibEntry to this AutoCompleter. - * @note The AutoCompleter itself decides which information should be stored for later completion. - */ - void addBibtexEntry(BibEntry entry); - - /** - * States whether the field consists of multiple values (false) or of a single value (true) - * - * Symptom: if false, org.jabref.gui.AutoCompleteListener#getCurrentWord(JTextComponent comp) - * returns current word only, if true, it returns the text beginning from the buffer. - */ - boolean isSingleUnitField(); - - /** - * Unclear what this method should do. - * TODO: Remove this method once the AutoCompleteListener is removed. - */ - String getPrefix(); - - /** - * Returns one or more possible completions for a given string. The returned - * completion depends on which informations were stored while adding - * BibtexEntries. If no suggestions for completions are found, then an empty list is returned. - * - * @see AutoCompleter#addBibtexEntry(BibEntry) - */ - List complete(String toComplete); - - /** - * Directly adds an item to the AutoCompleter. - * This method should be called only if the information does not comes directly from a BibEntry. - * Otherwise the {@link #addBibtexEntry(BibEntry)} is preferred. - * @param item item to add - */ - void addItemToIndex(E item); -} diff --git a/src/main/java/org/jabref/logic/autocompleter/AutoCompleterFactory.java b/src/main/java/org/jabref/logic/autocompleter/AutoCompleterFactory.java deleted file mode 100644 index 2d16a1ba75f..00000000000 --- a/src/main/java/org/jabref/logic/autocompleter/AutoCompleterFactory.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.jabref.logic.autocompleter; - -import java.util.Objects; - -import org.jabref.logic.journals.JournalAbbreviationLoader; -import org.jabref.model.entry.FieldName; -import org.jabref.model.entry.FieldProperty; -import org.jabref.model.entry.InternalBibtexFields; - -/** - * Returns an autocompleter to a given fieldname. - * - * @author kahlert, cordes - */ -public class AutoCompleterFactory { - - private final AutoCompletePreferences preferences; - private final JournalAbbreviationLoader abbreviationLoader; - - - public AutoCompleterFactory(AutoCompletePreferences preferences, JournalAbbreviationLoader abbreviationLoader) { - this.preferences = Objects.requireNonNull(preferences); - this.abbreviationLoader = Objects.requireNonNull(abbreviationLoader); - } - - public AutoCompleter getFor(String fieldName) { - Objects.requireNonNull(fieldName); - - if (InternalBibtexFields.getFieldProperties(fieldName).contains(FieldProperty.PERSON_NAMES)) { - return new PersonNameSuggestionProvider(fieldName, preferences); - } else { - return null; - } - } - - public AutoCompleter getPersonAutoCompleter() { - return new PersonNameSuggestionProvider(InternalBibtexFields.getPersonNameFields(), true, preferences); - } - - public AutoCompleteSuggestionProvider getForField(String fieldName) { - //if (InternalBibtexFields.getFieldProperties(fieldName).contains(FieldProperty.PERSON_NAMES)) { - // return new NameFieldAutoCompleter(fieldName, preferences); - //} else - if (InternalBibtexFields.getFieldProperties(fieldName).contains(FieldProperty.SINGLE_ENTRY_LINK)) { - return new BibEntrySuggestionProvider(); - } else if (InternalBibtexFields.getFieldProperties(fieldName).contains(FieldProperty.JOURNAL_NAME) - || FieldName.PUBLISHER.equals(fieldName)) { - return new JournalsSuggestionProvider(fieldName, preferences, abbreviationLoader); - } else { - return new WordSuggestionProvider(fieldName); - } - } -} diff --git a/src/main/java/org/jabref/logic/autocompleter/PersonNameStringConverter.java b/src/main/java/org/jabref/logic/autocompleter/PersonNameStringConverter.java new file mode 100644 index 00000000000..f3f55ca8131 --- /dev/null +++ b/src/main/java/org/jabref/logic/autocompleter/PersonNameStringConverter.java @@ -0,0 +1,63 @@ +package org.jabref.logic.autocompleter; + +import javafx.util.StringConverter; + +import org.jabref.model.entry.Author; +import org.jabref.model.entry.AuthorList; + +public class PersonNameStringConverter extends StringConverter { + + private final boolean autoCompFF; + private final boolean autoCompLF; + private final AutoCompleteFirstNameMode autoCompleteFirstNameMode; + + public PersonNameStringConverter(AutoCompletePreferences preferences) { + if (preferences.getOnlyCompleteFirstLast()) { + autoCompFF = true; + autoCompLF = false; + } else if (preferences.getOnlyCompleteLastFirst()) { + autoCompFF = false; + autoCompLF = true; + } else { + autoCompFF = true; + autoCompLF = true; + } + autoCompleteFirstNameMode = preferences.getFirstnameMode() == null ? AutoCompleteFirstNameMode.BOTH : preferences + .getFirstnameMode(); + } + + @Override + public String toString(Author author) { + + if (autoCompLF) { + switch (autoCompleteFirstNameMode) { + case ONLY_ABBREVIATED: + return author.getLastFirst(true); + case ONLY_FULL: + return author.getLastFirst(false); + case BOTH: + return author.getLastFirst(true); + default: + break; + } + } + if (autoCompFF) { + switch (autoCompleteFirstNameMode) { + case ONLY_ABBREVIATED: + return author.getFirstLast(true); + case ONLY_FULL: + return author.getFirstLast(false); + case BOTH: + return author.getFirstLast(true); + default: + break; + } + } + return author.getLastFirst(false); + } + + @Override + public Author fromString(String string) { + return AuthorList.parse(string).getAuthor(0); + } +} diff --git a/src/main/java/org/jabref/logic/autocompleter/PersonNameSuggestionProvider.java b/src/main/java/org/jabref/logic/autocompleter/PersonNameSuggestionProvider.java index 7137bcdc666..941c548ad7a 100644 --- a/src/main/java/org/jabref/logic/autocompleter/PersonNameSuggestionProvider.java +++ b/src/main/java/org/jabref/logic/autocompleter/PersonNameSuggestionProvider.java @@ -1,169 +1,61 @@ package org.jabref.logic.autocompleter; -import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.List; -import java.util.Locale; import java.util.Objects; import org.jabref.model.entry.Author; import org.jabref.model.entry.AuthorList; import org.jabref.model.entry.BibEntry; +import impl.org.controlsfx.autocompletion.SuggestionProvider; +import org.controlsfx.control.textfield.AutoCompletionBinding; + /** * Delivers possible completions as a list of {@link Author}s. */ -class PersonNameSuggestionProvider extends AbstractAutoCompleter { +public class PersonNameSuggestionProvider extends SuggestionProvider implements AutoCompleteSuggestionProvider { private final List fieldNames; - /** - * true if only last names should be completed and there is NO separation by " and ", but by " " - */ - private final boolean lastNameOnlyAndSeparationBySpace; - private final boolean autoCompFF; - private final boolean autoCompLF; - private final AutoCompleteFirstNameMode autoCompFirstnameMode; - - private String prefix = ""; - + private final Comparator authorComparator = Comparator.comparing(Author::getNameForAlphabetization); - /** - * @see AutoCompleterFactory - */ - PersonNameSuggestionProvider(String fieldName, AutoCompletePreferences preferences) { - this(Collections.singletonList(Objects.requireNonNull(fieldName)), false, preferences); + PersonNameSuggestionProvider(String fieldName) { + this(Collections.singletonList(Objects.requireNonNull(fieldName))); } - public PersonNameSuggestionProvider(List fieldNames, boolean lastNameOnlyAndSeparationBySpace, - AutoCompletePreferences preferences) { - super(preferences); + public PersonNameSuggestionProvider(List fieldNames) { + super(); this.fieldNames = Objects.requireNonNull(fieldNames); - this.lastNameOnlyAndSeparationBySpace = lastNameOnlyAndSeparationBySpace; - if (preferences.getOnlyCompleteFirstLast()) { - autoCompFF = true; - autoCompLF = false; - } else if (preferences.getOnlyCompleteLastFirst()) { - autoCompFF = false; - autoCompLF = true; - } else { - autoCompFF = true; - autoCompLF = true; - } - autoCompFirstnameMode = preferences.getFirstnameMode() == null ? AutoCompleteFirstNameMode.BOTH : preferences - .getFirstnameMode(); - } - @Override - public boolean isSingleUnitField() { - // quick hack - // when used at entry fields (!this.lastNameOnlyAndSeparationBySpace), this is a single unit field - // when used at the search form (this.lastNameOnlyAndSeparationBySpace), this is NOT a single unit field - // reason: search keywords are separated by space. - // This is OK for last names without prefix. "Lastname" works perfectly. - // querying for "van der Lastname" can be interpreted as - // a) "van" "der" "Lastname" - // b) "van der Lastname" (autocompletion lastname) - return !this.lastNameOnlyAndSeparationBySpace; } @Override - public void addBibtexEntry(BibEntry entry) { + public void indexEntry(BibEntry entry) { if (entry == null) { return; } + for (String fieldName : fieldNames) { entry.getField(fieldName).ifPresent(fieldValue -> { AuthorList authorList = AuthorList.parse(fieldValue); for (Author author : authorList.getAuthors()) { - handleAuthor(author); + addPossibleSuggestions(author); } }); } } - /** - * SIDE EFFECT: sets class variable prefix - * Delimiter: " and " or " " - * - * @return String without prefix - */ - private String determinePrefixAndReturnRemainder(String str, String delimiter) { - String result = str; - int index = result.toLowerCase(Locale.ROOT).lastIndexOf(delimiter); - if (index >= 0) { - prefix = result.substring(0, index + delimiter.length()); - result = result.substring(index + delimiter.length()); - } else { - prefix = ""; - } - return result; - } - - private void handleAuthor(Author author) { - if (lastNameOnlyAndSeparationBySpace) { - addItemToIndex(author.getLastOnly()); - } else { - if (autoCompLF) { - switch (autoCompFirstnameMode) { - case ONLY_ABBREVIATED: - addItemToIndex(author.getLastFirst(true)); - break; - case ONLY_FULL: - addItemToIndex(author.getLastFirst(false)); - break; - case BOTH: - addItemToIndex(author.getLastFirst(true)); - addItemToIndex(author.getLastFirst(false)); - break; - default: - break; - } - } - if (autoCompFF) { - switch (autoCompFirstnameMode) { - case ONLY_ABBREVIATED: - addItemToIndex(author.getFirstLast(true)); - break; - case ONLY_FULL: - addItemToIndex(author.getFirstLast(false)); - break; - case BOTH: - addItemToIndex(author.getFirstLast(true)); - addItemToIndex(author.getFirstLast(false)); - break; - default: - break; - } - } - } - - } - - @Override - public List complete(String toComplete) { - if (toComplete == null) { - return new ArrayList<>(); - } - - String result; - // Normally, one would implement that using - // class inheritance. But this seemed overengineered - if (this.lastNameOnlyAndSeparationBySpace) { - result = determinePrefixAndReturnRemainder(toComplete, " "); - } else { - result = determinePrefixAndReturnRemainder(toComplete, " and "); - } - return super.complete(result); - } - @Override - public String getPrefix() { - return prefix; + protected Comparator getComparator() { + return authorComparator; } @Override - protected int getLengthOfShortestWordToAdd() { - return 1; + protected boolean isMatch(Author suggestion, AutoCompletionBinding.ISuggestionRequest request) { + String userTextLower = request.getUserText().toLowerCase(); + String suggestionStr = suggestion.getNameForAlphabetization().toLowerCase(); + return suggestionStr.contains(userTextLower); } } diff --git a/src/main/java/org/jabref/logic/autocompleter/SuggestionProviders.java b/src/main/java/org/jabref/logic/autocompleter/SuggestionProviders.java index 86886f036fc..20c6c3fde26 100644 --- a/src/main/java/org/jabref/logic/autocompleter/SuggestionProviders.java +++ b/src/main/java/org/jabref/logic/autocompleter/SuggestionProviders.java @@ -8,6 +8,9 @@ import org.jabref.logic.journals.JournalAbbreviationLoader; import org.jabref.model.database.BibDatabase; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.FieldName; +import org.jabref.model.entry.FieldProperty; +import org.jabref.model.entry.InternalBibtexFields; public class SuggestionProviders { @@ -27,10 +30,9 @@ public SuggestionProviders(AutoCompletePreferences preferences, JournalAbbreviationLoader abbreviationLoader) { Objects.requireNonNull(preferences); - AutoCompleterFactory autoCompleterFactory = new AutoCompleterFactory(preferences, abbreviationLoader); List completeFields = preferences.getCompleteNames(); for (String field : completeFields) { - AutoCompleteSuggestionProvider autoCompleter = autoCompleterFactory.getForField(field); + AutoCompleteSuggestionProvider autoCompleter = initalizeSuggestionProvider(field, preferences, abbreviationLoader); providers.put(field, autoCompleter); } } @@ -53,4 +55,17 @@ public void indexEntry(BibEntry bibEntry) { autoCompleter.indexEntry(bibEntry); } } + + private AutoCompleteSuggestionProvider initalizeSuggestionProvider(String fieldName, AutoCompletePreferences preferences, JournalAbbreviationLoader abbreviationLoader) { + if (InternalBibtexFields.getFieldProperties(fieldName).contains(FieldProperty.PERSON_NAMES)) { + return new PersonNameSuggestionProvider(fieldName); + } else if (InternalBibtexFields.getFieldProperties(fieldName).contains(FieldProperty.SINGLE_ENTRY_LINK)) { + return new BibEntrySuggestionProvider(); + } else if (InternalBibtexFields.getFieldProperties(fieldName).contains(FieldProperty.JOURNAL_NAME) + || FieldName.PUBLISHER.equals(fieldName)) { + return new JournalsSuggestionProvider(fieldName, preferences, abbreviationLoader); + } else { + return new WordSuggestionProvider(fieldName); + } + } } diff --git a/src/test/java/org/jabref/logic/autocompleter/AutoCompleterFactoryTest.java b/src/test/java/org/jabref/logic/autocompleter/AutoCompleterFactoryTest.java deleted file mode 100644 index e01faba37ae..00000000000 --- a/src/test/java/org/jabref/logic/autocompleter/AutoCompleterFactoryTest.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.jabref.logic.autocompleter; - -import org.jabref.logic.journals.JournalAbbreviationLoader; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import static org.mockito.Mockito.mock; - -public class AutoCompleterFactoryTest { - - private AutoCompleterFactory autoCompleterFactory; - private JournalAbbreviationLoader abbreviationLoader; - - @Before - public void setUp() throws Exception { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - abbreviationLoader = mock(JournalAbbreviationLoader.class); - autoCompleterFactory = new AutoCompleterFactory(preferences, abbreviationLoader); - } - - @Test(expected = NullPointerException.class) - public void initFactoryWithNullPreferenceThrowsException() { - new AutoCompleterFactory(null, abbreviationLoader); - } - - @Test - public void getForUnknownFieldReturnsDefaultAutoCompleter() { - AutoCompleter autoCompleter = autoCompleterFactory.getFor("unknownField"); - Assert.assertTrue(autoCompleter != null); - } - - @Test(expected = NullPointerException.class) - public void getForNullThrowsException() { - autoCompleterFactory.getFor(null); - } - - @Test - public void getForAuthorReturnsNameFieldAutoCompleter() { - AutoCompleter autoCompleter = autoCompleterFactory.getFor("author"); - Assert.assertTrue(autoCompleter instanceof PersonNameSuggestionProvider); - } - - @Test - public void getForEditorReturnsNameFieldAutoCompleter() { - AutoCompleter autoCompleter = autoCompleterFactory.getFor("editor"); - Assert.assertTrue(autoCompleter instanceof PersonNameSuggestionProvider); - } - - @Test - public void getForCrossrefReturnsBibtexKeyAutoCompleter() { - AutoCompleter autoCompleter = autoCompleterFactory.getFor("crossref"); - Assert.assertTrue(autoCompleter instanceof BibEntrySuggestionProvider); - } - - @Test - public void getForJournalReturnsEntireFieldAutoCompleter() { - AutoCompleter autoCompleter = autoCompleterFactory.getFor("journal"); - Assert.assertTrue(autoCompleter instanceof FieldValueSuggestionProvider); - } - - @Test - public void getForPublisherReturnsEntireFieldAutoCompleter() { - AutoCompleter autoCompleter = autoCompleterFactory.getFor("publisher"); - Assert.assertTrue(autoCompleter instanceof FieldValueSuggestionProvider); - } - - @Test - public void getPersonAutoCompleterReturnsNameFieldAutoCompleter() { - AutoCompleter autoCompleter = autoCompleterFactory.getPersonAutoCompleter(); - Assert.assertTrue(autoCompleter instanceof PersonNameSuggestionProvider); - } -} diff --git a/src/test/java/org/jabref/logic/autocompleter/BibtexKeyAutoCompleterTest.java b/src/test/java/org/jabref/logic/autocompleter/BibtexKeyAutoCompleterTest.java index a2f9e3799fa..80bd52afb32 100644 --- a/src/test/java/org/jabref/logic/autocompleter/BibtexKeyAutoCompleterTest.java +++ b/src/test/java/org/jabref/logic/autocompleter/BibtexKeyAutoCompleterTest.java @@ -10,7 +10,7 @@ import org.junit.Before; import org.junit.Test; -import static org.jabref.logic.autocompleter.AutoCompleterTestUtil.getRequest; +import static org.jabref.gui.autocompleter.AutoCompleterUtil.getRequest; public class BibtexKeyAutoCompleterTest { private BibEntrySuggestionProvider autoCompleter; diff --git a/src/test/java/org/jabref/logic/autocompleter/DefaultAutoCompleterTest.java b/src/test/java/org/jabref/logic/autocompleter/DefaultAutoCompleterTest.java index f56de4c5cc4..b549258031b 100644 --- a/src/test/java/org/jabref/logic/autocompleter/DefaultAutoCompleterTest.java +++ b/src/test/java/org/jabref/logic/autocompleter/DefaultAutoCompleterTest.java @@ -10,7 +10,7 @@ import org.junit.Before; import org.junit.Test; -import static org.jabref.logic.autocompleter.AutoCompleterTestUtil.getRequest; +import static org.jabref.gui.autocompleter.AutoCompleterUtil.getRequest; public class DefaultAutoCompleterTest { diff --git a/src/test/java/org/jabref/logic/autocompleter/FieldValueSuggestionProviderTest.java b/src/test/java/org/jabref/logic/autocompleter/FieldValueSuggestionProviderTest.java index e01bc5c54a2..92075e64428 100644 --- a/src/test/java/org/jabref/logic/autocompleter/FieldValueSuggestionProviderTest.java +++ b/src/test/java/org/jabref/logic/autocompleter/FieldValueSuggestionProviderTest.java @@ -10,7 +10,7 @@ import org.junit.Before; import org.junit.Test; -import static org.jabref.logic.autocompleter.AutoCompleterTestUtil.getRequest; +import static org.jabref.gui.autocompleter.AutoCompleterUtil.getRequest; public class FieldValueSuggestionProviderTest { private FieldValueSuggestionProvider autoCompleter; diff --git a/src/test/java/org/jabref/logic/autocompleter/PersonNameSuggestionProviderTest.java b/src/test/java/org/jabref/logic/autocompleter/PersonNameSuggestionProviderTest.java index 323ec1ba12d..d87b9318baa 100644 --- a/src/test/java/org/jabref/logic/autocompleter/PersonNameSuggestionProviderTest.java +++ b/src/test/java/org/jabref/logic/autocompleter/PersonNameSuggestionProviderTest.java @@ -1,357 +1,279 @@ package org.jabref.logic.autocompleter; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; -import java.util.List; +import org.jabref.model.entry.Author; import org.jabref.model.entry.BibEntry; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.jabref.gui.autocompleter.AutoCompleterUtil.getRequest; public class PersonNameSuggestionProviderTest { - @SuppressWarnings("unused") - @Test(expected = NullPointerException.class) - public void initAutoCompleterWithNullPreferenceThrowsException() { - new PersonNameSuggestionProvider("field", null); - } + PersonNameSuggestionProvider autoCompleter; - @SuppressWarnings("unused") @Test(expected = NullPointerException.class) public void initAutoCompleterWithNullFieldThrowsException() { - new PersonNameSuggestionProvider(null, mock(AutoCompletePreferences.class)); + new PersonNameSuggestionProvider((String) null); + } + + @Before + public void setUp() throws Exception { + autoCompleter = new PersonNameSuggestionProvider("field"); } @Test public void completeWithoutAddingAnythingReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); - - List result = autoCompleter.complete("test"); + Collection result = autoCompleter.call(getRequest(("test"))); Assert.assertEquals(Collections.emptyList(), result); } @Test public void completeAfterAddingNullReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); - - autoCompleter.addBibtexEntry(null); + autoCompleter.indexEntry(null); - List result = autoCompleter.complete("test"); + Collection result = autoCompleter.call(getRequest(("test"))); Assert.assertEquals(Collections.emptyList(), result); } @Test public void completeAfterAddingEmptyEntryReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); - BibEntry entry = new BibEntry(); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexEntry(entry); - List result = autoCompleter.complete("test"); + Collection result = autoCompleter.call(getRequest(("test"))); Assert.assertEquals(Collections.emptyList(), result); } @Test public void completeAfterAddingEntryWithoutFieldReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); - BibEntry entry = new BibEntry(); entry.setField("title", "testTitle"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexEntry(entry); - List result = autoCompleter.complete("test"); + Collection result = autoCompleter.call(getRequest(("test"))); Assert.assertEquals(Collections.emptyList(), result); } @Test public void completeNameReturnsName() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); - BibEntry entry = new BibEntry(); entry.setField("field", "Testname"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexEntry(entry); - List result = autoCompleter.complete("Testname"); + Collection result = autoCompleter.call(getRequest(("Testname"))); Assert.assertEquals(Arrays.asList("Testname"), result); } @Test public void completeBeginnigOfNameReturnsName() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); - BibEntry entry = new BibEntry(); entry.setField("field", "Testname"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexEntry(entry); - List result = autoCompleter.complete("Test"); + Collection result = autoCompleter.call(getRequest(("Test"))); Assert.assertEquals(Arrays.asList("Testname"), result); } @Test public void completeLowercaseNameReturnsName() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); - BibEntry entry = new BibEntry(); entry.setField("field", "Testname"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexEntry(entry); - List result = autoCompleter.complete("test"); + Collection result = autoCompleter.call(getRequest(("test"))); Assert.assertEquals(Arrays.asList("Testname"), result); } @Test public void completeNullReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); - BibEntry entry = new BibEntry(); entry.setField("field", "testKey"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexEntry(entry); - List result = autoCompleter.complete(null); + Collection result = autoCompleter.call(getRequest((null))); Assert.assertEquals(Collections.emptyList(), result); } @Test public void completeEmptyStringReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); - BibEntry entry = new BibEntry(); entry.setField("field", "testKey"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexEntry(entry); - List result = autoCompleter.complete(""); + Collection result = autoCompleter.call(getRequest((""))); Assert.assertEquals(Collections.emptyList(), result); } @Test public void completeReturnsMultipleResults() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); - BibEntry entryOne = new BibEntry(); entryOne.setField("field", "testNameOne"); - autoCompleter.addBibtexEntry(entryOne); + autoCompleter.indexEntry(entryOne); BibEntry entryTwo = new BibEntry(); entryTwo.setField("field", "testNameTwo"); - autoCompleter.addBibtexEntry(entryTwo); + autoCompleter.indexEntry(entryTwo); - List result = autoCompleter.complete("testName"); + Collection result = autoCompleter.call(getRequest(("testName"))); Assert.assertEquals(Arrays.asList("testNameOne", "testNameTwo"), result); } - @Test - public void completeTooShortInputReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - when(preferences.getShortestLengthToComplete()).thenReturn(100); - PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); - - BibEntry entry = new BibEntry(); - entry.setField("field", "Testname"); - autoCompleter.addBibtexEntry(entry); - - List result = autoCompleter.complete("test"); - Assert.assertEquals(Collections.emptyList(), result); - } - @Test public void completePartOfNameReturnsNothing() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); - BibEntry entry = new BibEntry(); entry.setField("field", "Vassilis Kostakos"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexEntry(entry); - List result = autoCompleter.complete("osta"); + Collection result = autoCompleter.call(getRequest(("osta"))); Assert.assertEquals(Collections.emptyList(), result); } @Test public void completeBeginningOfFirstNameReturnsCompleteName() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); - BibEntry entry = new BibEntry(); entry.setField("field", "Vassilis Kostakos"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexEntry(entry); - List result = autoCompleter.complete("Vas"); + Collection result = autoCompleter.call(getRequest(("Vas"))); Assert.assertEquals(Arrays.asList("Vassilis Kostakos"), result); } @Test public void completeBeginningOfFirstNameReturnsCompleteNameWithJr() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); - BibEntry entry = new BibEntry(); entry.setField("field", "Reagle, Jr., Joseph M."); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexEntry(entry); - List result = autoCompleter.complete("Jos"); + Collection result = autoCompleter.call(getRequest(("Jos"))); Assert.assertEquals(Arrays.asList("Joseph M. Reagle, Jr."), result); } @Test public void completeBeginningOfFirstNameReturnsCompleteNameWithVon() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); - BibEntry entry = new BibEntry(); entry.setField("field", "Eric von Hippel"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexEntry(entry); - List result = autoCompleter.complete("Eric"); + Collection result = autoCompleter.call(getRequest(("Eric"))); Assert.assertEquals(Arrays.asList("Eric von Hippel"), result); } @Test public void completeBeginningOfLastNameReturnsNameWithUmlauts() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - when(preferences.getFirstnameMode()).thenReturn(AutoCompleteFirstNameMode.ONLY_FULL); - PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); + //when(preferences.getFirstnameMode()).thenReturn(AutoCompleteFirstNameMode.ONLY_FULL); BibEntry entry = new BibEntry(); entry.setField("field", "Honig Bär"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexEntry(entry); - List result = autoCompleter.complete("Bä"); + Collection result = autoCompleter.call(getRequest(("Bä"))); Assert.assertEquals(Arrays.asList("Bär, Honig"), result); } @Test public void completeBeginningOfLastNameReturnsNameAndNameWithInitialFirstname() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); - BibEntry entry = new BibEntry(); entry.setField("field", "Vassilis Kostakos"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexEntry(entry); - List result = autoCompleter.complete("Kosta"); + Collection result = autoCompleter.call(getRequest(("Kosta"))); Assert.assertEquals(Arrays.asList("Kostakos, V.", "Kostakos, Vassilis"), result); } @Test public void completeBeginningOfLastNameReturnsNameIfPref() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - when(preferences.getFirstnameMode()).thenReturn(AutoCompleteFirstNameMode.ONLY_FULL); - PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); + //when(preferences.getFirstnameMode()).thenReturn(AutoCompleteFirstNameMode.ONLY_FULL); BibEntry entry = new BibEntry(); entry.setField("field", "Vassilis Kostakos"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexEntry(entry); - List result = autoCompleter.complete("Kosta"); + Collection result = autoCompleter.call(getRequest(("Kosta"))); Assert.assertEquals(Arrays.asList("Kostakos, Vassilis"), result); } @Test public void completeBeginningOfLastNameReturnsNameWithJrIfPref() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - when(preferences.getFirstnameMode()).thenReturn(AutoCompleteFirstNameMode.ONLY_ABBREVIATED); - PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); + //when(preferences.getFirstnameMode()).thenReturn(AutoCompleteFirstNameMode.ONLY_ABBREVIATED); BibEntry entry = new BibEntry(); entry.setField("field", "Reagle, Jr., Joseph M."); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexEntry(entry); - List result = autoCompleter.complete("Rea"); + Collection result = autoCompleter.call(getRequest(("Rea"))); Assert.assertEquals(Arrays.asList("Reagle, Jr., J. M."), result); } @Test public void completeBeginningOfLastNameReturnsNameWithInitialFirstnameIfPref() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - when(preferences.getFirstnameMode()).thenReturn(AutoCompleteFirstNameMode.ONLY_ABBREVIATED); - PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); + //when(preferences.getFirstnameMode()).thenReturn(AutoCompleteFirstNameMode.ONLY_ABBREVIATED); BibEntry entry = new BibEntry(); entry.setField("field", "Vassilis Kostakos"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexEntry(entry); - List result = autoCompleter.complete("Kosta"); + Collection result = autoCompleter.call(getRequest(("Kosta"))); Assert.assertEquals(Arrays.asList("Kostakos, V."), result); } @Test public void completeVonReturnsNameWithInitialFirstnameIfPref() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - when(preferences.getFirstnameMode()).thenReturn(AutoCompleteFirstNameMode.ONLY_ABBREVIATED); - PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); + //when(preferences.getFirstnameMode()).thenReturn(AutoCompleteFirstNameMode.ONLY_ABBREVIATED); BibEntry entry = new BibEntry(); entry.setField("field", "Eric von Hippel"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexEntry(entry); - List result = autoCompleter.complete("von"); + Collection result = autoCompleter.call(getRequest(("von"))); Assert.assertEquals(Arrays.asList("von Hippel, E."), result); } @Test public void completeBeginningOfNameReturnsCompleteName() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); - BibEntry entry = new BibEntry(); entry.setField("field", "Vassilis Kostakos"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexEntry(entry); - List result = autoCompleter.complete("Kostakos, Va"); + Collection result = autoCompleter.call(getRequest(("Kostakos, Va"))); Assert.assertEquals(Arrays.asList("Kostakos, Vassilis"), result); } @Test public void completeBeginningOfLastNameReturnsNothingIfPref() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - when(preferences.getOnlyCompleteFirstLast()).thenReturn(true); - PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); + //when(preferences.getOnlyCompleteFirstLast()).thenReturn(true); BibEntry entry = new BibEntry(); entry.setField("field", "Vassilis Kostakos"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexEntry(entry); - List result = autoCompleter.complete("Kosta"); + Collection result = autoCompleter.call(getRequest(("Kosta"))); Assert.assertEquals(Collections.emptyList(), result); } @Test public void completeBeginningOfFirstNameReturnsNothingIfPref() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - when(preferences.getOnlyCompleteLastFirst()).thenReturn(true); - PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); + //when(preferences.getOnlyCompleteLastFirst()).thenReturn(true); BibEntry entry = new BibEntry(); entry.setField("field", "Vassilis Kostakos"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexEntry(entry); - List result = autoCompleter.complete("Vas"); + Collection result = autoCompleter.call(getRequest(("Vas"))); Assert.assertEquals(Collections.emptyList(), result); } @Test public void completeShortNameReturnsName() { - AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); - PersonNameSuggestionProvider autoCompleter = new PersonNameSuggestionProvider("field", preferences); - BibEntry entry = new BibEntry(); entry.setField("field", "nam"); - autoCompleter.addBibtexEntry(entry); + autoCompleter.indexEntry(entry); - List result = autoCompleter.complete("n"); + Collection result = autoCompleter.call(getRequest(("n"))); Assert.assertEquals(Arrays.asList("nam"), result); } } From 0841920ba29f1679a906408b20f594e73fb209e9 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Tue, 4 Jul 2017 20:50:10 +0200 Subject: [PATCH 06/10] Move auto completion support completely to gui package --- src/main/java/org/jabref/gui/BasePanel.java | 10 +++++----- .../autocompleter/AutoCompleteFirstNameMode.java | 2 +- .../jabref/gui/autocompleter/AutoCompleteListener.java | 2 -- .../autocompleter/AutoCompletePreferences.java | 10 +++++----- .../autocompleter/AutoCompleteSuggestionProvider.java | 2 +- .../jabref/gui/autocompleter/AutoCompleteSupport.java | 2 -- .../autocompleter/AutoCompleteUpdater.java} | 6 +++--- .../autocompleter/BibEntrySuggestionProvider.java | 2 +- .../ContentSelectorSuggestionProvider.java | 2 +- .../autocompleter/FieldValueSuggestionProvider.java | 2 +- .../autocompleter/JournalsSuggestionProvider.java | 2 +- .../autocompleter/PersonNameStringConverter.java | 2 +- .../autocompleter/PersonNameSuggestionProvider.java | 2 +- .../autocompleter/StringSuggestionProvider.java | 2 +- .../autocompleter/SuggestionProviders.java | 2 +- .../autocompleter/WordSuggestionProvider.java | 2 +- .../gui/fieldeditors/AbstractEditorViewModel.java | 2 +- .../java/org/jabref/gui/fieldeditors/DateEditor.java | 2 +- .../jabref/gui/fieldeditors/DateEditorViewModel.java | 2 +- .../gui/fieldeditors/EditorTypeEditorViewModel.java | 2 +- .../java/org/jabref/gui/fieldeditors/FieldEditors.java | 6 +++--- .../jabref/gui/fieldeditors/GenderEditorViewModel.java | 2 +- .../org/jabref/gui/fieldeditors/IdentifierEditor.java | 2 +- .../gui/fieldeditors/IdentifierEditorViewModel.java | 2 +- .../org/jabref/gui/fieldeditors/JournalEditor.java | 2 +- .../gui/fieldeditors/JournalEditorViewModel.java | 2 +- .../jabref/gui/fieldeditors/LinkedEntriesEditor.java | 2 +- .../gui/fieldeditors/LinkedEntriesEditorViewModel.java | 2 +- .../org/jabref/gui/fieldeditors/LinkedFilesEditor.java | 2 +- .../gui/fieldeditors/LinkedFilesEditorViewModel.java | 2 +- .../gui/fieldeditors/MapBasedEditorViewModel.java | 2 +- .../jabref/gui/fieldeditors/MonthEditorViewModel.java | 2 +- .../jabref/gui/fieldeditors/OptionEditorViewModel.java | 2 +- .../java/org/jabref/gui/fieldeditors/OwnerEditor.java | 2 +- .../jabref/gui/fieldeditors/OwnerEditorViewModel.java | 2 +- .../gui/fieldeditors/PaginationEditorViewModel.java | 2 +- .../gui/fieldeditors/PatentTypeEditorViewModel.java | 2 +- .../org/jabref/gui/fieldeditors/PersonsEditor.java | 4 ++-- .../gui/fieldeditors/PersonsEditorViewModel.java | 6 +++--- .../java/org/jabref/gui/fieldeditors/SimpleEditor.java | 2 +- .../jabref/gui/fieldeditors/SimpleEditorViewModel.java | 2 +- .../jabref/gui/fieldeditors/TypeEditorViewModel.java | 2 +- .../java/org/jabref/gui/fieldeditors/UrlEditor.java | 2 +- .../jabref/gui/fieldeditors/UrlEditorViewModel.java | 2 +- .../jabref/gui/fieldeditors/YesNoEditorViewModel.java | 2 +- .../org/jabref/gui/preftabs/EntryEditorPrefsTab.java | 4 ++-- .../java/org/jabref/gui/search/GlobalSearchBar.java | 2 +- .../java/org/jabref/preferences/JabRefPreferences.java | 2 +- .../autocompleter/BibtexKeyAutoCompleterTest.java | 2 +- .../autocompleter/DefaultAutoCompleterTest.java | 2 +- .../FieldValueSuggestionProviderTest.java | 2 +- .../PersonNameSuggestionProviderTest.java | 2 +- .../fieldeditors/IdentifierEditorViewModelTest.java | 2 +- 53 files changed, 67 insertions(+), 71 deletions(-) rename src/main/java/org/jabref/{logic => gui}/autocompleter/AutoCompleteFirstNameMode.java (68%) rename src/main/java/org/jabref/{logic => gui}/autocompleter/AutoCompletePreferences.java (98%) rename src/main/java/org/jabref/{logic => gui}/autocompleter/AutoCompleteSuggestionProvider.java (89%) rename src/main/java/org/jabref/{logic/autocompleter/AutoCompleteListener.java => gui/autocompleter/AutoCompleteUpdater.java} (81%) rename src/main/java/org/jabref/{logic => gui}/autocompleter/BibEntrySuggestionProvider.java (96%) rename src/main/java/org/jabref/{logic => gui}/autocompleter/ContentSelectorSuggestionProvider.java (96%) rename src/main/java/org/jabref/{logic => gui}/autocompleter/FieldValueSuggestionProvider.java (93%) rename src/main/java/org/jabref/{logic => gui}/autocompleter/JournalsSuggestionProvider.java (95%) rename src/main/java/org/jabref/{logic => gui}/autocompleter/PersonNameStringConverter.java (98%) rename src/main/java/org/jabref/{logic => gui}/autocompleter/PersonNameSuggestionProvider.java (97%) rename src/main/java/org/jabref/{logic => gui}/autocompleter/StringSuggestionProvider.java (95%) rename src/main/java/org/jabref/{logic => gui}/autocompleter/SuggestionProviders.java (98%) rename src/main/java/org/jabref/{logic => gui}/autocompleter/WordSuggestionProvider.java (95%) rename src/test/java/org/jabref/{logic => gui}/autocompleter/BibtexKeyAutoCompleterTest.java (98%) rename src/test/java/org/jabref/{logic => gui}/autocompleter/DefaultAutoCompleterTest.java (99%) rename src/test/java/org/jabref/{logic => gui}/autocompleter/FieldValueSuggestionProviderTest.java (99%) rename src/test/java/org/jabref/{logic => gui}/autocompleter/PersonNameSuggestionProviderTest.java (99%) diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 362bd98193a..23eade23fff 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -50,6 +50,10 @@ import org.jabref.gui.actions.BaseAction; import org.jabref.gui.actions.CleanupAction; import org.jabref.gui.actions.CopyBibTeXKeyAndLinkAction; +import org.jabref.gui.autocompleter.AutoCompletePreferences; +import org.jabref.gui.autocompleter.AutoCompleteUpdater; +import org.jabref.gui.autocompleter.PersonNameSuggestionProvider; +import org.jabref.gui.autocompleter.SuggestionProviders; import org.jabref.gui.bibtexkeypattern.SearchFixDuplicateLabels; import org.jabref.gui.contentselector.ContentSelectorDialog; import org.jabref.gui.desktop.JabRefDesktop; @@ -96,10 +100,6 @@ import org.jabref.gui.worker.CitationStyleToClipboardWorker; import org.jabref.gui.worker.MarkEntriesAction; import org.jabref.gui.worker.SendAsEMailAction; -import org.jabref.logic.autocompleter.AutoCompleteListener; -import org.jabref.logic.autocompleter.AutoCompletePreferences; -import org.jabref.logic.autocompleter.PersonNameSuggestionProvider; -import org.jabref.logic.autocompleter.SuggestionProviders; import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; import org.jabref.logic.citationstyle.CitationStyleCache; import org.jabref.logic.citationstyle.CitationStyleOutputFormat; @@ -1392,7 +1392,7 @@ private void setupAutoCompletion() { suggestionProviders = new SuggestionProviders(autoCompletePreferences, Globals.journalAbbreviationLoader); suggestionProviders.indexDatabase(getDatabase()); // Ensure that the suggestion providers are in sync with entries - this.getDatabase().registerListener(new AutoCompleteListener(suggestionProviders)); + this.getDatabase().registerListener(new AutoCompleteUpdater(suggestionProviders)); } else { // Create empty suggestion providers if auto completion is deactivated suggestionProviders = new SuggestionProviders(); diff --git a/src/main/java/org/jabref/logic/autocompleter/AutoCompleteFirstNameMode.java b/src/main/java/org/jabref/gui/autocompleter/AutoCompleteFirstNameMode.java similarity index 68% rename from src/main/java/org/jabref/logic/autocompleter/AutoCompleteFirstNameMode.java rename to src/main/java/org/jabref/gui/autocompleter/AutoCompleteFirstNameMode.java index b9e4e3e8c18..d31b52997a0 100644 --- a/src/main/java/org/jabref/logic/autocompleter/AutoCompleteFirstNameMode.java +++ b/src/main/java/org/jabref/gui/autocompleter/AutoCompleteFirstNameMode.java @@ -1,4 +1,4 @@ -package org.jabref.logic.autocompleter; +package org.jabref.gui.autocompleter; public enum AutoCompleteFirstNameMode { ONLY_FULL, diff --git a/src/main/java/org/jabref/gui/autocompleter/AutoCompleteListener.java b/src/main/java/org/jabref/gui/autocompleter/AutoCompleteListener.java index 03cfaec0b0a..644219afe4a 100644 --- a/src/main/java/org/jabref/gui/autocompleter/AutoCompleteListener.java +++ b/src/main/java/org/jabref/gui/autocompleter/AutoCompleteListener.java @@ -11,8 +11,6 @@ import javax.swing.text.BadLocationException; import javax.swing.text.JTextComponent; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/src/main/java/org/jabref/logic/autocompleter/AutoCompletePreferences.java b/src/main/java/org/jabref/gui/autocompleter/AutoCompletePreferences.java similarity index 98% rename from src/main/java/org/jabref/logic/autocompleter/AutoCompletePreferences.java rename to src/main/java/org/jabref/gui/autocompleter/AutoCompletePreferences.java index 36c95725f5f..05e0f5682e1 100644 --- a/src/main/java/org/jabref/logic/autocompleter/AutoCompletePreferences.java +++ b/src/main/java/org/jabref/gui/autocompleter/AutoCompletePreferences.java @@ -1,4 +1,4 @@ -package org.jabref.logic.autocompleter; +package org.jabref.gui.autocompleter; import java.util.List; import java.util.Map; @@ -76,14 +76,14 @@ public List getCompleteNames() { return preferences.getStringList(AUTOCOMPLETER_COMPLETE_FIELDS); } - public String getCompleteNamesAsString() { - return preferences.get(AUTOCOMPLETER_COMPLETE_FIELDS); - } - public void setCompleteNames(String value) { preferences.put(AUTOCOMPLETER_COMPLETE_FIELDS, value); } + public String getCompleteNamesAsString() { + return preferences.get(AUTOCOMPLETER_COMPLETE_FIELDS); + } + public JournalAbbreviationPreferences getJournalAbbreviationPreferences() { return preferences.getJournalAbbreviationPreferences(); } diff --git a/src/main/java/org/jabref/logic/autocompleter/AutoCompleteSuggestionProvider.java b/src/main/java/org/jabref/gui/autocompleter/AutoCompleteSuggestionProvider.java similarity index 89% rename from src/main/java/org/jabref/logic/autocompleter/AutoCompleteSuggestionProvider.java rename to src/main/java/org/jabref/gui/autocompleter/AutoCompleteSuggestionProvider.java index ea2e557a65e..1f188238191 100644 --- a/src/main/java/org/jabref/logic/autocompleter/AutoCompleteSuggestionProvider.java +++ b/src/main/java/org/jabref/gui/autocompleter/AutoCompleteSuggestionProvider.java @@ -1,4 +1,4 @@ -package org.jabref.logic.autocompleter; +package org.jabref.gui.autocompleter; import java.util.Collection; diff --git a/src/main/java/org/jabref/gui/autocompleter/AutoCompleteSupport.java b/src/main/java/org/jabref/gui/autocompleter/AutoCompleteSupport.java index c40adf6571b..2c952f9c50c 100644 --- a/src/main/java/org/jabref/gui/autocompleter/AutoCompleteSupport.java +++ b/src/main/java/org/jabref/gui/autocompleter/AutoCompleteSupport.java @@ -20,8 +20,6 @@ import javax.swing.event.PopupMenuListener; import javax.swing.text.JTextComponent; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; - /** * Endows a textbox with the ability to autocomplete the input. Based on code by Santhosh Kumar * (http://www.jroller.com/santhosh/date/20050620) James Lemieux (Glazed Lists AutoCompleteSupport) diff --git a/src/main/java/org/jabref/logic/autocompleter/AutoCompleteListener.java b/src/main/java/org/jabref/gui/autocompleter/AutoCompleteUpdater.java similarity index 81% rename from src/main/java/org/jabref/logic/autocompleter/AutoCompleteListener.java rename to src/main/java/org/jabref/gui/autocompleter/AutoCompleteUpdater.java index 728e4545cc7..7fe7fec4aba 100644 --- a/src/main/java/org/jabref/logic/autocompleter/AutoCompleteListener.java +++ b/src/main/java/org/jabref/gui/autocompleter/AutoCompleteUpdater.java @@ -1,4 +1,4 @@ -package org.jabref.logic.autocompleter; +package org.jabref.gui.autocompleter; import org.jabref.model.database.event.EntryAddedEvent; import org.jabref.model.entry.event.EntryChangedEvent; @@ -8,11 +8,11 @@ /** * Ensures that suggestion providers are up to date when entries are changed or added. */ -public class AutoCompleteListener { +public class AutoCompleteUpdater { private final SuggestionProviders suggestionProviders; - public AutoCompleteListener(SuggestionProviders suggestionProviders) { + public AutoCompleteUpdater(SuggestionProviders suggestionProviders) { this.suggestionProviders = suggestionProviders; } diff --git a/src/main/java/org/jabref/logic/autocompleter/BibEntrySuggestionProvider.java b/src/main/java/org/jabref/gui/autocompleter/BibEntrySuggestionProvider.java similarity index 96% rename from src/main/java/org/jabref/logic/autocompleter/BibEntrySuggestionProvider.java rename to src/main/java/org/jabref/gui/autocompleter/BibEntrySuggestionProvider.java index 0817e9639bc..99532aff197 100644 --- a/src/main/java/org/jabref/logic/autocompleter/BibEntrySuggestionProvider.java +++ b/src/main/java/org/jabref/gui/autocompleter/BibEntrySuggestionProvider.java @@ -1,4 +1,4 @@ -package org.jabref.logic.autocompleter; +package org.jabref.gui.autocompleter; import java.util.Comparator; diff --git a/src/main/java/org/jabref/logic/autocompleter/ContentSelectorSuggestionProvider.java b/src/main/java/org/jabref/gui/autocompleter/ContentSelectorSuggestionProvider.java similarity index 96% rename from src/main/java/org/jabref/logic/autocompleter/ContentSelectorSuggestionProvider.java rename to src/main/java/org/jabref/gui/autocompleter/ContentSelectorSuggestionProvider.java index 2a7bbd83724..085b997108c 100644 --- a/src/main/java/org/jabref/logic/autocompleter/ContentSelectorSuggestionProvider.java +++ b/src/main/java/org/jabref/gui/autocompleter/ContentSelectorSuggestionProvider.java @@ -1,4 +1,4 @@ -package org.jabref.logic.autocompleter; +package org.jabref.gui.autocompleter; import java.util.ArrayList; import java.util.Collection; diff --git a/src/main/java/org/jabref/logic/autocompleter/FieldValueSuggestionProvider.java b/src/main/java/org/jabref/gui/autocompleter/FieldValueSuggestionProvider.java similarity index 93% rename from src/main/java/org/jabref/logic/autocompleter/FieldValueSuggestionProvider.java rename to src/main/java/org/jabref/gui/autocompleter/FieldValueSuggestionProvider.java index f713a101c23..871723b2cd7 100644 --- a/src/main/java/org/jabref/logic/autocompleter/FieldValueSuggestionProvider.java +++ b/src/main/java/org/jabref/gui/autocompleter/FieldValueSuggestionProvider.java @@ -1,4 +1,4 @@ -package org.jabref.logic.autocompleter; +package org.jabref.gui.autocompleter; import java.util.Objects; diff --git a/src/main/java/org/jabref/logic/autocompleter/JournalsSuggestionProvider.java b/src/main/java/org/jabref/gui/autocompleter/JournalsSuggestionProvider.java similarity index 95% rename from src/main/java/org/jabref/logic/autocompleter/JournalsSuggestionProvider.java rename to src/main/java/org/jabref/gui/autocompleter/JournalsSuggestionProvider.java index a6ce494c597..f0749e3c7c7 100644 --- a/src/main/java/org/jabref/logic/autocompleter/JournalsSuggestionProvider.java +++ b/src/main/java/org/jabref/gui/autocompleter/JournalsSuggestionProvider.java @@ -1,4 +1,4 @@ -package org.jabref.logic.autocompleter; +package org.jabref.gui.autocompleter; import java.util.List; import java.util.stream.Collectors; diff --git a/src/main/java/org/jabref/logic/autocompleter/PersonNameStringConverter.java b/src/main/java/org/jabref/gui/autocompleter/PersonNameStringConverter.java similarity index 98% rename from src/main/java/org/jabref/logic/autocompleter/PersonNameStringConverter.java rename to src/main/java/org/jabref/gui/autocompleter/PersonNameStringConverter.java index f3f55ca8131..7ce9cd9ca2f 100644 --- a/src/main/java/org/jabref/logic/autocompleter/PersonNameStringConverter.java +++ b/src/main/java/org/jabref/gui/autocompleter/PersonNameStringConverter.java @@ -1,4 +1,4 @@ -package org.jabref.logic.autocompleter; +package org.jabref.gui.autocompleter; import javafx.util.StringConverter; diff --git a/src/main/java/org/jabref/logic/autocompleter/PersonNameSuggestionProvider.java b/src/main/java/org/jabref/gui/autocompleter/PersonNameSuggestionProvider.java similarity index 97% rename from src/main/java/org/jabref/logic/autocompleter/PersonNameSuggestionProvider.java rename to src/main/java/org/jabref/gui/autocompleter/PersonNameSuggestionProvider.java index 941c548ad7a..4e813759e75 100644 --- a/src/main/java/org/jabref/logic/autocompleter/PersonNameSuggestionProvider.java +++ b/src/main/java/org/jabref/gui/autocompleter/PersonNameSuggestionProvider.java @@ -1,4 +1,4 @@ -package org.jabref.logic.autocompleter; +package org.jabref.gui.autocompleter; import java.util.Collections; import java.util.Comparator; diff --git a/src/main/java/org/jabref/logic/autocompleter/StringSuggestionProvider.java b/src/main/java/org/jabref/gui/autocompleter/StringSuggestionProvider.java similarity index 95% rename from src/main/java/org/jabref/logic/autocompleter/StringSuggestionProvider.java rename to src/main/java/org/jabref/gui/autocompleter/StringSuggestionProvider.java index 093161dbe63..c25d05e2080 100644 --- a/src/main/java/org/jabref/logic/autocompleter/StringSuggestionProvider.java +++ b/src/main/java/org/jabref/gui/autocompleter/StringSuggestionProvider.java @@ -1,4 +1,4 @@ -package org.jabref.logic.autocompleter; +package org.jabref.gui.autocompleter; import java.util.Comparator; diff --git a/src/main/java/org/jabref/logic/autocompleter/SuggestionProviders.java b/src/main/java/org/jabref/gui/autocompleter/SuggestionProviders.java similarity index 98% rename from src/main/java/org/jabref/logic/autocompleter/SuggestionProviders.java rename to src/main/java/org/jabref/gui/autocompleter/SuggestionProviders.java index 20c6c3fde26..a2ea193f5ca 100644 --- a/src/main/java/org/jabref/logic/autocompleter/SuggestionProviders.java +++ b/src/main/java/org/jabref/gui/autocompleter/SuggestionProviders.java @@ -1,4 +1,4 @@ -package org.jabref.logic.autocompleter; +package org.jabref.gui.autocompleter; import java.util.HashMap; import java.util.List; diff --git a/src/main/java/org/jabref/logic/autocompleter/WordSuggestionProvider.java b/src/main/java/org/jabref/gui/autocompleter/WordSuggestionProvider.java similarity index 95% rename from src/main/java/org/jabref/logic/autocompleter/WordSuggestionProvider.java rename to src/main/java/org/jabref/gui/autocompleter/WordSuggestionProvider.java index f0e584bd84a..0f9c2ec56fa 100644 --- a/src/main/java/org/jabref/logic/autocompleter/WordSuggestionProvider.java +++ b/src/main/java/org/jabref/gui/autocompleter/WordSuggestionProvider.java @@ -1,4 +1,4 @@ -package org.jabref.logic.autocompleter; +package org.jabref.gui.autocompleter; import java.util.Objects; import java.util.StringTokenizer; diff --git a/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java index 1aa4aa66e1d..80d61cfaa3b 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java @@ -6,8 +6,8 @@ import javafx.beans.property.StringProperty; import org.jabref.gui.AbstractViewModel; +import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.gui.util.BindingsHelper; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.model.entry.BibEntry; import org.controlsfx.control.textfield.AutoCompletionBinding; diff --git a/src/main/java/org/jabref/gui/fieldeditors/DateEditor.java b/src/main/java/org/jabref/gui/fieldeditors/DateEditor.java index e2ce259b3ad..65a1dbcce55 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/DateEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/DateEditor.java @@ -6,9 +6,9 @@ import javafx.scene.Parent; import javafx.scene.layout.HBox; +import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.gui.util.ControlHelper; import org.jabref.gui.util.component.TemporalAccessorPicker; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.model.entry.BibEntry; public class DateEditor extends HBox implements FieldEditorFX { diff --git a/src/main/java/org/jabref/gui/fieldeditors/DateEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/DateEditorViewModel.java index fec3f7a0687..9346963f799 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/DateEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/DateEditorViewModel.java @@ -6,7 +6,7 @@ import javafx.util.StringConverter; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; +import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.model.entry.Date; import org.jabref.model.strings.StringUtil; diff --git a/src/main/java/org/jabref/gui/fieldeditors/EditorTypeEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/EditorTypeEditorViewModel.java index 00413673d5c..118430fea4b 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/EditorTypeEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/EditorTypeEditorViewModel.java @@ -1,6 +1,6 @@ package org.jabref.gui.fieldeditors; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; +import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.logic.l10n.Localization; import com.google.common.collect.BiMap; diff --git a/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java b/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java index f8827c4a748..80144bbaae8 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java +++ b/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java @@ -5,10 +5,10 @@ import org.jabref.Globals; import org.jabref.gui.DialogService; +import org.jabref.gui.autocompleter.AutoCompletePreferences; +import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; +import org.jabref.gui.autocompleter.SuggestionProviders; import org.jabref.gui.util.TaskExecutor; -import org.jabref.logic.autocompleter.AutoCompletePreferences; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; -import org.jabref.logic.autocompleter.SuggestionProviders; import org.jabref.logic.journals.JournalAbbreviationLoader; import org.jabref.logic.journals.JournalAbbreviationPreferences; import org.jabref.model.database.BibDatabaseContext; diff --git a/src/main/java/org/jabref/gui/fieldeditors/GenderEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/GenderEditorViewModel.java index af368bed751..8678807cb0b 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/GenderEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/GenderEditorViewModel.java @@ -1,6 +1,6 @@ package org.jabref.gui.fieldeditors; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; +import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.logic.l10n.Localization; import com.google.common.collect.BiMap; diff --git a/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditor.java b/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditor.java index 12a2b14a4f8..49640668bae 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditor.java @@ -13,10 +13,10 @@ import javafx.scene.layout.HBox; import org.jabref.gui.DialogService; +import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.gui.fieldeditors.contextmenu.EditorMenus; import org.jabref.gui.util.ControlHelper; import org.jabref.gui.util.TaskExecutor; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.FieldName; diff --git a/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java index 0f882c10b88..850d041c827 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java @@ -9,11 +9,11 @@ import javafx.beans.property.SimpleObjectProperty; import org.jabref.gui.DialogService; +import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.gui.mergeentries.FetchAndMergeEntry; import org.jabref.gui.util.BackgroundTask; import org.jabref.gui.util.TaskExecutor; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.logic.importer.WebFetchers; import org.jabref.logic.importer.util.IdentifierParser; import org.jabref.logic.l10n.Localization; diff --git a/src/main/java/org/jabref/gui/fieldeditors/JournalEditor.java b/src/main/java/org/jabref/gui/fieldeditors/JournalEditor.java index 153e01a3c4e..8d652c7cdaf 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/JournalEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/JournalEditor.java @@ -7,9 +7,9 @@ import javafx.scene.Parent; import javafx.scene.layout.HBox; +import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.gui.fieldeditors.contextmenu.EditorMenus; import org.jabref.gui.util.ControlHelper; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.logic.journals.JournalAbbreviationLoader; import org.jabref.logic.journals.JournalAbbreviationPreferences; import org.jabref.model.entry.BibEntry; diff --git a/src/main/java/org/jabref/gui/fieldeditors/JournalEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/JournalEditorViewModel.java index e0c20118716..278f6c955f2 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/JournalEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/JournalEditorViewModel.java @@ -2,7 +2,7 @@ import java.util.Optional; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; +import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.logic.journals.JournalAbbreviationLoader; import org.jabref.logic.journals.JournalAbbreviationPreferences; import org.jabref.logic.journals.JournalAbbreviationRepository; diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditor.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditor.java index 8356e08971b..f90dc27a89e 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditor.java @@ -5,9 +5,9 @@ import javafx.scene.Parent; import javafx.scene.layout.HBox; +import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.gui.util.ControlHelper; import org.jabref.gui.util.component.TagBar; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.ParsedEntryLink; diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditorViewModel.java index 60b9b14a0c9..dce4a28b009 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditorViewModel.java @@ -5,8 +5,8 @@ import javafx.collections.FXCollections; import javafx.util.StringConverter; +import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.gui.util.BindingsHelper; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.EntryLinkList; import org.jabref.model.entry.ParsedEntryLink; diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java index 3f4b29e679f..b02d6ff4598 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java @@ -22,11 +22,11 @@ import org.jabref.Globals; import org.jabref.gui.DialogService; +import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.gui.util.ControlHelper; import org.jabref.gui.util.TaskExecutor; import org.jabref.gui.util.ViewModelListCellFactory; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java index d3908ccba48..6f8c683d9f2 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java @@ -19,6 +19,7 @@ import org.jabref.Globals; import org.jabref.gui.DialogService; +import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.gui.externalfiles.DownloadExternalFile; import org.jabref.gui.externalfiles.FileDownloadTask; import org.jabref.gui.externalfiletype.ExternalFileType; @@ -28,7 +29,6 @@ import org.jabref.gui.util.BindingsHelper; import org.jabref.gui.util.FileDialogConfiguration; import org.jabref.gui.util.TaskExecutor; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.logic.importer.FulltextFetchers; import org.jabref.logic.l10n.Localization; import org.jabref.logic.net.URLDownload; diff --git a/src/main/java/org/jabref/gui/fieldeditors/MapBasedEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/MapBasedEditorViewModel.java index e76087268d1..8fd185db2f3 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/MapBasedEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/MapBasedEditorViewModel.java @@ -5,7 +5,7 @@ import javafx.util.StringConverter; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; +import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import com.google.common.collect.BiMap; diff --git a/src/main/java/org/jabref/gui/fieldeditors/MonthEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/MonthEditorViewModel.java index edf37221cbb..49c3c1592e5 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/MonthEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/MonthEditorViewModel.java @@ -5,7 +5,7 @@ import javafx.util.StringConverter; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; +import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.Month; import org.jabref.model.strings.StringUtil; diff --git a/src/main/java/org/jabref/gui/fieldeditors/OptionEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/OptionEditorViewModel.java index f4d7ffe50fc..4bafb4de7c8 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/OptionEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/OptionEditorViewModel.java @@ -4,7 +4,7 @@ import javafx.util.StringConverter; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; +import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; public abstract class OptionEditorViewModel extends AbstractEditorViewModel { diff --git a/src/main/java/org/jabref/gui/fieldeditors/OwnerEditor.java b/src/main/java/org/jabref/gui/fieldeditors/OwnerEditor.java index d4e8fd31aeb..ea869e1cf9e 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/OwnerEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/OwnerEditor.java @@ -5,8 +5,8 @@ import javafx.scene.Parent; import javafx.scene.layout.HBox; +import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.gui.util.ControlHelper; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.model.entry.BibEntry; import org.jabref.preferences.JabRefPreferences; diff --git a/src/main/java/org/jabref/gui/fieldeditors/OwnerEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/OwnerEditorViewModel.java index dded357ae6b..7c2bef29fae 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/OwnerEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/OwnerEditorViewModel.java @@ -1,6 +1,6 @@ package org.jabref.gui.fieldeditors; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; +import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.preferences.JabRefPreferences; public class OwnerEditorViewModel extends AbstractEditorViewModel { diff --git a/src/main/java/org/jabref/gui/fieldeditors/PaginationEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/PaginationEditorViewModel.java index 9bc3db6ec56..2b51e82266e 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/PaginationEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/PaginationEditorViewModel.java @@ -1,6 +1,6 @@ package org.jabref.gui.fieldeditors; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; +import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.logic.l10n.Localization; import com.google.common.collect.BiMap; diff --git a/src/main/java/org/jabref/gui/fieldeditors/PatentTypeEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/PatentTypeEditorViewModel.java index e9361e77f80..5523efe3cb6 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/PatentTypeEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/PatentTypeEditorViewModel.java @@ -1,6 +1,6 @@ package org.jabref.gui.fieldeditors; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; +import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.logic.l10n.Localization; import com.google.common.collect.BiMap; diff --git a/src/main/java/org/jabref/gui/fieldeditors/PersonsEditor.java b/src/main/java/org/jabref/gui/fieldeditors/PersonsEditor.java index bc438c16aed..36dd9ed425c 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/PersonsEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/PersonsEditor.java @@ -5,10 +5,10 @@ import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; +import org.jabref.gui.autocompleter.AutoCompletePreferences; +import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.gui.autocompleter.AutoCompletionTextInputBinding; import org.jabref.gui.fieldeditors.contextmenu.EditorMenus; -import org.jabref.logic.autocompleter.AutoCompletePreferences; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.model.entry.BibEntry; public class PersonsEditor extends HBox implements FieldEditorFX { diff --git a/src/main/java/org/jabref/gui/fieldeditors/PersonsEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/PersonsEditorViewModel.java index 79747169244..c41ac32773e 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/PersonsEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/PersonsEditorViewModel.java @@ -5,10 +5,10 @@ import javafx.util.StringConverter; import org.jabref.gui.autocompleter.AppendPersonNamesStrategy; +import org.jabref.gui.autocompleter.AutoCompletePreferences; +import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.gui.autocompleter.AutoCompletionStrategy; -import org.jabref.logic.autocompleter.AutoCompletePreferences; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; -import org.jabref.logic.autocompleter.PersonNameStringConverter; +import org.jabref.gui.autocompleter.PersonNameStringConverter; import org.jabref.model.entry.Author; import org.controlsfx.control.textfield.AutoCompletionBinding; diff --git a/src/main/java/org/jabref/gui/fieldeditors/SimpleEditor.java b/src/main/java/org/jabref/gui/fieldeditors/SimpleEditor.java index deb799f4862..876e4e48157 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/SimpleEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/SimpleEditor.java @@ -5,9 +5,9 @@ import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; +import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.gui.autocompleter.AutoCompletionTextInputBinding; import org.jabref.gui.fieldeditors.contextmenu.EditorMenus; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.model.entry.BibEntry; public class SimpleEditor extends HBox implements FieldEditorFX { diff --git a/src/main/java/org/jabref/gui/fieldeditors/SimpleEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/SimpleEditorViewModel.java index 2606072f330..5bb5bdb77f6 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/SimpleEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/SimpleEditorViewModel.java @@ -1,6 +1,6 @@ package org.jabref.gui.fieldeditors; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; +import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; public class SimpleEditorViewModel extends AbstractEditorViewModel { diff --git a/src/main/java/org/jabref/gui/fieldeditors/TypeEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/TypeEditorViewModel.java index 72c50125ec9..0ad32035de1 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/TypeEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/TypeEditorViewModel.java @@ -1,6 +1,6 @@ package org.jabref.gui.fieldeditors; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; +import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.logic.l10n.Localization; import com.google.common.collect.BiMap; diff --git a/src/main/java/org/jabref/gui/fieldeditors/UrlEditor.java b/src/main/java/org/jabref/gui/fieldeditors/UrlEditor.java index 6d2cb45884f..6bffe03deee 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/UrlEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/UrlEditor.java @@ -6,8 +6,8 @@ import javafx.scene.layout.HBox; import org.jabref.gui.DialogService; +import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.gui.util.ControlHelper; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.model.entry.BibEntry; public class UrlEditor extends HBox implements FieldEditorFX { diff --git a/src/main/java/org/jabref/gui/fieldeditors/UrlEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/UrlEditorViewModel.java index ece78c88560..051a5e34b56 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/UrlEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/UrlEditorViewModel.java @@ -6,8 +6,8 @@ import javafx.beans.property.SimpleBooleanProperty; import org.jabref.gui.DialogService; +import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.gui.desktop.JabRefDesktop; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.logic.l10n.Localization; import org.jabref.logic.net.URLUtil; import org.jabref.model.strings.StringUtil; diff --git a/src/main/java/org/jabref/gui/fieldeditors/YesNoEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/YesNoEditorViewModel.java index c77959ee0dd..7cad3e7e356 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/YesNoEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/YesNoEditorViewModel.java @@ -1,6 +1,6 @@ package org.jabref.gui.fieldeditors; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; +import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; diff --git a/src/main/java/org/jabref/gui/preftabs/EntryEditorPrefsTab.java b/src/main/java/org/jabref/gui/preftabs/EntryEditorPrefsTab.java index 796d45d35a9..112565b9226 100644 --- a/src/main/java/org/jabref/gui/preftabs/EntryEditorPrefsTab.java +++ b/src/main/java/org/jabref/gui/preftabs/EntryEditorPrefsTab.java @@ -13,9 +13,9 @@ import javax.swing.JTextField; import javax.swing.SpinnerNumberModel; +import org.jabref.gui.autocompleter.AutoCompleteFirstNameMode; +import org.jabref.gui.autocompleter.AutoCompletePreferences; import org.jabref.gui.keyboard.EmacsKeyBindings; -import org.jabref.logic.autocompleter.AutoCompleteFirstNameMode; -import org.jabref.logic.autocompleter.AutoCompletePreferences; import org.jabref.logic.l10n.Localization; import org.jabref.preferences.JabRefPreferences; diff --git a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java index d57af4ba9fa..37e12969722 100644 --- a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java +++ b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java @@ -25,13 +25,13 @@ import org.jabref.gui.IconTheme; import org.jabref.gui.JabRefFrame; import org.jabref.gui.OSXCompatibleToolbar; +import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.gui.autocompleter.AutoCompleteSupport; import org.jabref.gui.help.HelpAction; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.gui.maintable.MainTable; import org.jabref.gui.maintable.MainTableDataModel; import org.jabref.gui.util.component.JTextFieldWithPlaceholder; -import org.jabref.logic.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.logic.help.HelpFile; import org.jabref.logic.l10n.Localization; import org.jabref.logic.search.SearchQuery; diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 4ffcccd55cd..45dd5e6f28f 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -36,11 +36,11 @@ import org.jabref.JabRefException; import org.jabref.JabRefMain; +import org.jabref.gui.autocompleter.AutoCompletePreferences; import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.gui.entryeditor.EntryEditorTabList; import org.jabref.gui.keyboard.KeyBindingRepository; import org.jabref.gui.preftabs.ImportSettingsTab; -import org.jabref.logic.autocompleter.AutoCompletePreferences; import org.jabref.logic.bibtex.FieldContentParserPreferences; import org.jabref.logic.bibtex.LatexFieldFormatterPreferences; import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences; diff --git a/src/test/java/org/jabref/logic/autocompleter/BibtexKeyAutoCompleterTest.java b/src/test/java/org/jabref/gui/autocompleter/BibtexKeyAutoCompleterTest.java similarity index 98% rename from src/test/java/org/jabref/logic/autocompleter/BibtexKeyAutoCompleterTest.java rename to src/test/java/org/jabref/gui/autocompleter/BibtexKeyAutoCompleterTest.java index 80bd52afb32..48e196f1651 100644 --- a/src/test/java/org/jabref/logic/autocompleter/BibtexKeyAutoCompleterTest.java +++ b/src/test/java/org/jabref/gui/autocompleter/BibtexKeyAutoCompleterTest.java @@ -1,4 +1,4 @@ -package org.jabref.logic.autocompleter; +package org.jabref.gui.autocompleter; import java.util.Arrays; import java.util.Collection; diff --git a/src/test/java/org/jabref/logic/autocompleter/DefaultAutoCompleterTest.java b/src/test/java/org/jabref/gui/autocompleter/DefaultAutoCompleterTest.java similarity index 99% rename from src/test/java/org/jabref/logic/autocompleter/DefaultAutoCompleterTest.java rename to src/test/java/org/jabref/gui/autocompleter/DefaultAutoCompleterTest.java index b549258031b..5983d43da57 100644 --- a/src/test/java/org/jabref/logic/autocompleter/DefaultAutoCompleterTest.java +++ b/src/test/java/org/jabref/gui/autocompleter/DefaultAutoCompleterTest.java @@ -1,4 +1,4 @@ -package org.jabref.logic.autocompleter; +package org.jabref.gui.autocompleter; import java.util.Arrays; import java.util.Collection; diff --git a/src/test/java/org/jabref/logic/autocompleter/FieldValueSuggestionProviderTest.java b/src/test/java/org/jabref/gui/autocompleter/FieldValueSuggestionProviderTest.java similarity index 99% rename from src/test/java/org/jabref/logic/autocompleter/FieldValueSuggestionProviderTest.java rename to src/test/java/org/jabref/gui/autocompleter/FieldValueSuggestionProviderTest.java index 92075e64428..3494851023f 100644 --- a/src/test/java/org/jabref/logic/autocompleter/FieldValueSuggestionProviderTest.java +++ b/src/test/java/org/jabref/gui/autocompleter/FieldValueSuggestionProviderTest.java @@ -1,4 +1,4 @@ -package org.jabref.logic.autocompleter; +package org.jabref.gui.autocompleter; import java.util.Arrays; import java.util.Collection; diff --git a/src/test/java/org/jabref/logic/autocompleter/PersonNameSuggestionProviderTest.java b/src/test/java/org/jabref/gui/autocompleter/PersonNameSuggestionProviderTest.java similarity index 99% rename from src/test/java/org/jabref/logic/autocompleter/PersonNameSuggestionProviderTest.java rename to src/test/java/org/jabref/gui/autocompleter/PersonNameSuggestionProviderTest.java index d87b9318baa..899a64a120c 100644 --- a/src/test/java/org/jabref/logic/autocompleter/PersonNameSuggestionProviderTest.java +++ b/src/test/java/org/jabref/gui/autocompleter/PersonNameSuggestionProviderTest.java @@ -1,4 +1,4 @@ -package org.jabref.logic.autocompleter; +package org.jabref.gui.autocompleter; import java.util.Arrays; import java.util.Collection; diff --git a/src/test/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModelTest.java b/src/test/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModelTest.java index 01b5dfb6869..92c3e63eefa 100644 --- a/src/test/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModelTest.java +++ b/src/test/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModelTest.java @@ -1,8 +1,8 @@ package org.jabref.gui.fieldeditors; import org.jabref.gui.DialogService; +import org.jabref.gui.autocompleter.WordSuggestionProvider; import org.jabref.gui.util.CurrentThreadTaskExecutor; -import org.jabref.logic.autocompleter.WordSuggestionProvider; import org.junit.Before; import org.junit.Test; From eed5679e771ce63322629c2b005dc91124807b2c Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Mon, 10 Jul 2017 21:43:50 +0200 Subject: [PATCH 07/10] Replace auto completion support in search field by JavaFX --- src/main/java/org/jabref/gui/BasePanel.java | 2 +- .../AutoCompleteFirstNameMode.java | 16 +- .../autocompleter/AutoCompleteListener.java | 474 ------------------ .../AutoCompletePreferences.java | 86 ++-- .../autocompleter/AutoCompleteRenderer.java | 60 --- .../autocompleter/AutoCompleteSupport.java | 268 ---------- .../ListAutoCompleteRenderer.java | 88 ---- .../PersonNameStringConverter.java | 10 +- .../gui/entryeditor/FieldsEditorTab.java | 10 - .../jabref/gui/fieldeditors/FieldEditor.java | 6 - .../jabref/gui/fieldeditors/FieldEditors.java | 3 +- .../org/jabref/gui/fieldeditors/TextArea.java | 17 - .../jabref/gui/fieldeditors/TextField.java | 15 - .../gui/preftabs/EntryEditorPrefsTab.java | 25 +- .../jabref/gui/search/GlobalSearchBar.java | 69 +-- .../search/JTextFieldChangeListenerUtil.java | 87 ---- .../jabref/preferences/JabRefPreferences.java | 22 +- 17 files changed, 129 insertions(+), 1129 deletions(-) delete mode 100644 src/main/java/org/jabref/gui/autocompleter/AutoCompleteListener.java delete mode 100644 src/main/java/org/jabref/gui/autocompleter/AutoCompleteRenderer.java delete mode 100644 src/main/java/org/jabref/gui/autocompleter/AutoCompleteSupport.java delete mode 100644 src/main/java/org/jabref/gui/autocompleter/ListAutoCompleteRenderer.java delete mode 100644 src/main/java/org/jabref/gui/search/JTextFieldChangeListenerUtil.java diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 23eade23fff..51b46f984ab 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -1387,7 +1387,7 @@ public void setupMainPanel() { * Set up auto completion for this database */ private void setupAutoCompletion() { - AutoCompletePreferences autoCompletePreferences = new AutoCompletePreferences(Globals.prefs); + AutoCompletePreferences autoCompletePreferences = Globals.prefs.getAutoCompletePreferences(); if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_COMPLETE)) { suggestionProviders = new SuggestionProviders(autoCompletePreferences, Globals.journalAbbreviationLoader); suggestionProviders.indexDatabase(getDatabase()); diff --git a/src/main/java/org/jabref/gui/autocompleter/AutoCompleteFirstNameMode.java b/src/main/java/org/jabref/gui/autocompleter/AutoCompleteFirstNameMode.java index d31b52997a0..30543681808 100644 --- a/src/main/java/org/jabref/gui/autocompleter/AutoCompleteFirstNameMode.java +++ b/src/main/java/org/jabref/gui/autocompleter/AutoCompleteFirstNameMode.java @@ -1,7 +1,21 @@ package org.jabref.gui.autocompleter; +/** + * For "ONLY_FULL", the auto completer returns the full name, e.g. "Smith, Bob" + * For "ONLY_ABBREVIATED", the auto completer returns the first name abbreviated, e.g. "Smith, B." + * For "BOTH", the auto completer returns both versions. + */ public enum AutoCompleteFirstNameMode { ONLY_FULL, ONLY_ABBREVIATED, - BOTH + BOTH; + + public static AutoCompleteFirstNameMode parse(String input) { + try { + return AutoCompleteFirstNameMode.valueOf(input); + } catch (IllegalArgumentException ex) { + // Should only occur when preferences are set directly via preferences.put and not via setFirstnameMode + return AutoCompleteFirstNameMode.BOTH; + } + } } diff --git a/src/main/java/org/jabref/gui/autocompleter/AutoCompleteListener.java b/src/main/java/org/jabref/gui/autocompleter/AutoCompleteListener.java deleted file mode 100644 index 644219afe4a..00000000000 --- a/src/main/java/org/jabref/gui/autocompleter/AutoCompleteListener.java +++ /dev/null @@ -1,474 +0,0 @@ -package org.jabref.gui.autocompleter; - -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import java.awt.event.InputEvent; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.util.ArrayList; -import java.util.List; - -import javax.swing.text.BadLocationException; -import javax.swing.text.JTextComponent; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -public class AutoCompleteListener extends KeyAdapter implements FocusListener { - - //TODO: The logging behavior in this class is probably too fine-grained and only understandable to its original author - private static final Log LOGGER = LogFactory.getLog(AutoCompleteListener.class); - - private final AutoCompleteSuggestionProvider completer; - - // These variables keep track of the situation from time to time. - private String toSetIn; // null indicates that there are no completions available - private String lastBeginning; // the letters, the user has typed until know - private int lastCaretPosition = -1; - private List lastCompletions; - private int lastShownCompletion; - private boolean consumeEnterKey = true; - - // This field is set if the focus listener should call another focus listener - // after finishing. This is needed because the autocomplete listener must - // run before the focus listener responsible for storing the current edit. - private FocusListener nextFocusListener; - - public AutoCompleteListener(AutoCompleteSuggestionProvider completer) { - // if (logger.getHandlers().length == 0) { - // logger.setLevel(Level.FINEST); - // ConsoleHandler ch = new ConsoleHandler(); - // ch.setLevel(Level.FINEST); - // logger.addHandler(ch); - // } - this.completer = completer; - } - - /** - * This method is used if the focus listener should call another focus listener after finishing. This is needed - * because the autocomplete listener must run before the focus listener responsible for storing the current edit. - * - * @param listener The listener to call. - */ - public void setNextFocusListener(FocusListener listener) { - this.nextFocusListener = listener; - } - - /** - * This setting determines whether the autocomplete listener should consume the Enter key stroke when it leads to - * accepting a completion. If set to false, the JTextComponent will receive the Enter key press after the completion - * is done. The default value if true. - * - * @param t true to indicate that the Enter key should be consumed, false that it should be forwarded - */ - public void setConsumeEnterKey(boolean t) { - this.consumeEnterKey = t; - } - - @Override - public void keyPressed(KeyEvent e) { - if ((toSetIn != null) && (e.getKeyCode() == KeyEvent.VK_ENTER)) { - JTextComponent comp = (JTextComponent) e.getSource(); - - // replace typed characters by characters from completion - lastBeginning = lastCompletions.get(lastShownCompletion); - - int end = comp.getSelectionEnd(); - comp.select(end, end); - toSetIn = null; - if (consumeEnterKey) { - e.consume(); - } - } - // Cycle through alternative completions when user presses PGUP/PGDN: - else if ((e.getKeyCode() == KeyEvent.VK_PAGE_DOWN) && (toSetIn != null)) { - cycle((JTextComponent) e.getSource(), 1); - e.consume(); - } else if ((e.getKeyCode() == KeyEvent.VK_PAGE_UP) && (toSetIn != null)) { - cycle((JTextComponent) e.getSource(), -1); - e.consume(); - } - // else if ((e.getKeyCode() == KeyEvent.VK_BACK_SPACE)) { - // StringBuffer currentword = getCurrentWord((JTextComponent) e.getSource()); - // // delete last char to obey semantics of back space - // currentword.deleteCharAt(currentword.length()-1); - // doCompletion(currentword, e); - // } - else if (e.getKeyChar() == KeyEvent.CHAR_UNDEFINED) { - if (e.getKeyCode() == KeyEvent.VK_SHIFT) { - // shift is OK, everything else leads to a reset - LOGGER.debug("Special case: shift pressed. No action."); - } else { - resetAutoCompletion(); - } - } else { - LOGGER.debug("Special case: defined character, but not caught above"); - } - } - - private void cycle(JTextComponent comp, int increment) { - assert (lastCompletions != null); - assert (!lastCompletions.isEmpty()); - lastShownCompletion += increment; - if (lastShownCompletion >= lastCompletions.size()) { - lastShownCompletion = 0; - } else if (lastShownCompletion < 0) { - lastShownCompletion = lastCompletions.size() - 1; - } - String sno = lastCompletions.get(lastShownCompletion); - toSetIn = sno.substring(lastBeginning.length() - 1); - - StringBuilder alltext = new StringBuilder(comp.getText()); - - int oldSelectionStart = comp.getSelectionStart(); - int oldSelectionEnd = comp.getSelectionEnd(); - - // replace prefix with new prefix - int startPos = comp.getSelectionStart() - lastBeginning.length(); - alltext.delete(startPos, oldSelectionStart); - alltext.insert(startPos, sno.subSequence(0, lastBeginning.length())); - - // replace suffix with new suffix - alltext.delete(oldSelectionStart, oldSelectionEnd); - //int cp = oldSelectionEnd - deletedChars; - alltext.insert(oldSelectionStart, toSetIn.substring(1)); - - LOGGER.debug(alltext.toString()); - comp.setText(alltext.toString()); - //comp.setCaretPosition(cp+toSetIn.length()-1); - comp.select(oldSelectionStart, (oldSelectionStart + toSetIn.length()) - 1); - lastCaretPosition = comp.getCaretPosition(); - LOGGER.debug("ToSetIn: '" + toSetIn + "'"); - } - - private boolean atEndOfWord(JTextComponent textField) { - int nextCharPosition = textField.getCaretPosition(); - - // position not at the end of input - if (nextCharPosition < textField.getText().length()) { - char nextChar = textField.getText().charAt(nextCharPosition); - if (!Character.isWhitespace(nextChar)) { - return false; - } - } - return true; - } - - /** - * If user cancels autocompletion by a) entering another letter than the completed word (and there is no other auto - * completion) b) space the casing of the letters has to be kept - * - * Global variable "lastBeginning" keeps track of typed letters. We rely on this variable to reconstruct the text - * - * @param wordSeperatorTyped indicates whether the user has typed a white space character or a - */ - private void setUnmodifiedTypedLetters(JTextComponent comp, boolean lastBeginningContainsTypedCharacter, - boolean wordSeperatorTyped) { - if (lastBeginning == null) { - LOGGER.debug("No last beginning found"); - // There was no previous input (if the user typed a word, where no autocompletion is available) - // Thus, there is nothing to replace - return; - } - LOGGER.debug("lastBeginning: >" + lastBeginning + '<'); - if (comp.getSelectedText() == null) { - // if there is no selection - // the user has typed the complete word, but possibly with a different casing - // we need a replacement - if (wordSeperatorTyped) { - LOGGER.debug("Replacing complete word"); - } else { - // if user did not press a white space character (space, ...), - // then we do not do anything - return; - } - } else { - LOGGER.debug("Selected text " + comp.getSelectedText() + " will be removed"); - // remove completion suggestion - comp.replaceSelection(""); - } - - lastCaretPosition = comp.getCaretPosition(); - - int endIndex = lastCaretPosition - lastBeginning.length(); - if (lastBeginningContainsTypedCharacter) { - // the current letter is NOT contained in comp.getText(), but in lastBeginning - // thus lastBeginning.length() is one too large - endIndex++; - } - String text = comp.getText(); - comp.setText(text.substring(0, endIndex).concat(lastBeginning).concat(text.substring(lastCaretPosition))); - if (lastBeginningContainsTypedCharacter) { - // the current letter is NOT contained in comp.getText() - // Thus, cursor position also did not get updated - lastCaretPosition++; - } - comp.setCaretPosition(lastCaretPosition); - lastBeginning = null; - } - - /** - * Start a new completion attempt (instead of treating a continuation of an existing word or an interrupt of the - * current word) - */ - private void startCompletion(StringBuffer currentword, KeyEvent e) { - JTextComponent comp = (JTextComponent) e.getSource(); - - List completed = findCompletions(currentword.toString()); - String prefix = null; - String cWord = (prefix != null) && (!prefix.isEmpty()) ? currentword.toString() - .substring(prefix.length()) : currentword.toString(); - - LOGGER.debug("StartCompletion currentword: >" + currentword + "'<' prefix: >" + prefix + "'<' cword: >" + cWord - + '<'); - - int no = 0; // We use the first word in the array of completions. - if ((completed != null) && (!completed.isEmpty())) { - lastShownCompletion = 0; - lastCompletions = completed; - String sno = completed.get(no); - - // these two lines obey the user's input - //toSetIn = Character.toString(ch); - //toSetIn = toSetIn.concat(sno.substring(cWord.length())); - // BUT we obey the completion - toSetIn = sno.substring(cWord.length() - 1); - - LOGGER.debug("toSetIn: >" + toSetIn + '<'); - - StringBuilder alltext = new StringBuilder(comp.getText()); - int cp = comp.getCaretPosition(); - alltext.insert(cp, toSetIn); - comp.setText(alltext.toString()); - comp.setCaretPosition(cp); - comp.select(cp + 1, (cp + 1 + sno.length()) - cWord.length()); - e.consume(); - lastCaretPosition = comp.getCaretPosition(); - char ch = e.getKeyChar(); - - LOGGER.debug("Appending >" + ch + '<'); - - if (cWord.length() <= 1) { - lastBeginning = Character.toString(ch); - } else { - lastBeginning = cWord.substring(0, cWord.length() - 1).concat(Character.toString(ch)); - } - } - - } - - @Override - public void keyTyped(KeyEvent e) { - LOGGER.debug("key typed event caught " + e.getKeyCode()); - char ch = e.getKeyChar(); - if (ch == '\n') { - // this case is handled at keyPressed(e) - return; - } - - // don't do auto completion inside words - if (!(e.getSource() instanceof JTextComponent) || !atEndOfWord((JTextComponent) e.getSource())) { - return; - } - - if ((e.getModifiers() | InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK) { - // plain key or SHIFT + key is pressed, no handling of CTRL+key, META+key, ... - if (Character.isLetter(ch) || Character.isDigit(ch) - || (Character.isWhitespace(ch))) { - - JTextComponent comp = (JTextComponent) e.getSource(); - - if (toSetIn == null) { - LOGGER.debug("toSetIn is null"); - } else { - LOGGER.debug("toSetIn: >" + toSetIn + '<'); - } - - // The case-insensitive system is a bit tricky here - // If keyword is "TODO" and user types "tO", then this is treated as "continue" as the "O" matches the "O" - // If keyword is "TODO" and user types "To", then this is treated as "discont" as the "o" does NOT match the "O". - - if ((toSetIn != null) && (toSetIn.length() > 1) && (ch == toSetIn.charAt(1))) { - // User continues on the word that was suggested. - LOGGER.debug("cont"); - - toSetIn = toSetIn.substring(1); - if (!toSetIn.isEmpty()) { - int cp = comp.getCaretPosition(); - //comp.setCaretPosition(cp+1-toSetIn.); - comp.select((cp + 1) - toSetIn.length(), cp); - lastBeginning = lastBeginning + ch; - - e.consume(); - lastCaretPosition = comp.getCaretPosition(); - - lastCompletions = findCompletions(lastBeginning); - lastShownCompletion = 0; - for (int i = 0; i < lastCompletions.size(); i++) { - String lastCompletion = lastCompletions.get(i); - if (lastCompletion.endsWith(toSetIn)) { - lastShownCompletion = i; - break; - } - - } - if (toSetIn.length() < 2) { - // User typed the last character of the autocompleted word - // We have to replace the automcompletion word by the typed word. - // This helps if the user presses "space" after the completion - // "space" indicates that the user does NOT want the autocompletion, - // but the typed word - String text = comp.getText(); - comp.setText(text.substring(0, lastCaretPosition - lastBeginning.length()) + lastBeginning - + text.substring(lastCaretPosition)); - // there is no selected text, therefore we are not updating the selection - toSetIn = null; - } - return; - } - } - - if ((toSetIn != null) && ((toSetIn.length() <= 1) || (ch != toSetIn.charAt(1)))) { - // User discontinues the word that was suggested. - lastBeginning = lastBeginning + ch; - - LOGGER.debug("discont toSetIn: >" + toSetIn + "'<' lastBeginning: >" + lastBeginning + '<'); - - List completed = findCompletions(lastBeginning); - if ((completed != null) && (!completed.isEmpty())) { - lastShownCompletion = 0; - lastCompletions = completed; - String sno = completed.get(0); - // toSetIn = string used for autocompletion last time - // this string has to be removed - // lastCaretPosition is the position of the caret after toSetIn. - int lastLen = toSetIn.length() - 1; - toSetIn = sno.substring(lastBeginning.length() - 1); - String text = comp.getText(); - //we do not use toSetIn as we want to obey the casing of "sno" - comp.setText(text.substring(0, (lastCaretPosition - lastLen - lastBeginning.length()) + 1) + sno - + text.substring(lastCaretPosition)); - int startSelect = (lastCaretPosition + 1) - lastLen; - int endSelect = (lastCaretPosition + toSetIn.length()) - lastLen; - comp.select(startSelect, endSelect); - - lastCaretPosition = comp.getCaretPosition(); - e.consume(); - return; - } else { - setUnmodifiedTypedLetters(comp, true, false); - e.consume(); - toSetIn = null; - return; - } - } - - LOGGER.debug("case else"); - - comp.replaceSelection(""); - - StringBuffer currentword = getCurrentWord(comp); - - // only "real characters" end up here - assert (!Character.isISOControl(ch)); - currentword.append(ch); - startCompletion(currentword, e); - return; - } else { - if (Character.isWhitespace(ch)) { - LOGGER.debug("whitespace && !singleUnitField"); - // start a new search if end-of-field is reached - - // replace displayed letters with typed letters - setUnmodifiedTypedLetters((JTextComponent) e.getSource(), false, true); - resetAutoCompletion(); - return; - } - - LOGGER.debug("No letter/digit/whitespace or CHAR_UNDEFINED"); - // replace displayed letters with typed letters - setUnmodifiedTypedLetters((JTextComponent) e.getSource(), false, !Character.isISOControl(ch)); - resetAutoCompletion(); - return; - } - } - resetAutoCompletion(); - } - - /** - * Resets the auto completion data in a way that no leftovers are there - */ - private void resetAutoCompletion() { - LOGGER.debug("Resetting autocompletion"); - toSetIn = null; - lastBeginning = null; - } - - private List findCompletions(String beginning) { - return new ArrayList<>(completer.call(AutoCompleterUtil.getRequest((beginning)))); - } - - private StringBuffer getCurrentWord(JTextComponent comp) { - StringBuffer res = new StringBuffer(); - String upToCaret; - - try { - upToCaret = comp.getText(0, comp.getCaretPosition()); - // We now have the text from the start of the field up to the caret position. - // In most fields, we are only interested in the currently edited word, so we - // seek from the caret backward to the closest space: - - if ((comp.getCaretPosition() < comp.getText().length()) - && Character.isWhitespace(comp.getText().charAt(comp.getCaretPosition()))) { - // caret is in the middle of the text AND current character is a whitespace - // that means: a new word is started and there is no current word - return new StringBuffer(); - } - - int piv = upToCaret.length() - 1; - while ((piv >= 0) && !Character.isWhitespace(upToCaret.charAt(piv))) { - piv--; - } - // piv points to whitespace char or piv is -1 - // copy everything from the next char up to the end of "upToCaret" - res.append(upToCaret.substring(piv + 1)); - - LOGGER.debug("AutoCompListener: " + res); - } catch (BadLocationException ignore) { - // Ignored - } - - return res; - } - - @Override - public void focusGained(FocusEvent event) { - if (nextFocusListener != null) { - nextFocusListener.focusGained(event); - } - } - - @Override - public void focusLost(FocusEvent event) { - if (toSetIn != null) { - JTextComponent comp = (JTextComponent) event.getSource(); - clearCurrentSuggestion(comp); - } - if (nextFocusListener != null) { - nextFocusListener.focusLost(event); - } - } - - public void clearCurrentSuggestion(JTextComponent comp) { - if (toSetIn != null) { - int selStart = comp.getSelectionStart(); - String text = comp.getText(); - comp.setText(text.substring(0, selStart) + text.substring(comp.getSelectionEnd())); - comp.setCaretPosition(selStart); - lastCompletions = null; - lastShownCompletion = 0; - lastCaretPosition = -1; - toSetIn = null; - } - } -} diff --git a/src/main/java/org/jabref/gui/autocompleter/AutoCompletePreferences.java b/src/main/java/org/jabref/gui/autocompleter/AutoCompletePreferences.java index 05e0f5682e1..49db09bf9db 100644 --- a/src/main/java/org/jabref/gui/autocompleter/AutoCompletePreferences.java +++ b/src/main/java/org/jabref/gui/autocompleter/AutoCompletePreferences.java @@ -1,90 +1,72 @@ package org.jabref.gui.autocompleter; +import java.util.Arrays; import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.util.stream.Collectors; import org.jabref.logic.journals.JournalAbbreviationPreferences; -import org.jabref.preferences.JabRefPreferences; public class AutoCompletePreferences { - private static final String AUTOCOMPLETER_SHORTEST_TO_COMPLETE = "shortestToComplete"; - private static final String AUTOCOMPLETER_FIRSTNAME_MODE = "autoCompFirstNameMode"; - private static final String AUTOCOMPLETER_LAST_FIRST = "autoCompLF"; - private static final String AUTOCOMPLETER_FIRST_LAST = "autoCompFF"; - private static final String AUTOCOMPLETER_COMPLETE_FIELDS = "autoCompleteFields"; - - private final JabRefPreferences preferences; - - public AutoCompletePreferences(JabRefPreferences preferences) { - this.preferences = Objects.requireNonNull(preferences); - } - - public static void putDefaults(Map defaults) { - defaults.put(AUTOCOMPLETER_SHORTEST_TO_COMPLETE, 1); - defaults.put(AUTOCOMPLETER_FIRSTNAME_MODE, AutoCompleteFirstNameMode.BOTH.name()); - defaults.put(AUTOCOMPLETER_FIRST_LAST, Boolean.FALSE); // "Autocomplete names in 'Firstname Lastname' format only" - defaults.put(AUTOCOMPLETER_LAST_FIRST, Boolean.FALSE); // "Autocomplete names in 'Lastname, Firstname' format only" - defaults.put(AUTOCOMPLETER_COMPLETE_FIELDS, "author;editor;title;journal;publisher;keywords"); - } - - public int getShortestLengthToComplete() { - return preferences.getInt(AUTOCOMPLETER_SHORTEST_TO_COMPLETE); - } - - public void setShortestLengthToComplete(Integer value) { - preferences.putInt(AUTOCOMPLETER_SHORTEST_TO_COMPLETE, value); + private static final String DELIMITER = ";"; + private AutoCompleteFirstNameMode firstNameMode; + private boolean onlyCompleteLastFirst; + private boolean onlyCompleteFirstLast; + private List completeNames; + private JournalAbbreviationPreferences journalAbbreviationPreferences; + + public AutoCompletePreferences(AutoCompleteFirstNameMode firstNameMode, boolean onlyCompleteLastFirst, boolean onlyCompleteFirstLast, List completeNames, JournalAbbreviationPreferences journalAbbreviationPreferences) { + this.firstNameMode = firstNameMode; + this.onlyCompleteLastFirst = onlyCompleteLastFirst; + this.onlyCompleteFirstLast = onlyCompleteFirstLast; + this.completeNames = completeNames; + this.journalAbbreviationPreferences = journalAbbreviationPreferences; } /** * Returns how the first names are handled. - * For "ONLY_FULL", the auto completer returns the full name, e.g. "Smith, Bob" - * For "ONLY_ABBREVIATED", the auto completer returns the first name abbreviated, e.g. "Smith, B." - * For "BOTH", the auto completer returns both versions. */ - public AutoCompleteFirstNameMode getFirstnameMode() { - try { - return AutoCompleteFirstNameMode.valueOf(preferences.get(AUTOCOMPLETER_FIRSTNAME_MODE)); - } catch (IllegalArgumentException ex) { - // Should only occur when preferences are set directly via preferences.put and not via setFirstnameMode - return AutoCompleteFirstNameMode.BOTH; - } + public AutoCompleteFirstNameMode getFirstNameMode() { + return firstNameMode; } - public void setFirstnameMode(AutoCompleteFirstNameMode mode) { - preferences.put(AUTOCOMPLETER_FIRSTNAME_MODE, mode.name()); + public void setFirstNameMode(AutoCompleteFirstNameMode firstNameMode) { + this.firstNameMode = firstNameMode; } public boolean getOnlyCompleteLastFirst() { - return preferences.getBoolean(AUTOCOMPLETER_LAST_FIRST); + return onlyCompleteLastFirst; } - public void setOnlyCompleteLastFirst(boolean value) { - preferences.putBoolean(AUTOCOMPLETER_LAST_FIRST, value); + public void setOnlyCompleteLastFirst(boolean onlyCompleteLastFirst) { + this.onlyCompleteLastFirst = onlyCompleteLastFirst; } public boolean getOnlyCompleteFirstLast() { - return preferences.getBoolean(AUTOCOMPLETER_FIRST_LAST); + return onlyCompleteFirstLast; } - public void setOnlyCompleteFirstLast(boolean value) { - preferences.putBoolean(AUTOCOMPLETER_FIRST_LAST, value); + public void setOnlyCompleteFirstLast(boolean onlyCompleteFirstLast) { + this.onlyCompleteFirstLast = onlyCompleteFirstLast; } public List getCompleteNames() { - return preferences.getStringList(AUTOCOMPLETER_COMPLETE_FIELDS); + return completeNames; + } + + public void setCompleteNames(String input) { + setCompleteNames(Arrays.asList(input.split(DELIMITER))); } - public void setCompleteNames(String value) { - preferences.put(AUTOCOMPLETER_COMPLETE_FIELDS, value); + public void setCompleteNames(List completeNames) { + this.completeNames = completeNames; } public String getCompleteNamesAsString() { - return preferences.get(AUTOCOMPLETER_COMPLETE_FIELDS); + return completeNames.stream().collect(Collectors.joining(DELIMITER)); } public JournalAbbreviationPreferences getJournalAbbreviationPreferences() { - return preferences.getJournalAbbreviationPreferences(); + return journalAbbreviationPreferences; } } diff --git a/src/main/java/org/jabref/gui/autocompleter/AutoCompleteRenderer.java b/src/main/java/org/jabref/gui/autocompleter/AutoCompleteRenderer.java deleted file mode 100644 index 47e772751f0..00000000000 --- a/src/main/java/org/jabref/gui/autocompleter/AutoCompleteRenderer.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.jabref.gui.autocompleter; - -import java.awt.Component; -import java.awt.event.ActionListener; -import java.util.Collection; - -/** - * Renders the list of possible autocomplete items. Also takes care of the currently selected item. - * - * @param the type of the items - */ -public abstract class AutoCompleteRenderer { - - /** - * Refreshes the list of possible autocomplete items. Clears the currently selected item. - * - * @param items list of possible autocomplete items - */ - public abstract void update(Collection items); - - /** - * Creates the control which will be shown in the autocomplete popup. - * - * @param acceptAction the action to be performed if the current selection is chosen as the autocompletion - * @return the control to be added to the autocomplete popup - */ - public abstract Component init(ActionListener acceptAction); - - /** - * Selects the item at the given position. If the specified index is not valid, then the selection will be cleared. - * - * @param index position of the item - */ - public abstract void selectItem(int index); - - /** - * Selects the item relative to the currently selected item. If the specified offset is not valid, then the - * selection will be cleared. - * - * @param offset offset of the item - */ - public void selectItemRelative(int offset) { - int newIndex = getSelectedIndex() + offset; - selectItem(newIndex); - } - - /** - * Returns the index of the currently selected item. - * - * @return index of the selected item - */ - public abstract int getSelectedIndex(); - - /** - * Returns the currently selected item. - * - * @return selected item - */ - public abstract E getSelectedItem(); -} diff --git a/src/main/java/org/jabref/gui/autocompleter/AutoCompleteSupport.java b/src/main/java/org/jabref/gui/autocompleter/AutoCompleteSupport.java deleted file mode 100644 index 2c952f9c50c..00000000000 --- a/src/main/java/org/jabref/gui/autocompleter/AutoCompleteSupport.java +++ /dev/null @@ -1,268 +0,0 @@ -package org.jabref.gui.autocompleter; - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.FocusAdapter; -import java.awt.event.FocusEvent; -import java.awt.event.KeyEvent; -import java.util.Collection; - -import javax.swing.AbstractAction; -import javax.swing.BorderFactory; -import javax.swing.JComponent; -import javax.swing.JPopupMenu; -import javax.swing.KeyStroke; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; -import javax.swing.event.PopupMenuEvent; -import javax.swing.event.PopupMenuListener; -import javax.swing.text.JTextComponent; - -/** - * Endows a textbox with the ability to autocomplete the input. Based on code by Santhosh Kumar - * (http://www.jroller.com/santhosh/date/20050620) James Lemieux (Glazed Lists AutoCompleteSupport) - * - * @param type of items displayed in the autocomplete popup - */ -public class AutoCompleteSupport { - - private final AutoCompleteRenderer renderer; - private final JTextComponent textComp; - private final JPopupMenu popup = new JPopupMenu(); - private AutoCompleteSuggestionProvider autoCompleter; - private boolean selectsTextOnFocusGain = true; - - - /** - * Constructs a new AutoCompleteSupport for the textbox using the autocompleter and a renderer. - * - * @param textComp the textbox component for which autocompletion should be enabled - * @param autoCompleter the autocompleter providing the data - * @param renderer the renderer displaying the popup - */ - public AutoCompleteSupport(JTextComponent textComp, AutoCompleteSuggestionProvider autoCompleter, - AutoCompleteRenderer renderer) { - this.renderer = renderer; - this.textComp = textComp; - this.autoCompleter = autoCompleter; - - } - - /** - * Constructs a new AutoCompleteSupport for the textbox. The possible autocomplete items are displayed as a simple - * list. The autocompletion items are provided by an AutoCompleter which has to be specified later using - * {@link setAutoCompleter}. - * - * @param textComp the textbox component for which autocompletion should be enabled - */ - public AutoCompleteSupport(JTextComponent textComp) { - this(textComp, null, new ListAutoCompleteRenderer<>()); - } - - /** - * Inits the autocompletion popup. After this method is called, further input in the specified textbox will be - * autocompleted. - */ - public void install() { - // ActionListeners for navigating the suggested autocomplete items with the arrow keys - final ActionListener upAction = new MoveAction(-1); - final ActionListener downAction = new MoveAction(1); - // ActionListener hiding the autocomplete popup - final ActionListener hidePopupAction = e -> popup.setVisible(false); - - // ActionListener accepting the currently selected item as the autocompletion - final ActionListener acceptAction = e -> { - E itemToInsert = renderer.getSelectedItem(); - if (itemToInsert == null) { - return; - } - - String toInsert = itemToInsert.toString(); - - // Get position of last word separator (whitespace or comma) - int priv = textComp.getText().length() - 1; - while ((priv >= 0) && !Character.isWhitespace(textComp.getText().charAt(priv)) - && (textComp.getText().charAt(priv) != ',')) { - priv--; - } - // priv points to whitespace char or priv is -1 - // copy everything from the next char up to the end of "upToCaret" - textComp.setText(textComp.getText().substring(0, priv + 1) + toInsert); - - textComp.setCaretPosition(textComp.getText().length()); - popup.setVisible(false); - }; - - // Create popup - popup.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.LIGHT_GRAY)); - popup.setPopupSize(textComp.getWidth(), 200); - popup.setLayout(new BorderLayout()); - popup.setFocusable(false); - popup.setRequestFocusEnabled(false); - popup.add(renderer.init(acceptAction)); - - // Listen for changes to the text -> update autocomplete suggestions - textComp.getDocument().addDocumentListener(new DocumentListener() { - - @Override - public void insertUpdate(DocumentEvent e) { - postProcessTextChange(); - } - - @Override - public void removeUpdate(DocumentEvent e) { - postProcessTextChange(); - } - - @Override - public void changedUpdate(DocumentEvent e) { - // Do nothing - } - }); - - // Listen for up/down arrow keys -> move currently selected item up or down - // We have to reimplement this function here since we cannot be sure that a simple list will be used to display the items - // So better let the renderer decide what to do. - // (Moreover, the list does not have the focus so probably would not recognize the keystrokes in the first place.) - textComp.registerKeyboardAction(downAction, KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), - JComponent.WHEN_FOCUSED); - - textComp.registerKeyboardAction(upAction, KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), JComponent.WHEN_FOCUSED); - - // Listen for ESC key -> hide popup - textComp.registerKeyboardAction(hidePopupAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_IN_FOCUSED_WINDOW); - - // Listen to focus events -> select all the text on gaining the focus - this.textComp.addFocusListener(new ComboBoxEditorFocusHandler()); - - // Listen for ENTER key if popup is visible -> accept current autocomplete suggestion - popup.addPopupMenuListener(new PopupMenuListener() { - - @Override - public void popupMenuWillBecomeVisible(PopupMenuEvent e) { - textComp.registerKeyboardAction(acceptAction, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), - JComponent.WHEN_FOCUSED); - } - - @Override - public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { - textComp.unregisterKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)); - } - - @Override - public void popupMenuCanceled(PopupMenuEvent e) { - // Do nothing - } - }); - - } - - /** - * Returns whether the text in the textbox is selected when the textbox gains focus. Defaults to true. - * - * @return - */ - public boolean isSelectsTextOnFocusGain() { - return selectsTextOnFocusGain; - } - - /** - * Sets whether the text in the textbox is selected when the textbox gains focus. Default is true. - * - * @param selectsTextOnFocusGain new value - */ - public void setSelectsTextOnFocusGain(boolean selectsTextOnFocusGain) { - this.selectsTextOnFocusGain = selectsTextOnFocusGain; - } - - /** - * The text changed so update autocomplete suggestions accordingly. - */ - private void postProcessTextChange() { - if (autoCompleter == null) { - popup.setVisible(false); - return; - } - - String text = textComp.getText(); - Collection candidates = autoCompleter.call(AutoCompleterUtil.getRequest(text)); - renderer.update(candidates); - if (textComp.isEnabled() && (!candidates.isEmpty())) { - renderer.selectItem(0); - - popup.setPopupSize(textComp.getWidth(), 200); - popup.show(textComp, 0, textComp.getHeight()); - } else { - popup.setVisible(false); - } - - if (!textComp.hasFocus()) { - textComp.requestFocusInWindow(); - } - } - - /** - * Sets the autocompleter used to present autocomplete suggestions. - * - * @param autoCompleter the autocompleter providing the data - */ - public void setAutoCompleter(AutoCompleteSuggestionProvider autoCompleter) { - this.autoCompleter = autoCompleter; - } - - public boolean isVisible() { - return popup.isVisible(); - } - - public void setVisible(boolean visible) { - popup.setVisible(visible); - } - - /** - * The action invoked by hitting the up or down arrow key. If the popup is currently shown, that the action is - * relayed to it. Otherwise the arrow keys trigger the popup. - */ - private class MoveAction extends AbstractAction { - - private final int offset; - - - public MoveAction(int offset) { - this.offset = offset; - } - - @Override - public void actionPerformed(ActionEvent e) { - - if (popup.isVisible()) { - renderer.selectItemRelative(offset); - } else { - popup.show(textComp, 0, textComp.getHeight()); - } - - } - } - - /** - * Selects all text when the textbox gains focus. The behavior is controlled by the value returned from - * {@link AutoCompleteSupport#isSelectsTextOnFocusGain()}. - */ - private class ComboBoxEditorFocusHandler extends FocusAdapter { - - @Override - public void focusGained(FocusEvent e) { - if (isSelectsTextOnFocusGain() && !e.isTemporary()) { - textComp.selectAll(); - } - } - - @Override - public void focusLost(FocusEvent e) { - // Do nothing - } - } - -} diff --git a/src/main/java/org/jabref/gui/autocompleter/ListAutoCompleteRenderer.java b/src/main/java/org/jabref/gui/autocompleter/ListAutoCompleteRenderer.java deleted file mode 100644 index 48018dd7a0e..00000000000 --- a/src/main/java/org/jabref/gui/autocompleter/ListAutoCompleteRenderer.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.jabref.gui.autocompleter; - -import java.awt.Component; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.Collection; -import java.util.Vector; - -import javax.swing.BorderFactory; -import javax.swing.DefaultListModel; -import javax.swing.JList; -import javax.swing.JScrollPane; -import javax.swing.ListSelectionModel; -import javax.swing.ScrollPaneConstants; - -/** - * Renders possible autocomplete items in form of a simple list. - * - * @param the type of the items - */ -public class ListAutoCompleteRenderer extends AutoCompleteRenderer { - - private final DefaultListModel model = new DefaultListModel<>(); - private final JList list = new JList<>(model); - - /** - * Every selection change by the user is interpreted as accepting the new item as autocompletion. Thus we need this - * helper variable to prevent that also programmatically trigger an autocompletion. - */ - private Boolean interpretSelectionChangeAsAccept = true; - - @Override - public void update(Collection autoCompletions) { - if (autoCompletions == null) { - model.removeAllElements(); - } else { - list.setListData(new Vector<>(autoCompletions)); - list.clearSelection(); - } - } - - @Override - public Component init(ActionListener newAcceptAction) { - // Init list - list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - list.setFocusable(false); - list.setRequestFocusEnabled(false); - list.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5)); - list.addListSelectionListener(e -> { - if (interpretSelectionChangeAsAccept && (newAcceptAction != null)) { - newAcceptAction.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, null)); - } - }); - - // Init pane containing the list - JScrollPane scrollPane = new JScrollPane(list); - scrollPane.setFocusable(false); - scrollPane.setRequestFocusEnabled(false); - scrollPane.setBorder(BorderFactory.createEmptyBorder()); - scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); - scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); - - return scrollPane; - } - - @Override - public E getSelectedItem() { - return list.getSelectedValue(); - } - - @Override - public void selectItem(int index) { - interpretSelectionChangeAsAccept = false; - // Set new index if valid otherwise clean selection - if ((index >= 0) && (index < list.getModel().getSize())) { - list.setSelectedIndex(index); - list.ensureIndexIsVisible(index); - } else { - list.clearSelection(); - } - interpretSelectionChangeAsAccept = true; - } - - @Override - public int getSelectedIndex() { - return list.getSelectedIndex(); - } -} diff --git a/src/main/java/org/jabref/gui/autocompleter/PersonNameStringConverter.java b/src/main/java/org/jabref/gui/autocompleter/PersonNameStringConverter.java index 7ce9cd9ca2f..f9ff3de842c 100644 --- a/src/main/java/org/jabref/gui/autocompleter/PersonNameStringConverter.java +++ b/src/main/java/org/jabref/gui/autocompleter/PersonNameStringConverter.java @@ -11,6 +11,12 @@ public class PersonNameStringConverter extends StringConverter { private final boolean autoCompLF; private final AutoCompleteFirstNameMode autoCompleteFirstNameMode; + public PersonNameStringConverter(boolean autoCompFF, boolean autoCompLF, AutoCompleteFirstNameMode autoCompleteFirstNameMode) { + this.autoCompFF = autoCompFF; + this.autoCompLF = autoCompLF; + this.autoCompleteFirstNameMode = autoCompleteFirstNameMode; + } + public PersonNameStringConverter(AutoCompletePreferences preferences) { if (preferences.getOnlyCompleteFirstLast()) { autoCompFF = true; @@ -22,8 +28,8 @@ public PersonNameStringConverter(AutoCompletePreferences preferences) { autoCompFF = true; autoCompLF = true; } - autoCompleteFirstNameMode = preferences.getFirstnameMode() == null ? AutoCompleteFirstNameMode.BOTH : preferences - .getFirstnameMode(); + + autoCompleteFirstNameMode = preferences.getFirstNameMode(); } @Override diff --git a/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java b/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java index 5f5ebdc6c69..caa0743a6dd 100644 --- a/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java @@ -109,16 +109,6 @@ private Region setupPanel(JabRefFrame frame, BasePanel bPanel, boolean compresse } Optional extra = parent.getExtra(fieldEditor); - - // Add autocompleter listener, if required for this field: - /* - AutoCompleter autoCompleter = bPanel.getSuggestionProviders().get(field); - AutoCompleteListener autoCompleteListener = null; - if (autoCompleter != null) { - autoCompleteListener = new AutoCompleteListener(autoCompleter); - } - setupJTextComponent(fieldEditor.getTextComponent(), autoCompleteListener); - fieldEditor.setAutoCompleteListener(autoCompleteListener); */ FieldEditorFX fieldEditor = FieldEditors.getForField(fieldName, Globals.TASK_EXECUTOR, new FXDialogService(), diff --git a/src/main/java/org/jabref/gui/fieldeditors/FieldEditor.java b/src/main/java/org/jabref/gui/fieldeditors/FieldEditor.java index d80d525a4a1..711b3ffc550 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/FieldEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/FieldEditor.java @@ -4,8 +4,6 @@ import javax.swing.JComponent; -import org.jabref.gui.autocompleter.AutoCompleteListener; - /** * FieldEditors is a common interface between the TextField and TextArea. */ @@ -71,8 +69,4 @@ default boolean hasFocus() { void undo(); void redo(); - - void setAutoCompleteListener(AutoCompleteListener listener); - - void clearAutoCompleteSuggestion(); } diff --git a/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java b/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java index 80144bbaae8..6f02ed966f6 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java +++ b/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java @@ -5,7 +5,6 @@ import org.jabref.Globals; import org.jabref.gui.DialogService; -import org.jabref.gui.autocompleter.AutoCompletePreferences; import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.gui.autocompleter.SuggestionProviders; import org.jabref.gui.util.TaskExecutor; @@ -58,7 +57,7 @@ public static FieldEditorFX getForField(String fieldName, TaskExecutor taskExecu } else if (fieldExtras.contains(FieldProperty.SINGLE_ENTRY_LINK) || fieldExtras.contains(FieldProperty.MULTIPLE_ENTRY_LINK)) { return new LinkedEntriesEditor(fieldName, databaseContext, suggestionProvider); } else if (fieldExtras.contains(FieldProperty.PERSON_NAMES)) { - return new PersonsEditor(fieldName, suggestionProvider, new AutoCompletePreferences(preferences)); + return new PersonsEditor(fieldName, suggestionProvider, preferences.getAutoCompletePreferences()); } // default diff --git a/src/main/java/org/jabref/gui/fieldeditors/TextArea.java b/src/main/java/org/jabref/gui/fieldeditors/TextArea.java index 4c86c31a318..600d08e7f37 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/TextArea.java +++ b/src/main/java/org/jabref/gui/fieldeditors/TextArea.java @@ -10,7 +10,6 @@ import javafx.scene.Scene; import org.jabref.gui.GUIGlobals; -import org.jabref.gui.autocompleter.AutoCompleteListener; import org.jabref.gui.util.DefaultTaskExecutor; import org.apache.commons.logging.Log; @@ -29,8 +28,6 @@ public class TextArea implements FieldEditor { private final EditorTextArea textArea; private String fieldName; - private AutoCompleteListener autoCompleteListener; - public TextArea(String fieldName, String content) { this(fieldName, content, ""); } @@ -163,20 +160,6 @@ public void redo() { // Nothing } - @Override - public void setAutoCompleteListener(AutoCompleteListener listener) { - autoCompleteListener = listener; - } - - @Override - public void clearAutoCompleteSuggestion() { - /* - if (autoCompleteListener != null) { - autoCompleteListener.clearCurrentSuggestion(this); - } - */ - } - @Override public void requestFocus() { diff --git a/src/main/java/org/jabref/gui/fieldeditors/TextField.java b/src/main/java/org/jabref/gui/fieldeditors/TextField.java index 646e619b39e..6a240db224d 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/TextField.java +++ b/src/main/java/org/jabref/gui/fieldeditors/TextField.java @@ -15,7 +15,6 @@ import org.jabref.Globals; import org.jabref.gui.GUIGlobals; import org.jabref.gui.actions.Actions; -import org.jabref.gui.autocompleter.AutoCompleteListener; import org.jabref.gui.util.component.JTextFieldWithPlaceholder; import org.apache.commons.logging.Log; @@ -31,8 +30,6 @@ public class TextField extends JTextFieldWithPlaceholder implements FieldEditor private final String fieldName; private UndoManager undo; - private AutoCompleteListener autoCompleteListener; - public TextField(String fieldName, String content, boolean changeColorOnFocus) { this(fieldName, content, changeColorOnFocus, ""); @@ -135,18 +132,6 @@ public void redo() { // Nothing } - @Override - public void setAutoCompleteListener(AutoCompleteListener listener) { - autoCompleteListener = listener; - } - - @Override - public void clearAutoCompleteSuggestion() { - if (autoCompleteListener != null) { - autoCompleteListener.clearCurrentSuggestion(this); - } - } - private void setupPasteListener() { // Bind paste command to KeyBinds.PASTE getInputMap().put(Globals.getKeyPrefs().getKey(org.jabref.gui.keyboard.KeyBinding.PASTE), Actions.PASTE); diff --git a/src/main/java/org/jabref/gui/preftabs/EntryEditorPrefsTab.java b/src/main/java/org/jabref/gui/preftabs/EntryEditorPrefsTab.java index 112565b9226..8760c25c44c 100644 --- a/src/main/java/org/jabref/gui/preftabs/EntryEditorPrefsTab.java +++ b/src/main/java/org/jabref/gui/preftabs/EntryEditorPrefsTab.java @@ -9,9 +9,7 @@ import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JRadioButton; -import javax.swing.JSpinner; import javax.swing.JTextField; -import javax.swing.SpinnerNumberModel; import org.jabref.gui.autocompleter.AutoCompleteFirstNameMode; import org.jabref.gui.autocompleter.AutoCompletePreferences; @@ -23,6 +21,9 @@ import com.jgoodies.forms.layout.CellConstraints; import com.jgoodies.forms.layout.FormLayout; +import static org.jabref.gui.autocompleter.AutoCompleteFirstNameMode.ONLY_ABBREVIATED; +import static org.jabref.gui.autocompleter.AutoCompleteFirstNameMode.ONLY_FULL; + class EntryEditorPrefsTab extends JPanel implements PrefsTab { private final JCheckBox autoOpenForm; @@ -38,7 +39,6 @@ class EntryEditorPrefsTab extends JPanel implements PrefsTab { private final JRadioButton firstNameModeFull; private final JRadioButton firstNameModeAbbr; private final JRadioButton firstNameModeBoth; - private final JSpinner shortestToComplete; private final JTextField autoCompFields; private final JabRefPreferences prefs; @@ -47,7 +47,7 @@ class EntryEditorPrefsTab extends JPanel implements PrefsTab { public EntryEditorPrefsTab(JabRefPreferences prefs) { this.prefs = prefs; - autoCompletePreferences = new AutoCompletePreferences(prefs); + autoCompletePreferences = prefs.getAutoCompletePreferences(); setLayout(new BorderLayout()); autoOpenForm = new JCheckBox(Localization.lang("Open editor when a new entry is created")); @@ -58,9 +58,6 @@ public EntryEditorPrefsTab(JabRefPreferences prefs) { autoComplete = new JCheckBox(Localization.lang("Enable word/name autocompletion")); recommendations = new JCheckBox(Localization.lang("Show 'Related_Articles' tab")); - shortestToComplete = new JSpinner( - new SpinnerNumberModel(autoCompletePreferences.getShortestLengthToComplete(), 1, 5, 1)); - // allowed name formats autoCompFF = new JRadioButton(Localization.lang("Autocomplete names in 'Firstname Lastname' format only")); autoCompLF = new JRadioButton(Localization.lang("Autocomplete names in 'Lastname, Firstname' format only")); @@ -122,9 +119,6 @@ public EntryEditorPrefsTab(JabRefPreferences prefs) { builder3.append(label); builder3.append(autoCompFields); - JLabel label2 = new JLabel(Localization.lang("Autocomplete after following number of characters") + ":"); - builder3.append(label2); - builder3.append(shortestToComplete); builder.add(builder3.getPanel(), cc.xyw(2, 19, 3)); builder.addSeparator(Localization.lang("Name format used for autocompletion"), cc.xyw(2, 21, 4)); @@ -150,7 +144,6 @@ private void setAutoCompleteElementsEnabled(boolean enabled) { firstNameModeAbbr.setEnabled(enabled); firstNameModeFull.setEnabled(enabled); firstNameModeBoth.setEnabled(enabled); - shortestToComplete.setEnabled(enabled); } @Override @@ -163,7 +156,6 @@ public void setValues() { recommendations.setSelected(prefs.getBoolean(JabRefPreferences.SHOW_RECOMMENDATIONS)); autoComplete.setSelected(prefs.getBoolean(JabRefPreferences.AUTO_COMPLETE)); autoCompFields.setText(autoCompletePreferences.getCompleteNamesAsString()); - shortestToComplete.setValue(autoCompletePreferences.getShortestLengthToComplete()); if (autoCompletePreferences.getOnlyCompleteFirstLast()) { autoCompFF.setSelected(true); @@ -173,7 +165,7 @@ public void setValues() { autoCompBoth.setSelected(true); } - switch (autoCompletePreferences.getFirstnameMode()) { + switch (autoCompletePreferences.getFirstNameMode()) { case ONLY_ABBREVIATED: firstNameModeAbbr.setSelected(true); break; @@ -218,7 +210,6 @@ public void storeSettings() { EmacsKeyBindings.load(); } } - autoCompletePreferences.setShortestLengthToComplete((Integer) shortestToComplete.getValue()); prefs.putBoolean(JabRefPreferences.AUTO_COMPLETE, autoComplete.isSelected()); autoCompletePreferences.setCompleteNames(autoCompFields.getText()); if (autoCompBoth.isSelected()) { @@ -234,11 +225,11 @@ else if (autoCompFF.isSelected()) { autoCompletePreferences.setOnlyCompleteLastFirst(true); } if (firstNameModeAbbr.isSelected()) { - autoCompletePreferences.setFirstnameMode(AutoCompleteFirstNameMode.ONLY_ABBREVIATED); + autoCompletePreferences.setFirstNameMode(ONLY_ABBREVIATED); } else if (firstNameModeFull.isSelected()) { - autoCompletePreferences.setFirstnameMode(AutoCompleteFirstNameMode.ONLY_FULL); + autoCompletePreferences.setFirstNameMode(ONLY_FULL); } else { - autoCompletePreferences.setFirstnameMode(AutoCompleteFirstNameMode.BOTH); + autoCompletePreferences.setFirstNameMode(AutoCompleteFirstNameMode.BOTH); } } diff --git a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java index 37e12969722..e5665523871 100644 --- a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java +++ b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java @@ -19,28 +19,38 @@ import javax.swing.JToolBar; import javax.swing.SwingUtilities; +import javafx.css.PseudoClass; +import javafx.embed.swing.JFXPanel; +import javafx.scene.Scene; +import javafx.scene.control.TextField; +import javafx.scene.control.Tooltip; + import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.GUIGlobals; import org.jabref.gui.IconTheme; import org.jabref.gui.JabRefFrame; import org.jabref.gui.OSXCompatibleToolbar; +import org.jabref.gui.autocompleter.AppendPersonNamesStrategy; +import org.jabref.gui.autocompleter.AutoCompleteFirstNameMode; import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; -import org.jabref.gui.autocompleter.AutoCompleteSupport; +import org.jabref.gui.autocompleter.AutoCompletionTextInputBinding; +import org.jabref.gui.autocompleter.PersonNameStringConverter; import org.jabref.gui.help.HelpAction; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.gui.maintable.MainTable; import org.jabref.gui.maintable.MainTableDataModel; -import org.jabref.gui.util.component.JTextFieldWithPlaceholder; +import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.logic.help.HelpFile; import org.jabref.logic.l10n.Localization; import org.jabref.logic.search.SearchQuery; import org.jabref.logic.search.SearchQueryHighlightObservable; -import org.jabref.logic.util.OS; import org.jabref.model.entry.Author; import org.jabref.model.entry.BibEntry; import org.jabref.preferences.SearchPreferences; +import org.fxmisc.easybind.EasyBind; + public class GlobalSearchBar extends JPanel { private static final Color NEUTRAL_COLOR = Color.WHITE; @@ -48,17 +58,20 @@ public class GlobalSearchBar extends JPanel { private static final Color RESULTS_FOUND_COLOR = new Color(217, 232, 202); private static final Color ADVANCED_SEARCH_COLOR = new Color(102, 255, 255); + private static final PseudoClass CLASS_NO_RESULTS = PseudoClass.getPseudoClass("emptyResult"); + private static final PseudoClass CLASS_RESULTS_FOUND = PseudoClass.getPseudoClass("emptyResult"); + + private final JabRefFrame frame; private final JLabel searchIcon = new JLabel(IconTheme.JabRefIcon.SEARCH.getSmallIcon()); - private final JTextFieldWithPlaceholder searchField = new JTextFieldWithPlaceholder(Localization.lang("Search") + "..."); + private final TextField searchField = new TextField(); private final JToggleButton caseSensitive; private final JToggleButton regularExp; private final JButton searchModeButton = new JButton(); private final JLabel currentResults = new JLabel(""); private final SearchQueryHighlightObservable searchQueryHighlightObservable = new SearchQueryHighlightObservable(); private JButton openCurrentResultsInDialog = new JButton(IconTheme.JabRefIcon.OPEN_IN_NEW_WINDOW.getSmallIcon()); - private AutoCompleteSupport autoCompleteSupport = new AutoCompleteSupport<>(searchField); private SearchWorker searchWorker; private GlobalSearchWorker globalSearchWorker; @@ -81,7 +94,6 @@ public GlobalSearchBar(JabRefFrame frame) { // fits the standard "found x entries"-message thus hinders the searchbar to jump around while searching if the frame width is too small currentResults.setPreferredSize(new Dimension(150, 5)); currentResults.setFont(currentResults.getFont().deriveFont(Font.BOLD)); - searchField.setColumns(30); JToggleButton globalSearch = new JToggleButton(IconTheme.JabRefIcon.GLOBAL_SEARCH.getSmallIcon(), searchPreferences.isGlobalSearch()); globalSearch.setToolTipText(Localization.lang("Search in all open libraries")); @@ -145,10 +157,9 @@ public void actionPerformed(ActionEvent e) { clearSearchButton.setToolTipText(Localization.lang("Clear")); clearSearchButton.addActionListener(event -> endSearch()); - searchField.addFocusListener(Globals.getFocusListener()); - searchField.addActionListener(event -> performSearch()); - JTextFieldChangeListenerUtil.addChangeListener(searchField, e -> performSearch()); + EasyBind.subscribe(searchField.textProperty(), searchText -> performSearch()); + /* String endSearch = "endSearch"; searchField.getInputMap().put(Globals.getKeyPrefs().getKey(KeyBinding.CLEAR_SEARCH), endSearch); searchField.getActionMap().put(endSearch, new AbstractAction() { @@ -161,9 +172,9 @@ public void actionPerformed(ActionEvent event) { } } }); + */ - autoCompleteSupport.install(); - + /* String acceptSearch = "acceptSearch"; searchField.getInputMap().put(Globals.getKeyPrefs().getKey(KeyBinding.ACCEPT), acceptSearch); searchField.getActionMap().put(acceptSearch, new AbstractAction() { @@ -175,18 +186,20 @@ public void actionPerformed(ActionEvent e) { currentBasePanel.getMainTable().requestFocus(); } }); + */ + + JFXPanel container = new JFXPanel(); + DefaultTaskExecutor.runInJavaFXThread(() -> { + container.setScene(new Scene(searchField)); + }); + searchField.setPromptText(Localization.lang("Search") + "..."); setLayout(new FlowLayout(FlowLayout.RIGHT)); JToolBar toolBar = new OSXCompatibleToolbar(); toolBar.setFloatable(false); - if (OS.OS_X) { - searchField.putClientProperty("JTextField.variant", "search"); - toolBar.add(searchField); - } else { - toolBar.add(searchIcon); - toolBar.add(searchField); - toolBar.add(clearSearchButton); - } + toolBar.add(searchIcon); + toolBar.add(container); + toolBar.add(clearSearchButton); toolBar.addSeparator(); toolBar.add(openCurrentResultsInDialog); toolBar.addSeparator(); @@ -286,7 +299,7 @@ public void endSearch() { * Focuses the search field if it is not focused. */ public void focus() { - if (!searchField.hasFocus()) { + if (!searchField.isFocused()) { searchField.requestFocus(); } searchField.selectAll(); @@ -295,7 +308,6 @@ public void focus() { private void clearSearch(BasePanel currentBasePanel) { currentResults.setText(""); searchField.setText(""); - searchField.setBackground(NEUTRAL_COLOR); searchIcon.setIcon(IconTheme.JabRefIcon.SEARCH.getSmallIcon()); searchQueryHighlightObservable.reset(); openCurrentResultsInDialog.setEnabled(false); @@ -339,7 +351,7 @@ public void performSearch() { } private void informUserAboutInvalidSearchQuery() { - searchField.setBackground(NO_RESULTS_COLOR); + searchField.pseudoClassStateChanged(CLASS_NO_RESULTS, true); searchQueryHighlightObservable.reset(); @@ -354,7 +366,10 @@ private void informUserAboutInvalidSearchQuery() { } public void setAutoCompleter(AutoCompleteSuggestionProvider searchCompleter) { - this.autoCompleteSupport.setAutoCompleter(searchCompleter); + AutoCompletionTextInputBinding.autoComplete(searchField, + searchCompleter, + new PersonNameStringConverter(true, true, AutoCompleteFirstNameMode.BOTH), + new AppendPersonNamesStrategy()); } public SearchQueryHighlightObservable getSearchQueryHighlightObservable() { @@ -376,12 +391,12 @@ private SearchQuery getSearchQuery() { public void updateResults(int matched, String description, boolean grammarBasedSearch) { if (matched == 0) { currentResults.setText(Localization.lang("No results found.")); - this.searchField.setBackground(NO_RESULTS_COLOR); + searchField.pseudoClassStateChanged(CLASS_NO_RESULTS, true); } else { currentResults.setText(Localization.lang("Found %0 results.", String.valueOf(matched))); - this.searchField.setBackground(RESULTS_FOUND_COLOR); + searchField.pseudoClassStateChanged(CLASS_RESULTS_FOUND, true); } - this.searchField.setToolTipText("" + description + ""); + searchField.setTooltip(new Tooltip(description)); if (grammarBasedSearch) { searchIcon.setIcon(IconTheme.JabRefIcon.SEARCH.getSmallIcon().createWithNewColor(ADVANCED_SEARCH_COLOR)); @@ -405,8 +420,6 @@ public void setSearchTerm(String searchTerm, boolean dontSelectSearchBar) { setDontSelectSearchBar(dontSelectSearchBar); searchField.setText(searchTerm); - // to hinder the autocomplete window to popup - autoCompleteSupport.setVisible(false); } public void setDontSelectSearchBar(boolean dontSelectSearchBar) { diff --git a/src/main/java/org/jabref/gui/search/JTextFieldChangeListenerUtil.java b/src/main/java/org/jabref/gui/search/JTextFieldChangeListenerUtil.java deleted file mode 100644 index 643e2777d44..00000000000 --- a/src/main/java/org/jabref/gui/search/JTextFieldChangeListenerUtil.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.jabref.gui.search; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.util.Objects; - -import javax.swing.JTextArea; -import javax.swing.JTextField; -import javax.swing.SwingUtilities; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; -import javax.swing.text.Document; -import javax.swing.text.JTextComponent; - -/** - * Taken from http://stackoverflow.com/questions/3953208/value-change-listener-to-jtextfield - */ -public class JTextFieldChangeListenerUtil { - - private JTextFieldChangeListenerUtil() { - } - - /** - * Installs a listener to receive notification when the text of any - * {@code JTextComponent} is changed. Internally, it installs a - * {@link DocumentListener} on the text component's {@link Document}, - * and a {@link PropertyChangeListener} on the text component to detect - * if the {@code Document} itself is replaced. - * - * Taken from - * - * @param text any text component, such as a {@link JTextField} - * or {@link JTextArea} - * @param changeListener a listener to receive {@link ChangeEvent}s - * when the text is changed; the source object for the events - * will be the text component - * @throws NullPointerException if either parameter is null - */ - public static void addChangeListener(JTextComponent text, ChangeListener changeListener) { - Objects.requireNonNull(text); - Objects.requireNonNull(changeListener); - DocumentListener dl = new DocumentListener() { - - private int lastChange; - private int lastNotifiedChange; - - @Override - public void insertUpdate(DocumentEvent e) { - changedUpdate(e); - } - - @Override - public void removeUpdate(DocumentEvent e) { - changedUpdate(e); - } - - @Override - public void changedUpdate(DocumentEvent e) { - lastChange++; - SwingUtilities.invokeLater(() -> { - if (lastNotifiedChange != lastChange) { - lastNotifiedChange = lastChange; - changeListener.stateChanged(new ChangeEvent(text)); - } - }); - } - }; - text.addPropertyChangeListener("document", (PropertyChangeEvent e) -> { - Document d1 = (Document)e.getOldValue(); - Document d2 = (Document)e.getNewValue(); - if (d1 != null) { - d1.removeDocumentListener(dl); - } - if (d2 != null) { - d2.addDocumentListener(dl); - } - dl.changedUpdate(null); - }); - Document d = text.getDocument(); - if (d != null) { - d.addDocumentListener(dl); - } - } - -} diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 45dd5e6f28f..6a56c76511c 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -36,6 +36,7 @@ import org.jabref.JabRefException; import org.jabref.JabRefMain; +import org.jabref.gui.autocompleter.AutoCompleteFirstNameMode; import org.jabref.gui.autocompleter.AutoCompletePreferences; import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.gui.entryeditor.EntryEditorTabList; @@ -390,6 +391,12 @@ public class JabRefPreferences implements PreferencesService { private static final String PREVIEW_PANEL_HEIGHT = "previewPanelHeight"; private static final String PREVIEW_STYLE = "previewStyle"; private static final String PREVIEW_ENABLED = "previewEnabled"; + // Auto completion + private static final String AUTOCOMPLETER_FIRSTNAME_MODE = "autoCompFirstNameMode"; + private static final String AUTOCOMPLETER_LAST_FIRST = "autoCompLF"; + private static final String AUTOCOMPLETER_FIRST_LAST = "autoCompFF"; + private static final String AUTOCOMPLETER_COMPLETE_FIELDS = "autoCompleteFields"; + // Helper string private static final String USER_HOME = System.getProperty("user.home"); // solves the issue java.lang.RuntimeException: Internal graphics not initialized yet @@ -565,7 +572,10 @@ private JabRefPreferences() { defaults.put(EDITOR_EMACS_KEYBINDINGS_REBIND_CA, Boolean.TRUE); defaults.put(EDITOR_EMACS_KEYBINDINGS_REBIND_CF, Boolean.TRUE); defaults.put(AUTO_COMPLETE, Boolean.FALSE); - AutoCompletePreferences.putDefaults(defaults); + defaults.put(AUTOCOMPLETER_FIRSTNAME_MODE, AutoCompleteFirstNameMode.BOTH.name()); + defaults.put(AUTOCOMPLETER_FIRST_LAST, Boolean.FALSE); // "Autocomplete names in 'Firstname Lastname' format only" + defaults.put(AUTOCOMPLETER_LAST_FIRST, Boolean.FALSE); // "Autocomplete names in 'Lastname, Firstname' format only" + defaults.put(AUTOCOMPLETER_COMPLETE_FIELDS, "author;editor;title;journal;publisher;keywords"); defaults.put(GROUP_INTERSECT_SELECTIONS, Boolean.FALSE); defaults.put(GROUPS_DEFAULT_FIELD, FieldName.KEYWORDS); defaults.put(AUTO_ASSIGN_GROUP, Boolean.TRUE); @@ -1600,4 +1610,14 @@ public AutoLinkPreferences getAutoLinkPreferences() { getKeywordDelimiter() ); } + + public AutoCompletePreferences getAutoCompletePreferences() { + return new AutoCompletePreferences( + AutoCompleteFirstNameMode.parse(get(AUTOCOMPLETER_FIRSTNAME_MODE)), + getBoolean(AUTOCOMPLETER_LAST_FIRST), + getBoolean(AUTOCOMPLETER_FIRST_LAST), + getStringList(AUTOCOMPLETER_COMPLETE_FIELDS), + getJournalAbbreviationPreferences() + ); + } } From 5686a02dd08a5fa78fc3d340806e93f3aa78fb4b Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Tue, 11 Jul 2017 10:59:17 +0200 Subject: [PATCH 08/10] Improve searchbar --- src/main/java/org/jabref/gui/BasePanel.java | 2 +- src/main/java/org/jabref/gui/JabRefFrame.java | 2 +- .../jabref/gui/search/GlobalSearchBar.java | 30 ++++--------------- .../jabref/gui/search/SearchTextField.java | 20 +++++++++++++ src/main/resources/l10n/JabRef_da.properties | 3 -- src/main/resources/l10n/JabRef_de.properties | 3 -- src/main/resources/l10n/JabRef_el.properties | 3 -- src/main/resources/l10n/JabRef_en.properties | 3 -- src/main/resources/l10n/JabRef_es.properties | 3 -- src/main/resources/l10n/JabRef_fa.properties | 3 -- src/main/resources/l10n/JabRef_fr.properties | 3 -- src/main/resources/l10n/JabRef_in.properties | 3 -- src/main/resources/l10n/JabRef_it.properties | 3 -- src/main/resources/l10n/JabRef_ja.properties | 3 -- src/main/resources/l10n/JabRef_nl.properties | 3 -- src/main/resources/l10n/JabRef_no.properties | 3 -- .../resources/l10n/JabRef_pt_BR.properties | 3 -- src/main/resources/l10n/JabRef_ru.properties | 3 -- src/main/resources/l10n/JabRef_sv.properties | 3 -- src/main/resources/l10n/JabRef_tr.properties | 3 -- src/main/resources/l10n/JabRef_vi.properties | 3 -- src/main/resources/l10n/JabRef_zh.properties | 3 -- 22 files changed, 27 insertions(+), 81 deletions(-) create mode 100644 src/main/java/org/jabref/gui/search/SearchTextField.java diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 51b46f984ab..13e6db4589d 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -2134,7 +2134,7 @@ public void listen(EntryAddedEvent addedEntryEvent) { @Subscribe public void listen(EntryChangedEvent entryChangedEvent) { - frame.getGlobalSearchBar().setDontSelectSearchBar(true); + frame.getGlobalSearchBar().setDontSelectSearchBar(); frame.getGlobalSearchBar().performSearch(); } diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 894f88d4985..1b25660beb2 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -624,7 +624,7 @@ public void windowClosing(WindowEvent e) { if (currentSearchQuery.isPresent()) { content = currentSearchQuery.get().getQuery(); } - globalSearchBar.setSearchTerm(content, true); + globalSearchBar.setSearchTerm(content); } currentBasePanel.getPreviewPanel().updateLayout(); diff --git a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java index e5665523871..f90cdb743d0 100644 --- a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java +++ b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java @@ -64,8 +64,7 @@ public class GlobalSearchBar extends JPanel { private final JabRefFrame frame; - private final JLabel searchIcon = new JLabel(IconTheme.JabRefIcon.SEARCH.getSmallIcon()); - private final TextField searchField = new TextField(); + private final TextField searchField = SearchTextField.create(); private final JToggleButton caseSensitive; private final JToggleButton regularExp; private final JButton searchModeButton = new JButton(); @@ -153,10 +152,6 @@ public void actionPerformed(ActionEvent e) { updateSearchModeButtonText(); searchModeButton.addActionListener(event -> toggleSearchModeAndSearch()); - JButton clearSearchButton = new JButton(IconTheme.JabRefIcon.CLOSE.getSmallIcon()); - clearSearchButton.setToolTipText(Localization.lang("Clear")); - clearSearchButton.addActionListener(event -> endSearch()); - EasyBind.subscribe(searchField.textProperty(), searchText -> performSearch()); /* @@ -192,14 +187,11 @@ public void actionPerformed(ActionEvent e) { DefaultTaskExecutor.runInJavaFXThread(() -> { container.setScene(new Scene(searchField)); }); - searchField.setPromptText(Localization.lang("Search") + "..."); setLayout(new FlowLayout(FlowLayout.RIGHT)); JToolBar toolBar = new OSXCompatibleToolbar(); toolBar.setFloatable(false); - toolBar.add(searchIcon); toolBar.add(container); - toolBar.add(clearSearchButton); toolBar.addSeparator(); toolBar.add(openCurrentResultsInDialog); toolBar.addSeparator(); @@ -308,7 +300,6 @@ public void focus() { private void clearSearch(BasePanel currentBasePanel) { currentResults.setText(""); searchField.setText(""); - searchIcon.setIcon(IconTheme.JabRefIcon.SEARCH.getSmallIcon()); searchQueryHighlightObservable.reset(); openCurrentResultsInDialog.setEnabled(false); @@ -358,9 +349,7 @@ private void informUserAboutInvalidSearchQuery() { BasePanel currentBasePanel = frame.getCurrentBasePanel(); currentBasePanel.getMainTable().getTableModel().updateSearchState(MainTableDataModel.DisplayOption.DISABLED); - searchIcon.setIcon(IconTheme.JabRefIcon.SEARCH.getSmallIcon().createWithNewColor(NO_RESULTS_COLOR)); String illegalSearch = Localization.lang("Search failed: illegal search expression"); - searchIcon.setToolTipText(illegalSearch); currentResults.setText(illegalSearch); openCurrentResultsInDialog.setEnabled(false); } @@ -397,15 +386,6 @@ public void updateResults(int matched, String description, boolean grammarBasedS searchField.pseudoClassStateChanged(CLASS_RESULTS_FOUND, true); } searchField.setTooltip(new Tooltip(description)); - - if (grammarBasedSearch) { - searchIcon.setIcon(IconTheme.JabRefIcon.SEARCH.getSmallIcon().createWithNewColor(ADVANCED_SEARCH_COLOR)); - searchIcon.setToolTipText(Localization.lang("Advanced search active.")); - } else { - searchIcon.setIcon(IconTheme.JabRefIcon.SEARCH.getSmallIcon()); - searchIcon.setToolTipText(Localization.lang("Normal search active.")); - } - openCurrentResultsInDialog.setEnabled(true); } @@ -413,17 +393,17 @@ public void setSearchResultFrame(SearchResultFrame searchResultFrame) { this.searchResultFrame = searchResultFrame; } - public void setSearchTerm(String searchTerm, boolean dontSelectSearchBar) { + public void setSearchTerm(String searchTerm) { if (searchTerm.equals(searchField.getText())) { return; } - setDontSelectSearchBar(dontSelectSearchBar); + setDontSelectSearchBar(); searchField.setText(searchTerm); } - public void setDontSelectSearchBar(boolean dontSelectSearchBar) { - this.dontSelectSearchBar = dontSelectSearchBar; + public void setDontSelectSearchBar() { + this.dontSelectSearchBar = true; } private void updateOpenCurrentResultsTooltip(boolean globalSearchEnabled) { diff --git a/src/main/java/org/jabref/gui/search/SearchTextField.java b/src/main/java/org/jabref/gui/search/SearchTextField.java new file mode 100644 index 00000000000..a3a9cf6c44b --- /dev/null +++ b/src/main/java/org/jabref/gui/search/SearchTextField.java @@ -0,0 +1,20 @@ +package org.jabref.gui.search; + + +import javafx.scene.control.TextField; + +import org.jabref.gui.IconTheme; +import org.jabref.logic.l10n.Localization; + +import org.controlsfx.control.textfield.CustomTextField; +import org.controlsfx.control.textfield.TextFields; + +public class SearchTextField { + + public static TextField create() { + CustomTextField textField = (CustomTextField) TextFields.createClearableTextField(); + textField.setPromptText(Localization.lang("Search") + "..."); + textField.setLeft(IconTheme.JabRefIcon.SEARCH.getGraphicNode()); + return textField; + } +} diff --git a/src/main/resources/l10n/JabRef_da.properties b/src/main/resources/l10n/JabRef_da.properties index da661c9bbca..8b3c7810984 100644 --- a/src/main/resources/l10n/JabRef_da.properties +++ b/src/main/resources/l10n/JabRef_da.properties @@ -1554,7 +1554,6 @@ Use_full_firstname_whenever_possible= Use_abbreviated_firstname_whenever_possible= Use_abbreviated_and_full_firstname= Autocompletion_options= -Autocomplete_after_following_number_of_characters= Name_format_used_for_autocompletion= Treatment_of_first_names= Cleanup_entries= @@ -1832,8 +1831,6 @@ Search_results_in_library_%0_for_%1= Search_globally= No_results_found.= Found_%0_results.= -Advanced_search_active.= -Normal_search_active.= plain_text= This_search_contains_entries_in_which_any_field_contains_the_regular_expression_%0= This_search_contains_entries_in_which_any_field_contains_the_term_%0= diff --git a/src/main/resources/l10n/JabRef_de.properties b/src/main/resources/l10n/JabRef_de.properties index 8d44784a4b2..5baa10461d8 100644 --- a/src/main/resources/l10n/JabRef_de.properties +++ b/src/main/resources/l10n/JabRef_de.properties @@ -1554,7 +1554,6 @@ Use_full_firstname_whenever_possible=Den_ganzen_Vornamen_nutzen,_wenn_möglich Use_abbreviated_firstname_whenever_possible=Den_abgekürzten_Vornamen_benutzen,_wenn_möglich Use_abbreviated_and_full_firstname=Abgekürzte_und_ganze_Vornamen_verwenden Autocompletion_options=Autovervollständigungs-Optionen -Autocomplete_after_following_number_of_characters=Autovervollständigung_nach_der_folgenden_Anzahl_an_Zeichen Name_format_used_for_autocompletion=Namensformat_für_die_Autovervollständigung Treatment_of_first_names=Behandlung_von_Vornamen Cleanup_entries=Einträge_aufräumen @@ -1832,8 +1831,6 @@ Search_results_in_library_%0_for_%1=Suchergebnisse_in_Bibliothek_%0_für_%1 Search_globally=Global_suchen No_results_found.=Keine_Ergebnisse_gefunden. Found_%0_results.=%0_Ergebnisse_gefunden. -Advanced_search_active.=Erweiterte_Suche_aktiv. -Normal_search_active.=Normale_Suche_aktiv. plain_text=Klartext This_search_contains_entries_in_which_any_field_contains_the_regular_expression_%0=Diese_Suche_enthält_Einträge,_die_in_einem_beliebigen_Feld_den_regulären_Ausdruck_%0_enthalten This_search_contains_entries_in_which_any_field_contains_the_term_%0=Diese_Suche_enthält_Einträge,_die_in_einem_beliebigen_Feld_den_Begriff_%0_enthalten diff --git a/src/main/resources/l10n/JabRef_el.properties b/src/main/resources/l10n/JabRef_el.properties index 6375c68f8d5..6c709a76c17 100644 --- a/src/main/resources/l10n/JabRef_el.properties +++ b/src/main/resources/l10n/JabRef_el.properties @@ -1554,7 +1554,6 @@ Use_full_firstname_whenever_possible=Use_full_firstname_whenever_possible Use_abbreviated_firstname_whenever_possible=Use_abbreviated_firstname_whenever_possible Use_abbreviated_and_full_firstname=Use_abbreviated_and_full_firstname Autocompletion_options=Autocompletion_options -Autocomplete_after_following_number_of_characters=Autocomplete_after_following_number_of_characters Name_format_used_for_autocompletion=Name_format_used_for_autocompletion Treatment_of_first_names=Treatment_of_first_names Cleanup_entries=Cleanup_entries @@ -1832,8 +1831,6 @@ Search_results_in_library_%0_for_%1= Search_globally=Search_globally No_results_found.=No_results_found. Found_%0_results.=Found_%0_results. -Advanced_search_active.=Advanced_search_active. -Normal_search_active.=Normal_search_active. plain_text=plain_text This_search_contains_entries_in_which_any_field_contains_the_regular_expression_%0=This_search_contains_entries_in_which_any_field_contains_the_regular_expression_%0 This_search_contains_entries_in_which_any_field_contains_the_term_%0=This_search_contains_entries_in_which_any_field_contains_the_term_%0 diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index e56631fb3f0..bc93a0257d4 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -1554,7 +1554,6 @@ Use_full_firstname_whenever_possible=Use_full_firstname_whenever_possible Use_abbreviated_firstname_whenever_possible=Use_abbreviated_firstname_whenever_possible Use_abbreviated_and_full_firstname=Use_abbreviated_and_full_firstname Autocompletion_options=Autocompletion_options -Autocomplete_after_following_number_of_characters=Autocomplete_after_following_number_of_characters Name_format_used_for_autocompletion=Name_format_used_for_autocompletion Treatment_of_first_names=Treatment_of_first_names Cleanup_entries=Cleanup_entries @@ -1832,8 +1831,6 @@ Search_results_in_library_%0_for_%1=Search_results_in_library_%0_for_%1 Search_globally=Search_globally No_results_found.=No_results_found. Found_%0_results.=Found_%0_results. -Advanced_search_active.=Advanced_search_active. -Normal_search_active.=Normal_search_active. plain_text=plain_text This_search_contains_entries_in_which_any_field_contains_the_regular_expression_%0=This_search_contains_entries_in_which_any_field_contains_the_regular_expression_%0 This_search_contains_entries_in_which_any_field_contains_the_term_%0=This_search_contains_entries_in_which_any_field_contains_the_term_%0 diff --git a/src/main/resources/l10n/JabRef_es.properties b/src/main/resources/l10n/JabRef_es.properties index 4fc710e9cb4..6e5d67a5915 100644 --- a/src/main/resources/l10n/JabRef_es.properties +++ b/src/main/resources/l10n/JabRef_es.properties @@ -1554,7 +1554,6 @@ Use_full_firstname_whenever_possible=Usar_nombre_de_pila_completo_cuando_sea_pos Use_abbreviated_firstname_whenever_possible=Usar_nombre_de_pila_abreviado_cuando_sea_posible Use_abbreviated_and_full_firstname=Usar_apellido_completo_y_abreviado Autocompletion_options=Opciones_de_autocompletar -Autocomplete_after_following_number_of_characters=Autocompletar_después_del_siguiente_número_de_caracteres Name_format_used_for_autocompletion=Formato_de_nombre_usado_para_autocompletar Treatment_of_first_names=Tratamiento_de_nombres_de_pila Cleanup_entries=Limpiar_entradas @@ -1832,8 +1831,6 @@ Search_results_in_library_%0_for_%1=Resultados_para_%1_en_la_biblioteca_&0 Search_globally=Buscar_globalmente. No_results_found.=No_se_encontraron_resultados. Found_%0_results.=Se_encontraron_%0_resultados. -Advanced_search_active.=Búsqueda_avanzada_activa. -Normal_search_active.=Búsqueda_normal_activa. plain_text=texto_plano This_search_contains_entries_in_which_any_field_contains_the_regular_expression_%0=Esta_búsqueda_contiene_entradas_en_las_cuales_cualquier_campo_contiene_la_expresión_regular_%0 This_search_contains_entries_in_which_any_field_contains_the_term_%0=Esta_búsqueda_contiene_entradas_en_las_cuales_cualquier_campo_contiene_el_término_%0 diff --git a/src/main/resources/l10n/JabRef_fa.properties b/src/main/resources/l10n/JabRef_fa.properties index 15ad66d0c45..d03c710ffeb 100644 --- a/src/main/resources/l10n/JabRef_fa.properties +++ b/src/main/resources/l10n/JabRef_fa.properties @@ -1554,7 +1554,6 @@ Use_full_firstname_whenever_possible= Use_abbreviated_firstname_whenever_possible= Use_abbreviated_and_full_firstname= Autocompletion_options= -Autocomplete_after_following_number_of_characters= Name_format_used_for_autocompletion= Treatment_of_first_names= Cleanup_entries= @@ -1832,8 +1831,6 @@ Search_results_in_library_%0_for_%1= Search_globally= No_results_found.= Found_%0_results.= -Advanced_search_active.= -Normal_search_active.= plain_text= This_search_contains_entries_in_which_any_field_contains_the_regular_expression_%0= This_search_contains_entries_in_which_any_field_contains_the_term_%0= diff --git a/src/main/resources/l10n/JabRef_fr.properties b/src/main/resources/l10n/JabRef_fr.properties index 844ccef84e1..8e28c76b130 100644 --- a/src/main/resources/l10n/JabRef_fr.properties +++ b/src/main/resources/l10n/JabRef_fr.properties @@ -1554,7 +1554,6 @@ Use_full_firstname_whenever_possible=Utiliser_le_prénom_en_entier_quand_c'est_p Use_abbreviated_firstname_whenever_possible=Utiliser_le_prénom_abrégé_quand_c'est_possible Use_abbreviated_and_full_firstname=Utiliser_le_prénom_abrégé_et_entier Autocompletion_options=Options_de_la_complétion_automatique -Autocomplete_after_following_number_of_characters=Complétion_automatique_après_un_nombre_de_caractères_égal_à Name_format_used_for_autocompletion=Format_de_nom_utilisé_pour_la_complétion_automatique Treatment_of_first_names=Traitement_des_prénoms Cleanup_entries=Nettoyage_des_entrées @@ -1832,8 +1831,6 @@ Search_results_in_library_%0_for_%1=Résultats_de_recherche_dans_le_fichier_%0_p Search_globally=Rechercher_globalement No_results_found.=Aucun_résultat_trouvé. Found_%0_results.=%0_résultats_trouvés. -Advanced_search_active.=Recherche_avancée_active. -Normal_search_active.=Recherche_normale_active. plain_text=texte_brut This_search_contains_entries_in_which_any_field_contains_the_regular_expression_%0=Cette_recherche_contient_des_entrées_pour_lesquelles_au_moins_un_champ_contient_l'expression_régulière_%0 This_search_contains_entries_in_which_any_field_contains_the_term_%0=Cette_recherche_contient_des_entrées_pour_lesquelles_au_moins_un_champ_contient_le_terme_%0 diff --git a/src/main/resources/l10n/JabRef_in.properties b/src/main/resources/l10n/JabRef_in.properties index c52556b7503..085d45cb78f 100644 --- a/src/main/resources/l10n/JabRef_in.properties +++ b/src/main/resources/l10n/JabRef_in.properties @@ -1554,7 +1554,6 @@ Use_full_firstname_whenever_possible=Gunakan_nama_kecil_penuh_kalau_mungkin Use_abbreviated_firstname_whenever_possible=Gunakan_singkatan_nama_kecil_kalau_mungkin Use_abbreviated_and_full_firstname=Gunakan_nama_kecil_yang_penuh_dan_disingkatkan Autocompletion_options=Opsi_pelengkapian_otomatis -Autocomplete_after_following_number_of_characters=Melengkapi_otomatis_setelah_jumlah_karakter_berikut Name_format_used_for_autocompletion=Format_nama_yang_digunakan_untuk_pelengkapan_otomatis Treatment_of_first_names= Cleanup_entries=Bersihkan_entri @@ -1832,8 +1831,6 @@ Search_results_in_library_%0_for_%1=Hasil_pencarian_untuk_%0_dalam_basisdata_%1 Search_globally=Cari_secara_global No_results_found.=Tidak_menemukan_hasil_pencarian. Found_%0_results.=Menemukan_%0_hasil_pencarian. -Advanced_search_active.=Pencarian_lanjut_aktif. -Normal_search_active.=Pencarian_biasa_aktif. plain_text=teks_biasa This_search_contains_entries_in_which_any_field_contains_the_regular_expression_%0= This_search_contains_entries_in_which_any_field_contains_the_term_%0= diff --git a/src/main/resources/l10n/JabRef_it.properties b/src/main/resources/l10n/JabRef_it.properties index 9d076421dc2..2b43a27e176 100644 --- a/src/main/resources/l10n/JabRef_it.properties +++ b/src/main/resources/l10n/JabRef_it.properties @@ -1554,7 +1554,6 @@ Use_full_firstname_whenever_possible=Usa_nome_completo_quando_possibile Use_abbreviated_firstname_whenever_possible=Usa_nome_abbreviato_quando_possibile Use_abbreviated_and_full_firstname=Usa_nome_abbreviato_e_completo Autocompletion_options=Opzioni_di_autocompletamento -Autocomplete_after_following_number_of_characters=Attiva_autocompletamento_dopo_il_seguente_numero_di_caratteri Name_format_used_for_autocompletion=Formato_dei_nomi_usato_per_l'autocompletamento Treatment_of_first_names=Gestione_dei_nomi Cleanup_entries=Ripulisci_voci @@ -1832,8 +1831,6 @@ Search_results_in_library_%0_for_%1=Risultati_della_ricerca_di_%1_nella_libreria Search_globally=Ricerca_globale No_results_found.=Nessun_risultato_trovato. Found_%0_results.=Trovati_%0_risultati. -Advanced_search_active.=Ricerca_avanzata_attiva. -Normal_search_active.=Ricerca_normale_attiva. plain_text=Testo_semplice This_search_contains_entries_in_which_any_field_contains_the_regular_expression_%0=Questa_ricerca_contiene_occorrenze_in_cui_qualsiasi_campo_contiene_l'espressione_regolare_%0 This_search_contains_entries_in_which_any_field_contains_the_term_%0=Questa_ricerca_contiene_occorrenze_in_cui_qualsiasi_campo_contiene_il_termine_%0 diff --git a/src/main/resources/l10n/JabRef_ja.properties b/src/main/resources/l10n/JabRef_ja.properties index e2f1df70300..e052697a154 100644 --- a/src/main/resources/l10n/JabRef_ja.properties +++ b/src/main/resources/l10n/JabRef_ja.properties @@ -1554,7 +1554,6 @@ Use_full_firstname_whenever_possible=可能な場合は常に完全なファー Use_abbreviated_firstname_whenever_possible=可能な場合は常に短縮したファーストネームを使用 Use_abbreviated_and_full_firstname=短縮したファーストネームと完全なファーストネームを両方使用 Autocompletion_options=自動補完オプション -Autocomplete_after_following_number_of_characters=右記の文字数以上で自動補完 Name_format_used_for_autocompletion=自動補完に使用される氏名の書式 Treatment_of_first_names=名(first_name)の取り扱い Cleanup_entries=項目の整理 @@ -1832,8 +1831,6 @@ Search_results_in_library_%0_for_%1=%0をデータベース%1で検索した結 Search_globally=大域検索 No_results_found.=検出されませんでした。 Found_%0_results.=%0件検出しました。 -Advanced_search_active.=詳細検索が進行中です。 -Normal_search_active.=通常検索が進行中です。 plain_text=平文 This_search_contains_entries_in_which_any_field_contains_the_regular_expression_%0=この検索結果は、フィールドのうちどれかに正規表現%0が含まれている項目を表示します。 This_search_contains_entries_in_which_any_field_contains_the_term_%0=この検索結果は、フィールドのうちどれかに用語%0が含まれている項目を表示します。 diff --git a/src/main/resources/l10n/JabRef_nl.properties b/src/main/resources/l10n/JabRef_nl.properties index d6792c9a5b0..02860311b20 100644 --- a/src/main/resources/l10n/JabRef_nl.properties +++ b/src/main/resources/l10n/JabRef_nl.properties @@ -1554,7 +1554,6 @@ Use_full_firstname_whenever_possible= Use_abbreviated_firstname_whenever_possible= Use_abbreviated_and_full_firstname= Autocompletion_options= -Autocomplete_after_following_number_of_characters= Name_format_used_for_autocompletion= Treatment_of_first_names= Cleanup_entries= @@ -1832,8 +1831,6 @@ Search_results_in_library_%0_for_%1= Search_globally= No_results_found.= Found_%0_results.= -Advanced_search_active.= -Normal_search_active.= plain_text= This_search_contains_entries_in_which_any_field_contains_the_regular_expression_%0= This_search_contains_entries_in_which_any_field_contains_the_term_%0= diff --git a/src/main/resources/l10n/JabRef_no.properties b/src/main/resources/l10n/JabRef_no.properties index 9bd96d50753..f216ae176fa 100644 --- a/src/main/resources/l10n/JabRef_no.properties +++ b/src/main/resources/l10n/JabRef_no.properties @@ -1554,7 +1554,6 @@ Use_full_firstname_whenever_possible= Use_abbreviated_firstname_whenever_possible= Use_abbreviated_and_full_firstname= Autocompletion_options= -Autocomplete_after_following_number_of_characters= Name_format_used_for_autocompletion= Treatment_of_first_names= Cleanup_entries= @@ -1832,8 +1831,6 @@ Search_results_in_library_%0_for_%1= Search_globally= No_results_found.= Found_%0_results.= -Advanced_search_active.= -Normal_search_active.= plain_text= This_search_contains_entries_in_which_any_field_contains_the_regular_expression_%0= This_search_contains_entries_in_which_any_field_contains_the_term_%0= diff --git a/src/main/resources/l10n/JabRef_pt_BR.properties b/src/main/resources/l10n/JabRef_pt_BR.properties index 533892661db..ec20491fe73 100644 --- a/src/main/resources/l10n/JabRef_pt_BR.properties +++ b/src/main/resources/l10n/JabRef_pt_BR.properties @@ -1554,7 +1554,6 @@ Use_full_firstname_whenever_possible=Usar_primeiro_nome_inteiro_sempre_que_poss Use_abbreviated_firstname_whenever_possible=Usar_primeiro_nome_abreviado_sempre_que_possível Use_abbreviated_and_full_firstname=Usar_primeiro_nome_abreviado_e_inteiro Autocompletion_options=Opções_de_autocompletar -Autocomplete_after_following_number_of_characters=Autocompletar_após_um_número_de_caracteres Name_format_used_for_autocompletion=Formato_de_nome_usado_para_autocompletar Treatment_of_first_names=Tratamento_dos_primeiros_nomes Cleanup_entries=Limpar_entradas @@ -1832,8 +1831,6 @@ Search_results_in_library_%0_for_%1= Search_globally= No_results_found.=Nenhum_resultado_encontrado. Found_%0_results.=Encontrados_%0_resultados. -Advanced_search_active.=Busca_avançada_ativa. -Normal_search_active.= plain_text= This_search_contains_entries_in_which_any_field_contains_the_regular_expression_%0= This_search_contains_entries_in_which_any_field_contains_the_term_%0= diff --git a/src/main/resources/l10n/JabRef_ru.properties b/src/main/resources/l10n/JabRef_ru.properties index aae08dd5db2..90c695c2433 100644 --- a/src/main/resources/l10n/JabRef_ru.properties +++ b/src/main/resources/l10n/JabRef_ru.properties @@ -1554,7 +1554,6 @@ Use_full_firstname_whenever_possible=Использовать_полное_им Use_abbreviated_firstname_whenever_possible=Использовать_сокращенное_имя_(если_возможно) Use_abbreviated_and_full_firstname=Использовать_сокращенное_и_полное_имя Autocompletion_options=Параметры_автозавершения -Autocomplete_after_following_number_of_characters=Автозавершение_после_следующего_числа_знаков Name_format_used_for_autocompletion=Формат_имени_для_автозавершения Treatment_of_first_names=Способ_обработки_имен Cleanup_entries=Очистить_записи @@ -1832,8 +1831,6 @@ Search_results_in_library_%0_for_%1=Результаты_поиска_в_БД_%0 Search_globally=Глобальный_поиск No_results_found.=Результаты_не_найдены. Found_%0_results.=Найдено_%0_результатов. -Advanced_search_active.=Включен_расширенный_поиск. -Normal_search_active.=Включен_нормальный_поиск. plain_text=обычный_текст This_search_contains_entries_in_which_any_field_contains_the_regular_expression_%0=Поиск_содержит_записи,_в_которых_любое_поле_содержит_регулярное_выражение_%0 This_search_contains_entries_in_which_any_field_contains_the_term_%0=Поиск_содержит_записи,_в_которых_любое_поле_содержит_условие_%0 diff --git a/src/main/resources/l10n/JabRef_sv.properties b/src/main/resources/l10n/JabRef_sv.properties index dff772667a0..80b93a74b8d 100644 --- a/src/main/resources/l10n/JabRef_sv.properties +++ b/src/main/resources/l10n/JabRef_sv.properties @@ -1554,7 +1554,6 @@ Use_full_firstname_whenever_possible=Använd_hela_förnamnet_om_möjligt Use_abbreviated_firstname_whenever_possible=Använd_om_möjligt_förkortade_förnamn Use_abbreviated_and_full_firstname=Använd_förkortade_och_hela_förnamn Autocompletion_options=Inställningar_för_automatisk_komplettering -Autocomplete_after_following_number_of_characters=Komplettera_automatiskt_efter_följande_antal_bokstäver Name_format_used_for_autocompletion=Namnformat_för_automatisk_komplettering Treatment_of_first_names=Hantering_av_förnamn Cleanup_entries=Städa_upp_poster @@ -1832,8 +1831,6 @@ Search_results_in_library_%0_for_%1=Söker_efter_%1_i_libraryn_%0 Search_globally=Sök_globalt No_results_found.=Inga_resultat_hittades. Found_%0_results.=Hittade_%0_resultat. -Advanced_search_active.=Avancerad_sökning_aktiv. -Normal_search_active.=Normal_sökning_aktiv. plain_text=klartext This_search_contains_entries_in_which_any_field_contains_the_regular_expression_%0=Denna_sökning_innehåller_poster_där_något_fält_innehåller_det_reguljära_uttrycket_%0 This_search_contains_entries_in_which_any_field_contains_the_term_%0=Denna_sökning_innehåller_poster_där_något_fält_innehåller_termen_%0 diff --git a/src/main/resources/l10n/JabRef_tr.properties b/src/main/resources/l10n/JabRef_tr.properties index b16629ed740..3a69fadf8a2 100644 --- a/src/main/resources/l10n/JabRef_tr.properties +++ b/src/main/resources/l10n/JabRef_tr.properties @@ -1554,7 +1554,6 @@ Use_full_firstname_whenever_possible=Mümkün_oldukça_tam_ilk_ismi_kullanınız Use_abbreviated_firstname_whenever_possible=Mümkün_oldukça_kısaltılmış_ilk_ismi_kullanınız Use_abbreviated_and_full_firstname=Kısaltılmış_ve_tam_ilk_ismi_kullanınız Autocompletion_options=Otomatik_tamamlama_seçenekleri -Autocomplete_after_following_number_of_characters=Şu_sayıdaki_karakterden_sonra_otomatik_tamamla Name_format_used_for_autocompletion=Otomatik_tamamlama_için_kullanılan_isim_biçemi Treatment_of_first_names=İlk_isimlerin_işlenme_şekli Cleanup_entries=Girdileri_temizle @@ -1832,8 +1831,6 @@ Search_results_in_library_%0_for_%1=Sonuçları_%1_için_%0_veritabanında_ara Search_globally=Küresel_ara No_results_found.=Hiçbir_sonuç_bulunmadı. Found_%0_results.=%0_sonuç_bulundu. -Advanced_search_active.=İleri_düzey_arama_aktif. -Normal_search_active.=Normal_arama_aktif. plain_text=salt_metin This_search_contains_entries_in_which_any_field_contains_the_regular_expression_%0=Bu_arama,_%0_düzenli_ifadesini_içeren_herhangi_bir_alan_bulunan_girdileri_içerir This_search_contains_entries_in_which_any_field_contains_the_term_%0=Bu_arama,_%0_terimini_içeren_herhangi_bir_alan_bulunan_girdileri_içerir diff --git a/src/main/resources/l10n/JabRef_vi.properties b/src/main/resources/l10n/JabRef_vi.properties index b359f585f00..ebb1ae5abfb 100644 --- a/src/main/resources/l10n/JabRef_vi.properties +++ b/src/main/resources/l10n/JabRef_vi.properties @@ -1554,7 +1554,6 @@ Use_full_firstname_whenever_possible= Use_abbreviated_firstname_whenever_possible= Use_abbreviated_and_full_firstname= Autocompletion_options= -Autocomplete_after_following_number_of_characters= Name_format_used_for_autocompletion= Treatment_of_first_names= Cleanup_entries= @@ -1832,8 +1831,6 @@ Search_results_in_library_%0_for_%1= Search_globally= No_results_found.= Found_%0_results.= -Advanced_search_active.= -Normal_search_active.= plain_text= This_search_contains_entries_in_which_any_field_contains_the_regular_expression_%0= This_search_contains_entries_in_which_any_field_contains_the_term_%0= diff --git a/src/main/resources/l10n/JabRef_zh.properties b/src/main/resources/l10n/JabRef_zh.properties index cef673bfa2c..7f6778e2aa7 100644 --- a/src/main/resources/l10n/JabRef_zh.properties +++ b/src/main/resources/l10n/JabRef_zh.properties @@ -1554,7 +1554,6 @@ Use_full_firstname_whenever_possible=尽可能使用完整的_Firstname Use_abbreviated_firstname_whenever_possible=尽可能使用缩写的_Firstname Use_abbreviated_and_full_firstname=混杂使用缩写和完整的_Firstname Autocompletion_options=自动补全选项 -Autocomplete_after_following_number_of_characters=在键入多少字符时开始自动补全 Name_format_used_for_autocompletion=自动补全的姓名格式 Treatment_of_first_names=Firstname_的处理 Cleanup_entries=清理选中记录 @@ -1832,8 +1831,6 @@ Search_results_in_library_%0_for_%1=在文献库_%0_中搜索_%1_的结果 Search_globally=全局搜索 No_results_found.=没有找到结果. Found_%0_results.=找到_%0_条结果. -Advanced_search_active.=高级搜索行为。 -Normal_search_active.=普通搜索行为。 plain_text=纯文本 This_search_contains_entries_in_which_any_field_contains_the_regular_expression_%0=这次搜索的结果记录符合条件:记录的任意域包含正则表达式_%0 This_search_contains_entries_in_which_any_field_contains_the_term_%0=这次搜索的结果记录符合条件:记录的任意域包含词组_%0 From c39ac7b2fb5ce82a0b9d46ade12d958d806c9f8c Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Tue, 11 Jul 2017 12:08:09 +0200 Subject: [PATCH 09/10] Code cleanup and changelog entry added --- CHANGELOG.md | 1 + src/main/java/org/jabref/gui/BasePanel.java | 2 +- .../AutoCompletePreferences.java | 20 ++++++++++++++----- .../AutoCompletionTextInputBinding.java | 1 - .../gui/preftabs/EntryEditorPrefsTab.java | 5 +++-- .../jabref/gui/search/SearchTextField.java | 1 - .../jabref/preferences/JabRefPreferences.java | 13 ++++++++++-- .../gui/autocompleter/AutoCompleterUtil.java | 0 8 files changed, 31 insertions(+), 12 deletions(-) rename src/{main => test}/java/org/jabref/gui/autocompleter/AutoCompleterUtil.java (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bdae58da4e..192b1595e42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - The buttons were changed to icons. - Completely new interface to add or modify linked files. - Removed the hidden feature that a double click in the editor inserted the current date. + - Complete new implementation of the the auto complete feature. - All authors and editors are separated using semicolons when exporting to csv. [#2762](https://github.com/JabRef/jabref/issues/2762) - Improved wording of "Show recommendations: into "Show 'Related Articles' tab" in the preferences - We added integration of the Library of Congress catalog as a fetcher based on the [LCCN identifier](https://en.wikipedia.org/wiki/Library_of_Congress_Control_Number). [Feature request 636 in the forum](http://discourse.jabref.org/t/loc-marc-mods-connection/636) diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 13e6db4589d..f048050424b 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -1388,7 +1388,7 @@ public void setupMainPanel() { */ private void setupAutoCompletion() { AutoCompletePreferences autoCompletePreferences = Globals.prefs.getAutoCompletePreferences(); - if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_COMPLETE)) { + if (autoCompletePreferences.shouldAutoComplete()) { suggestionProviders = new SuggestionProviders(autoCompletePreferences, Globals.journalAbbreviationLoader); suggestionProviders.indexDatabase(getDatabase()); // Ensure that the suggestion providers are in sync with entries diff --git a/src/main/java/org/jabref/gui/autocompleter/AutoCompletePreferences.java b/src/main/java/org/jabref/gui/autocompleter/AutoCompletePreferences.java index 49db09bf9db..48226d3ec33 100644 --- a/src/main/java/org/jabref/gui/autocompleter/AutoCompletePreferences.java +++ b/src/main/java/org/jabref/gui/autocompleter/AutoCompletePreferences.java @@ -9,13 +9,15 @@ public class AutoCompletePreferences { private static final String DELIMITER = ";"; + private boolean shouldAutoComplete; private AutoCompleteFirstNameMode firstNameMode; private boolean onlyCompleteLastFirst; private boolean onlyCompleteFirstLast; private List completeNames; private JournalAbbreviationPreferences journalAbbreviationPreferences; - public AutoCompletePreferences(AutoCompleteFirstNameMode firstNameMode, boolean onlyCompleteLastFirst, boolean onlyCompleteFirstLast, List completeNames, JournalAbbreviationPreferences journalAbbreviationPreferences) { + public AutoCompletePreferences(boolean shouldAutoComplete, AutoCompleteFirstNameMode firstNameMode, boolean onlyCompleteLastFirst, boolean onlyCompleteFirstLast, List completeNames, JournalAbbreviationPreferences journalAbbreviationPreferences) { + this.shouldAutoComplete = shouldAutoComplete; this.firstNameMode = firstNameMode; this.onlyCompleteLastFirst = onlyCompleteLastFirst; this.onlyCompleteFirstLast = onlyCompleteFirstLast; @@ -23,6 +25,14 @@ public AutoCompletePreferences(AutoCompleteFirstNameMode firstNameMode, boolean this.journalAbbreviationPreferences = journalAbbreviationPreferences; } + public void setShouldAutoComplete(boolean shouldAutoComplete) { + this.shouldAutoComplete = shouldAutoComplete; + } + + public boolean shouldAutoComplete() { + return shouldAutoComplete; + } + /** * Returns how the first names are handled. */ @@ -54,14 +64,14 @@ public List getCompleteNames() { return completeNames; } - public void setCompleteNames(String input) { - setCompleteNames(Arrays.asList(input.split(DELIMITER))); - } - public void setCompleteNames(List completeNames) { this.completeNames = completeNames; } + public void setCompleteNames(String input) { + setCompleteNames(Arrays.asList(input.split(DELIMITER))); + } + public String getCompleteNamesAsString() { return completeNames.stream().collect(Collectors.joining(DELIMITER)); } diff --git a/src/main/java/org/jabref/gui/autocompleter/AutoCompletionTextInputBinding.java b/src/main/java/org/jabref/gui/autocompleter/AutoCompletionTextInputBinding.java index 384d5067ec3..3c3ce92bb55 100644 --- a/src/main/java/org/jabref/gui/autocompleter/AutoCompletionTextInputBinding.java +++ b/src/main/java/org/jabref/gui/autocompleter/AutoCompletionTextInputBinding.java @@ -94,7 +94,6 @@ private AutoCompletionTextInputBinding(final TextInputControl textInputControl, getCompletionTarget().focusedProperty().addListener(focusChangedListener); } - private static StringConverter defaultStringConverter() { return new StringConverter() { @Override diff --git a/src/main/java/org/jabref/gui/preftabs/EntryEditorPrefsTab.java b/src/main/java/org/jabref/gui/preftabs/EntryEditorPrefsTab.java index 8760c25c44c..28bc7ebce77 100644 --- a/src/main/java/org/jabref/gui/preftabs/EntryEditorPrefsTab.java +++ b/src/main/java/org/jabref/gui/preftabs/EntryEditorPrefsTab.java @@ -154,7 +154,7 @@ public void setValues() { emacsRebindCtrlA.setSelected(prefs.getBoolean(JabRefPreferences.EDITOR_EMACS_KEYBINDINGS_REBIND_CA)); emacsRebindCtrlF.setSelected(prefs.getBoolean(JabRefPreferences.EDITOR_EMACS_KEYBINDINGS_REBIND_CF)); recommendations.setSelected(prefs.getBoolean(JabRefPreferences.SHOW_RECOMMENDATIONS)); - autoComplete.setSelected(prefs.getBoolean(JabRefPreferences.AUTO_COMPLETE)); + autoComplete.setSelected(autoCompletePreferences.shouldAutoComplete()); autoCompFields.setText(autoCompletePreferences.getCompleteNamesAsString()); if (autoCompletePreferences.getOnlyCompleteFirstLast()) { @@ -210,7 +210,7 @@ public void storeSettings() { EmacsKeyBindings.load(); } } - prefs.putBoolean(JabRefPreferences.AUTO_COMPLETE, autoComplete.isSelected()); + autoCompletePreferences.setShouldAutoComplete(autoComplete.isSelected()); autoCompletePreferences.setCompleteNames(autoCompFields.getText()); if (autoCompBoth.isSelected()) { autoCompletePreferences.setOnlyCompleteFirstLast(false); @@ -231,6 +231,7 @@ else if (autoCompFF.isSelected()) { } else { autoCompletePreferences.setFirstNameMode(AutoCompleteFirstNameMode.BOTH); } + prefs.storeAutoCompletePreferences(autoCompletePreferences); } @Override diff --git a/src/main/java/org/jabref/gui/search/SearchTextField.java b/src/main/java/org/jabref/gui/search/SearchTextField.java index a3a9cf6c44b..e018ac2efd9 100644 --- a/src/main/java/org/jabref/gui/search/SearchTextField.java +++ b/src/main/java/org/jabref/gui/search/SearchTextField.java @@ -1,6 +1,5 @@ package org.jabref.gui.search; - import javafx.scene.control.TextField; import org.jabref.gui.IconTheme; diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 6a56c76511c..4334f0d4c95 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -181,7 +181,6 @@ public class JabRefPreferences implements PreferencesService { public static final String PREFS_EXPORT_PATH = "prefsExportPath"; public static final String WORKING_DIRECTORY = "workingDirectory"; public static final String NUMBER_COL_WIDTH = "numberColWidth"; - public static final String AUTO_COMPLETE = "autoComplete"; public static final String EDITOR_EMACS_KEYBINDINGS = "editorEMACSkeyBindings"; public static final String EDITOR_EMACS_KEYBINDINGS_REBIND_CA = "editorEMACSkeyBindingsRebindCA"; public static final String EDITOR_EMACS_KEYBINDINGS_REBIND_CF = "editorEMACSkeyBindingsRebindCF"; @@ -392,6 +391,7 @@ public class JabRefPreferences implements PreferencesService { private static final String PREVIEW_STYLE = "previewStyle"; private static final String PREVIEW_ENABLED = "previewEnabled"; // Auto completion + private static final String AUTO_COMPLETE = "autoComplete"; private static final String AUTOCOMPLETER_FIRSTNAME_MODE = "autoCompFirstNameMode"; private static final String AUTOCOMPLETER_LAST_FIRST = "autoCompLF"; private static final String AUTOCOMPLETER_FIRST_LAST = "autoCompFF"; @@ -571,7 +571,7 @@ private JabRefPreferences() { defaults.put(EDITOR_EMACS_KEYBINDINGS, Boolean.FALSE); defaults.put(EDITOR_EMACS_KEYBINDINGS_REBIND_CA, Boolean.TRUE); defaults.put(EDITOR_EMACS_KEYBINDINGS_REBIND_CF, Boolean.TRUE); - defaults.put(AUTO_COMPLETE, Boolean.FALSE); + defaults.put(AUTO_COMPLETE, Boolean.TRUE); defaults.put(AUTOCOMPLETER_FIRSTNAME_MODE, AutoCompleteFirstNameMode.BOTH.name()); defaults.put(AUTOCOMPLETER_FIRST_LAST, Boolean.FALSE); // "Autocomplete names in 'Firstname Lastname' format only" defaults.put(AUTOCOMPLETER_LAST_FIRST, Boolean.FALSE); // "Autocomplete names in 'Lastname, Firstname' format only" @@ -1613,6 +1613,7 @@ public AutoLinkPreferences getAutoLinkPreferences() { public AutoCompletePreferences getAutoCompletePreferences() { return new AutoCompletePreferences( + getBoolean(AUTO_COMPLETE), AutoCompleteFirstNameMode.parse(get(AUTOCOMPLETER_FIRSTNAME_MODE)), getBoolean(AUTOCOMPLETER_LAST_FIRST), getBoolean(AUTOCOMPLETER_FIRST_LAST), @@ -1620,4 +1621,12 @@ public AutoCompletePreferences getAutoCompletePreferences() { getJournalAbbreviationPreferences() ); } + + public void storeAutoCompletePreferences(AutoCompletePreferences autoCompletePreferences) { + putBoolean(AUTO_COMPLETE, autoCompletePreferences.shouldAutoComplete()); + put(AUTOCOMPLETER_FIRSTNAME_MODE, autoCompletePreferences.getFirstNameMode().name()); + putBoolean(AUTOCOMPLETER_LAST_FIRST, autoCompletePreferences.getOnlyCompleteLastFirst()); + putBoolean(AUTOCOMPLETER_FIRST_LAST, autoCompletePreferences.getOnlyCompleteFirstLast()); + putStringList(AUTOCOMPLETER_COMPLETE_FIELDS, autoCompletePreferences.getCompleteNames()); + } } diff --git a/src/main/java/org/jabref/gui/autocompleter/AutoCompleterUtil.java b/src/test/java/org/jabref/gui/autocompleter/AutoCompleterUtil.java similarity index 100% rename from src/main/java/org/jabref/gui/autocompleter/AutoCompleterUtil.java rename to src/test/java/org/jabref/gui/autocompleter/AutoCompleterUtil.java From cc8a9db450247a6f977f05971ec9ef41e7528622 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Tue, 11 Jul 2017 16:08:38 +0200 Subject: [PATCH 10/10] Fix tests --- .../PersonNameSuggestionProvider.java | 2 +- ...va => BibEntrySuggestionProviderTest.java} | 19 +- .../FieldValueSuggestionProviderTest.java | 21 +-- .../PersonNameSuggestionProviderTest.java | 171 ++++-------------- 4 files changed, 59 insertions(+), 154 deletions(-) rename src/test/java/org/jabref/gui/autocompleter/{BibtexKeyAutoCompleterTest.java => BibEntrySuggestionProviderTest.java} (84%) diff --git a/src/main/java/org/jabref/gui/autocompleter/PersonNameSuggestionProvider.java b/src/main/java/org/jabref/gui/autocompleter/PersonNameSuggestionProvider.java index 4e813759e75..379ddc4ac99 100644 --- a/src/main/java/org/jabref/gui/autocompleter/PersonNameSuggestionProvider.java +++ b/src/main/java/org/jabref/gui/autocompleter/PersonNameSuggestionProvider.java @@ -55,7 +55,7 @@ protected Comparator getComparator() { @Override protected boolean isMatch(Author suggestion, AutoCompletionBinding.ISuggestionRequest request) { String userTextLower = request.getUserText().toLowerCase(); - String suggestionStr = suggestion.getNameForAlphabetization().toLowerCase(); + String suggestionStr = suggestion.getLastFirst(false).toLowerCase(); return suggestionStr.contains(userTextLower); } } diff --git a/src/test/java/org/jabref/gui/autocompleter/BibtexKeyAutoCompleterTest.java b/src/test/java/org/jabref/gui/autocompleter/BibEntrySuggestionProviderTest.java similarity index 84% rename from src/test/java/org/jabref/gui/autocompleter/BibtexKeyAutoCompleterTest.java rename to src/test/java/org/jabref/gui/autocompleter/BibEntrySuggestionProviderTest.java index 48e196f1651..b66163a940d 100644 --- a/src/test/java/org/jabref/gui/autocompleter/BibtexKeyAutoCompleterTest.java +++ b/src/test/java/org/jabref/gui/autocompleter/BibEntrySuggestionProviderTest.java @@ -12,7 +12,7 @@ import static org.jabref.gui.autocompleter.AutoCompleterUtil.getRequest; -public class BibtexKeyAutoCompleterTest { +public class BibEntrySuggestionProviderTest { private BibEntrySuggestionProvider autoCompleter; @Before @@ -50,7 +50,7 @@ public void completeKeyReturnsKey() { autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("testKey"))); - Assert.assertEquals(Arrays.asList("testKey"), result); + Assert.assertEquals(Collections.singletonList(entry), result); } @Test @@ -60,7 +60,7 @@ public void completeBeginnigOfKeyReturnsKey() { autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("test"))); - Assert.assertEquals(Arrays.asList("testKey"), result); + Assert.assertEquals(Collections.singletonList(entry), result); } @Test @@ -70,17 +70,16 @@ public void completeLowercaseKeyReturnsKey() { autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("testkey"))); - Assert.assertEquals(Arrays.asList("testKey"), result); + Assert.assertEquals(Collections.singletonList(entry), result); } - @Test - public void completeNullReturnsNothing() { + @Test(expected = NullPointerException.class) + public void completeNullThrowsException() { BibEntry entry = new BibEntry(); entry.setCiteKey("testKey"); autoCompleter.indexEntry(entry); - Collection result = autoCompleter.call(getRequest((null))); - Assert.assertEquals(Collections.emptyList(), result); + autoCompleter.call(getRequest((null))); } @Test @@ -103,7 +102,7 @@ public void completeReturnsMultipleResults() { autoCompleter.indexEntry(entryTwo); Collection result = autoCompleter.call(getRequest(("testKey"))); - Assert.assertEquals(Arrays.asList("testKeyOne", "testKeyTwo"), result); + Assert.assertEquals(Arrays.asList(entryTwo, entryOne), result); } @Test @@ -113,6 +112,6 @@ public void completeShortKeyReturnsKey() { autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("k"))); - Assert.assertEquals(Arrays.asList("key"), result); + Assert.assertEquals(Collections.singletonList(entry), result); } } diff --git a/src/test/java/org/jabref/gui/autocompleter/FieldValueSuggestionProviderTest.java b/src/test/java/org/jabref/gui/autocompleter/FieldValueSuggestionProviderTest.java index 3494851023f..1ecf2600084 100644 --- a/src/test/java/org/jabref/gui/autocompleter/FieldValueSuggestionProviderTest.java +++ b/src/test/java/org/jabref/gui/autocompleter/FieldValueSuggestionProviderTest.java @@ -89,14 +89,13 @@ public void completeLowercaseValueReturnsValue() { Assert.assertEquals(Arrays.asList("testValue"), result); } - @Test - public void completeNullReturnsNothing() { + @Test(expected = NullPointerException.class) + public void completeNullThrowsException() { BibEntry entry = new BibEntry(); entry.setField("field", "testKey"); autoCompleter.indexEntry(entry); - Collection result = autoCompleter.call(getRequest((null))); - Assert.assertEquals(Collections.emptyList(), result); + autoCompleter.call(getRequest((null))); } @Test @@ -123,33 +122,33 @@ public void completeReturnsMultipleResults() { } @Test - public void completeShortStringReturnsNothing() { + public void completeShortStringReturnsFieldValue() { BibEntry entry = new BibEntry(); entry.setField("field", "val"); autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("va"))); - Assert.assertEquals(Collections.emptyList(), result); + Assert.assertEquals(Collections.singletonList("val"), result); } @Test - public void completeBeginnigOfSecondWordReturnsNothing() { + public void completeBeginnigOfSecondWordReturnsWholeFieldValue() { BibEntry entry = new BibEntry(); entry.setField("field", "test value"); autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("val"))); - Assert.assertEquals(Collections.emptyList(), result); + Assert.assertEquals(Collections.singletonList("test value"), result); } @Test - public void completePartOfWordReturnsNothing() { + public void completePartOfWordReturnsWholeFieldValue() { BibEntry entry = new BibEntry(); entry.setField("field", "test value"); autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("lue"))); - Assert.assertEquals(Collections.emptyList(), result); + Assert.assertEquals(Collections.singletonList("test value"), result); } @Test @@ -159,6 +158,6 @@ public void completeReturnsWholeFieldValue() { autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("te"))); - Assert.assertEquals(Arrays.asList("test value"), result); + Assert.assertEquals(Collections.singletonList("test value"), result); } } diff --git a/src/test/java/org/jabref/gui/autocompleter/PersonNameSuggestionProviderTest.java b/src/test/java/org/jabref/gui/autocompleter/PersonNameSuggestionProviderTest.java index 899a64a120c..9b4365b08dd 100644 --- a/src/test/java/org/jabref/gui/autocompleter/PersonNameSuggestionProviderTest.java +++ b/src/test/java/org/jabref/gui/autocompleter/PersonNameSuggestionProviderTest.java @@ -15,7 +15,9 @@ public class PersonNameSuggestionProviderTest { - PersonNameSuggestionProvider autoCompleter; + private static final Author vassilisKostakos = new Author("Vassilis", "V.", "", "Kostakos", ""); + private PersonNameSuggestionProvider autoCompleter; + private BibEntry entry; @Test(expected = NullPointerException.class) public void initAutoCompleterWithNullFieldThrowsException() { @@ -25,6 +27,9 @@ public void initAutoCompleterWithNullFieldThrowsException() { @Before public void setUp() throws Exception { autoCompleter = new PersonNameSuggestionProvider("field"); + + entry = new BibEntry(); + entry.setField("field", "Vassilis Kostakos"); } @Test @@ -62,48 +67,35 @@ public void completeAfterAddingEntryWithoutFieldReturnsNothing() { @Test public void completeNameReturnsName() { - BibEntry entry = new BibEntry(); - entry.setField("field", "Testname"); autoCompleter.indexEntry(entry); - Collection result = autoCompleter.call(getRequest(("Testname"))); - Assert.assertEquals(Arrays.asList("Testname"), result); + Collection result = autoCompleter.call(getRequest(("Kostakos"))); + Assert.assertEquals(Collections.singletonList(vassilisKostakos), result); } @Test - public void completeBeginnigOfNameReturnsName() { - BibEntry entry = new BibEntry(); - entry.setField("field", "Testname"); + public void completeBeginningOfNameReturnsName() { autoCompleter.indexEntry(entry); - Collection result = autoCompleter.call(getRequest(("Test"))); - Assert.assertEquals(Arrays.asList("Testname"), result); + Collection result = autoCompleter.call(getRequest(("Kosta"))); + Assert.assertEquals(Collections.singletonList(vassilisKostakos), result); } @Test - public void completeLowercaseNameReturnsName() { - BibEntry entry = new BibEntry(); - entry.setField("field", "Testname"); + public void completeLowercaseBeginningOfNameReturnsName() { autoCompleter.indexEntry(entry); - Collection result = autoCompleter.call(getRequest(("test"))); - Assert.assertEquals(Arrays.asList("Testname"), result); + Collection result = autoCompleter.call(getRequest(("kosta"))); + Assert.assertEquals(Collections.singletonList(vassilisKostakos), result); } - @Test - public void completeNullReturnsNothing() { - BibEntry entry = new BibEntry(); - entry.setField("field", "testKey"); - autoCompleter.indexEntry(entry); - - Collection result = autoCompleter.call(getRequest((null))); - Assert.assertEquals(Collections.emptyList(), result); + @Test(expected = NullPointerException.class) + public void completeNullThrowsException() { + autoCompleter.call(getRequest((null))); } @Test public void completeEmptyStringReturnsNothing() { - BibEntry entry = new BibEntry(); - entry.setField("field", "testKey"); autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest((""))); @@ -112,168 +104,83 @@ public void completeEmptyStringReturnsNothing() { @Test public void completeReturnsMultipleResults() { - BibEntry entryOne = new BibEntry(); - entryOne.setField("field", "testNameOne"); - autoCompleter.indexEntry(entryOne); + autoCompleter.indexEntry(entry); BibEntry entryTwo = new BibEntry(); - entryTwo.setField("field", "testNameTwo"); + entryTwo.setField("field", "Kosta"); autoCompleter.indexEntry(entryTwo); + Author authorTwo = new Author("", "", "", "Kosta", ""); - Collection result = autoCompleter.call(getRequest(("testName"))); - Assert.assertEquals(Arrays.asList("testNameOne", "testNameTwo"), result); + Collection result = autoCompleter.call(getRequest(("Ko"))); + Assert.assertEquals(Arrays.asList(authorTwo, vassilisKostakos), result); } @Test - public void completePartOfNameReturnsNothing() { - BibEntry entry = new BibEntry(); - entry.setField("field", "Vassilis Kostakos"); + public void completePartOfNameReturnsName() { autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("osta"))); - Assert.assertEquals(Collections.emptyList(), result); + Assert.assertEquals(Collections.singletonList(vassilisKostakos), result); } @Test - public void completeBeginningOfFirstNameReturnsCompleteName() { - BibEntry entry = new BibEntry(); - entry.setField("field", "Vassilis Kostakos"); + public void completeBeginningOfFirstNameReturnsName() { autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("Vas"))); - Assert.assertEquals(Arrays.asList("Vassilis Kostakos"), result); + Assert.assertEquals(Collections.singletonList(vassilisKostakos), result); } @Test - public void completeBeginningOfFirstNameReturnsCompleteNameWithJr() { + public void completeBeginningOfFirstNameReturnsNameWithJr() { BibEntry entry = new BibEntry(); entry.setField("field", "Reagle, Jr., Joseph M."); autoCompleter.indexEntry(entry); + Author author = new Author("Joseph M.", "J. M.", "", "Reagle", "Jr."); Collection result = autoCompleter.call(getRequest(("Jos"))); - Assert.assertEquals(Arrays.asList("Joseph M. Reagle, Jr."), result); + Assert.assertEquals(Collections.singletonList(author), result); } @Test - public void completeBeginningOfFirstNameReturnsCompleteNameWithVon() { + public void completeBeginningOfFirstNameReturnsNameWithVon() { BibEntry entry = new BibEntry(); entry.setField("field", "Eric von Hippel"); autoCompleter.indexEntry(entry); + Author author = new Author("Eric", "E.", "von", "Hippel", ""); Collection result = autoCompleter.call(getRequest(("Eric"))); - Assert.assertEquals(Arrays.asList("Eric von Hippel"), result); + Assert.assertEquals(Collections.singletonList(author), result); } @Test public void completeBeginningOfLastNameReturnsNameWithUmlauts() { - //when(preferences.getFirstnameMode()).thenReturn(AutoCompleteFirstNameMode.ONLY_FULL); - BibEntry entry = new BibEntry(); entry.setField("field", "Honig Bär"); autoCompleter.indexEntry(entry); + Author author = new Author("Honig", "H.", "", "Bär", ""); Collection result = autoCompleter.call(getRequest(("Bä"))); - Assert.assertEquals(Arrays.asList("Bär, Honig"), result); - } - - @Test - public void completeBeginningOfLastNameReturnsNameAndNameWithInitialFirstname() { - BibEntry entry = new BibEntry(); - entry.setField("field", "Vassilis Kostakos"); - autoCompleter.indexEntry(entry); - - Collection result = autoCompleter.call(getRequest(("Kosta"))); - Assert.assertEquals(Arrays.asList("Kostakos, V.", "Kostakos, Vassilis"), result); - } - - @Test - public void completeBeginningOfLastNameReturnsNameIfPref() { - //when(preferences.getFirstnameMode()).thenReturn(AutoCompleteFirstNameMode.ONLY_FULL); - - BibEntry entry = new BibEntry(); - entry.setField("field", "Vassilis Kostakos"); - autoCompleter.indexEntry(entry); - - Collection result = autoCompleter.call(getRequest(("Kosta"))); - Assert.assertEquals(Arrays.asList("Kostakos, Vassilis"), result); - } - - @Test - public void completeBeginningOfLastNameReturnsNameWithJrIfPref() { - //when(preferences.getFirstnameMode()).thenReturn(AutoCompleteFirstNameMode.ONLY_ABBREVIATED); - - BibEntry entry = new BibEntry(); - entry.setField("field", "Reagle, Jr., Joseph M."); - autoCompleter.indexEntry(entry); - - Collection result = autoCompleter.call(getRequest(("Rea"))); - Assert.assertEquals(Arrays.asList("Reagle, Jr., J. M."), result); + Assert.assertEquals(Collections.singletonList(author), result); } @Test - public void completeBeginningOfLastNameReturnsNameWithInitialFirstnameIfPref() { - //when(preferences.getFirstnameMode()).thenReturn(AutoCompleteFirstNameMode.ONLY_ABBREVIATED); - - BibEntry entry = new BibEntry(); - entry.setField("field", "Vassilis Kostakos"); - autoCompleter.indexEntry(entry); - - Collection result = autoCompleter.call(getRequest(("Kosta"))); - Assert.assertEquals(Arrays.asList("Kostakos, V."), result); - } - - @Test - public void completeVonReturnsNameWithInitialFirstnameIfPref() { - //when(preferences.getFirstnameMode()).thenReturn(AutoCompleteFirstNameMode.ONLY_ABBREVIATED); - + public void completeVonReturnsName() { BibEntry entry = new BibEntry(); entry.setField("field", "Eric von Hippel"); autoCompleter.indexEntry(entry); + Author author = new Author("Eric", "E.", "von", "Hippel", ""); Collection result = autoCompleter.call(getRequest(("von"))); - Assert.assertEquals(Arrays.asList("von Hippel, E."), result); + Assert.assertEquals(Collections.singletonList(author), result); } @Test - public void completeBeginningOfNameReturnsCompleteName() { + public void completeBeginningOfFullNameReturnsName() { BibEntry entry = new BibEntry(); entry.setField("field", "Vassilis Kostakos"); autoCompleter.indexEntry(entry); Collection result = autoCompleter.call(getRequest(("Kostakos, Va"))); - Assert.assertEquals(Arrays.asList("Kostakos, Vassilis"), result); - } - - @Test - public void completeBeginningOfLastNameReturnsNothingIfPref() { - //when(preferences.getOnlyCompleteFirstLast()).thenReturn(true); - - BibEntry entry = new BibEntry(); - entry.setField("field", "Vassilis Kostakos"); - autoCompleter.indexEntry(entry); - - Collection result = autoCompleter.call(getRequest(("Kosta"))); - Assert.assertEquals(Collections.emptyList(), result); - } - - @Test - public void completeBeginningOfFirstNameReturnsNothingIfPref() { - //when(preferences.getOnlyCompleteLastFirst()).thenReturn(true); - - BibEntry entry = new BibEntry(); - entry.setField("field", "Vassilis Kostakos"); - autoCompleter.indexEntry(entry); - - Collection result = autoCompleter.call(getRequest(("Vas"))); - Assert.assertEquals(Collections.emptyList(), result); - } - - @Test - public void completeShortNameReturnsName() { - BibEntry entry = new BibEntry(); - entry.setField("field", "nam"); - autoCompleter.indexEntry(entry); - - Collection result = autoCompleter.call(getRequest(("n"))); - Assert.assertEquals(Arrays.asList("nam"), result); + Assert.assertEquals(Collections.singletonList(vassilisKostakos), result); } }