Skip to content

Commit

Permalink
Fix maintable not updated when changing entry type (#5925)
Browse files Browse the repository at this point in the history
* Fix maintable not updated when changing entry type


Fixes #5906

* fix checkstyle

* use easybind with cast
  • Loading branch information
Siedlerchr authored Feb 10, 2020
1 parent 6a9c915 commit a94add9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 30 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We fixed an issue where cleaning up entries broke web URLs, if "Make paths of linked files relative (if possible)" was enabled, which resulted in various other issues subsequently. [#5861](https://github.com/JabRef/jabref/issues/5861)
- We fixed an issue where the tab "Required fields" of the entry editor did not show all required fields, if at least two of the defined required fields are linked with a logical or. [#5859](https://github.com/JabRef/jabref/issues/5859)
- We fixed several issues concerning managing external file types: Now everything is usable and fully functional. Previously, there were problems with the radio buttons, with saving the settings and with loading an input field value. Furthermore, different behavior for Windows and other operating systems was given, which was unified as well. [#5846](https://github.com/JabRef/jabref/issues/5846)
- We fixed an issue where changing the type of an entry did not update the main table [#5906](https://github.com/JabRef/jabref/issues/5906)


### Removed
- Ampersands are no longer escaped by default in the `bib` file. If you want to keep the current behaviour, you can use the new "Escape Ampersands" formatter as a save action.
Expand Down
63 changes: 33 additions & 30 deletions src/main/java/org/jabref/model/entry/BibEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

import com.google.common.base.Strings;
import com.google.common.eventbus.EventBus;
import org.fxmisc.easybind.EasyBind;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -68,7 +69,7 @@ public class BibEntry implements Cloneable {
/**
* Cache that stores the field as keyword lists (format <Field, Separator, Keyword list>)
*/
private MultiKeyMap<Field, Character, KeywordList> fieldsAsKeywords = new MultiKeyMap<>();
private final MultiKeyMap<Field, Character, KeywordList> fieldsAsKeywords = new MultiKeyMap<>();

private final EventBus eventBus = new EventBus();
private String id;
Expand Down Expand Up @@ -148,27 +149,27 @@ private Optional<Field> getSourceField(Field targetField, EntryType targetEntry,
}

//// 2. Handle special field mappings
if ((sourceEntry == StandardEntryType.MvBook && targetEntry == StandardEntryType.InBook) ||
(sourceEntry == StandardEntryType.MvBook && targetEntry == StandardEntryType.BookInBook) ||
(sourceEntry == StandardEntryType.MvBook && targetEntry == StandardEntryType.SuppBook) ||
(sourceEntry == StandardEntryType.Book && targetEntry == StandardEntryType.InBook) ||
(sourceEntry == StandardEntryType.Book && targetEntry == StandardEntryType.BookInBook) ||
(sourceEntry == StandardEntryType.Book && targetEntry == StandardEntryType.SuppBook)) {
if (((sourceEntry == StandardEntryType.MvBook) && (targetEntry == StandardEntryType.InBook)) ||
((sourceEntry == StandardEntryType.MvBook) && (targetEntry == StandardEntryType.BookInBook)) ||
((sourceEntry == StandardEntryType.MvBook) && (targetEntry == StandardEntryType.SuppBook)) ||
((sourceEntry == StandardEntryType.Book) && (targetEntry == StandardEntryType.InBook)) ||
((sourceEntry == StandardEntryType.Book) && (targetEntry == StandardEntryType.BookInBook)) ||
((sourceEntry == StandardEntryType.Book) && (targetEntry == StandardEntryType.SuppBook))) {
if (targetField == StandardField.AUTHOR) { return Optional.of(StandardField.AUTHOR); }
if (targetField == StandardField.BOOKAUTHOR) { return Optional.of(StandardField.AUTHOR); }
}

if ((sourceEntry == StandardEntryType.MvBook && targetEntry == StandardEntryType.Book) ||
(sourceEntry == StandardEntryType.MvBook && targetEntry == StandardEntryType.InBook) ||
(sourceEntry == StandardEntryType.MvBook && targetEntry == StandardEntryType.BookInBook) ||
(sourceEntry == StandardEntryType.MvBook && targetEntry == StandardEntryType.SuppBook) ||
(sourceEntry == StandardEntryType.MvCollection && targetEntry == StandardEntryType.Collection) ||
(sourceEntry == StandardEntryType.MvCollection && targetEntry == StandardEntryType.InCollection) ||
(sourceEntry == StandardEntryType.MvCollection && targetEntry == StandardEntryType.SuppCollection) ||
(sourceEntry == StandardEntryType.MvProceedings && targetEntry == StandardEntryType.Proceedings) ||
(sourceEntry == StandardEntryType.MvProceedings && targetEntry == StandardEntryType.InProceedings) ||
(sourceEntry == StandardEntryType.MvReference && targetEntry == StandardEntryType.Reference) ||
(sourceEntry == StandardEntryType.MvReference && targetEntry == StandardEntryType.InReference)) {
if (((sourceEntry == StandardEntryType.MvBook) && (targetEntry == StandardEntryType.Book)) ||
((sourceEntry == StandardEntryType.MvBook) && (targetEntry == StandardEntryType.InBook)) ||
((sourceEntry == StandardEntryType.MvBook) && (targetEntry == StandardEntryType.BookInBook)) ||
((sourceEntry == StandardEntryType.MvBook) && (targetEntry == StandardEntryType.SuppBook)) ||
((sourceEntry == StandardEntryType.MvCollection) && (targetEntry == StandardEntryType.Collection)) ||
((sourceEntry == StandardEntryType.MvCollection) && (targetEntry == StandardEntryType.InCollection)) ||
((sourceEntry == StandardEntryType.MvCollection) && (targetEntry == StandardEntryType.SuppCollection)) ||
((sourceEntry == StandardEntryType.MvProceedings) && (targetEntry == StandardEntryType.Proceedings)) ||
((sourceEntry == StandardEntryType.MvProceedings) && (targetEntry == StandardEntryType.InProceedings)) ||
((sourceEntry == StandardEntryType.MvReference) && (targetEntry == StandardEntryType.Reference)) ||
((sourceEntry == StandardEntryType.MvReference) && (targetEntry == StandardEntryType.InReference))) {
if (targetField == StandardField.MAINTITLE) { return Optional.of(StandardField.TITLE); }
if (targetField == StandardField.MAINSUBTITLE) { return Optional.of(StandardField.SUBTITLE); }
if (targetField == StandardField.MAINTITLEADDON) { return Optional.of(StandardField.TITLEADDON); }
Expand All @@ -186,13 +187,13 @@ private Optional<Field> getSourceField(Field targetField, EntryType targetEntry,
}
}

if ((sourceEntry == StandardEntryType.Book && targetEntry == StandardEntryType.InBook) ||
(sourceEntry == StandardEntryType.Book && targetEntry == StandardEntryType.BookInBook) ||
(sourceEntry == StandardEntryType.Book && targetEntry == StandardEntryType.SuppBook) ||
(sourceEntry == StandardEntryType.Collection && targetEntry == StandardEntryType.InCollection) ||
(sourceEntry == StandardEntryType.Collection && targetEntry == StandardEntryType.SuppCollection) ||
(sourceEntry == StandardEntryType.Reference && targetEntry == StandardEntryType.InReference) ||
(sourceEntry == StandardEntryType.Proceedings && targetEntry == StandardEntryType.InProceedings)) {
if (((sourceEntry == StandardEntryType.Book) && (targetEntry == StandardEntryType.InBook)) ||
((sourceEntry == StandardEntryType.Book) && (targetEntry == StandardEntryType.BookInBook)) ||
((sourceEntry == StandardEntryType.Book) && (targetEntry == StandardEntryType.SuppBook)) ||
((sourceEntry == StandardEntryType.Collection) && (targetEntry == StandardEntryType.InCollection)) ||
((sourceEntry == StandardEntryType.Collection) && (targetEntry == StandardEntryType.SuppCollection)) ||
((sourceEntry == StandardEntryType.Reference) && (targetEntry == StandardEntryType.InReference)) ||
((sourceEntry == StandardEntryType.Proceedings) && (targetEntry == StandardEntryType.InProceedings))) {
if (targetField == StandardField.BOOKTITLE) { return Optional.of(StandardField.TITLE); }
if (targetField == StandardField.BOOKSUBTITLE) { return Optional.of(StandardField.SUBTITLE); }
if (targetField == StandardField.BOOKTITLEADDON) { return Optional.of(StandardField.TITLEADDON); }
Expand All @@ -210,8 +211,8 @@ private Optional<Field> getSourceField(Field targetField, EntryType targetEntry,
}
}

if ((sourceEntry == IEEETranEntryType.Periodical && targetEntry == StandardEntryType.Article) ||
(sourceEntry == IEEETranEntryType.Periodical && targetEntry == StandardEntryType.SuppPeriodical)) {
if (((sourceEntry == IEEETranEntryType.Periodical) && (targetEntry == StandardEntryType.Article)) ||
((sourceEntry == IEEETranEntryType.Periodical) && (targetEntry == StandardEntryType.SuppPeriodical))) {
if (targetField == StandardField.JOURNALTITLE) { return Optional.of(StandardField.TITLE); }
if (targetField == StandardField.JOURNALSUBTITLE) { return Optional.of(StandardField.SUBTITLE); }

Expand Down Expand Up @@ -915,8 +916,10 @@ public Optional<Month> getMonth() {
}

public ObjectBinding<String> getFieldBinding(Field field) {
//noinspection unchecked
return Bindings.valueAt(fields, field);
if ((field == InternalField.TYPE_HEADER) || (field == InternalField.OBSOLETE_TYPE_HEADER)) {
return (ObjectBinding<String>) EasyBind.map(type, EntryType::getDisplayName);
}
return Bindings.valueAt(fields, field);
}

public ObjectBinding<String> getCiteKeyBinding() {
Expand All @@ -937,7 +940,7 @@ public ObservableMap<Field, String> getFieldsObservable() {
* Returns a list of observables that represent the data of the entry.
*/
public Observable[] getObservables() {
return new Observable[] {fields};
return new Observable[] {fields, type};
}

private interface GetFieldInterface {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/model/entry/field/InternalField.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public enum InternalField implements Field {
TIMESTAMP("timestamp", FieldProperty.DATE),
GROUPS("groups"),
KEY_FIELD("bibtexkey"),
/**
* field which indicates the entrytype
*/
TYPE_HEADER("entrytype"),
OBSOLETE_TYPE_HEADER("bibtextype"),
MARKED_INTERNAL("__markedentry"), // used in old versions of JabRef. Currently used for conversion only
Expand Down

0 comments on commit a94add9

Please sign in to comment.