Search in sources :

Example 1 with EnumMenuItem

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

the class MenuIdChooserImplTest method testIdEepromGenerationOnEmptyTree.

@Test
public void testIdEepromGenerationOnEmptyTree() {
    MenuTree menuTree = new MenuTree();
    chooser = new MenuIdChooserImpl(menuTree);
    assertEquals(1, chooser.nextHighestId());
    assertEquals(2, chooser.nextHighestEeprom());
    EnumMenuItem item = EnumMenuItemBuilder.anEnumMenuItemBuilder().withId(1).withEepromAddr(-1).withName("Test").withEnumList(Collections.emptyList()).menuItem();
    menuTree.addMenuItem(MenuTree.ROOT, item);
    assertEquals(2, chooser.nextHighestEeprom());
}
Also used : MenuTree(com.thecoderscorner.menu.domain.state.MenuTree) EnumMenuItem(com.thecoderscorner.menu.domain.EnumMenuItem) Test(org.junit.jupiter.api.Test)

Example 2 with EnumMenuItem

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

the class UIEnumMenuItemTest method checkThatConsumerCalledWith.

private void checkThatConsumerCalledWith(String... expected) {
    ArgumentCaptor<MenuItem> captor = ArgumentCaptor.forClass(MenuItem.class);
    verify(mockedConsumer, atLeastOnce()).accept(any(), captor.capture());
    EnumMenuItem item = (EnumMenuItem) captor.getValue();
    assertThat(item.getEnumEntries()).containsExactly(expected);
}
Also used : EnumMenuItem(com.thecoderscorner.menu.domain.EnumMenuItem) MenuItem(com.thecoderscorner.menu.domain.MenuItem) EnumMenuItem(com.thecoderscorner.menu.domain.EnumMenuItem) UIMenuItem(com.thecoderscorner.menu.editorui.uimodel.UIMenuItem)

Example 3 with EnumMenuItem

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

the class UIEnumMenuItem method getChangedMenuItem.

@Override
protected Optional<EnumMenuItem> getChangedMenuItem() {
    List<FieldError> errors = new ArrayList<>();
    ObservableList<String> items = listView.getItems();
    if (items.isEmpty()) {
        errors.add(new FieldError("There must be at least one choice", "Choices"));
    } else if (items.stream().anyMatch(str -> str.isEmpty() || str.matches(".*[\"\\\\].*$"))) {
        errors.add(new FieldError("Choices must not contain speech marks or backslash", "Choices"));
    }
    EnumMenuItemBuilder builder = EnumMenuItemBuilder.anEnumMenuItemBuilder().withExisting(getMenuItem()).withEnumList(items);
    getChangedDefaults(builder, errors);
    return getItemOrReportError(builder.menuItem(), errors);
}
Also used : Button(javafx.scene.control.Button) HBox(javafx.scene.layout.HBox) Label(javafx.scene.control.Label) ListView(javafx.scene.control.ListView) TextFieldListCell(javafx.scene.control.cell.TextFieldListCell) MenuItem(com.thecoderscorner.menu.domain.MenuItem) EnumMenuItem(com.thecoderscorner.menu.domain.EnumMenuItem) FXCollections(javafx.collections.FXCollections) MenuIdChooser(com.thecoderscorner.menu.editorui.project.MenuIdChooser) ArrayList(java.util.ArrayList) List(java.util.List) ListChangeListener(javafx.collections.ListChangeListener) EnumMenuItemBuilder(com.thecoderscorner.menu.domain.EnumMenuItemBuilder) BiConsumer(java.util.function.BiConsumer) Optional(java.util.Optional) ObservableList(javafx.collections.ObservableList) VariableNameGenerator(com.thecoderscorner.menu.editorui.generator.core.VariableNameGenerator) GridPane(javafx.scene.layout.GridPane) ArrayList(java.util.ArrayList) EnumMenuItemBuilder(com.thecoderscorner.menu.domain.EnumMenuItemBuilder)

Aggregations

EnumMenuItem (com.thecoderscorner.menu.domain.EnumMenuItem)3 MenuItem (com.thecoderscorner.menu.domain.MenuItem)2 EnumMenuItemBuilder (com.thecoderscorner.menu.domain.EnumMenuItemBuilder)1 MenuTree (com.thecoderscorner.menu.domain.state.MenuTree)1 VariableNameGenerator (com.thecoderscorner.menu.editorui.generator.core.VariableNameGenerator)1 MenuIdChooser (com.thecoderscorner.menu.editorui.project.MenuIdChooser)1 UIMenuItem (com.thecoderscorner.menu.editorui.uimodel.UIMenuItem)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 BiConsumer (java.util.function.BiConsumer)1 FXCollections (javafx.collections.FXCollections)1 ListChangeListener (javafx.collections.ListChangeListener)1 ObservableList (javafx.collections.ObservableList)1 Button (javafx.scene.control.Button)1 Label (javafx.scene.control.Label)1 ListView (javafx.scene.control.ListView)1 TextFieldListCell (javafx.scene.control.cell.TextFieldListCell)1 GridPane (javafx.scene.layout.GridPane)1 HBox (javafx.scene.layout.HBox)1