diff --git a/src/main/java/es/kauron/jstudy/controller/TableController.java b/src/main/java/es/kauron/jstudy/controller/TableController.java index ae265ca..fd4fa12 100644 --- a/src/main/java/es/kauron/jstudy/controller/TableController.java +++ b/src/main/java/es/kauron/jstudy/controller/TableController.java @@ -36,8 +36,6 @@ public class TableController implements Initializable { private TableView table; @FXML private TableColumn answerCol, questionCol; - @FXML - private Button editButton, duplicateButton, swapButton, testSelectionButton, deleteButton, saveButton; private ObservableList 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) 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 list, Controller controller, File file) { diff --git a/src/main/resources/es/kauron/jstudy/view/table.fxml b/src/main/resources/es/kauron/jstudy/view/table.fxml index 0a447a1..bfe94b1 100644 --- a/src/main/resources/es/kauron/jstudy/view/table.fxml +++ b/src/main/resources/es/kauron/jstudy/view/table.fxml @@ -2,116 +2,47 @@ - - + - - - - - - - - - - + - - - - - - - + - - - - - + + + + - + - + + + + + + + + + + + + + + + + - +