mirror of
https://gitlab.com/kauron/jstudy
synced 2025-09-30 21:01:10 +02: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
|
||||
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
|
||||
MenuItem menuEdit = new MenuItem("_Edit");
|
||||
menuEdit.setOnAction(this::onEditAction);
|
||||
|
@ -62,6 +69,16 @@ public class TableController implements Initializable {
|
|||
(ListChangeListener<? super Integer>) obs -> menuEdit.setDisable(obs.getList().size() != 1));
|
||||
searchField.textProperty().addListener((obj, o, 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) {
|
||||
|
@ -98,6 +115,10 @@ public class TableController implements Initializable {
|
|||
|
||||
@FXML
|
||||
protected void onAddAction(ActionEvent event) {
|
||||
if (newQuestionField.getText().trim().isEmpty() && newAnswerField.getText().trim().isEmpty()) {
|
||||
newQuestionField.requestFocus();
|
||||
return;
|
||||
}
|
||||
if (editing.get() == null) {
|
||||
TestItem item = new TestItem(newQuestionField.getText().trim(), newAnswerField.getText().trim());
|
||||
data.add(item);
|
||||
|
@ -139,8 +160,11 @@ public class TableController implements Initializable {
|
|||
@FXML
|
||||
protected void onDuplicateAction(ActionEvent event) {
|
||||
if (table.getSelectionModel().getSelectedIndices().size() > 0) saved.set(false);
|
||||
for (int i : table.getSelectionModel().getSelectedIndices())
|
||||
data.add(new TestItem(filtered.get(i)));
|
||||
for (int i : table.getSelectionModel().getSelectedIndices()) {
|
||||
TestItem item = new TestItem(filtered.get(i));
|
||||
item.questionProperty().setValue(item.getQuestion() + " 2");
|
||||
data.add(item);
|
||||
}
|
||||
table.requestFocus();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue