From a94add91136925ebda17b206ab63b8c7305dbb42 Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 10 Feb 2020 14:42:03 +0100 Subject: [PATCH] Fix maintable not updated when changing entry type (#5925) * Fix maintable not updated when changing entry type Fixes #5906 * fix checkstyle * use easybind with cast --- CHANGELOG.md | 2 + .../java/org/jabref/model/entry/BibEntry.java | 63 ++++++++++--------- .../model/entry/field/InternalField.java | 3 + 3 files changed, 38 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab9c738d4c2..7dd0c42e3b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/src/main/java/org/jabref/model/entry/BibEntry.java b/src/main/java/org/jabref/model/entry/BibEntry.java index 49e548b2a44..8d5fcb68207 100644 --- a/src/main/java/org/jabref/model/entry/BibEntry.java +++ b/src/main/java/org/jabref/model/entry/BibEntry.java @@ -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; @@ -68,7 +69,7 @@ public class BibEntry implements Cloneable { /** * Cache that stores the field as keyword lists (format ) */ - private MultiKeyMap fieldsAsKeywords = new MultiKeyMap<>(); + private final MultiKeyMap fieldsAsKeywords = new MultiKeyMap<>(); private final EventBus eventBus = new EventBus(); private String id; @@ -148,27 +149,27 @@ private Optional 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); } @@ -186,13 +187,13 @@ private Optional 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); } @@ -210,8 +211,8 @@ private Optional 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); } @@ -915,8 +916,10 @@ public Optional getMonth() { } public ObjectBinding getFieldBinding(Field field) { - //noinspection unchecked - return Bindings.valueAt(fields, field); + if ((field == InternalField.TYPE_HEADER) || (field == InternalField.OBSOLETE_TYPE_HEADER)) { + return (ObjectBinding) EasyBind.map(type, EntryType::getDisplayName); + } + return Bindings.valueAt(fields, field); } public ObjectBinding getCiteKeyBinding() { @@ -937,7 +940,7 @@ public ObservableMap 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 { diff --git a/src/main/java/org/jabref/model/entry/field/InternalField.java b/src/main/java/org/jabref/model/entry/field/InternalField.java index 2338da7fa1b..9fabf4801e1 100644 --- a/src/main/java/org/jabref/model/entry/field/InternalField.java +++ b/src/main/java/org/jabref/model/entry/field/InternalField.java @@ -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