made some improvements

This commit is contained in:
Jonas Hinterdorfer 2025-05-13 12:14:02 +02:00
parent 850381769a
commit 8502728738
3 changed files with 25 additions and 5 deletions

View File

@ -66,6 +66,7 @@ public class TestController {
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);

View File

@ -11,6 +11,7 @@ import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;
import javafx.fxml.FXML;
import javafx.scene.control.*;
@ -19,6 +20,8 @@ import java.sql.SQLException;
import static at.ionas999.questioncatalog.Utils.showConfirmationButton;
public class ViewController {
@FXML
private TextField searchField;
@FXML
private ComboBox<QuestionCatalog> selectBox;
@FXML
@ -29,7 +32,7 @@ public class ViewController {
private ListView<Question> questionListView;
private ObjectProperty<Question> currentQuestion = new SimpleObjectProperty<>();
private ObservableList<Question> questions;
private FilteredList<Question> questions;
private BooleanProperty isInEditState = new SimpleBooleanProperty(false);
@FXML
@ -44,12 +47,22 @@ public class ViewController {
answerField.editableProperty().bind(isInEditState);
deleteButton.disableProperty().bind(isInEditState);
questionListView.disableProperty().bind(isInEditState);
searchField.textProperty().addListener((_,_,newValue) ->{
if(newValue == null)
newValue = "";
String finalNewValue = newValue;
questions.setPredicate(x -> x.getQuestion().contains(finalNewValue));
});
}
private void loadQuestions(QuestionCatalog catalog) {
if (catalog == null) return;
try {
questions = FXCollections.observableList(QuestionService.GetQuestionsFromCatalog(catalog.getId()));
questions = new FilteredList<>(
FXCollections.observableList
(QuestionService.GetQuestionsFromCatalog(
catalog.getId())));
questionListView.setItems(questions);
} catch (SQLException e) {
throw new RuntimeException(e);

View File

@ -15,9 +15,15 @@
</HBox>
</top>
<left>
<ListView fx:id="questionListView" prefHeight="364.0" prefWidth="209.0" />
</left>
<left>
<VBox spacing="5.0" prefWidth="209.0">
<padding>
<Insets top="10.0" left="10.0" right="10.0" bottom="10.0" />
</padding>
<TextField fx:id="searchField" promptText="Search questions..." />
<ListView fx:id="questionListView" prefHeight="364.0" VBox.vgrow="ALWAYS" />
</VBox>
</left>
<center>
<VBox spacing="10.0">