Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix multiple entries allowed in crossref (issue #5284) #5724

Merged
merged 7 commits into from
Dec 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, this indent change is an Eclipse vs. IntelliJ-thing. I won't nitpick here. Next time, please only commit code changes, not just reformat changes.

.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;
}
}