updated
This commit is contained in:
parent
0e82bc231a
commit
53943ded0e
@ -56,42 +56,62 @@ public class TestController {
|
||||
private int correctCount = 0;
|
||||
private int inCorrectCount = 0;
|
||||
|
||||
@FXML
|
||||
private void initialize() throws SQLException {
|
||||
catalogs = FXCollections.observableList(QuestionCatalogService.GetCatalogsWithoutQuestions());
|
||||
catalogComboBox.setItems(catalogs);
|
||||
correctAnswerArea.visibleProperty().bind(isInCorrectionState);
|
||||
correctBtn.visibleProperty().bind(isInCorrectionState);
|
||||
incorrectBtn.visibleProperty().bind(isInCorrectionState);
|
||||
userAnswerArea.editableProperty().bind(isInCorrectionState.not());
|
||||
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.visibleProperty().bind(isInConfiguringState);
|
||||
nextQuestionBtn.disableProperty().bind(isInConfiguringState);
|
||||
nextQuestionBtn.visibleProperty().bind(isInCorrectionState.not());
|
||||
correctAnswerLable.visibleProperty().bind(isInCorrectionState);
|
||||
@FXML
|
||||
private void initialize() throws SQLException {
|
||||
catalogs = FXCollections.observableList(QuestionCatalogService.GetCatalogsWithoutQuestions());
|
||||
catalogComboBox.setItems(catalogs);
|
||||
correctAnswerArea.visibleProperty().bind(isInCorrectionState);
|
||||
correctBtn.visibleProperty().bind(isInCorrectionState);
|
||||
incorrectBtn.visibleProperty().bind(isInCorrectionState);
|
||||
userAnswerArea.editableProperty().bind(isInCorrectionState.not());
|
||||
questionSlider.disableProperty().bind(isInConfiguringState.not());
|
||||
questionCountField.disableProperty().bind(isInConfiguringState.not());
|
||||
catalogComboBox.disableProperty().bind(isInConfiguringState.not());
|
||||
startBtn.textProperty().bind(Bindings.when(isInConfiguringState).then("Start").otherwise("Cancel"));
|
||||
startBtn.visibleProperty().bind(isInConfiguringState);
|
||||
nextQuestionBtn.disableProperty().bind(isInConfiguringState);
|
||||
nextQuestionBtn.visibleProperty().bind(isInCorrectionState.not());
|
||||
correctAnswerLable.visibleProperty().bind(isInCorrectionState);
|
||||
|
||||
Bindings.bindBidirectional(questionCountField.textProperty(), questionSlider.valueProperty(), new NumberStringConverter());
|
||||
Bindings.bindBidirectional(questionCountField.textProperty(), questionSlider.valueProperty(), new NumberStringConverter());
|
||||
|
||||
questionSlider.setBlockIncrement(1);
|
||||
questionSlider.valueProperty().addListener((_, _, newValue) -> {
|
||||
questionSlider.setValue(newValue.intValue());
|
||||
});
|
||||
questionSlider.setBlockIncrement(1);
|
||||
questionSlider.valueProperty().addListener((_, _, newValue) -> {
|
||||
questionSlider.setValue(newValue.intValue());
|
||||
});
|
||||
|
||||
catalogComboBox.valueProperty().addListener((_,_,newValue) -> {
|
||||
if(newValue == null)
|
||||
return;
|
||||
QuestionCatalog c = (QuestionCatalog) newValue;
|
||||
try {
|
||||
this.questionSlider.setMax(QuestionCatalogService.GetAmountOfQuestionsFromCatalog(c.getId()));
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
catalogComboBox.valueProperty().addListener((_, _, newValue) -> {
|
||||
if (newValue == null)
|
||||
return;
|
||||
QuestionCatalog c = (QuestionCatalog) newValue;
|
||||
try {
|
||||
this.questionSlider.setMax(QuestionCatalogService.GetAmountOfQuestionsFromCatalog(c.getId()));
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
|
||||
// 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
|
||||
private void onCorrectBtnClick(ActionEvent actionEvent) {
|
||||
|
||||
@ -37,9 +37,9 @@ 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
|
||||
@FXML
|
||||
private void initialize() throws SQLException {
|
||||
ObservableList<QuestionCatalog> catalogs = FXCollections.observableList(QuestionCatalogService.GetCatalogsWithoutQuestions());
|
||||
selectBox.setItems(catalogs);
|
||||
@ -51,11 +51,27 @@ public class ViewController {
|
||||
answerField.editableProperty().bind(isInEditState);
|
||||
deleteButton.disableProperty().bind(isInEditState);
|
||||
questionListView.disableProperty().bind(isInEditState);
|
||||
searchField.textProperty().addListener((_,_,newValue) ->{
|
||||
if(newValue == null)
|
||||
newValue = "";
|
||||
|
||||
// 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);
|
||||
}
|
||||
@ -106,4 +123,4 @@ public class ViewController {
|
||||
Stage stage = Utils.getStageFromActionEven(actionEvent);
|
||||
Utils.switchScenes("main.fxml", stage);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user