From 0394f32aaa734a92a61407e1fecbcaf510c65049 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sun, 9 Feb 2020 17:45:12 +0100 Subject: [PATCH 1/3] Fix maintable not updated when changing entry type Fixes #5906 --- CHANGELOG.md | 2 ++ src/main/java/org/jabref/model/entry/BibEntry.java | 9 +++++++-- .../java/org/jabref/model/entry/field/InternalField.java | 3 +++ 3 files changed, 12 insertions(+), 2 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..0f629c4c87d 100644 --- a/src/main/java/org/jabref/model/entry/BibEntry.java +++ b/src/main/java/org/jabref/model/entry/BibEntry.java @@ -914,8 +914,13 @@ public Optional getMonth() { return getFieldOrAlias(StandardField.MONTH).flatMap(Month::parse); } + public ObjectBinding getFieldBinding(Field field) { - //noinspection unchecked + if (field == InternalField.TYPE_HEADER || field == InternalField.OBSOLETE_TYPE_HEADER) { + return Bindings.createObjectBinding(() -> { + return type.getValue().getDisplayName(); + }, type); + } return Bindings.valueAt(fields, field); } @@ -937,7 +942,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 From 3bc527dbab322b70010f81a09cc196b2ca83ad73 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sun, 9 Feb 2020 17:50:32 +0100 Subject: [PATCH 2/3] fix checkstyle --- src/main/java/org/jabref/model/entry/BibEntry.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/jabref/model/entry/BibEntry.java b/src/main/java/org/jabref/model/entry/BibEntry.java index 0f629c4c87d..cf3bc17137c 100644 --- a/src/main/java/org/jabref/model/entry/BibEntry.java +++ b/src/main/java/org/jabref/model/entry/BibEntry.java @@ -914,7 +914,6 @@ public Optional getMonth() { return getFieldOrAlias(StandardField.MONTH).flatMap(Month::parse); } - public ObjectBinding getFieldBinding(Field field) { if (field == InternalField.TYPE_HEADER || field == InternalField.OBSOLETE_TYPE_HEADER) { return Bindings.createObjectBinding(() -> { From 9059e8088b5c7d41d1e27b457811d653351c84e0 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Mon, 10 Feb 2020 14:23:09 +0100 Subject: [PATCH 3/3] use easybind with cast --- .../java/org/jabref/model/entry/BibEntry.java | 65 +++++++++---------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/src/main/java/org/jabref/model/entry/BibEntry.java b/src/main/java/org/jabref/model/entry/BibEntry.java index cf3bc17137c..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,12 +916,10 @@ public Optional getMonth() { } public ObjectBinding getFieldBinding(Field field) { - if (field == InternalField.TYPE_HEADER || field == InternalField.OBSOLETE_TYPE_HEADER) { - return Bindings.createObjectBinding(() -> { - return type.getValue().getDisplayName(); - }, type); - } - 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() {