updated
This commit is contained in:
parent
0e82bc231a
commit
53943ded0e
@ -56,42 +56,62 @@ public class TestController {
|
|||||||
private int correctCount = 0;
|
private int correctCount = 0;
|
||||||
private int inCorrectCount = 0;
|
private int inCorrectCount = 0;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void initialize() throws SQLException {
|
private void initialize() throws SQLException {
|
||||||
catalogs = FXCollections.observableList(QuestionCatalogService.GetCatalogsWithoutQuestions());
|
catalogs = FXCollections.observableList(QuestionCatalogService.GetCatalogsWithoutQuestions());
|
||||||
catalogComboBox.setItems(catalogs);
|
catalogComboBox.setItems(catalogs);
|
||||||
correctAnswerArea.visibleProperty().bind(isInCorrectionState);
|
correctAnswerArea.visibleProperty().bind(isInCorrectionState);
|
||||||
correctBtn.visibleProperty().bind(isInCorrectionState);
|
correctBtn.visibleProperty().bind(isInCorrectionState);
|
||||||
incorrectBtn.visibleProperty().bind(isInCorrectionState);
|
incorrectBtn.visibleProperty().bind(isInCorrectionState);
|
||||||
userAnswerArea.editableProperty().bind(isInCorrectionState.not());
|
userAnswerArea.editableProperty().bind(isInCorrectionState.not());
|
||||||
questionSlider.disableProperty().bind(isInConfiguringState.not());
|
questionSlider.disableProperty().bind(isInConfiguringState.not());
|
||||||
questionCountField.disableProperty().bind(isInConfiguringState.not());
|
questionCountField.disableProperty().bind(isInConfiguringState.not());
|
||||||
catalogComboBox.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);
|
startBtn.visibleProperty().bind(isInConfiguringState);
|
||||||
nextQuestionBtn.disableProperty().bind(isInConfiguringState);
|
nextQuestionBtn.disableProperty().bind(isInConfiguringState);
|
||||||
nextQuestionBtn.visibleProperty().bind(isInCorrectionState.not());
|
nextQuestionBtn.visibleProperty().bind(isInCorrectionState.not());
|
||||||
correctAnswerLable.visibleProperty().bind(isInCorrectionState);
|
correctAnswerLable.visibleProperty().bind(isInCorrectionState);
|
||||||
|
|
||||||
Bindings.bindBidirectional(questionCountField.textProperty(), questionSlider.valueProperty(), new NumberStringConverter());
|
Bindings.bindBidirectional(questionCountField.textProperty(), questionSlider.valueProperty(), new NumberStringConverter());
|
||||||
|
|
||||||
questionSlider.setBlockIncrement(1);
|
questionSlider.setBlockIncrement(1);
|
||||||
questionSlider.valueProperty().addListener((_, _, newValue) -> {
|
questionSlider.valueProperty().addListener((_, _, newValue) -> {
|
||||||
questionSlider.setValue(newValue.intValue());
|
questionSlider.setValue(newValue.intValue());
|
||||||
});
|
});
|
||||||
|
|
||||||
catalogComboBox.valueProperty().addListener((_,_,newValue) -> {
|
catalogComboBox.valueProperty().addListener((_, _, newValue) -> {
|
||||||
if(newValue == null)
|
if (newValue == null)
|
||||||
return;
|
return;
|
||||||
QuestionCatalog c = (QuestionCatalog) newValue;
|
QuestionCatalog c = (QuestionCatalog) newValue;
|
||||||
try {
|
try {
|
||||||
this.questionSlider.setMax(QuestionCatalogService.GetAmountOfQuestionsFromCatalog(c.getId()));
|
this.questionSlider.setMax(QuestionCatalogService.GetAmountOfQuestionsFromCatalog(c.getId()));
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(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
|
@FXML
|
||||||
private void onCorrectBtnClick(ActionEvent actionEvent) {
|
private void onCorrectBtnClick(ActionEvent actionEvent) {
|
||||||
|
|||||||
@ -37,9 +37,9 @@ public class ViewController {
|
|||||||
|
|
||||||
private ObjectProperty<Question> currentQuestion = new SimpleObjectProperty<>();
|
private ObjectProperty<Question> currentQuestion = new SimpleObjectProperty<>();
|
||||||
private FilteredList<Question> questions;
|
private FilteredList<Question> questions;
|
||||||
private BooleanProperty isInEditState = new SimpleBooleanProperty(false);
|
private final BooleanProperty isInEditState = new SimpleBooleanProperty(false);
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void initialize() throws SQLException {
|
private void initialize() throws SQLException {
|
||||||
ObservableList<QuestionCatalog> catalogs = FXCollections.observableList(QuestionCatalogService.GetCatalogsWithoutQuestions());
|
ObservableList<QuestionCatalog> catalogs = FXCollections.observableList(QuestionCatalogService.GetCatalogsWithoutQuestions());
|
||||||
selectBox.setItems(catalogs);
|
selectBox.setItems(catalogs);
|
||||||
@ -51,11 +51,27 @@ public class ViewController {
|
|||||||
answerField.editableProperty().bind(isInEditState);
|
answerField.editableProperty().bind(isInEditState);
|
||||||
deleteButton.disableProperty().bind(isInEditState);
|
deleteButton.disableProperty().bind(isInEditState);
|
||||||
questionListView.disableProperty().bind(isInEditState);
|
questionListView.disableProperty().bind(isInEditState);
|
||||||
searchField.textProperty().addListener((_,_,newValue) ->{
|
|
||||||
if(newValue == null)
|
// Disable searchField if no catalog is selected
|
||||||
newValue = "";
|
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;
|
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() {
|
private void deleteQuestion() {
|
||||||
if (currentQuestion.get() == null || !showConfirmationButton("Delete question: \n" + currentQuestion.get().getQuestion())) return;
|
if (currentQuestion.get() == null || !showConfirmationButton("Delete question: \n" + currentQuestion.get().getQuestion())) return;
|
||||||
QuestionService.DeleteQuestion(currentQuestion.get().getId());
|
QuestionService.DeleteQuestion(currentQuestion.get().getId());
|
||||||
questions.remove(currentQuestion.get());
|
questions.getSource().remove(currentQuestion.get());
|
||||||
questionListView.refresh();
|
questionListView.refresh();
|
||||||
currentQuestion = null;
|
currentQuestion.set(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
@ -96,6 +112,7 @@ public class ViewController {
|
|||||||
currentQuestion.get().setAnswer(answerField.getText());
|
currentQuestion.get().setAnswer(answerField.getText());
|
||||||
QuestionService.UpdateQuestion(currentQuestion.get());
|
QuestionService.UpdateQuestion(currentQuestion.get());
|
||||||
isInEditState.set(false);
|
isInEditState.set(false);
|
||||||
|
questionListView.refresh();
|
||||||
} else {
|
} else {
|
||||||
isInEditState.set(true);
|
isInEditState.set(true);
|
||||||
}
|
}
|
||||||
@ -106,4 +123,4 @@ public class ViewController {
|
|||||||
Stage stage = Utils.getStageFromActionEven(actionEvent);
|
Stage stage = Utils.getStageFromActionEven(actionEvent);
|
||||||
Utils.switchScenes("main.fxml", stage);
|
Utils.switchScenes("main.fxml", stage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user