Search in sources :

Example 1 with MenuItem

use of com.thecoderscorner.menu.domain.MenuItem in project tcMenu by davetcc.

the class CurrentEditorProject method applyCommand.

public void applyCommand(EditedItemChange.Command command, MenuItem newItem, SubMenuItem parent) {
    if (command == EditedItemChange.Command.NEW) {
        uncommittedItems.add(newItem.getId());
    } else if (command == EditedItemChange.Command.REMOVE) {
        uncommittedItems.remove(newItem.getId());
    }
    MenuItem oldItem = changeHistory.stream().filter(item -> item.getItem() != null && item.getItem().getId() == newItem.getId()).reduce((first, second) -> second).map(MenuItemChange::getItem).orElse(newItem);
    MenuItemChange change = new EditedItemChange(newItem, oldItem, parent, command);
    applyCommand(change);
}
Also used : CodeGeneratorOptionsBuilder(com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptionsBuilder) java.util(java.util) MenuItem(com.thecoderscorner.menu.domain.MenuItem) CurrentProjectEditorUI(com.thecoderscorner.menu.editorui.uimodel.CurrentProjectEditorUI) ARDUINO_AVR(com.thecoderscorner.menu.editorui.generator.plugin.EmbeddedPlatform.ARDUINO_AVR) IOException(java.io.IOException) SubMenuItem(com.thecoderscorner.menu.domain.SubMenuItem) NoAuthenticatorDefinition(com.thecoderscorner.menu.editorui.generator.parameters.auth.NoAuthenticatorDefinition) Paths(java.nio.file.Paths) NoEepromDefinition(com.thecoderscorner.menu.editorui.generator.parameters.eeprom.NoEepromDefinition) CodeGeneratorOptions(com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptions) ConfigurationStorage(com.thecoderscorner.menu.editorui.storage.ConfigurationStorage) MenuTree(com.thecoderscorner.menu.domain.state.MenuTree) IoExpanderDefinitionCollection(com.thecoderscorner.menu.editorui.generator.parameters.IoExpanderDefinitionCollection) Level(java.lang.System.Logger.Level) MenuItem(com.thecoderscorner.menu.domain.MenuItem) SubMenuItem(com.thecoderscorner.menu.domain.SubMenuItem)

Example 2 with MenuItem

use of com.thecoderscorner.menu.domain.MenuItem in project tcMenu by davetcc.

the class MenuEditorTestCases method testAddingRemovingAndMovingOnOpenedProject.

@Test
public void testAddingRemovingAndMovingOnOpenedProject(FxRobot robot) throws Exception {
    openTheCompleteMenuTree(robot);
    checkTheTreeMatchesMenuTree(robot, MenuTree.ROOT);
    // smoke test of the prototype area, there is a proper test of the text rendering elsewhere
    assertTrue(((TextArea) robot.lookup("#prototypeTextArea").query()).getText().contains("FloatTest         -12345.1235"));
    // we stub out the new item dialog as it has its
    MenuItem itemToAdd = aNewMenuItem();
    Mockito.when(editorProjectUI.showNewItemDialog(project.getMenuTree())).thenReturn(Optional.ofNullable(itemToAdd));
    // now we get hold of the sub menu and the items in the submenu
    SubMenuItem subItem = project.getMenuTree().getSubMenuById(100).orElseThrow();
    MenuItem childItem = project.getMenuTree().getMenuById(2).orElseThrow();
    TreeView<MenuItem> treeView = robot.lookup("#menuTree").query();
    // change selection in the tree to the submenu and press the add item button
    assertTrue(recursiveSelectTreeItem(treeView, treeView.getRoot(), subItem));
    robot.clickOn("#menuTreeAdd");
    // make sure the item is in the tree and make sure it's been drawn properly
    assertOnItemInTree(itemToAdd, true);
    checkTheTreeMatchesMenuTree(robot, itemToAdd);
    // now we are going to move the new item up then back down. Before this we will check
    // the ordering to ensure it started off in the right order.
    assertThat(project.getMenuTree().getMenuItems(subItem)).containsExactly(childItem, itemToAdd);
    // move it up and see that the menu changes order and gets drawn properly
    robot.clickOn("#menuTreeUp");
    assertThat(project.getMenuTree().getMenuItems(subItem)).containsExactly(itemToAdd, childItem);
    checkTheTreeMatchesMenuTree(robot, itemToAdd);
    // and back again to the previous ordering.
    robot.clickOn("#menuTreeDown");
    assertThat(project.getMenuTree().getMenuItems(subItem)).containsExactly(childItem, itemToAdd);
    checkTheTreeMatchesMenuTree(robot, itemToAdd);
    // and then lastly lets get rid of the item we just added. Root should be selected afterwards.
    robot.clickOn("#menuTreeRemove");
    assertOnItemInTree(itemToAdd, false);
    checkTheTreeMatchesMenuTree(robot, MenuTree.ROOT);
    // at this point the project should be dirty
    assertTrue(project.isDirty());
    // save the project
    pushCtrlAndKey(robot, KeyCode.S);
    Mockito.verify(persistor, atLeastOnce()).save("fileName", "project desc", project.getMenuTree(), project.getGeneratorOptions());
    // now project should be clean
    assertFalse(project.isDirty());
}
Also used : UISubMenuItem(com.thecoderscorner.menu.editorui.uimodel.UISubMenuItem) MenuItem(com.thecoderscorner.menu.domain.MenuItem) UISubMenuItem(com.thecoderscorner.menu.editorui.uimodel.UISubMenuItem) Test(org.junit.jupiter.api.Test)

