From 6d5c7917a29f92739317f5d4fe0ab8ad113924ba Mon Sep 17 00:00:00 2001 From: Carlos Galindo Date: Fri, 13 Sep 2019 10:51:24 +0200 Subject: [PATCH] Table: added cancel button for editing --- .../jstudy/controller/TableController.java | 20 +++++------ .../es/kauron/jstudy/view/table.fxml | 34 +++++++++++-------- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/main/java/es/kauron/jstudy/controller/TableController.java b/src/main/java/es/kauron/jstudy/controller/TableController.java index f2c8468..693028b 100644 --- a/src/main/java/es/kauron/jstudy/controller/TableController.java +++ b/src/main/java/es/kauron/jstudy/controller/TableController.java @@ -95,7 +95,6 @@ public class TableController implements Initializable { List getData() {return new ArrayList<>(data);} String getName() {return name.get();} - @FXML protected void onSaveAction(ActionEvent event) { while (file == null) { FileChooser chooser = new FileChooser(); @@ -123,20 +122,14 @@ public class TableController implements Initializable { if (editing.get() == null) { TestItem item = new TestItem(newQuestionField.getText().trim(), newAnswerField.getText().trim()); data.add(item); - newQuestionField.setText(""); - newAnswerField.setText(""); saved.set(false); } else { editing.get().answerProperty().set(newAnswerField.getText().trim()); editing.get().questionProperty().set(newQuestionField.getText().trim()); - editing.set(null); - newQuestionField.setText(""); - newAnswerField.setText(""); } - newQuestionField.requestFocus(); + onCancelAction(event); } - @FXML protected void onEditAction(ActionEvent event) { ObservableList list = table.getSelectionModel().getSelectedItems(); if (list.size() != 1) return; @@ -148,6 +141,14 @@ public class TableController implements Initializable { } @FXML + protected void onCancelAction(ActionEvent event) { + if (editing.get() != null) + editing.set(null); + newQuestionField.setText(""); + newAnswerField.setText(""); + newQuestionField.requestFocus(); + } + protected void onSwapAction(ActionEvent event) { if (table.getSelectionModel().getSelectedIndices().size() > 0) saved.set(false); for (TestItem item : table.getSelectionModel().getSelectedItems()) { @@ -158,7 +159,6 @@ public class TableController implements Initializable { table.requestFocus(); } - @FXML protected void onDuplicateAction(ActionEvent event) { if (table.getSelectionModel().getSelectedIndices().size() > 0) saved.set(false); for (int i : table.getSelectionModel().getSelectedIndices()) { @@ -169,14 +169,12 @@ public class TableController implements Initializable { table.requestFocus(); } - @FXML protected void onDeleteAction(ActionEvent event) { if (table.getSelectionModel().getSelectedIndices().size() > 0) saved.set(false); data.removeAll(table.getSelectionModel().getSelectedItems()); table.requestFocus(); } - @FXML protected void onTestSelectionAction(ActionEvent event) { parent.newTest(table.getSelectionModel().getSelectedItems()); } diff --git a/src/main/resources/es/kauron/jstudy/view/table.fxml b/src/main/resources/es/kauron/jstudy/view/table.fxml index 66d9e92..93baded 100644 --- a/src/main/resources/es/kauron/jstudy/view/table.fxml +++ b/src/main/resources/es/kauron/jstudy/view/table.fxml @@ -2,6 +2,8 @@ + + @@ -14,22 +16,26 @@ + - + - - - - - - - - - + + +