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

ActionHelper to test for present file #6151

Merged
merged 10 commits into from
Apr 17, 2020
Merged

Conversation

calixtus
Copy link
Member

@calixtus calixtus commented Mar 21, 2020

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.

@JabRef JabRef deleted a comment from codecov bot Mar 24, 2020
@calixtus
Copy link
Member Author

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.

grafik

Theoretically, this one is mergable.

@calixtus calixtus marked this pull request as ready for review March 24, 2020 16:36
@calixtus calixtus changed the title [WIP] ActionHelper to test for present file ActionHelper to test for present file Mar 24, 2020
@calixtus calixtus added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Mar 24, 2020
Copy link
Member

@tobiasdiez tobiasdiez left a 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();
Copy link
Member

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).

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

@calixtus calixtus left a 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?

@@ -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();
Copy link
Member Author

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?

@JabRef JabRef deleted a comment from codecov bot Mar 28, 2020
@calixtus calixtus changed the title ActionHelper to test for present file [WIP] ActionHelper to test for present file Mar 28, 2020
@calixtus calixtus added status: help wanted and removed status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers labels Mar 28, 2020
@calixtus calixtus added status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers and removed status: help wanted labels Apr 13, 2020
@calixtus calixtus changed the title [WIP] ActionHelper to test for present file ActionHelper to test for present file Apr 13, 2020
# Conflicts:
#	src/main/java/org/jabref/model/entry/BibEntry.java
@tobiasdiez tobiasdiez merged commit 07cb5b8 into JabRef:master Apr 17, 2020
@calixtus calixtus deleted the fix_koppor_430 branch April 17, 2020 16:08
Siedlerchr added a commit that referenced this pull request Apr 17, 2020
…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
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disable "Open Document Viewer" if file has no attachments
2 participants