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 all 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
1 change: 1 addition & 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, checks 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 Down
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-message" />
</VBox>
</ScrollPane>
</Tab>
Expand Down
44 changes: 37 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,26 @@ 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) {
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 +304,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