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

Add referenced entry's observers to update the entry in the main-table #7754

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class BibEntryTableViewModel {
private final Binding<List<AbstractGroup>> matchedGroups;
private final BibDatabaseContext bibDatabaseContext;


public BibEntryTableViewModel(BibEntry entry, BibDatabaseContext bibDatabaseContext, ObservableValue<MainTableFieldValueFormatter> fieldValueFormatter) {
this.entry = entry;
this.fieldValueFormatter = fieldValueFormatter;
Expand Down Expand Up @@ -133,6 +134,8 @@ public ObservableValue<String> getFields(OrFields fields) {
}

ArrayList<Observable> observables = new ArrayList<>(List.of(entry.getObservables()));
Optional<BibEntry> referenced = bibDatabaseContext.getDatabase().getReferencedEntry(entry);
referenced.ifPresent(bibEntry -> observables.addAll(List.of(bibEntry.getObservables())));
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

I don't know enough of JavaFX to tell you for sure how to address this. I'd suggest not removing the caching (fieldValues.get(fields);) and instead deal with the dependencies differently.

  • You can extend StringBinding and use .bind and .unbind to "manually" deal with the dependencies. (this is probably not a good approach)
  • You can extend a different binding (ObjectBinding?) and have it handle changes to the referenced entry. In this scenario, the StringBinding has this ObjectBinding among its dependencies instead of the referenced bibentry's getObservables().
  • At least superficially this seems like a good application for EasyBind because,
    1. You can create an optional binding, e.g., entry.getFieldBinding(StandardField.CROSSREF)
      1. This means you can create an OptionalBinding<BibEntry> referencedBibEntry
    2. It should be possible to keep an observableArrayList with extractor (FXCollections.observableArrayList(BibEntry::getObservables)) updated with the ifValuePresent method of the OptionalBinding<BibEntry> EasyBind.subscribe. That should keep the list up-to-date when the referenced BibEntry is changed/removed and when the observables in the referenced bibEntry.getObservables are modified
    3. This list should now be usable as a dependency

Note that the two last approaches should be used or called from the constructor since they will update on changes to the referenced BibEntry.

I'd appreciate it if someone with more experience of JavaFX chimes in with opinions 😛

Copy link
Member

Choose a reason for hiding this comment

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

Discussion:

@artcile{a,
crossref={b}
}

@book{b}

to

@artcile{a,
crossref={c}
}

@book{b}

@book{c}

Changes to c are not reflected accordingly.

observables.add(fieldValueFormatter);

value = Bindings.createStringBinding(() ->
Expand Down