-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
base: main
Are you sure you want to change the base?
Conversation
src/main/java/org/jabref/gui/maintable/BibEntryTableViewModel.java
Outdated
Show resolved
Hide resolved
ArrayList<Observable> observables = new ArrayList<>(List.of(entry.getObservables())); | ||
Optional<BibEntry> referenced = fieldValueFormatter.getValue().getReferencedEntry(entry); | ||
referenced.ifPresent(bibEntry -> observables.addAll(List.of(bibEntry.getObservables()))); |
There was a problem hiding this comment.
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, theStringBinding
has thisObjectBinding
among its dependencies instead of the referenced bibentry'sgetObservables()
. - At least superficially this seems like a good application for EasyBind because,
- You can create an optional binding, e.g.,
entry.getFieldBinding(StandardField.CROSSREF)
- This means you can create an
OptionalBinding<BibEntry> referencedBibEntry
- This means you can create an
- It should be possible to keep an observableArrayList with extractor (
FXCollections.observableArrayList(BibEntry::getObservables)
) updated withtheEasyBind.subscribe. That should keep the list up-to-date when the referencedifValuePresent
method of theOptionalBinding<BibEntry>
BibEntry
is changed/removed and when the observables in the referencedbibEntry.getObservables
are modified - This list should now be usable as a dependency
- You can create an optional binding, e.g.,
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 😛
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed it in our DevCall and have some comments to move forward here.
src/main/java/org/jabref/gui/maintable/BibEntryTableViewModel.java
Outdated
Show resolved
Hide resolved
ObservableValue<String> value = fieldValues.get(fields); | ||
if (value != null) { | ||
return value; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be kept. If it does not work on your side, please comment. This caching helps us to gain performance (in the case of large databases, as this is initialized at the start of JabRef).
We need to update the cache if the referenced crossref
entry is changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decision: We need to keep this code - and will handle the issue for changed crossref
value later (and incorporate the comments of https://github.com/JabRef/jabref/pull/7754/files#r641697015)
ArrayList<Observable> observables = new ArrayList<>(List.of(entry.getObservables())); | ||
Optional<BibEntry> referenced = fieldValueFormatter.getValue().getReferencedEntry(entry); | ||
referenced.ifPresent(bibEntry -> observables.addAll(List.of(bibEntry.getObservables()))); |
There was a problem hiding this comment.
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.
Thank you for all your comments. In fact, this was my first attempt to solve the issue and it just worked (ugly indeed). The reason I delete the code about the init cache is that if the value is not null, it just return without considering update. So maybe we can consider update the binding in the corresponding places( |
@SuXiChangZhen our thinking is that with the caching re-enabled, this is still an improvement on the previous behavior. Perhaps the caching can be re-enabled, you use Regarding a "proper way to solve this", unless you have an interest in EasyBind/JavaFX in particular, it is probably not going to be worth your time, it might be better to pick a different issue. If you want to give it an attempt anyway, we'd still propose fixing the other parts we commented on in this PR, merge, and then create a follow-up PR. I can expand on the suggested approach in #7754 (comment) but I make no guarantees that it will work nor that it is the "proper way" 😛 |
@k3KAW8Pnf7mkmdSMPHz27 Would you mind taking ove the PR so we can finish it? Just add the caching |
828a066
to
1b50be6
Compare
Ok. I am very sorry for force-pushing to your repository @SuXiChangZhen, definitively last time I am trying that X) @Siedlerchr thank you for the git-support X) |
The changes in this PR are the following
What remains after this PR,
|
The crossref field is already in the array of the triggers for the CreateStringBinding-method? |
Yes, but due to the caching, the dependencies on the cross-refs entry’s fields won’t update when cross-ref does (we need to “depend” on all observables in the cross-referenced entry to know when to update, and that is funky to do) This was why the caching was removed in the original solution. |
Ah, ok. Rebuilding the cache from an invalidation listener? |
That would probably work. In “theory”, you shouldn't need to rebuild it. Anyway, that part is why this issue is a bit of a mess. As is, this PR is imo an improvement on the previous behavior without that part as well. |
We shoudd make a decision here: Merge it, as it is an improvement to the current situation, although it does not solve the issue at all, or try to fix it completly. Putting this on line for next dev call. |
# Conflicts: # src/main/java/org/jabref/gui/maintable/BibEntryTableViewModel.java
…fix-for-issue-7730 # Conflicts: # src/main/java/org/jabref/gui/maintable/BibEntryTableViewModel.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your code currently does not meet JabRef's code guidelines.
We use Checkstyle to identify issues.
Please carefully follow the setup guide for the codestyle.
Afterwards, please run checkstyle locally and fix the issues.
In case of issues with the import order, double check that you activated Auto Import.
You can trigger fixing imports by pressing Ctrl+Alt+O to trigger Optimize Imports.
I change the
getField
method so that every time it will bind entry and referenced entry(if exists). Although the behavior now seems correct, I don't think it is an appropriate way to solve the problem. Hope for some suggestions.Mitigates #7730
CHANGELOG.md
described in a way that is understandable for the average user (if applicable)