Skip to content

Commit bee4d64

Browse files
Julien29121998koppor
authored andcommitted
Fix multiple entries allowed in crossref (issue #5284) (#5724)
Co-authored-by: Julien Bénard Co-authored-by: Lucas Beretti Co-authored-by: Venceslas Roullier
1 parent 0b8b1d6 commit bee4d64

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
6464
- We fixed an exception which occurred when an invalid jstyle was loaded. [#5452](https://github.com/JabRef/jabref/issues/5452)
6565
- We fixed an issue where the command line arguments `importBibtex` and `importToOpen` did not import into the currently open library, but opened a new one. [#5537](https://github.com/JabRef/jabref/issues/5537)
6666
- We fixed an error where the preview theme did not adapt to the "Dark" mode [#5463](https://github.com/JabRef/jabref/issues/5463)
67+
- We fixed an issue where multiple entries were allowed in the "crossref" field [#5284](https://github.com/JabRef/jabref/issues/5284)
6768
- We fixed an issue where the merge dialog showed the wrong text colour in "Dark" mode [#5516](https://github.com/JabRef/jabref/issues/5516)
6869
- We fixed visibility issues with the scrollbar and group selection highlight in "Dark" mode, and enabled "Dark" mode for the OpenOffice preview in the style selection window. [#5522](https://github.com/JabRef/jabref/issues/5522)
6970
- We fixed an issue where the author field was not correctly parsed during bibtex key-generation. [#5551](https://github.com/JabRef/jabref/issues/5551)

src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ public static FieldEditorFX getForField(final Field field,
8484
} else {
8585
return new OptionEditor<>(new TypeEditorViewModel(field, suggestionProvider, fieldCheckers));
8686
}
87-
} else if (fieldProperties.contains(FieldProperty.SINGLE_ENTRY_LINK) || fieldProperties.contains(FieldProperty.MULTIPLE_ENTRY_LINK)) {
87+
} else if (fieldProperties.contains(FieldProperty.SINGLE_ENTRY_LINK)) {
88+
return new LinkedEntriesEditor(field, databaseContext, suggestionProvider, fieldCheckers);
89+
} else if (fieldProperties.contains(FieldProperty.MULTIPLE_ENTRY_LINK)) {
8890
return new LinkedEntriesEditor(field, databaseContext, suggestionProvider, fieldCheckers);
8991
} else if (fieldProperties.contains(FieldProperty.PERSON_NAMES)) {
9092
return new PersonsEditor(field, suggestionProvider, preferences, fieldCheckers, isSingleLine);

src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditor.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,19 @@
1818

1919
public class LinkedEntriesEditor extends HBox implements FieldEditorFX {
2020

21-
@FXML private final LinkedEntriesEditorViewModel viewModel;
22-
@FXML private TagBar<ParsedEntryLink> linkedEntriesBar;
21+
@FXML
22+
private final LinkedEntriesEditorViewModel viewModel;
23+
@FXML
24+
private TagBar<ParsedEntryLink> linkedEntriesBar;
2325

2426
public LinkedEntriesEditor(Field field, BibDatabaseContext databaseContext, AutoCompleteSuggestionProvider<?> suggestionProvider, FieldCheckers fieldCheckers) {
2527
this.viewModel = new LinkedEntriesEditorViewModel(field, suggestionProvider, databaseContext, fieldCheckers);
2628

2729
ViewLoader.view(this)
28-
.root(this)
29-
.load();
30+
.root(this)
31+
.load();
3032

33+
linkedEntriesBar.setFieldProperties(field.getProperties());
3134
linkedEntriesBar.setStringConverter(viewModel.getStringConverter());
3235
linkedEntriesBar.setOnTagClicked((parsedEntryLink, mouseEvent) -> viewModel.jumpToEntry(parsedEntryLink));
3336

src/main/java/org/jabref/gui/util/component/TagBar.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.Collection;
44
import java.util.function.BiConsumer;
5+
import java.util.Set;
56
import java.util.stream.Collectors;
67

78
import javafx.beans.property.ListProperty;
@@ -16,6 +17,7 @@
1617
import javafx.scene.layout.HBox;
1718
import javafx.util.StringConverter;
1819

20+
import org.jabref.model.entry.field.FieldProperty;
1921
import org.jabref.model.strings.StringUtil;
2022

2123
import com.airhacks.afterburner.views.ViewLoader;
@@ -27,18 +29,21 @@ public class TagBar<T> extends HBox {
2729

2830
private final ListProperty<T> tags;
2931
private StringConverter<T> stringConverter;
30-
@FXML private TextField inputTextField;
31-
@FXML private HBox tagList;
32+
@FXML
33+
private TextField inputTextField;
34+
@FXML
35+
private HBox tagList;
3236
private BiConsumer<T, MouseEvent> onTagClicked;
37+
private java.util.Set<FieldProperty> properties;
3338

3439
public TagBar() {
3540
tags = new SimpleListProperty<>(FXCollections.observableArrayList());
3641
tags.addListener(this::onTagsChanged);
3742

3843
// Load FXML
3944
ViewLoader.view(this)
40-
.root(this)
41-
.load();
45+
.root(this)
46+
.load();
4247
getStylesheets().add(0, TagBar.class.getResource("TagBar.css").toExternalForm());
4348
}
4449

@@ -66,6 +71,9 @@ private void onTagsChanged(ListChangeListener.Change<? extends T> change) {
6671
tagList.getChildren().addAll(change.getFrom(), change.getAddedSubList().stream().map(this::createTag).collect(Collectors.toList()));
6772
}
6873
}
74+
if (this.properties.contains(FieldProperty.SINGLE_ENTRY_LINK)) {
75+
inputTextField.setDisable(!tags.isEmpty());
76+
}
6977
}
7078

7179
private Tag<T> createTag(T item) {
@@ -83,7 +91,7 @@ private void addTextAsNewTag(ActionEvent event) {
8391
String inputText = inputTextField.getText();
8492
if (StringUtil.isNotBlank(inputText)) {
8593
T newTag = stringConverter.fromString(inputText);
86-
if ((newTag != null) && !tags.contains(newTag)) {
94+
if ((newTag != null) && !tags.contains(newTag) && (tags.isEmpty() || this.properties.contains(FieldProperty.MULTIPLE_ENTRY_LINK))) {
8795
tags.add(newTag);
8896
inputTextField.clear();
8997
}
@@ -97,4 +105,8 @@ public void setStringConverter(StringConverter<T> stringConverter) {
97105
public void setOnTagClicked(BiConsumer<T, MouseEvent> onTagClicked) {
98106
this.onTagClicked = onTagClicked;
99107
}
108+
109+
public void setFieldProperties(Set<FieldProperty> properties) {
110+
this.properties = properties;
111+
}
100112
}

0 commit comments

Comments
 (0)