mirror of
https://gitlab.com/kauron/jstudy
synced 2024-12-22 00:13:33 +01:00
Table: copying/moving rows between tables.
This commit is contained in:
parent
8a279ae1cb
commit
26ae5b01b8
2 changed files with 58 additions and 7 deletions
|
@ -308,10 +308,7 @@ public class Controller implements Initializable {
|
|||
|
||||
MenuItem merge = new MenuItem("Merge with other table");
|
||||
merge.setOnAction(event -> {
|
||||
Map<String, TableController> 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<String, TableController> choices = genTabChoices(loader.getController());
|
||||
|
||||
ChoiceDialog<String> dialog = new ChoiceDialog<>();
|
||||
dialog.setTitle("Merging tables...");
|
||||
|
@ -352,6 +349,14 @@ public class Controller implements Initializable {
|
|||
return null;
|
||||
}
|
||||
|
||||
Map<String, TableController> genTabChoices(Initializable controller) {
|
||||
Map<java.lang.String, TableController> 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<TestItem> list) {
|
||||
try {
|
||||
FXMLLoader loader = new FXMLLoader(Main.class.getResource("view/test.fxml"));
|
||||
|
@ -382,6 +387,24 @@ public class Controller implements Initializable {
|
|||
}
|
||||
}
|
||||
|
||||
boolean appendItemsToTab(List<TestItem> items, TableController controller) {
|
||||
Map<String, TableController> choices = genTabChoices(controller);
|
||||
|
||||
ChoiceDialog<String> dialog = new ChoiceDialog<>();
|
||||
dialog.setTitle("Copying rows...");
|
||||
dialog.setHeaderText("Please select another table to put the rows in");
|
||||
dialog.getItems().addAll(choices.keySet());
|
||||
Optional<String> 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()) {
|
||||
|
|
|
@ -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<TestItem> list) {
|
||||
if (list.size() > 0) {
|
||||
saved.set(false);
|
||||
List<Action<TestItem>> actions = new ArrayList<>(list.size());
|
||||
for (TestItem i : list)
|
||||
actions.add(new AddAction<>(i, data));
|
||||
Collections.reverse(actions);
|
||||
doIt(new CollectionAction<>(actions));
|
||||
}
|
||||
}
|
||||
|
||||
List<TestItem> getData() {return new ArrayList<>(data);}
|
||||
String getName() {return name.get();}
|
||||
|
||||
void onMoveData(ActionEvent event) {
|
||||
List<TestItem> 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();
|
||||
|
|
Loading…
Reference in a new issue