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 checks and warnings in SLR for non-empty directories #11088

Merged
merged 8 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- Citation relations now get more information, and have quick access to view the articles in a browser without adding them to the library [#10869](https://github.com/JabRef/jabref/issues/10869)
- Importer/Exporter for CFF format now supports JabRef `cites` and `related` relationships, as well as all fields from the CFF specification. [#10993](https://github.com/JabRef/jabref/issues/10993)
- The XMP-Exporter no longer writes the content of the `file`-field. [#11083](https://github.com/JabRef/jabref/pull/11083)
- We added notes and warnings for the case of selection of non-empty directories while starting a new Systematic Literature Review. [#600](https://github.com/koppor/jabref/issues/600)

### Fixed

Expand All @@ -81,6 +82,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- Fixed an issue on Windows where TeXworks path was not resolved if it was installed with MiKTeX. [#10977](https://github.com/JabRef/jabref/issues/10977)
- We fixed an issue with where JabRef would throw an error when using MathSciNet search, as it was unable to parse the fetched JSON coreectly. [10996](https://github.com/JabRef/jabref/issues/10996)
- We fixed an issue where the "Import by ID" function would throw an error when a DOI that contains URL-encoded characters was entered. [#10648](https://github.com/JabRef/jabref/issues/10648)
- We fixed a bug where a new Systematic Literature Review was allowed to start even if a non-empty directory is selected, later throwing an error. [#620](https://github.com/koppor/jabref/issues/620)
subhramit marked this conversation as resolved.
Show resolved Hide resolved

### Removed

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/gui/slr/ManageStudyDefinition.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.slr-tab {
-fx-padding: 1em;
}
.warning-label {
-fx-text-fill: red;
}
subhramit marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/gui/slr/ManageStudyDefinition.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@
</graphic>
</Button>
</HBox>
<Label text="%Note: The study directory should be empty."/>
<Label fx:id="directoryWarning" text="%Warning: The selected directory is not empty." visible="false" styleClass="warning-label" />
</VBox>
</ScrollPane>
</Tab>
Expand Down
45 changes: 38 additions & 7 deletions src/main/java/org/jabref/gui/slr/ManageStudyDefinitionView.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package org.jabref.gui.slr;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;
import java.util.StringJoiner;
import java.util.function.Consumer;
import java.util.stream.Stream;

import javafx.beans.binding.Bindings;
import javafx.beans.property.SimpleStringProperty;
Expand Down Expand Up @@ -70,6 +73,8 @@ public class ManageStudyDefinitionView extends BaseDialog<SlrStudyAndDirectory>
@FXML private TableColumn<StudyCatalogItem, Boolean> catalogEnabledColumn;
@FXML private TableColumn<StudyCatalogItem, String> catalogColumn;

@FXML private Label directoryWarning;

@Inject private DialogService dialogService;
@Inject private PreferencesService prefs;
@Inject private ThemeManager themeManager;
Expand Down Expand Up @@ -130,12 +135,13 @@ private void setupSaveSurveyButton(boolean isEdit) {
saveSurveyButton.setText(Localization.lang("Start survey"));
}

saveSurveyButton.disableProperty().bind(Bindings.or(Bindings.or(Bindings.or(Bindings.or(
Bindings.isEmpty(viewModel.getQueries()),
Bindings.isEmpty(viewModel.getCatalogs())),
Bindings.isEmpty(viewModel.getAuthors())),
viewModel.getTitle().isEmpty()),
viewModel.getDirectory().isEmpty()));
saveSurveyButton.disableProperty().bind(Bindings.or(Bindings.or(Bindings.or(Bindings.or(Bindings.or(
Bindings.isEmpty(viewModel.getQueries()),
Bindings.isEmpty(viewModel.getCatalogs())),
Bindings.isEmpty(viewModel.getAuthors())),
viewModel.getTitle().isEmpty()),
viewModel.getDirectory().isEmpty()),
directoryWarning.visibleProperty()));

setResultConverter(button -> {
if (button == saveSurveyButtonType) {
Expand Down Expand Up @@ -176,6 +182,27 @@ private void initialize() {
initCatalogsTab();
}

private void updateDirectoryWarning(Path directory) {
if (!Files.isDirectory(directory)) {
directoryWarning.setText(Localization.lang("Warning: The selected directory is not a valid directory."));
directoryWarning.setVisible(true);
} else {
try (Stream<Path> entries = Files.list(directory)) {
if (entries.findAny().isPresent()) {
directoryWarning.setText(Localization.lang("Warning: The selected directory is not empty."));
directoryWarning.setVisible(true);
} else {
directoryWarning.setVisible(false);
}
} catch (
IOException e) {
// Handle the exception appropriately (e.g., log the error)
subhramit marked this conversation as resolved.
Show resolved Hide resolved
directoryWarning.setText(Localization.lang("Warning: Failed to check if the directory is empty."));
directoryWarning.setVisible(true);
}
}
}

private void initAuthorTab() {
setupCommonPropertiesForTables(addAuthor, this::addAuthor, authorsColumn, authorsActionColumn);
setupCellFactories(authorsColumn, authorsActionColumn, viewModel::deleteAuthor);
Expand Down Expand Up @@ -278,6 +305,10 @@ public void selectStudyDirectory() {
.withInitialDirectory(pathToStudyDataDirectory)
.build();

viewModel.setStudyDirectory(dialogService.showDirectorySelectionDialog(directoryDialogConfiguration));
Optional<Path> selectedDirectoryOptional = dialogService.showDirectorySelectionDialog(directoryDialogConfiguration);
selectedDirectoryOptional.ifPresent(selectedDirectory -> {
viewModel.setStudyDirectory(Optional.of(selectedDirectory));
updateDirectoryWarning(selectedDirectory);
});
}
}
5 changes: 5 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2639,3 +2639,8 @@ Redownload\ missing\ files=Redownload missing files
Redownload\ missing\ files\ for\ current\ library?=Redownload missing files for current library?

File\ directory\ needs\ to\ be\ set\ or\ does\ not\ exist.\nPlease\ save\ your\ library\ and\ check\ the\ preferences.=File directory needs to be set or does not exist.\nPlease save your library and check the preferences.

Note\:\ The\ study\ directory\ should\ be\ empty.=Note: The study directory should be empty.
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 UI pattern of JabRef is to use colors to indicate "Note" and "Warning".

OK, we do have some strings with "Warning:" in front. Too much work to discuss this now. I'll just merge and we can do a follow-up for consistent UI later.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure.

Warning\:\ The\ selected\ directory\ is\ not\ empty.=Warning: The selected directory is not empty.
Warning\:\ Failed\ to\ check\ if\ the\ directory\ is\ empty.=Warning: Failed to check if the directory is empty.
Warning\:\ The\ selected\ directory\ is\ not\ a\ valid\ directory.=Warning: The selected directory is not a valid directory.
Loading