Search in sources :

Example 1 with PersistedMenu

use of com.thecoderscorner.menu.persist.PersistedMenu in project tcMenu by davetcc.

the class MenuEditorTestCases method testCopyingSingleItemInTree.

@Test
void testCopyingSingleItemInTree(FxRobot robot) throws Exception {
    // open the usual suspect.
    openTheCompleteMenuTree(robot);
    checkTheTreeMatchesMenuTree(robot, MenuTree.ROOT);
    // select the item with ID 100 which is a submenu.
    TreeView<MenuItem> treeView = robot.lookup("#menuTree").query();
    SubMenuItem subItem = project.getMenuTree().getSubMenuById(100).orElseThrow();
    assertTrue(recursiveSelectTreeItem(treeView, treeView.getRoot(), subItem));
    Thread.sleep(500);
    // sub menus can not be copied
    verifyThat("#menuTreeCopy", node -> !node.isDisabled());
    // now select the first sub item of the sub menu, which can be copied
    MenuItem itemToCopy = project.getMenuTree().getMenuById(2).orElseThrow();
    assertTrue(recursiveSelectTreeItem(treeView, treeView.getRoot(), itemToCopy));
    // make sure there isn't an ID of 101 already in the tree and then copy it.
    assertFalse(project.getMenuTree().getMenuById(101).isPresent());
    when(persistor.itemsToCopyText(any(), any())).thenReturn("tcMenuCopy:[{\"parentId\":0,\"type\":\"analogItem\",\"item\":{\"maxValue\":255,\"offset\":0,\"divisor\":100,\"unitName\":\"A\",\"name\":\"Current\",\"id\":2,\"eepromAddress\":4,\"functionName\":\"onCurrentChange\",\"readOnly\":false,\"localOnly\":false,\"visible\":true}}]");
    when(persistor.copyTextToItems(any())).thenReturn(List.of(new PersistedMenu(MenuTree.ROOT, itemToCopy)));
    robot.clickOn("#menuTreeCopy");
    // wait for copy to take effect first.
    int i = 0;
    while (i < 100 && robot.lookup("#menuTreePaste").queryButton().isDisable()) {
        Thread.sleep(50);
        i++;
    }
    Thread.sleep(250);
    robot.clickOn("#menuTreePaste");
    // now check that the new duplicate is created.
    Optional<MenuItem> maybeItem = project.getMenuTree().getMenuById(101);
    assertTrue(maybeItem.isPresent());
    assertThat(itemToCopy).isExactlyInstanceOf(maybeItem.get().getClass());
    checkTheTreeMatchesMenuTree(robot, itemToCopy);
}
Also used : UISubMenuItem(com.thecoderscorner.menu.editorui.uimodel.UISubMenuItem) MenuItem(com.thecoderscorner.menu.domain.MenuItem) UISubMenuItem(com.thecoderscorner.menu.editorui.uimodel.UISubMenuItem) PersistedMenu(com.thecoderscorner.menu.persist.PersistedMenu) Test(org.junit.jupiter.api.Test)

Example 2 with PersistedMenu

use of com.thecoderscorner.menu.persist.PersistedMenu in project tcMenu by davetcc.

the class JsonMenuItemSerializer method populateListInOrder.

public List<PersistedMenu> populateListInOrder(SubMenuItem node, MenuTree menuTree) {
    ArrayList<PersistedMenu> list = new ArrayList<>();
    List<MenuItem> items = menuTree.getMenuItems(node);
    for (MenuItem item : items) {
        list.add(new PersistedMenu(node, item));
        if (item.hasChildren()) {
            list.addAll(populateListInOrder(MenuItemHelper.asSubMenu(item), menuTree));
        }
    }
    return list;
}
Also used : PersistedMenu(com.thecoderscorner.menu.persist.PersistedMenu)

Example 3 with PersistedMenu

use of com.thecoderscorner.menu.persist.PersistedMenu in project tcMenu by davetcc.

the class JsonMenuItemSerializer method itemsToCopyText.

public String itemsToCopyText(MenuItem startingPoint, MenuTree tree) {
    List<PersistedMenu> items;
    if (startingPoint instanceof SubMenuItem) {
        items = populateListInOrder((SubMenuItem) startingPoint, tree);
    } else {
        // has to be an array list.
        items = new ArrayList<>();
        items.add(new PersistedMenu(tree.findParent(startingPoint), startingPoint));
    }
    return TCMENU_COPY_PREFIX + gson.toJson(items);
}
Also used : PersistedMenu(com.thecoderscorner.menu.persist.PersistedMenu)

Aggregations

PersistedMenu (com.thecoderscorner.menu.persist.PersistedMenu)3 MenuItem (com.thecoderscorner.menu.domain.MenuItem)1 UISubMenuItem (com.thecoderscorner.menu.editorui.uimodel.UISubMenuItem)1 Test (org.junit.jupiter.api.Test)1