Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ public class ManageStudyDefinitionView extends BaseDialog<SlrStudyAndDirectory>

@FXML private Label directoryWarning;

@FXML private Label validationHeaderLabel;
@FXML private Label titleValidationLabel;
@FXML private Label authorsValidationLabel;
@FXML private Label questionsValidationLabel;
@FXML private Label queriesValidationLabel;
@FXML private Label catalogsValidationLabel;

@Inject private DialogService dialogService;
@Inject private GuiPreferences preferences;

Expand Down Expand Up @@ -173,6 +180,7 @@ private void initialize() {
initQuestionsTab();
initQueriesTab();
initCatalogsTab();
initValidationBindings();
}

private void updateDirectoryWarning(Path directory) {
Expand Down Expand Up @@ -247,6 +255,34 @@ private void initCatalogsTab() {
catalogTable.setItems(viewModel.getCatalogs());
}

private void initValidationBindings() {
// Header label
validationHeaderLabel.textProperty().bind(viewModel.validationHeaderMessageProperty());
validationHeaderLabel.visibleProperty().bind(Bindings.isNotEmpty(viewModel.validationHeaderMessageProperty()));
validationHeaderLabel.managedProperty().bind(validationHeaderLabel.visibleProperty());

// Specific validation messages
titleValidationLabel.textProperty().bind(viewModel.titleValidationMessageProperty());
titleValidationLabel.visibleProperty().bind(Bindings.isNotEmpty(viewModel.titleValidationMessageProperty()));
titleValidationLabel.managedProperty().bind(titleValidationLabel.visibleProperty());

authorsValidationLabel.textProperty().bind(viewModel.authorsValidationMessageProperty());
authorsValidationLabel.visibleProperty().bind(Bindings.isNotEmpty(viewModel.authorsValidationMessageProperty()));
authorsValidationLabel.managedProperty().bind(authorsValidationLabel.visibleProperty());

questionsValidationLabel.textProperty().bind(viewModel.questionsValidationMessageProperty());
questionsValidationLabel.visibleProperty().bind(Bindings.isNotEmpty(viewModel.questionsValidationMessageProperty()));
questionsValidationLabel.managedProperty().bind(questionsValidationLabel.visibleProperty());

queriesValidationLabel.textProperty().bind(viewModel.queriesValidationMessageProperty());
queriesValidationLabel.visibleProperty().bind(Bindings.isNotEmpty(viewModel.queriesValidationMessageProperty()));
queriesValidationLabel.managedProperty().bind(queriesValidationLabel.visibleProperty());

catalogsValidationLabel.textProperty().bind(viewModel.catalogsValidationMessageProperty());
catalogsValidationLabel.visibleProperty().bind(Bindings.isNotEmpty(viewModel.catalogsValidationMessageProperty()));
catalogsValidationLabel.managedProperty().bind(catalogsValidationLabel.visibleProperty());
}

private void setupCommonPropertiesForTables(Node addControl,
Runnable addAction,
TableColumn<?, String> contentColumn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Set;
import java.util.stream.Collectors;

import javafx.beans.binding.Bindings;
import javafx.beans.property.Property;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
Expand Down Expand Up @@ -64,6 +65,13 @@ public class ManageStudyDefinitionViewModel {

private final WorkspacePreferences workspacePreferences;

private final StringProperty titleValidationMessage = new SimpleStringProperty();
private final StringProperty authorsValidationMessage = new SimpleStringProperty();
private final StringProperty questionsValidationMessage = new SimpleStringProperty();
private final StringProperty queriesValidationMessage = new SimpleStringProperty();
private final StringProperty catalogsValidationMessage = new SimpleStringProperty();
private final StringProperty validationHeaderMessage = new SimpleStringProperty();

/**
* Constructor for a new study
*/
Expand All @@ -84,6 +92,8 @@ public ManageStudyDefinitionViewModel(ImportFormatPreferences importFormatPrefer
.toList());
this.dialogService = dialogService;
this.workspacePreferences = workspacePreferences;

initializeValidationBindings();
}

/**
Expand Down Expand Up @@ -119,6 +129,47 @@ public ManageStudyDefinitionViewModel(@NonNull Study study,
this.directory.set(studyDirectory.toString());
this.workspacePreferences = workspacePreferences;
this.dialogService = dialogService;

initializeValidationBindings();
}

private void initializeValidationBindings() {
titleValidationMessage.bind(Bindings.when(title.isEmpty())
Copy link
Member

Choose a reason for hiding this comment

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

Please use our ValidationSatus approach with the controlsfx visualizer

private void setupValidation() {
validator = new CompositeValidator();
nameValidator = new FunctionBasedValidator<>(
nameProperty,
StringUtil::isNotBlank,
ValidationMessage.error(Localization.lang("Please enter a name for the group.")));
nameContainsDelimiterValidator = new FunctionBasedValidator<>(
nameProperty,
name -> !name.contains(Character.toString(preferences.getBibEntryPreferences().getKeywordSeparator())),
ValidationMessage.warning(
Localization.lang(
"The group name contains the keyword separator \"%0\" and thus probably does not work as expected.",
Character.toString(preferences.getBibEntryPreferences().getKeywordSeparator())
)));
sameNameValidator = new FunctionBasedValidator<>(
nameProperty,
name -> {
Optional<GroupTreeNode> rootGroup = currentDatabase.getMetaData().getGroups();
if (rootGroup.isPresent()) {
boolean groupsExistWithSameName = !rootGroup.get().findChildrenSatisfying(group -> group.getName().equals(name)).isEmpty();
if ((editedGroup == null) && groupsExistWithSameName) {
// New group but there is already one group with the same name
return false;
}
// Edit group, changed name to something that is already present
return (editedGroup == null) || editedGroup.getName().equals(name) || !groupsExistWithSameName;
}
return true;
},
ValidationMessage.warning(
Localization.lang("There already exists a group with the same name.\nIf you use it, it will inherit all entries from this other group.")
)
);

PS: Next time tell your AI tool to follow existing patterns in the codebase

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, you got me

But I thought those things only work for fields

.then(Localization.lang("Study title is required"))
.otherwise(""));

authorsValidationMessage.bind(Bindings.when(Bindings.isEmpty(authors))
.then(Localization.lang("At least one author is required"))
.otherwise(""));

questionsValidationMessage.bind(Bindings.when(Bindings.isEmpty(researchQuestions))
.then(Localization.lang("At least one research question is required"))
.otherwise(""));

queriesValidationMessage.bind(Bindings.when(Bindings.isEmpty(queries))
.then(Localization.lang("At least one query is required"))
.otherwise(""));

catalogsValidationMessage.bind(Bindings.when(
Bindings.createBooleanBinding(() ->
databases.stream().noneMatch(StudyCatalogItem::isEnabled), databases))
.then(Localization.lang("At least one catalog must be selected"))
.otherwise(""));

validationHeaderMessage.bind(Bindings.when(
Bindings.or(
Bindings.or(
Bindings.or(
Bindings.or(title.isEmpty(), Bindings.isEmpty(authors)),
Bindings.isEmpty(researchQuestions)
),
Bindings.isEmpty(queries)
),
Bindings.createBooleanBinding(() ->
databases.stream().noneMatch(StudyCatalogItem::isEnabled), databases)
))
.then(Localization.lang("In order to proceed:"))
.otherwise(""));
}

public StringProperty getTitle() {
Expand Down Expand Up @@ -241,4 +292,28 @@ public void updateSelectedCatalogs() {

workspacePreferences.setSelectedSlrCatalogs(selectedCatalogsList);
}

public StringProperty validationHeaderMessageProperty() {
return validationHeaderMessage;
}

public StringProperty titleValidationMessageProperty() {
return titleValidationMessage;
}

public StringProperty authorsValidationMessageProperty() {
return authorsValidationMessage;
}

public StringProperty questionsValidationMessageProperty() {
return questionsValidationMessage;
}

public StringProperty queriesValidationMessageProperty() {
return queriesValidationMessage;
}

public StringProperty catalogsValidationMessageProperty() {
return catalogsValidationMessage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,17 @@
</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 spacing="5.0" fx:id="validationContainer">
<Label fx:id="validationHeaderLabel" text="%In order to proceed:" style="-fx-text-fill: -jr-error; -fx-font-weight: bold" visible="false" managed="false" />
<VBox spacing="3.0">
<Label fx:id="titleValidationLabel" visible="false" managed="false" />
<Label fx:id="authorsValidationLabel" visible="false" managed="false" />
<Label fx:id="questionsValidationLabel" visible="false" managed="false" />
<Label fx:id="queriesValidationLabel" visible="false" managed="false" />
<Label fx:id="catalogsValidationLabel" visible="false" managed="false" />
</VBox>
</VBox>
</VBox>
</ScrollPane>
</Tab>
Expand Down
Loading