diff --git a/src/main/java/es/kauron/jstudy/controller/Controller.java b/src/main/java/es/kauron/jstudy/controller/Controller.java index 7e0168d..ab3d1d4 100644 --- a/src/main/java/es/kauron/jstudy/controller/Controller.java +++ b/src/main/java/es/kauron/jstudy/controller/Controller.java @@ -308,10 +308,7 @@ public class Controller implements Initializable { MenuItem merge = new MenuItem("Merge with other table"); merge.setOnAction(event -> { - Map choices = new HashMap<>(tabMap.values().size() - 1); - for (Initializable tc : tabMap.values()) - if (tc instanceof TableController && tc != loader.getController()) - choices.put(((TableController) tc).getName(), ((TableController) tc)); + Map choices = genTabChoices(loader.getController()); ChoiceDialog dialog = new ChoiceDialog<>(); dialog.setTitle("Merging tables..."); @@ -352,6 +349,14 @@ public class Controller implements Initializable { return null; } + Map genTabChoices(Initializable controller) { + Map choices = new HashMap<>(tabMap.values().size() - 1); + for (Initializable tc : tabMap.values()) + if (tc instanceof TableController && tc != controller) + choices.put(((TableController) tc).getName(), ((TableController) tc)); + return choices; + } + void newTest(List list) { try { FXMLLoader loader = new FXMLLoader(Main.class.getResource("view/test.fxml")); @@ -382,6 +387,24 @@ public class Controller implements Initializable { } } + boolean appendItemsToTab(List items, TableController controller) { + Map choices = genTabChoices(controller); + + ChoiceDialog dialog = new ChoiceDialog<>(); + dialog.setTitle("Copying rows..."); + dialog.setHeaderText("Please select another table to put the rows in"); + dialog.getItems().addAll(choices.keySet()); + Optional result = dialog.showAndWait(); + + if (result.isPresent() && choices.get(result.get()) != null) { + choices.get(result.get()).appendData(items); + // Select the tab +// tabPane.getSelectionModel().select(choices.get(result.get())); + return true; + } + return false; + } + @FXML protected void onAboutAction(ActionEvent event) { if (Desktop.isDesktopSupported()) { diff --git a/src/main/java/es/kauron/jstudy/controller/TableController.java b/src/main/java/es/kauron/jstudy/controller/TableController.java index a2b27ff..4d7b529 100644 --- a/src/main/java/es/kauron/jstudy/controller/TableController.java +++ b/src/main/java/es/kauron/jstudy/controller/TableController.java @@ -61,13 +61,20 @@ public class TableController extends UndoController { mDup.disableProperty().bind(mDel.disableProperty()); MenuItem mSwap = new MenuItem("_Swap"); mSwap.setOnAction(this::onSwapAction); - mSwap.disableProperty().bind(mDup.disableProperty()); + mSwap.disableProperty().bind(mDel.disableProperty()); MenuItem mTest = new MenuItem("_Test selected"); mTest.setOnAction(this::onTestSelectionAction); - mTest.disableProperty().bind(mSwap.disableProperty()); + mTest.disableProperty().bind(mDel.disableProperty()); + MenuItem mMove = new MenuItem("_Move"); + mMove.setOnAction(this::onMoveData); + mMove.disableProperty().bind(mDel.disableProperty()); + MenuItem mCopy = new MenuItem("_Copy"); + mCopy.setOnAction(this::onMoveData); + mCopy.disableProperty().bind(mDel.disableProperty()); mEdit.setDisable(true); mDel.setDisable(true); - table.setContextMenu(new ContextMenu(mEdit, mDel, mDup, mSwap, new SeparatorMenuItem(), mTest)); + table.setContextMenu(new ContextMenu(mEdit, mDel, mDup, mSwap, new SeparatorMenuItem(), + mTest, mCopy, mMove)); table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); answerCol.setCellValueFactory(e -> e.getValue().answerProperty()); @@ -104,9 +111,30 @@ public class TableController extends UndoController { saved.set(file != null); } + void appendData(List list) { + if (list.size() > 0) { + saved.set(false); + List> actions = new ArrayList<>(list.size()); + for (TestItem i : list) + actions.add(new AddAction<>(i, data)); + Collections.reverse(actions); + doIt(new CollectionAction<>(actions)); + } + } + List getData() {return new ArrayList<>(data);} String getName() {return name.get();} + void onMoveData(ActionEvent event) { + List items = table.getSelectionModel().getSelectedItems(); + if (items.size() == 0) return; + if (!parent.appendItemsToTab(items, this)) + return; + if (((MenuItem) event.getTarget()).getText().contains("Move")) { + onDeleteAction(event); + } + } + protected void onSaveAction(ActionEvent event) { while (file == null) { FileChooser chooser = new FileChooser();