Skip to content

Commit

Permalink
Fix multiple entries allowed in crossref (issue #5284) (#5724)
Browse files Browse the repository at this point in the history
Co-authored-by: Julien Bénard
Co-authored-by: Lucas Beretti
Co-authored-by: Venceslas Roullier
  • Loading branch information
Julien29121998 authored and koppor committed Dec 15, 2019
1 parent 0b8b1d6 commit bee4d64
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We fixed an exception which occurred when an invalid jstyle was loaded. [#5452](https://github.com/JabRef/jabref/issues/5452)
- 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)
- We fixed an error where the preview theme did not adapt to the "Dark" mode [#5463](https://github.com/JabRef/jabref/issues/5463)
- We fixed an issue where multiple entries were allowed in the "crossref" field [#5284](https://github.com/JabRef/jabref/issues/5284)
- We fixed an issue where the merge dialog showed the wrong text colour in "Dark" mode [#5516](https://github.com/JabRef/jabref/issues/5516)
- 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)
- We fixed an issue where the author field was not correctly parsed during bibtex key-generation. [#5551](https://github.com/JabRef/jabref/issues/5551)
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ public static FieldEditorFX getForField(final Field field,
} else {
return new OptionEditor<>(new TypeEditorViewModel(field, suggestionProvider, fieldCheckers));
}
} else if (fieldProperties.contains(FieldProperty.SINGLE_ENTRY_LINK) || fieldProperties.contains(FieldProperty.MULTIPLE_ENTRY_LINK)) {
} else if (fieldProperties.contains(FieldProperty.SINGLE_ENTRY_LINK)) {
return new LinkedEntriesEditor(field, databaseContext, suggestionProvider, fieldCheckers);
} else if (fieldProperties.contains(FieldProperty.MULTIPLE_ENTRY_LINK)) {
return new LinkedEntriesEditor(field, databaseContext, suggestionProvider, fieldCheckers);
} else if (fieldProperties.contains(FieldProperty.PERSON_NAMES)) {
return new PersonsEditor(field, suggestionProvider, preferences, fieldCheckers, isSingleLine);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@

public class LinkedEntriesEditor extends HBox implements FieldEditorFX {

@FXML private final LinkedEntriesEditorViewModel viewModel;
@FXML private TagBar<ParsedEntryLink> linkedEntriesBar;
@FXML
private final LinkedEntriesEditorViewModel viewModel;
@FXML
private TagBar<ParsedEntryLink> linkedEntriesBar;

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

ViewLoader.view(this)
.root(this)
.load();
.root(this)
.load();

linkedEntriesBar.setFieldProperties(field.getProperties());
linkedEntriesBar.setStringConverter(viewModel.getStringConverter());
linkedEntriesBar.setOnTagClicked((parsedEntryLink, mouseEvent) -> viewModel.jumpToEntry(parsedEntryLink));

Expand Down
22 changes: 17 additions & 5 deletions src/main/java/org/jabref/gui/util/component/TagBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Collection;
import java.util.function.BiConsumer;
import java.util.Set;
import java.util.stream.Collectors;

import javafx.beans.property.ListProperty;
Expand All @@ -16,6 +17,7 @@
import javafx.scene.layout.HBox;
import javafx.util.StringConverter;

import org.jabref.model.entry.field.FieldProperty;
import org.jabref.model.strings.StringUtil;

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

private final ListProperty<T> tags;
private StringConverter<T> stringConverter;
@FXML private TextField inputTextField;
@FXML private HBox tagList;
@FXML
private TextField inputTextField;
@FXML
private HBox tagList;
private BiConsumer<T, MouseEvent> onTagClicked;
private java.util.Set<FieldProperty> properties;

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

// Load FXML
ViewLoader.view(this)
.root(this)
.load();
.root(this)
.load();
getStylesheets().add(0, TagBar.class.getResource("TagBar.css").toExternalForm());
}

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

private Tag<T> createTag(T item) {
Expand All @@ -83,7 +91,7 @@ private void addTextAsNewTag(ActionEvent event) {
String inputText = inputTextField.getText();
if (StringUtil.isNotBlank(inputText)) {
T newTag = stringConverter.fromString(inputText);
if ((newTag != null) && !tags.contains(newTag)) {
if ((newTag != null) && !tags.contains(newTag) && (tags.isEmpty() || this.properties.contains(FieldProperty.MULTIPLE_ENTRY_LINK))) {
tags.add(newTag);
inputTextField.clear();
}
Expand All @@ -97,4 +105,8 @@ public void setStringConverter(StringConverter<T> stringConverter) {
public void setOnTagClicked(BiConsumer<T, MouseEvent> onTagClicked) {
this.onTagClicked = onTagClicked;
}

public void setFieldProperties(Set<FieldProperty> properties) {
this.properties = properties;
}
}

0 comments on commit bee4d64

Please sign in to comment.