Skip to content

Commit 2abe5aa

Browse files
InAnYankoppor
andauthored
feat(slr): improve validation messages for starting SLR (#14225)
* feat(slr): improve validation messages for starting SLR * fix(i18n): add localization strings * chore(slr): reformat code --------- Co-authored-by: Oliver Kopp <kopp.dev@gmail.com>
1 parent 447e5ca commit 2abe5aa

File tree

4 files changed

+127
-2
lines changed

4 files changed

+127
-2
lines changed

jabgui/src/main/java/org/jabref/gui/slr/ManageStudyDefinitionView.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ public class ManageStudyDefinitionView extends BaseDialog<SlrStudyAndDirectory>
7070

7171
@FXML private Label directoryWarning;
7272

73+
@FXML private Label validationHeaderLabel;
74+
@FXML private Label titleValidationLabel;
75+
@FXML private Label authorsValidationLabel;
76+
@FXML private Label questionsValidationLabel;
77+
@FXML private Label queriesValidationLabel;
78+
@FXML private Label catalogsValidationLabel;
79+
7380
@Inject private DialogService dialogService;
7481
@Inject private GuiPreferences preferences;
7582

@@ -173,6 +180,7 @@ private void initialize() {
173180
initQuestionsTab();
174181
initQueriesTab();
175182
initCatalogsTab();
183+
initValidationBindings();
176184
}
177185

178186
private void updateDirectoryWarning(Path directory) {
@@ -247,6 +255,34 @@ private void initCatalogsTab() {
247255
catalogTable.setItems(viewModel.getCatalogs());
248256
}
249257

258+
private void initValidationBindings() {
259+
// Header label
260+
validationHeaderLabel.textProperty().bind(viewModel.validationHeaderMessageProperty());
261+
validationHeaderLabel.visibleProperty().bind(Bindings.isNotEmpty(viewModel.validationHeaderMessageProperty()));
262+
validationHeaderLabel.managedProperty().bind(validationHeaderLabel.visibleProperty());
263+
264+
// Specific validation messages
265+
titleValidationLabel.textProperty().bind(viewModel.titleValidationMessageProperty());
266+
titleValidationLabel.visibleProperty().bind(Bindings.isNotEmpty(viewModel.titleValidationMessageProperty()));
267+
titleValidationLabel.managedProperty().bind(titleValidationLabel.visibleProperty());
268+
269+
authorsValidationLabel.textProperty().bind(viewModel.authorsValidationMessageProperty());
270+
authorsValidationLabel.visibleProperty().bind(Bindings.isNotEmpty(viewModel.authorsValidationMessageProperty()));
271+
authorsValidationLabel.managedProperty().bind(authorsValidationLabel.visibleProperty());
272+
273+
questionsValidationLabel.textProperty().bind(viewModel.questionsValidationMessageProperty());
274+
questionsValidationLabel.visibleProperty().bind(Bindings.isNotEmpty(viewModel.questionsValidationMessageProperty()));
275+
questionsValidationLabel.managedProperty().bind(questionsValidationLabel.visibleProperty());
276+
277+
queriesValidationLabel.textProperty().bind(viewModel.queriesValidationMessageProperty());
278+
queriesValidationLabel.visibleProperty().bind(Bindings.isNotEmpty(viewModel.queriesValidationMessageProperty()));
279+
queriesValidationLabel.managedProperty().bind(queriesValidationLabel.visibleProperty());
280+
281+
catalogsValidationLabel.textProperty().bind(viewModel.catalogsValidationMessageProperty());
282+
catalogsValidationLabel.visibleProperty().bind(Bindings.isNotEmpty(viewModel.catalogsValidationMessageProperty()));
283+
catalogsValidationLabel.managedProperty().bind(catalogsValidationLabel.visibleProperty());
284+
}
285+
250286
private void setupCommonPropertiesForTables(Node addControl,
251287
Runnable addAction,
252288
TableColumn<?, String> contentColumn,

jabgui/src/main/java/org/jabref/gui/slr/ManageStudyDefinitionViewModel.java

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.Set;
99
import java.util.stream.Collectors;
1010

11+
import javafx.beans.binding.Bindings;
1112
import javafx.beans.property.Property;
1213
import javafx.beans.property.SimpleStringProperty;
1314
import javafx.beans.property.StringProperty;
@@ -64,6 +65,13 @@ public class ManageStudyDefinitionViewModel {
6465

6566
private final WorkspacePreferences workspacePreferences;
6667

68+
private final StringProperty titleValidationMessage = new SimpleStringProperty();
69+
private final StringProperty authorsValidationMessage = new SimpleStringProperty();
70+
private final StringProperty questionsValidationMessage = new SimpleStringProperty();
71+
private final StringProperty queriesValidationMessage = new SimpleStringProperty();
72+
private final StringProperty catalogsValidationMessage = new SimpleStringProperty();
73+
private final StringProperty validationHeaderMessage = new SimpleStringProperty();
74+
6775
/**
6876
* Constructor for a new study
6977
*/
@@ -84,6 +92,8 @@ public ManageStudyDefinitionViewModel(ImportFormatPreferences importFormatPrefer
8492
.toList());
8593
this.dialogService = dialogService;
8694
this.workspacePreferences = workspacePreferences;
95+
96+
initializeValidationBindings();
8797
}
8898

8999
/**
@@ -119,6 +129,47 @@ public ManageStudyDefinitionViewModel(@NonNull Study study,
119129
this.directory.set(studyDirectory.toString());
120130
this.workspacePreferences = workspacePreferences;
121131
this.dialogService = dialogService;
132+
133+
initializeValidationBindings();
134+
}
135+
136+
private void initializeValidationBindings() {
137+
titleValidationMessage.bind(Bindings.when(title.isEmpty())
138+
.then(Localization.lang("Study title is required"))
139+
.otherwise(""));
140+
141+
authorsValidationMessage.bind(Bindings.when(Bindings.isEmpty(authors))
142+
.then(Localization.lang("At least one author is required"))
143+
.otherwise(""));
144+
145+
questionsValidationMessage.bind(Bindings.when(Bindings.isEmpty(researchQuestions))
146+
.then(Localization.lang("At least one research question is required"))
147+
.otherwise(""));
148+
149+
queriesValidationMessage.bind(Bindings.when(Bindings.isEmpty(queries))
150+
.then(Localization.lang("At least one query is required"))
151+
.otherwise(""));
152+
153+
catalogsValidationMessage.bind(Bindings.when(
154+
Bindings.createBooleanBinding(() ->
155+
databases.stream().noneMatch(StudyCatalogItem::isEnabled), databases))
156+
.then(Localization.lang("At least one catalog must be selected"))
157+
.otherwise(""));
158+
159+
validationHeaderMessage.bind(Bindings.when(
160+
Bindings.or(
161+
Bindings.or(
162+
Bindings.or(
163+
Bindings.or(title.isEmpty(), Bindings.isEmpty(authors)),
164+
Bindings.isEmpty(researchQuestions)
165+
),
166+
Bindings.isEmpty(queries)
167+
),
168+
Bindings.createBooleanBinding(() ->
169+
databases.stream().noneMatch(StudyCatalogItem::isEnabled), databases)
170+
))
171+
.then(Localization.lang("In order to proceed:"))
172+
.otherwise(""));
122173
}
123174

124175
public StringProperty getTitle() {
@@ -241,4 +292,28 @@ public void updateSelectedCatalogs() {
241292

242293
workspacePreferences.setSelectedSlrCatalogs(selectedCatalogsList);
243294
}
295+
296+
public StringProperty validationHeaderMessageProperty() {
297+
return validationHeaderMessage;
298+
}
299+
300+
public StringProperty titleValidationMessageProperty() {
301+
return titleValidationMessage;
302+
}
303+
304+
public StringProperty authorsValidationMessageProperty() {
305+
return authorsValidationMessage;
306+
}
307+
308+
public StringProperty questionsValidationMessageProperty() {
309+
return questionsValidationMessage;
310+
}
311+
312+
public StringProperty queriesValidationMessageProperty() {
313+
return queriesValidationMessage;
314+
}
315+
316+
public StringProperty catalogsValidationMessageProperty() {
317+
return catalogsValidationMessage;
318+
}
244319
}

jabgui/src/main/resources/org/jabref/gui/slr/ManageStudyDefinition.fxml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,17 @@
270270
</graphic>
271271
</Button>
272272
</HBox>
273-
<Label text="%Note: The study directory should be empty."/>
274273
<Label fx:id="directoryWarning" text="%Warning: The selected directory is not empty." visible="false" styleClass="warning-message" />
274+
<VBox spacing="5.0" fx:id="validationContainer">
275+
<Label fx:id="validationHeaderLabel" text="%In order to proceed:" style="-fx-text-fill: -jr-error; -fx-font-weight: bold" visible="false" managed="false" />
276+
<VBox spacing="3.0">
277+
<Label fx:id="titleValidationLabel" visible="false" managed="false" />
278+
<Label fx:id="authorsValidationLabel" visible="false" managed="false" />
279+
<Label fx:id="questionsValidationLabel" visible="false" managed="false" />
280+
<Label fx:id="queriesValidationLabel" visible="false" managed="false" />
281+
<Label fx:id="catalogsValidationLabel" visible="false" managed="false" />
282+
</VBox>
283+
</VBox>
275284
</VBox>
276285
</ScrollPane>
277286
</Tab>

jablib/src/main/resources/l10n/JabRef_en.properties

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2930,7 +2930,12 @@ Group\ icons=Group icons
29302930
Redownload\ missing\ files=Redownload missing files
29312931
Redownload\ missing\ files\ for\ current\ library?=Redownload missing files for current library?
29322932
2933-
Note\:\ The\ study\ directory\ should\ be\ empty.=Note: The study directory should be empty.
2933+
In\ order\ to\ proceed\:=In order to proceed:
2934+
At\ least\ one\ author\ is\ required=At least one author is required
2935+
At\ least\ one\ catalog\ must\ be\ selected=At least one catalog must be selected
2936+
At\ least\ one\ query\ is\ required=At least one query is required
2937+
At\ least\ one\ research\ question\ is\ required=At least one research question is required
2938+
Study\ title\ is\ required=Study title is required
29342939
Warning\:\ The\ selected\ directory\ is\ not\ empty.=Warning: The selected directory is not empty.
29352940
Warning\:\ Failed\ to\ check\ if\ the\ directory\ is\ empty.=Warning: Failed to check if the directory is empty.
29362941
Warning\:\ The\ selected\ directory\ is\ not\ a\ valid\ directory.=Warning: The selected directory is not a valid directory.

0 commit comments

Comments
 (0)