Example 3 with MenuItem

use of com.thecoderscorner.menu.domain.MenuItem in project tcMenu by davetcc.

the class MenuEditorTestCases method assertOnItemInTree.

/**
 * Assert if the item was (or was not) found anywhere in the tree
 * @param itemToAdd item to check
 * @param shouldBeThere if it should be expected to be there or not.
 */
private void assertOnItemInTree(MenuItem itemToAdd, boolean shouldBeThere) {
    MenuTree tree = project.getMenuTree();
    Set<MenuItem> items = tree.getAllSubMenus().stream().flatMap(sub -> tree.getMenuItems(sub).stream()).collect(Collectors.toSet());
    assertEquals(shouldBeThere, items.contains(itemToAdd));
}
Also used : MenuTree(com.thecoderscorner.menu.domain.state.MenuTree) javafx.scene.control(javafx.scene.control) LibraryStatus(com.thecoderscorner.menu.editorui.generator.util.LibraryStatus) PersistedMenu(com.thecoderscorner.menu.persist.PersistedMenu) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LibraryVersionDetector(com.thecoderscorner.menu.editorui.generator.LibraryVersionDetector) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) LabeledMatchers(org.testfx.matcher.control.LabeledMatchers) ConfigurationStorage(com.thecoderscorner.menu.editorui.storage.ConfigurationStorage) Start(org.testfx.framework.junit5.Start) MenuTree(com.thecoderscorner.menu.domain.state.MenuTree) Pane(javafx.scene.layout.Pane) CodePluginConfig(com.thecoderscorner.menu.editorui.generator.plugin.CodePluginConfig) MenuItem(com.thecoderscorner.menu.domain.MenuItem) FxAssert.verifyThat(org.testfx.api.FxAssert.verifyThat) VersionInfo(com.thecoderscorner.menu.persist.VersionInfo) Collectors(java.util.stream.Collectors) UISubMenuItem(com.thecoderscorner.menu.editorui.uimodel.UISubMenuItem) Platform(javafx.application.Platform) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) TCMENU_DIR(com.thecoderscorner.menu.editorui.generator.arduino.ArduinoDirectoryStructureHelper.DirectoryPath.TCMENU_DIR) VariableNameGenerator(com.thecoderscorner.menu.editorui.generator.core.VariableNameGenerator) InstallationType(com.thecoderscorner.menu.editorui.generator.arduino.ArduinoLibraryInstaller.InstallationType) Scene(javafx.scene.Scene) java.util(java.util) TextInputControlMatchers(org.testfx.matcher.control.TextInputControlMatchers) com.thecoderscorner.menu.editorui.project(com.thecoderscorner.menu.editorui.project) Supplier(java.util.function.Supplier) ArduinoLibraryInstaller(com.thecoderscorner.menu.editorui.generator.arduino.ArduinoLibraryInstaller) TestUtils(com.thecoderscorner.menu.editorui.util.TestUtils) ArgumentCaptor(org.mockito.ArgumentCaptor) ReleaseType(com.thecoderscorner.menu.editorui.generator.OnlineLibraryVersionDetector.ReleaseType) FXMLLoader(javafx.fxml.FXMLLoader) BiConsumer(java.util.function.BiConsumer) FxRobot(org.testfx.api.FxRobot) TestUtils.pushCtrlAndKey(com.thecoderscorner.menu.editorui.util.TestUtils.pushCtrlAndKey) SKETCHES_DIR(com.thecoderscorner.menu.editorui.generator.arduino.ArduinoDirectoryStructureHelper.DirectoryPath.SKETCHES_DIR) ApplicationExtension(org.testfx.framework.junit5.ApplicationExtension) KeyCode(javafx.scene.input.KeyCode) com.thecoderscorner.menu.domain(com.thecoderscorner.menu.domain) MenuEditorController(com.thecoderscorner.menu.editorui.controller.MenuEditorController) CurrentProjectEditorUI(com.thecoderscorner.menu.editorui.uimodel.CurrentProjectEditorUI) IOException(java.io.IOException) FxAssert(org.testfx.api.FxAssert) AppInformationPanel(com.thecoderscorner.menu.editorui.dialog.AppInformationPanel) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) AfterEach(org.junit.jupiter.api.AfterEach) ArduinoDirectoryStructureHelper(com.thecoderscorner.menu.editorui.generator.arduino.ArduinoDirectoryStructureHelper) Stage(javafx.stage.Stage) Assertions(org.junit.jupiter.api.Assertions) CodePluginManager(com.thecoderscorner.menu.editorui.generator.plugin.CodePluginManager) MenuItem(com.thecoderscorner.menu.domain.MenuItem) UISubMenuItem(com.thecoderscorner.menu.editorui.uimodel.UISubMenuItem)

