mirror of
https://gitlab.com/kauron/jstudy
synced 2024-11-13 07:33:44 +01:00
Table: added cancel button for editing
This commit is contained in:
parent
4406bd4aed
commit
6d5c7917a2
2 changed files with 29 additions and 25 deletions
|
@ -95,7 +95,6 @@ public class TableController implements Initializable {
|
|||
List<TestItem> 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<TestItem> 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());
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?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">
|
||||
<children>
|
||||
|
@ -14,22 +16,26 @@
|
|||
<Tooltip text="Add a new entry to the table" />
|
||||
</tooltip>
|
||||
</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" />
|
||||
<Button onAction="#onTestAction" prefWidth="105.0" text="_Test all">
|
||||
<tooltip>
|
||||
<Tooltip text="Begin a test for the whole table" />
|
||||
</tooltip>
|
||||
</Button>
|
||||
<Button onAction="#onTestAction" prefWidth="105.0" text="_Test all">
|
||||
<tooltip>
|
||||
<Tooltip text="Begin a test for the whole table" />
|
||||
</tooltip>
|
||||
</Button>
|
||||
</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>
|
||||
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||
</VBox.margin>
|
||||
<VBox.margin>
|
||||
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||
</VBox.margin>
|
||||
</HBox>
|
||||
<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">
|
||||
<columns>
|
||||
|
|
Loading…
Reference in a new issue