diff --git a/.idea/runConfigurations/JabRef_Main.xml b/.idea/runConfigurations/JabRef_Main.xml
index d57c0fd5ac5..3935f776742 100644
--- a/.idea/runConfigurations/JabRef_Main.xml
+++ b/.idea/runConfigurations/JabRef_Main.xml
@@ -3,7 +3,7 @@
-
+
@@ -13,4 +13,4 @@
-
\ No newline at end of file
+
diff --git a/src/main/java/org/jabref/gui/Base.css b/src/main/java/org/jabref/gui/Base.css
index f9fac1bd799..e081cdf8c45 100644
--- a/src/main/java/org/jabref/gui/Base.css
+++ b/src/main/java/org/jabref/gui/Base.css
@@ -1174,10 +1174,16 @@ TextFlow * {
-fx-fill: -fx-text-background-color;
}
+.chips-pane > .editor {
+ -fx-pref-height: 30px;
+ -fx-padding: 0px 0px 0px -8px;
+ -fx-margin: 0em;
+
.searchBar:invalid {
-fx-background-color: rgba(240, 128, 128, 0.5);
}
.searchBar:unsupported {
-fx-background-color: rgba(255, 159, 67, 0.5);
+
}
diff --git a/src/main/java/org/jabref/gui/autocompleter/ContentSelectorSuggestionProvider.java b/src/main/java/org/jabref/gui/autocompleter/ContentSelectorSuggestionProvider.java
index dc2299fa685..01e56ff5350 100644
--- a/src/main/java/org/jabref/gui/autocompleter/ContentSelectorSuggestionProvider.java
+++ b/src/main/java/org/jabref/gui/autocompleter/ContentSelectorSuggestionProvider.java
@@ -1,5 +1,7 @@
package org.jabref.gui.autocompleter;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import java.util.stream.Stream;
@@ -22,4 +24,14 @@ public ContentSelectorSuggestionProvider(SuggestionProvider suggestionPr
public Stream getSource() {
return Stream.concat(contentSelectorValues.stream(), suggestionProvider.getSource());
}
+
+ @Override
+ public Collection getPossibleSuggestions() {
+ List suggestions = new ArrayList<>();
+ if (suggestionProvider != null) {
+ suggestions.addAll(suggestionProvider.getPossibleSuggestions());
+ }
+ suggestions.addAll(contentSelectorValues);
+ return suggestions;
+ }
}
diff --git a/src/main/java/org/jabref/gui/autocompleter/SuggestionProvider.java b/src/main/java/org/jabref/gui/autocompleter/SuggestionProvider.java
index 8d6bba4633a..341c9ef8f5e 100644
--- a/src/main/java/org/jabref/gui/autocompleter/SuggestionProvider.java
+++ b/src/main/java/org/jabref/gui/autocompleter/SuggestionProvider.java
@@ -60,6 +60,16 @@ public final Collection provideSuggestions(ISuggestionRequest request) {
protected abstract Equivalence getEquivalence();
+ public Collection getPossibleSuggestions() {
+ Comparator comparator = getComparator().reversed();
+ Equivalence equivalence = getEquivalence();
+ return getSource().map(equivalence::wrap) // Need to do a bit of acrobatic as there is no distinctBy method
+ .distinct()
+ .map(Equivalence.Wrapper::get)
+ .sorted(comparator)
+ .collect(Collectors.toList());
+ }
+
/**
* Get the comparator to order the suggestions
*/
diff --git a/src/main/java/org/jabref/gui/autocompleter/SuggestionProviders.java b/src/main/java/org/jabref/gui/autocompleter/SuggestionProviders.java
index 1d4a039735f..47e1309fc1c 100644
--- a/src/main/java/org/jabref/gui/autocompleter/SuggestionProviders.java
+++ b/src/main/java/org/jabref/gui/autocompleter/SuggestionProviders.java
@@ -32,10 +32,9 @@ public SuggestionProvider> getForField(Field field) {
Set fieldProperties = field.getProperties();
if (fieldProperties.contains(FieldProperty.PERSON_NAMES)) {
return new PersonNameSuggestionProvider(field, database);
- } else if (fieldProperties.contains(FieldProperty.SINGLE_ENTRY_LINK)) {
+ } else if (fieldProperties.contains(FieldProperty.SINGLE_ENTRY_LINK) || fieldProperties.contains(FieldProperty.MULTIPLE_ENTRY_LINK)) {
return new BibEntrySuggestionProvider(database);
- } else if (fieldProperties.contains(FieldProperty.JOURNAL_NAME)
- || StandardField.PUBLISHER.equals(field)) {
+ } else if (fieldProperties.contains(FieldProperty.JOURNAL_NAME) || StandardField.PUBLISHER.equals(field)) {
return new JournalsSuggestionProvider(field, database, abbreviationRepository);
} else {
return new WordSuggestionProvider(field, database);
diff --git a/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java b/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java
index f0c0d9f4467..a342e9c74e6 100644
--- a/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java
+++ b/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java
@@ -14,6 +14,7 @@
import org.jabref.logic.integrity.FieldCheckers;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.model.database.BibDatabaseContext;
+import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.FieldFactory;
import org.jabref.model.entry.field.FieldProperty;
@@ -27,6 +28,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+@SuppressWarnings("unchecked")
public class FieldEditors {
private static final Logger LOGGER = LoggerFactory.getLogger(FieldEditors.class);
@@ -83,9 +85,9 @@ public static FieldEditorFX getForField(final Field field,
return new OptionEditor<>(new TypeEditorViewModel(field, suggestionProvider, fieldCheckers));
}
} else if (fieldProperties.contains(FieldProperty.SINGLE_ENTRY_LINK)) {
- return new LinkedEntriesEditor(field, databaseContext, suggestionProvider, fieldCheckers);
+ return new LinkedEntriesEditor(field, databaseContext, (SuggestionProvider) suggestionProvider, fieldCheckers);
} else if (fieldProperties.contains(FieldProperty.MULTIPLE_ENTRY_LINK)) {
- return new LinkedEntriesEditor(field, databaseContext, suggestionProvider, fieldCheckers);
+ return new LinkedEntriesEditor(field, databaseContext, (SuggestionProvider) suggestionProvider, fieldCheckers);
} else if (fieldProperties.contains(FieldProperty.PERSON_NAMES)) {
return new PersonsEditor(field, suggestionProvider, preferences, fieldCheckers, isMultiLine);
} else if (StandardField.KEYWORDS.equals(field)) {
@@ -98,7 +100,6 @@ public static FieldEditorFX getForField(final Field field,
}
}
- @SuppressWarnings("unchecked")
private static SuggestionProvider> getSuggestionProvider(Field field, SuggestionProviders suggestionProviders, MetaData metaData) {
SuggestionProvider> suggestionProvider = suggestionProviders.getForField(field);
diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditor.fxml b/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditor.fxml
index d473486a222..4b75bbe6311 100644
--- a/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditor.fxml
+++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditor.fxml
@@ -1,8 +1,8 @@
-
+
-
+
diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditor.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditor.java
index 9568cfce925..3067ee36a11 100644
--- a/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditor.java
+++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditor.java
@@ -1,13 +1,14 @@
package org.jabref.gui.fieldeditors;
+import java.util.stream.Collectors;
+
import javafx.beans.binding.Bindings;
import javafx.fxml.FXML;
import javafx.scene.Parent;
import javafx.scene.layout.HBox;
-import org.jabref.gui.autocompleter.AutoCompletionTextInputBinding;
import org.jabref.gui.autocompleter.SuggestionProvider;
-import org.jabref.gui.util.component.TagBar;
+import org.jabref.gui.util.ViewModelListCellFactory;
import org.jabref.logic.integrity.FieldCheckers;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
@@ -15,27 +16,38 @@
import org.jabref.model.entry.field.Field;
import com.airhacks.afterburner.views.ViewLoader;
+import com.jfoenix.controls.JFXChip;
+import com.jfoenix.controls.JFXChipView;
+import com.jfoenix.controls.JFXDefaultChip;
public class LinkedEntriesEditor extends HBox implements FieldEditorFX {
@FXML
private final LinkedEntriesEditorViewModel viewModel;
@FXML
- private TagBar linkedEntriesBar;
+ private JFXChipView chipView;
- public LinkedEntriesEditor(Field field, BibDatabaseContext databaseContext, SuggestionProvider> suggestionProvider, FieldCheckers fieldCheckers) {
+ public LinkedEntriesEditor(Field field, BibDatabaseContext databaseContext, SuggestionProvider suggestionProvider, FieldCheckers fieldCheckers) {
this.viewModel = new LinkedEntriesEditorViewModel(field, suggestionProvider, databaseContext, fieldCheckers);
ViewLoader.view(this)
.root(this)
.load();
- linkedEntriesBar.setFieldProperties(field.getProperties());
- linkedEntriesBar.setStringConverter(viewModel.getStringConverter());
- linkedEntriesBar.setOnTagClicked((parsedEntryLink, mouseEvent) -> viewModel.jumpToEntry(parsedEntryLink));
+ chipView.setConverter(viewModel.getStringConverter());
+ var autoCompletionItemFactory = new ViewModelListCellFactory()
+ .withText(ParsedEntryLink::getKey);
+ chipView.getAutoCompletePopup().setSuggestionsCellFactory(autoCompletionItemFactory);
+ chipView.getAutoCompletePopup().setCellLimit(5);
+ chipView.getSuggestions().addAll(suggestionProvider.getPossibleSuggestions().stream().map(ParsedEntryLink::new).collect(Collectors.toList()));
+
+ chipView.setChipFactory((view, item) -> {
+ JFXChip chip = new JFXDefaultChip<>(view, item);
+ chip.setOnMouseClicked(event -> viewModel.jumpToEntry(item));
+ return chip;
+ });
- AutoCompletionTextInputBinding.autoComplete(linkedEntriesBar.getInputTextField(), viewModel::complete, viewModel.getStringConverter());
- Bindings.bindContentBidirectional(linkedEntriesBar.tagsProperty(), viewModel.linkedEntriesProperty());
+ Bindings.bindContentBidirectional(chipView.getChips(), viewModel.linkedEntriesProperty());
}
public LinkedEntriesEditorViewModel getViewModel() {
diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditorViewModel.java
index cdd2f3c9581..947294e5234 100644
--- a/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditorViewModel.java
+++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditorViewModel.java
@@ -1,8 +1,5 @@
package org.jabref.gui.fieldeditors;
-import java.util.Collection;
-import java.util.stream.Collectors;
-
import javafx.beans.property.ListProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.collections.FXCollections;
@@ -12,13 +9,10 @@
import org.jabref.gui.util.BindingsHelper;
import org.jabref.logic.integrity.FieldCheckers;
import org.jabref.model.database.BibDatabaseContext;
-import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.EntryLinkList;
import org.jabref.model.entry.ParsedEntryLink;
import org.jabref.model.entry.field.Field;
-import org.controlsfx.control.textfield.AutoCompletionBinding;
-
public class LinkedEntriesEditorViewModel extends AbstractEditorViewModel {
private final BibDatabaseContext databaseContext;
@@ -36,20 +30,12 @@ public LinkedEntriesEditorViewModel(Field field, SuggestionProvider> suggestio
newText -> EntryLinkList.parse(newText, databaseContext.getDatabase()));
}
- @Override
- @SuppressWarnings("unchecked")
- public Collection complete(AutoCompletionBinding.ISuggestionRequest request) {
- // We have to cast the BibEntries from the BibEntrySuggestionProvider to ParsedEntryLink
- Collection bibEntries = (Collection) super.complete(request);
- return bibEntries.stream().map(ParsedEntryLink::new).collect(Collectors.toList());
- }
-
public ListProperty linkedEntriesProperty() {
return linkedEntries;
}
public StringConverter getStringConverter() {
- return new StringConverter() {
+ return new StringConverter<>() {
@Override
public String toString(ParsedEntryLink linkedEntry) {
@@ -61,7 +47,7 @@ public String toString(ParsedEntryLink linkedEntry) {
@Override
public ParsedEntryLink fromString(String key) {
- return databaseContext.getDatabase().getEntryByKey(key).map(ParsedEntryLink::new).orElse(null);
+ return new ParsedEntryLink(key, databaseContext.getDatabase());
}
};
}
diff --git a/src/main/java/org/jabref/model/entry/ParsedEntryLink.java b/src/main/java/org/jabref/model/entry/ParsedEntryLink.java
index 4fad9539ac9..0daace9039c 100644
--- a/src/main/java/org/jabref/model/entry/ParsedEntryLink.java
+++ b/src/main/java/org/jabref/model/entry/ParsedEntryLink.java
@@ -9,12 +9,12 @@ public class ParsedEntryLink {
private String key;
private Optional linkedEntry;
- private BibDatabase dataBase;
+ private BibDatabase database;
- public ParsedEntryLink(String key, BibDatabase dataBase) {
+ public ParsedEntryLink(String key, BibDatabase database) {
this.key = key;
- this.linkedEntry = dataBase.getEntryByKey(this.key);
- this.dataBase = dataBase;
+ this.linkedEntry = database.getEntryByKey(this.key);
+ this.database = database;
}
public ParsedEntryLink(BibEntry bibEntry) {
@@ -32,7 +32,7 @@ public Optional getLinkedEntry() {
public void setKey(String newKey) {
this.key = newKey;
- this.linkedEntry = getDataBase().getEntryByKey(this.key);
+ this.linkedEntry = getDatabase().getEntryByKey(this.key);
}
@Override
@@ -52,7 +52,7 @@ public boolean equals(Object obj) {
return Objects.equals(key, other.key) && Objects.equals(linkedEntry, other.linkedEntry);
}
- public BibDatabase getDataBase() {
- return dataBase;
+ public BibDatabase getDatabase() {
+ return database;
}
}
diff --git a/src/test/java/org/jabref/model/entry/EntryLinkListTest.java b/src/test/java/org/jabref/model/entry/EntryLinkListTest.java
index 50696605e78..6d89a39d22f 100644
--- a/src/test/java/org/jabref/model/entry/EntryLinkListTest.java
+++ b/src/test/java/org/jabref/model/entry/EntryLinkListTest.java
@@ -45,7 +45,7 @@ public void givenFieldValueAndDatabaseWhenParsingThenExpectKey() {
@Test
public void givenFieldValueAndDatabaseWhenParsingThenExpectDataBase() {
- assertEquals(database, link.getDataBase());
+ assertEquals(database, link.getDatabase());
}
@Test