1
0
Fork 0
mirror of https://gitlab.com/kauron/jstudy synced 2024-12-22 16:33:33 +01:00

Added context menu to tabs (duplication and merging)

This commit is contained in:
Carlos Galindo 2016-12-09 18:10:01 +01:00
parent 3e41a528a5
commit 0d4be04d58
Signed by: kauron
GPG key ID: 83E68706DEE119A3

View file

@ -169,8 +169,30 @@ public class Controller implements Initializable {
tabPane.getSelectionModel().selectNext(); tabPane.getSelectionModel().selectNext();
}); });
MenuItem merge = new MenuItem("Merge with other table");
merge.setOnAction(event -> {
Map<String, TableController> choices = new HashMap<>(tabMap.values().size() - 1);
for (TableController tc : tabMap.values())
if (tc != loader.getController())
choices.put(tc.getName(), tc);
ChoiceDialog<String> dialog = new ChoiceDialog<>();
dialog.setTitle("Merging tables...");
dialog.setHeaderText("Please select another table to merge with this one");
dialog.getItems().addAll(choices.keySet());
Optional<String> result = dialog.showAndWait();
if (result.isPresent() && choices.get(result.get()) != null) {
List<TestItem> newList = new ArrayList<>(list);
newList.addAll(choices.get(result.get()).getData());
Tab newTab = createTableTab("Merge", newList, null);
tabPane.getTabs().add(tabPane.getTabs().indexOf(tab) + 1, newTab);
tabPane.getSelectionModel().selectNext();
}
});
tab.setContent(tableRoot); tab.setContent(tableRoot);
tab.setContextMenu(new ContextMenu(duplicate)); tab.setContextMenu(new ContextMenu(duplicate, merge));
tab.setOnCloseRequest(event -> { tab.setOnCloseRequest(event -> {
if (!((TableController) loader.getController()).saved.get()) { if (!((TableController) loader.getController()).saved.get()) {
Alert dialog = new Alert(Alert.AlertType.WARNING); Alert dialog = new Alert(Alert.AlertType.WARNING);