mirror of
https://gitlab.com/kauron/jstudy
synced 2024-12-22 08:23:33 +01:00
Table: moved buttons to context menu.
This commit is contained in:
parent
889295a0b2
commit
c608f52c61
2 changed files with 42 additions and 105 deletions
|
@ -36,8 +36,6 @@ public class TableController implements Initializable {
|
|||
private TableView<TestItem> table;
|
||||
@FXML
|
||||
private TableColumn<TestItem, String> answerCol, questionCol;
|
||||
@FXML
|
||||
private Button editButton, duplicateButton, swapButton, testSelectionButton, deleteButton, saveButton;
|
||||
|
||||
private ObservableList<TestItem> data;
|
||||
private Controller parent;
|
||||
|
@ -47,17 +45,25 @@ public class TableController implements Initializable {
|
|||
|
||||
@Override
|
||||
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);
|
||||
answerCol.setCellValueFactory(e -> e.getValue().answerProperty());
|
||||
questionCol.setCellValueFactory(e -> e.getValue().questionProperty());
|
||||
table.getSelectionModel().getSelectedIndices().addListener((ListChangeListener<? super Integer>) obs -> {
|
||||
editButton.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);
|
||||
menuEdit.setDisable(obs.getList().size() != 1);
|
||||
});
|
||||
saveButton.disableProperty().bind(saved);
|
||||
}
|
||||
|
||||
void setData(String name, List<TestItem> list, Controller controller, File file) {
|
||||
|
|
|
@ -2,116 +2,47 @@
|
|||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.image.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<HBox xmlns="http://javafx.com/javafx/8.0.76-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>
|
||||
<TableView fx:id="table" minHeight="-Infinity" minWidth="-Infinity" prefHeight="380.0" prefWidth="400.0"
|
||||
HBox.hgrow="ALWAYS">
|
||||
<columns>
|
||||
<TableColumn fx:id="questionCol" prefWidth="75.0" text="Question"/>
|
||||
<TableColumn fx:id="answerCol" prefWidth="75.0" text="Answer"/>
|
||||
</columns>
|
||||
<columnResizePolicy>
|
||||
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/>
|
||||
</columnResizePolicy>
|
||||
</TableView>
|
||||
<VBox spacing="5.0">
|
||||
<HBox alignment="CENTER_LEFT" 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>
|
||||
<Button defaultButton="true" onAction="#onAddAction" prefWidth="105.0" text="_Add new">
|
||||
<tooltip>
|
||||
<Tooltip text="Save table to a file for future use"/>
|
||||
<Tooltip text="Add a new entry to the table" />
|
||||
</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">
|
||||
<HBox alignment="CENTER_RIGHT" spacing="5.0" HBox.hgrow="ALWAYS" 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 text="Begin a test for the whole table" />
|
||||
</tooltip>
|
||||
</Button>
|
||||
</children>
|
||||
<VBox.margin>
|
||||
<Insets/>
|
||||
</VBox.margin>
|
||||
</VBox>
|
||||
<HBox.margin>
|
||||
<Insets />
|
||||
</HBox.margin>
|
||||
</HBox>
|
||||
</children>
|
||||
<HBox.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>
|
||||
<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>
|
||||
<TableColumn fx:id="questionCol" prefWidth="75.0" text="Question" />
|
||||
<TableColumn fx:id="answerCol" prefWidth="75.0" text="Answer" />
|
||||
</columns>
|
||||
<columnResizePolicy>
|
||||
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
|
||||
</columnResizePolicy>
|
||||
</TableView>
|
||||
</children>
|
||||
</HBox>
|
||||
</VBox>
|
||||
|
|
Loading…
Reference in a new issue