mirror of
https://gitlab.com/kauron/jstudy
synced 2024-12-22 16:33:33 +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);}
|
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());
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,22 +16,26 @@
|
||||||
<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>
|
||||||
<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>
|
<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" />
|
||||||
</HBox.margin>
|
</VBox.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>
|
|
||||||
</HBox>
|
</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">
|
<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>
|
<columns>
|
||||||
|
|
Loading…
Reference in a new issue