This commit is contained in:
Jonas Hinterdorfer 2025-05-13 15:55:45 +02:00
parent 0e82bc231a
commit 53943ded0e
2 changed files with 77 additions and 40 deletions

View File

@ -67,7 +67,7 @@ public class TestController {
questionSlider.disableProperty().bind(isInConfiguringState.not());
questionCountField.disableProperty().bind(isInConfiguringState.not());
catalogComboBox.disableProperty().bind(isInConfiguringState.not());
startBtn.textProperty().bind(Bindings.when(isInConfiguringState).then("Start").otherwise("Cancle"));
startBtn.textProperty().bind(Bindings.when(isInConfiguringState).then("Start").otherwise("Cancel"));
startBtn.visibleProperty().bind(isInConfiguringState);
nextQuestionBtn.disableProperty().bind(isInConfiguringState);
nextQuestionBtn.visibleProperty().bind(isInCorrectionState.not());
@ -91,6 +91,26 @@ public class TestController {
}
});
// Add validation for questionCountField
questionCountField.textProperty().addListener((observable, oldValue, newValue) -> {
if (!newValue.matches("\\d*")) {
questionCountField.setText(newValue.replaceAll("[^\\d]", ""));
} else {
int value = newValue.isEmpty() ? 0 : Integer.parseInt(newValue);
if (value < questionSlider.getMin() || value > questionSlider.getMax()) {
questionCountField.setStyle("-fx-border-color: red;");
} else {
questionCountField.setStyle("");
}
}
});
// Add validation for catalogComboBox
startBtn.disableProperty().bind(
catalogComboBox.valueProperty().isNull()
.or(questionCountField.textProperty().isEmpty())
.or(questionCountField.styleProperty().isEqualTo("-fx-border-color: red;"))
);
}
@FXML

View File

@ -37,7 +37,7 @@ public class ViewController {
private ObjectProperty<Question> currentQuestion = new SimpleObjectProperty<>();
private FilteredList<Question> questions;
private BooleanProperty isInEditState = new SimpleBooleanProperty(false);
private final BooleanProperty isInEditState = new SimpleBooleanProperty(false);
@FXML
private void initialize() throws SQLException {
@ -51,11 +51,27 @@ public class ViewController {
answerField.editableProperty().bind(isInEditState);
deleteButton.disableProperty().bind(isInEditState);
questionListView.disableProperty().bind(isInEditState);
// Disable searchField if no catalog is selected
searchField.disableProperty().bind(selectBox.getSelectionModel().selectedItemProperty().isNull());
// Disable editButton if fields are empty
editButton.disableProperty().bind(
questionField.textProperty().isEmpty()
.or(answerField.textProperty().isEmpty())
.or(selectBox.getSelectionModel().selectedItemProperty().isNull())
);
deleteButton.disableProperty().bind(
questionField.textProperty().isEmpty()
.or(answerField.textProperty().isEmpty())
.or(selectBox.getSelectionModel().selectedItemProperty().isNull())
);
searchField.textProperty().addListener((_, _, newValue) -> {
if (newValue == null)
newValue = "";
String finalNewValue = newValue;
questions.setPredicate(x -> x.getQuestion().contains(finalNewValue));
questions.setPredicate(x -> x.getQuestion().toLowerCase().contains(finalNewValue.toLowerCase()));
});
}
@ -84,9 +100,9 @@ public class ViewController {
private void deleteQuestion() {
if (currentQuestion.get() == null || !showConfirmationButton("Delete question: \n" + currentQuestion.get().getQuestion())) return;
QuestionService.DeleteQuestion(currentQuestion.get().getId());
questions.remove(currentQuestion.get());
questions.getSource().remove(currentQuestion.get());
questionListView.refresh();
currentQuestion = null;
currentQuestion.set(null);
}
@FXML
@ -96,6 +112,7 @@ public class ViewController {
currentQuestion.get().setAnswer(answerField.getText());
QuestionService.UpdateQuestion(currentQuestion.get());
isInEditState.set(false);
questionListView.refresh();
} else {
isInEditState.set(true);
}