1
0
Fork 0
mirror of https://gitlab.com/kauron/jstudy synced 2024-11-13 15:43:44 +01:00

Table: added cancel button for editing

This commit is contained in:
Carlos Galindo 2019-09-13 10:51:24 +02:00
parent 4406bd4aed
commit 6d5c7917a2
Signed by: kauron
GPG key ID: 83E68706DEE119A3
2 changed files with 29 additions and 25 deletions

View file

@ -95,7 +95,6 @@ public class TableController implements Initializable {
List<TestItem> getData() {return new ArrayList<>(data);} List<TestItem> getData() {return new ArrayList<>(data);}
String getName() {return name.get();} String getName() {return name.get();}
@FXML
protected void onSaveAction(ActionEvent event) { protected void onSaveAction(ActionEvent event) {
while (file == null) { while (file == null) {
FileChooser chooser = new FileChooser(); FileChooser chooser = new FileChooser();
@ -123,20 +122,14 @@ public class TableController implements Initializable {
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);
newQuestionField.setText("");
newAnswerField.setText("");
saved.set(false); saved.set(false);
} else { } else {
editing.get().answerProperty().set(newAnswerField.getText().trim()); editing.get().answerProperty().set(newAnswerField.getText().trim());
editing.get().questionProperty().set(newQuestionField.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) { protected void onEditAction(ActionEvent event) {
ObservableList<TestItem> list = table.getSelectionModel().getSelectedItems(); ObservableList<TestItem> list = table.getSelectionModel().getSelectedItems();
if (list.size() != 1) return; if (list.size() != 1) return;
@ -148,6 +141,14 @@ public class TableController implements Initializable {
} }
@FXML @FXML
protected void onCancelAction(ActionEvent event) {
if (editing.get() != null)
editing.set(null);
newQuestionField.setText("");
newAnswerField.setText("");
newQuestionField.requestFocus();
}
protected void onSwapAction(ActionEvent event) { protected void onSwapAction(ActionEvent event) {
if (table.getSelectionModel().getSelectedIndices().size() > 0) saved.set(false); if (table.getSelectionModel().getSelectedIndices().size() > 0) saved.set(false);
for (TestItem item : table.getSelectionModel().getSelectedItems()) { for (TestItem item : table.getSelectionModel().getSelectedItems()) {
@ -158,7 +159,6 @@ public class TableController implements Initializable {
table.requestFocus(); table.requestFocus();
} }
@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()) {
@ -169,14 +169,12 @@ public class TableController implements Initializable {
table.requestFocus(); table.requestFocus();
} }
@FXML
protected void onDeleteAction(ActionEvent event) { protected void onDeleteAction(ActionEvent event) {
if (table.getSelectionModel().getSelectedIndices().size() > 0) saved.set(false); if (table.getSelectionModel().getSelectedIndices().size() > 0) saved.set(false);
data.removeAll(table.getSelectionModel().getSelectedItems()); data.removeAll(table.getSelectionModel().getSelectedItems());
table.requestFocus(); table.requestFocus();
} }
@FXML
protected void onTestSelectionAction(ActionEvent event) { protected void onTestSelectionAction(ActionEvent event) {
parent.newTest(table.getSelectionModel().getSelectedItems()); parent.newTest(table.getSelectionModel().getSelectedItems());
} }

View file

@ -2,6 +2,8 @@
<?import javafx.geometry.Insets?> <?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?> <?import javafx.scene.control.*?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<VBox xmlns="http://javafx.com/javafx/8.0.202-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="es.kauron.jstudy.controller.TableController"> <VBox xmlns="http://javafx.com/javafx/8.0.202-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="es.kauron.jstudy.controller.TableController">
<children> <children>
@ -14,6 +16,16 @@
<Tooltip text="Add a new entry to the table" /> <Tooltip text="Add a new entry to the table" />
</tooltip> </tooltip>
</Button> </Button>
<Button onAction="#onCancelAction" cancelButton="true" >
<graphic>
<ImageView fitHeight="10.0" preserveRatio="true">
<Image url="@../img/Delete.png" />
</ImageView>
</graphic>
<tooltip>
<Tooltip text="Clear question and answer fields, and cancel edit" />
</tooltip>
</Button>
<TextField fx:id="searchField" maxWidth="1.7976931348623157E308" promptText="Search..." HBox.hgrow="ALWAYS" /> <TextField fx:id="searchField" maxWidth="1.7976931348623157E308" promptText="Search..." HBox.hgrow="ALWAYS" />
<Button onAction="#onTestAction" prefWidth="105.0" text="_Test all"> <Button onAction="#onTestAction" prefWidth="105.0" text="_Test all">
<tooltip> <tooltip>
@ -21,12 +33,6 @@
</tooltip> </tooltip>
</Button> </Button>
</children> </children>
<HBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</HBox.margin>
<HBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</HBox.margin>
<VBox.margin> <VBox.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" />
</VBox.margin> </VBox.margin>