Example 4 with MenuItem

use of com.thecoderscorner.menu.domain.MenuItem 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 5 with MenuItem

use of com.thecoderscorner.menu.domain.MenuItem in project tcMenu by davetcc.

the class MenuEditorTestCases method testAreaInformationPanelNeedingUpdate.

@Test
void testAreaInformationPanelNeedingUpdate(FxRobot robot) throws Exception {
    when(installer.statusOfAllLibraries()).thenReturn(new LibraryStatus(true, true, true, false));
    when(installer.getVersionOfLibrary("module.name", AVAILABLE_PLUGIN)).thenReturn(new VersionInfo("1.0.2"));
    openTheCompleteMenuTree(robot);
    SubMenuItem subItem = project.getMenuTree().getSubMenuById(100).orElseThrow();
    TreeView<MenuItem> treeView = robot.lookup("#menuTree").query();
    assertTrue(recursiveSelectTreeItem(treeView, treeView.getRoot(), subItem));
    assertTrue(recursiveSelectTreeItem(treeView, treeView.getRoot(), MenuTree.ROOT));
    Thread.sleep(500);
    verifyThat("#tcMenuStatusArea", LabeledMatchers.hasText("Libraries need updating, check in General Settings"));
}
Also used : LibraryStatus(com.thecoderscorner.menu.editorui.generator.util.LibraryStatus) VersionInfo(com.thecoderscorner.menu.persist.VersionInfo) UISubMenuItem(com.thecoderscorner.menu.editorui.uimodel.UISubMenuItem) MenuItem(com.thecoderscorner.menu.domain.MenuItem) UISubMenuItem(com.thecoderscorner.menu.editorui.uimodel.UISubMenuItem) Test(org.junit.jupiter.api.Test)

Aggregations

MenuItem (com.thecoderscorner.menu.domain.MenuItem)34 Test (org.junit.jupiter.api.Test)22 VariableNameGenerator (com.thecoderscorner.menu.editorui.generator.core.VariableNameGenerator)15 UISubMenuItem (com.thecoderscorner.menu.editorui.uimodel.UISubMenuItem)12 UIMenuItem (com.thecoderscorner.menu.editorui.uimodel.UIMenuItem)10 ActionMenuItem (com.thecoderscorner.menu.domain.ActionMenuItem)7 SubMenuItem (com.thecoderscorner.menu.domain.SubMenuItem)6 LibraryStatus (com.thecoderscorner.menu.editorui.generator.util.LibraryStatus)5 MenuTree (com.thecoderscorner.menu.domain.state.MenuTree)4 BiConsumer (java.util.function.BiConsumer)4 CustomBuilderMenuItem (com.thecoderscorner.menu.domain.CustomBuilderMenuItem)3 FloatMenuItem (com.thecoderscorner.menu.domain.FloatMenuItem)3 Rgb32MenuItem (com.thecoderscorner.menu.domain.Rgb32MenuItem)3 ConfigurationStorage (com.thecoderscorner.menu.editorui.storage.ConfigurationStorage)3 CurrentProjectEditorUI (com.thecoderscorner.menu.editorui.uimodel.CurrentProjectEditorUI)3 PersistedMenu (com.thecoderscorner.menu.persist.PersistedMenu)3 VersionInfo (com.thecoderscorner.menu.persist.VersionInfo)3 IOException (java.io.IOException)3 java.util (java.util)3 CountDownLatch (java.util.concurrent.CountDownLatch)3