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

Table: moved buttons to context menu.

This commit is contained in:
Carlos Galindo 2019-09-12 00:29:57 +02:00
parent 889295a0b2
commit c608f52c61
Signed by: kauron
GPG key ID: 83E68706DEE119A3
2 changed files with 42 additions and 105 deletions

View file

@ -36,8 +36,6 @@ public class TableController implements Initializable {
private TableView<TestItem> table; private TableView<TestItem> table;
@FXML @FXML
private TableColumn<TestItem, String> answerCol, questionCol; private TableColumn<TestItem, String> answerCol, questionCol;
@FXML
private Button editButton, duplicateButton, swapButton, testSelectionButton, deleteButton, saveButton;
private ObservableList<TestItem> data; private ObservableList<TestItem> data;
private Controller parent; private Controller parent;
@ -47,17 +45,25 @@ public class TableController implements Initializable {
@Override @Override
public void initialize(URL url, ResourceBundle resourceBundle) { public void initialize(URL url, ResourceBundle resourceBundle) {
// Add context menu to Table
MenuItem menuEdit = new MenuItem("_Edit");
menuEdit.setOnAction(this::onEditAction);
MenuItem menuDelete = new MenuItem("_Delete");
menuDelete.setOnAction(this::onDeleteAction);
MenuItem menuDup = new MenuItem("D_uplicate");
menuDup.setOnAction(this::onDuplicateAction);
MenuItem menuSwap = new MenuItem("_Swap");
menuSwap.setOnAction(this::onSwapAction);
MenuItem menuTest = new MenuItem("_Test selected");
menuTest.setOnAction(this::onTestSelectionAction);
table.setContextMenu(new ContextMenu(menuEdit, menuDelete, menuDup, menuSwap, new SeparatorMenuItem(), menuTest));
table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
answerCol.setCellValueFactory(e -> e.getValue().answerProperty()); answerCol.setCellValueFactory(e -> e.getValue().answerProperty());
questionCol.setCellValueFactory(e -> e.getValue().questionProperty()); questionCol.setCellValueFactory(e -> e.getValue().questionProperty());
table.getSelectionModel().getSelectedIndices().addListener((ListChangeListener<? super Integer>) obs -> { table.getSelectionModel().getSelectedIndices().addListener((ListChangeListener<? super Integer>) obs -> {
editButton.setDisable(obs.getList().size() != 1); menuEdit.setDisable(obs.getList().size() != 1);
swapButton.setDisable(obs.getList().size() < 1);
deleteButton.setDisable(obs.getList().size() < 1);
duplicateButton.setDisable(obs.getList().size() < 1);
testSelectionButton.setDisable(obs.getList().size() < 1);
}); });
saveButton.disableProperty().bind(saved);
} }
void setData(String name, List<TestItem> list, Controller controller, File file) { void setData(String name, List<TestItem> list, Controller controller, File file) {

View file

@ -2,13 +2,40 @@
<?import javafx.geometry.Insets?> <?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?> <?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<HBox xmlns="http://javafx.com/javafx/8.0.76-ea" xmlns:fx="http://javafx.com/fxml/1" <VBox xmlns="http://javafx.com/javafx/8.0.202-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="es.kauron.jstudy.controller.TableController">
fx:controller="es.kauron.jstudy.controller.TableController">
<children> <children>
<TableView fx:id="table" minHeight="-Infinity" minWidth="-Infinity" prefHeight="380.0" prefWidth="400.0" <HBox alignment="CENTER_LEFT" spacing="5.0">
HBox.hgrow="ALWAYS"> <children>
<Button defaultButton="true" onAction="#onAddAction" prefWidth="105.0" text="_Add new">
<tooltip>
<Tooltip text="Add a new entry to the table" />
</tooltip>
</Button>
<HBox alignment="CENTER_RIGHT" spacing="5.0" HBox.hgrow="ALWAYS" VBox.vgrow="ALWAYS">
<children>
<Button layoutX="10.0" layoutY="273.0" onAction="#onTestAction" prefWidth="105.0" text="_Test all">
<tooltip>
<Tooltip text="Begin a test for the whole table" />
</tooltip>
</Button>
</children>
<HBox.margin>
<Insets />
</HBox.margin>
</HBox>
</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>
</HBox>
<TableView fx:id="table" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="200.0" prefWidth="400.0" HBox.hgrow="ALWAYS" VBox.vgrow="ALWAYS">
<columns> <columns>
<TableColumn fx:id="questionCol" prefWidth="75.0" text="Question" /> <TableColumn fx:id="questionCol" prefWidth="75.0" text="Question" />
<TableColumn fx:id="answerCol" prefWidth="75.0" text="Answer" /> <TableColumn fx:id="answerCol" prefWidth="75.0" text="Answer" />
@ -17,101 +44,5 @@
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" /> <TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy> </columnResizePolicy>
</TableView> </TableView>
<VBox spacing="5.0">
<children>
<Button fx:id="saveButton" alignment="CENTER" contentDisplay="CENTER" layoutX="10.0" layoutY="163.0"
onAction="#onSaveAction" prefWidth="105.0">
<graphic>
<ImageView fitHeight="50.0" fitWidth="50.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../img/Save.png"/>
</image>
</ImageView>
</graphic>
<VBox.margin>
<Insets/>
</VBox.margin>
<tooltip>
<Tooltip text="Save table to a file for future use"/>
</tooltip>
</Button>
<Button defaultButton="true" onAction="#onAddAction" prefWidth="105.0" text="_Add">
<tooltip>
<Tooltip text="Add a new entry to the table"/>
</tooltip>
</Button>
<Button fx:id="editButton" alignment="TOP_LEFT" onAction="#onEditAction" prefWidth="105.0" text="_Edit">
<graphic>
<ImageView fitHeight="25.0" fitWidth="25.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../img/Edit.png"/>
</image>
</ImageView>
</graphic>
<tooltip>
<Tooltip text="Edit the selected entry"/>
</tooltip>
</Button>
<Button fx:id="swapButton" alignment="TOP_LEFT" layoutX="10.0" layoutY="76.0" onAction="#onSwapAction"
prefWidth="105.0" text="S_wap">
<graphic>
<ImageView fitHeight="25.0" fitWidth="25.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../img/Replace.png"/>
</image>
</ImageView>
</graphic>
<tooltip>
<Tooltip text="Make the answer the question and vice versa"/>
</tooltip>
</Button>
<Button fx:id="duplicateButton" alignment="TOP_LEFT" layoutX="10.0" layoutY="76.0" onAction="#onDuplicateAction"
prefWidth="105.0" text="D_uplicate">
<graphic>
<ImageView fitHeight="25.0" fitWidth="25.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../img/Copy.png"/>
</image>
</ImageView>
</graphic>
<tooltip>
<Tooltip text="Make a copy (may appear at the end)"/>
</tooltip>
</Button>
<Button fx:id="deleteButton" alignment="TOP_LEFT" onAction="#onDeleteAction" prefWidth="105.0" text="_Delete">
<graphic>
<ImageView fitHeight="25.0" fitWidth="25.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../img/Delete.png"/>
</image>
</ImageView>
</graphic>
<tooltip>
<Tooltip text="Delete all selected entries FOREVER"/>
</tooltip>
</Button>
<VBox alignment="BOTTOM_CENTER" spacing="5.0" VBox.vgrow="ALWAYS">
<children>
<Button fx:id="testSelectionButton" onAction="#onTestSelectionAction" prefWidth="105.0"
text="Test _selected">
<tooltip>
<Tooltip text="Begin a test with the selected rows"/>
</tooltip>
</Button>
<Button layoutX="10.0" layoutY="273.0" onAction="#onTestAction" prefWidth="105.0" text="_Test all">
<tooltip>
<Tooltip text="Begin a test for the whole table"/>
</tooltip>
</Button>
</children> </children>
<VBox.margin>
<Insets/>
</VBox.margin>
</VBox> </VBox>
</children>
<HBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0"/>
</HBox.margin>
</VBox>
</children>
</HBox>