From 0468fa8d2d6122d533f3ea8a0bac8e17070bd05f Mon Sep 17 00:00:00 2001 From: sxcz <11812714@mail.sustech.edu.cn> Date: Wed, 19 May 2021 13:03:05 +0800 Subject: [PATCH 1/4] fix for issue 7730 --- CHANGELOG.md | 1 + .../org/jabref/gui/maintable/BibEntryTableViewModel.java | 9 +++------ .../gui/maintable/MainTableFieldValueFormatter.java | 9 +++++++++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd26fa03dce..eae1e1eb617 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -698,6 +698,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We fixed an issue where opening the menu 'Library properties' marked the library as modified [#6451](https://github.com/JabRef/jabref/issues/6451) - We fixed an issue when importing resulted in an exception [#7343](https://github.com/JabRef/jabref/issues/7343) - We fixed an issue where the field in the Field formatter dropdown selection were sorted in random order. [#7710](https://github.com/JabRef/jabref/issues/7710) +- We fixed an issue where the crossref entry's table preview does not update immediately. [#7730] (https://github.com/JabRef/jabref/issues/7730) ### Removed diff --git a/src/main/java/org/jabref/gui/maintable/BibEntryTableViewModel.java b/src/main/java/org/jabref/gui/maintable/BibEntryTableViewModel.java index a9dedaedb59..8347b8b15a6 100644 --- a/src/main/java/org/jabref/gui/maintable/BibEntryTableViewModel.java +++ b/src/main/java/org/jabref/gui/maintable/BibEntryTableViewModel.java @@ -108,15 +108,12 @@ public ObservableValue> getSpecialField(Spe } public ObservableValue getFields(OrFields fields) { - ObservableValue value = fieldValues.get(fields); - if (value != null) { - return value; - } - ArrayList observables = new ArrayList<>(List.of(entry.getObservables())); + Optional referenced = fieldValueFormatter.getValue().getReferencedEntry(entry); + referenced.ifPresent(bibEntry -> observables.addAll(List.of(bibEntry.getObservables()))); observables.add(fieldValueFormatter); - value = Bindings.createStringBinding(() -> + ObservableValue value = Bindings.createStringBinding(() -> fieldValueFormatter.getValue().formatFieldsValues(fields, entry), observables.toArray(Observable[]::new)); fieldValues.put(fields, value); diff --git a/src/main/java/org/jabref/gui/maintable/MainTableFieldValueFormatter.java b/src/main/java/org/jabref/gui/maintable/MainTableFieldValueFormatter.java index 48a03e9478a..231e604769e 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableFieldValueFormatter.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableFieldValueFormatter.java @@ -84,4 +84,13 @@ private String formatFieldWithAuthorValue(final String nameToFormat) { case NATBIB -> authors.latexFree().getAsNatbib(); }; } + + /*** + * Finds the entry in the crossref field + * @param entry the entry to be searched + * @return The referenced entry + */ + public Optional getReferencedEntry(BibEntry entry) { + return bibDatabase.getReferencedEntry(entry); + } } From d0a522aaf66064a305350254cd1f7dbe2bfb3a47 Mon Sep 17 00:00:00 2001 From: sxcz <11812714@mail.sustech.edu.cn> Date: Wed, 19 May 2021 13:15:24 +0800 Subject: [PATCH 2/4] fix checkstyle --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eae1e1eb617..ffd3026f933 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -698,7 +698,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We fixed an issue where opening the menu 'Library properties' marked the library as modified [#6451](https://github.com/JabRef/jabref/issues/6451) - We fixed an issue when importing resulted in an exception [#7343](https://github.com/JabRef/jabref/issues/7343) - We fixed an issue where the field in the Field formatter dropdown selection were sorted in random order. [#7710](https://github.com/JabRef/jabref/issues/7710) -- We fixed an issue where the crossref entry's table preview does not update immediately. [#7730] (https://github.com/JabRef/jabref/issues/7730) +- We fixed an issue where the crossref entry's table preview does not update immediately. [#7730](https://github.com/JabRef/jabref/issues/7730) ### Removed From abcdcad31bd836e7a9d60c6d3bb7410b2c4424a7 Mon Sep 17 00:00:00 2001 From: Jonatan Asketorp <2598631+k3KAW8Pnf7mkmdSMPHz27@users.noreply.github.com> Date: Thu, 22 Jul 2021 16:40:33 -0400 Subject: [PATCH 3/4] Fix caching --- .../org/jabref/gui/maintable/BibEntryTableViewModel.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/maintable/BibEntryTableViewModel.java b/src/main/java/org/jabref/gui/maintable/BibEntryTableViewModel.java index 8347b8b15a6..abe8c5f9923 100644 --- a/src/main/java/org/jabref/gui/maintable/BibEntryTableViewModel.java +++ b/src/main/java/org/jabref/gui/maintable/BibEntryTableViewModel.java @@ -108,12 +108,17 @@ public ObservableValue> getSpecialField(Spe } public ObservableValue getFields(OrFields fields) { + ObservableValue value = fieldValues.get(fields); + if (value != null) { + return value; + } + ArrayList observables = new ArrayList<>(List.of(entry.getObservables())); Optional referenced = fieldValueFormatter.getValue().getReferencedEntry(entry); referenced.ifPresent(bibEntry -> observables.addAll(List.of(bibEntry.getObservables()))); observables.add(fieldValueFormatter); - ObservableValue value = Bindings.createStringBinding(() -> + value = Bindings.createStringBinding(() -> fieldValueFormatter.getValue().formatFieldsValues(fields, entry), observables.toArray(Observable[]::new)); fieldValues.put(fields, value); From 1b50be6cdd1a2d226791d7b6ba0cf225662d3080 Mon Sep 17 00:00:00 2001 From: Jonatan Asketorp <2598631+k3KAW8Pnf7mkmdSMPHz27@users.noreply.github.com> Date: Thu, 22 Jul 2021 16:44:03 -0400 Subject: [PATCH 4/4] Remove wrapper for `getReferencedEntry` --- .../org/jabref/gui/maintable/BibEntryTableViewModel.java | 5 ++++- .../gui/maintable/MainTableFieldValueFormatter.java | 9 --------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/jabref/gui/maintable/BibEntryTableViewModel.java b/src/main/java/org/jabref/gui/maintable/BibEntryTableViewModel.java index abe8c5f9923..076ee67f196 100644 --- a/src/main/java/org/jabref/gui/maintable/BibEntryTableViewModel.java +++ b/src/main/java/org/jabref/gui/maintable/BibEntryTableViewModel.java @@ -17,6 +17,7 @@ import org.jabref.gui.specialfields.SpecialFieldValueViewModel; import org.jabref.gui.util.uithreadaware.UiThreadBinding; import org.jabref.logic.importer.util.FileFieldParser; +import org.jabref.model.database.BibDatabase; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.LinkedFile; @@ -39,10 +40,12 @@ public class BibEntryTableViewModel { private final EasyBinding> linkedFiles; private final EasyBinding> linkedIdentifiers; private final Binding> matchedGroups; + private final BibDatabase bibDatabase; public BibEntryTableViewModel(BibEntry entry, BibDatabaseContext bibDatabaseContext, ObservableValue fieldValueFormatter) { this.entry = entry; this.fieldValueFormatter = fieldValueFormatter; + this.bibDatabase = bibDatabaseContext.getDatabase(); this.linkedFiles = getField(StandardField.FILE).map(FileFieldParser::parse).orElse(Collections.emptyList()); this.linkedIdentifiers = createLinkedIdentifiersBinding(entry); @@ -114,7 +117,7 @@ public ObservableValue getFields(OrFields fields) { } ArrayList observables = new ArrayList<>(List.of(entry.getObservables())); - Optional referenced = fieldValueFormatter.getValue().getReferencedEntry(entry); + Optional referenced = bibDatabase.getReferencedEntry(entry); referenced.ifPresent(bibEntry -> observables.addAll(List.of(bibEntry.getObservables()))); observables.add(fieldValueFormatter); diff --git a/src/main/java/org/jabref/gui/maintable/MainTableFieldValueFormatter.java b/src/main/java/org/jabref/gui/maintable/MainTableFieldValueFormatter.java index 231e604769e..48a03e9478a 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableFieldValueFormatter.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableFieldValueFormatter.java @@ -84,13 +84,4 @@ private String formatFieldWithAuthorValue(final String nameToFormat) { case NATBIB -> authors.latexFree().getAsNatbib(); }; } - - /*** - * Finds the entry in the crossref field - * @param entry the entry to be searched - * @return The referenced entry - */ - public Optional getReferencedEntry(BibEntry entry) { - return bibDatabase.getReferencedEntry(entry); - } }