-
-
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
ActionHelper to test for present file #6151
Conversation
I added some validation. The regular validation mechanics of controlsfx seem somewhat broken. The icon is shown, but behind every other ui element, so instead I just marked the background of the cells with files that do not exist in the filesystem in the warning color. Theoretically, this one is mergable. |
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.
Thanks! Looks good to me in general, but I have a few comments/suggestions.
@@ -36,4 +40,18 @@ public static BooleanExpression isAnyFieldSetForSelectedEntry(List<Field> fields | |||
entry.getFieldsObservable(), | |||
stateManager.getSelectedEntries()); | |||
} | |||
|
|||
public static BooleanExpression isFilePresentForSelectedEntry(StateManager stateManager, PreferencesService preferencesService) { | |||
List<LinkedFile> files = stateManager.getSelectedEntries().get(0).getFiles(); |
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 think the current code runs into similar problems that we had recently in a PR by @stefan-kolb: if the currently selected entry changes, then the binding is not updated.
Here, this should be relatively easy to fix:
EasyBind.flatMap(stateManager.getSelectedEntries().getValueAt(0), entry -> entry.getFiles())
.map(files -> to boolean)
Here the getFiles
methods needs to be changed to return an observable list. This can be done using the current code and a EasyBind.map(getFieldBinding(FILE), ... parse)
.
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 played a bit around with it. I was able to make getFiles return an ObservableList (by BindingsHelper::map, I had no luck with EasyBind), but EasyBind.flatMap does not exist, so i worked with map. But now the ActionHelper never works. I really don't know how to proceed, what am I doing wrong?
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.
Sorry, it wasn't in EasyBind but here:
public static <T, U> ObservableList<U> map(ObservableValue<T> source, Function<T, List<U>> mapper) { |
thus BindingsHelper.map(getFieldBinding(FILES), string -> parseFiles())
should work. If not I'll have a closer look at it tomorrow.
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 always think way too complicated.
I just moved the call to getFiles()
into the calculation part and added stateManager.getSelectedEntries
as an additional dependency, so the list is always recalculated if the currently selected entry changes.
I have tested it and it works.
src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/gui/util/ViewModelListCellFactory.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/gui/util/ViewModelListCellFactory.java
Outdated
Show resolved
Hide resolved
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.
Validation is fixed, but the ActionHelper keeps me awake.... Someone please help?
src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java
Outdated
Show resolved
Hide resolved
@@ -36,4 +40,18 @@ public static BooleanExpression isAnyFieldSetForSelectedEntry(List<Field> fields | |||
entry.getFieldsObservable(), | |||
stateManager.getSelectedEntries()); | |||
} | |||
|
|||
public static BooleanExpression isFilePresentForSelectedEntry(StateManager stateManager, PreferencesService preferencesService) { | |||
List<LinkedFile> files = stateManager.getSelectedEntries().get(0).getFiles(); |
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 played a bit around with it. I was able to make getFiles return an ObservableList (by BindingsHelper::map, I had no luck with EasyBind), but EasyBind.flatMap does not exist, so i worked with map. But now the ActionHelper never works. I really don't know how to proceed, what am I doing wrong?
src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java
Outdated
Show resolved
Hide resolved
# Conflicts: # src/main/java/org/jabref/model/entry/BibEntry.java
…ionCaseInsensitive * upstream/master: (25 commits) ActionHelper to test for present file (#6151) Reduce memory footprint (#6298) Add missing abbreviated journal names (#6292) fix l10n again fix checkstyle fix l10n Try to minimize CodeCov "wrong metrics" Showing correct icon on main table linked files column (#6264) Fix labels for outdated dependency issue Change one more line Squashed 'src/main/resources/csl-styles/' changes from c31d9ca..c1793d2 Resolve unit test from failing Add one more change Fix errors RIS import takes the wrong date and duplicates abstract (#6272) Update EntryTypeView.java Change to the old school format Fix XmpExporterTest (#6289) Add checkstyle screenshot (and lint guidelines-...md) Squashed 'src/main/resources/csl-styles/' changes from db54e56..c31d9ca ...
This PR fixes koppor#430
It took a little bit more refactoring than expected, for it does not only check, if StandardField.FILE has text inside, but if the file is also really present in the file system. There are some design decisions i'm unsure of:
There is no alert about that no file is really present. The menu entry is just disabled, although there is a file symbol in the main table (since StandardField.FILE is not empty).
Feedback could be implemented in the files editor in the entry editor as validation.
The other thing is that in theory at last, the table does not yet automatically update, if a file is added or removed (so no file is attached). This would require probably an array of observables to be used as an invalidation alert. I'm unsure where to start with that. However, only in theory. Pracitcally the entry is unselected automatically if I change something about the attached files in the entry editor. So nobody would notice, if this would not be implemented.