mirror of
https://gitlab.com/kauron/jstudy
synced 2024-11-13 07:33:44 +01:00
Table: removed the possibility for repeated questions
This commit is contained in:
parent
5d5f400495
commit
a599508fc3
2 changed files with 37 additions and 22 deletions
|
@ -41,7 +41,14 @@ public class TableController implements Initializable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL url, ResourceBundle resourceBundle) {
|
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||||
addButton.textProperty().bind(Bindings.when(editing.isNull()).then("_Add item").otherwise("_Save item"));
|
addButton.textProperty().bind(Bindings.when(addButton.disableProperty())
|
||||||
|
.then("Question repeated")
|
||||||
|
.otherwise(Bindings.when(editing.isNull())
|
||||||
|
.then("_Add item")
|
||||||
|
.otherwise("_Save item")));
|
||||||
|
addButton.getTooltip().textProperty().bind(Bindings.when(editing.isNull())
|
||||||
|
.then("Add an entry to the table")
|
||||||
|
.otherwise("Save changes in the selected entry"));
|
||||||
// Add context menu to Table
|
// Add context menu to Table
|
||||||
MenuItem menuEdit = new MenuItem("_Edit");
|
MenuItem menuEdit = new MenuItem("_Edit");
|
||||||
menuEdit.setOnAction(this::onEditAction);
|
menuEdit.setOnAction(this::onEditAction);
|
||||||
|
@ -62,6 +69,16 @@ public class TableController implements Initializable {
|
||||||
(ListChangeListener<? super Integer>) obs -> menuEdit.setDisable(obs.getList().size() != 1));
|
(ListChangeListener<? super Integer>) obs -> menuEdit.setDisable(obs.getList().size() != 1));
|
||||||
searchField.textProperty().addListener((obj, o, n) ->
|
searchField.textProperty().addListener((obj, o, n) ->
|
||||||
filtered.setPredicate((item) -> item.getQuestion().contains(n) || item.getAnswer().contains(n)));
|
filtered.setPredicate((item) -> item.getQuestion().contains(n) || item.getAnswer().contains(n)));
|
||||||
|
newQuestionField.textProperty().addListener((obj, o, n) -> {
|
||||||
|
for (TestItem item : data) {
|
||||||
|
if (item == editing.get()) continue;
|
||||||
|
if (item.getQuestion().equals(n.trim())) {
|
||||||
|
addButton.setDisable(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addButton.setDisable(false);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void setData(String name, List<TestItem> list, Controller controller, File file) {
|
void setData(String name, List<TestItem> list, Controller controller, File file) {
|
||||||
|
@ -98,6 +115,10 @@ public class TableController implements Initializable {
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
protected void onAddAction(ActionEvent event) {
|
protected void onAddAction(ActionEvent event) {
|
||||||
|
if (newQuestionField.getText().trim().isEmpty() && newAnswerField.getText().trim().isEmpty()) {
|
||||||
|
newQuestionField.requestFocus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (editing.get() == null) {
|
if (editing.get() == null) {
|
||||||
TestItem item = new TestItem(newQuestionField.getText().trim(), newAnswerField.getText().trim());
|
TestItem item = new TestItem(newQuestionField.getText().trim(), newAnswerField.getText().trim());
|
||||||
data.add(item);
|
data.add(item);
|
||||||
|
@ -139,8 +160,11 @@ public class TableController implements Initializable {
|
||||||
@FXML
|
@FXML
|
||||||
protected void onDuplicateAction(ActionEvent event) {
|
protected void onDuplicateAction(ActionEvent event) {
|
||||||
if (table.getSelectionModel().getSelectedIndices().size() > 0) saved.set(false);
|
if (table.getSelectionModel().getSelectedIndices().size() > 0) saved.set(false);
|
||||||
for (int i : table.getSelectionModel().getSelectedIndices())
|
for (int i : table.getSelectionModel().getSelectedIndices()) {
|
||||||
data.add(new TestItem(filtered.get(i)));
|
TestItem item = new TestItem(filtered.get(i));
|
||||||
|
item.questionProperty().setValue(item.getQuestion() + " 2");
|
||||||
|
data.add(item);
|
||||||
|
}
|
||||||
table.requestFocus();
|
table.requestFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,27 +7,20 @@
|
||||||
<children>
|
<children>
|
||||||
<HBox alignment="CENTER_LEFT" spacing="5.0">
|
<HBox alignment="CENTER_LEFT" spacing="5.0">
|
||||||
<children>
|
<children>
|
||||||
<TextField fx:id="newQuestionField" promptText="Question" />
|
<TextField fx:id="newQuestionField" promptText="Question" HBox.hgrow="ALWAYS" />
|
||||||
<TextField fx:id="newAnswerField" promptText="Answer" />
|
<TextField fx:id="newAnswerField" promptText="Answer" HBox.hgrow="ALWAYS" />
|
||||||
<Button defaultButton="true" fx:id="addButton" onAction="#onAddAction" prefWidth="105.0" text="_Add new">
|
<Button fx:id="addButton" defaultButton="true" maxWidth="1.7976931348623157E308" onAction="#onAddAction" prefWidth="105.0" text="_Add new" HBox.hgrow="SOMETIMES">
|
||||||
<tooltip>
|
<tooltip>
|
||||||
<Tooltip text="Add a new entry to the table" />
|
<Tooltip text="Add a new entry to the table" />
|
||||||
</tooltip>
|
</tooltip>
|
||||||
</Button>
|
</Button>
|
||||||
<TextField fx:id="searchField" promptText="Search..." />
|
<TextField fx:id="searchField" maxWidth="1.7976931348623157E308" promptText="Search..." HBox.hgrow="ALWAYS" />
|
||||||
<HBox alignment="CENTER_RIGHT" spacing="5.0" HBox.hgrow="ALWAYS" VBox.vgrow="ALWAYS">
|
<Button onAction="#onTestAction" prefWidth="105.0" text="_Test all">
|
||||||
<children>
|
|
||||||
<Button layoutX="10.0" layoutY="273.0" onAction="#onTestAction" prefWidth="105.0" text="_Test all">
|
|
||||||
<tooltip>
|
<tooltip>
|
||||||
<Tooltip text="Begin a test for the whole table" />
|
<Tooltip text="Begin a test for the whole table" />
|
||||||
</tooltip>
|
</tooltip>
|
||||||
</Button>
|
</Button>
|
||||||
</children>
|
</children>
|
||||||
<HBox.margin>
|
|
||||||
<Insets />
|
|
||||||
</HBox.margin>
|
|
||||||
</HBox>
|
|
||||||
</children>
|
|
||||||
<HBox.margin>
|
<HBox.margin>
|
||||||
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||||
</HBox.margin>
|
</HBox.margin>
|
||||||
|
@ -38,9 +31,7 @@
|
||||||
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||||
</VBox.margin>
|
</VBox.margin>
|
||||||
</HBox>
|
</HBox>
|
||||||
<TableView fx:id="table" onMouseClicked="#onTableMouseClicked" onKeyPressed="#onTableKeyEvent" maxHeight="1.7976931348623157E308"
|
<TableView fx:id="table" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" onKeyPressed="#onTableKeyEvent" onMouseClicked="#onTableMouseClicked" prefHeight="200.0" prefWidth="400.0" HBox.hgrow="ALWAYS" VBox.vgrow="ALWAYS">
|
||||||
maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity"
|
|
||||||
prefHeight="200.0" prefWidth="400.0" HBox.hgrow="ALWAYS" VBox.vgrow="ALWAYS">
|
|
||||||
<columns>
|
<columns>
|
||||||
<TableColumn fx:id="questionCol" prefWidth="75.0" text="Question" />
|
<TableColumn fx:id="questionCol" prefWidth="75.0" text="Question" />
|
||||||
<TableColumn fx:id="answerCol" prefWidth="75.0" text="Answer" />
|
<TableColumn fx:id="answerCol" prefWidth="75.0" text="Answer" />
|
||||||
|
|
Loading…
Reference in a new issue