Search in sources :

Example 1 with CodeGeneratorOptions

use of com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptions in project tcMenu by davetcc.

the class GenerateCodeDialog method showCodeGenerator.

public void showCodeGenerator(Stage stage, boolean modal) {
    this.mainStage = stage;
    BorderPane pane = new BorderPane();
    pane.getStyleClass().add("background");
    placeDirectoryAndEmbeddedPanels(pane);
    centerPane = new VBox(5);
    addTitleLabel(centerPane, "Select the input type:");
    CodeGeneratorOptions genOptions = project.getGeneratorOptions();
    var allItems = project.getMenuTree().getAllMenuItems();
    reloadAllPlugins(platforms.getEmbeddedPlatformFromId(genOptions.getEmbeddedPlatform()));
    CodePluginItem itemInput = findItemByUuidOrDefault(inputsSupported, genOptions.getLastInputUuid(), Optional.empty());
    CodePluginItem itemDisplay = findItemByUuidOrDefault(displaysSupported, genOptions.getLastDisplayUuid(), Optional.empty());
    CodePluginItem itemTheme = findItemByUuidOrDefault(themesSupported, genOptions.getLastThemeUuid(), Optional.of(DEFAULT_THEME_ID));
    initialPlugins.addAll(List.of(itemInput.getId(), itemDisplay.getId(), itemTheme.getId()));
    setAllPropertiesToLastValues(itemInput);
    setAllPropertiesToLastValues(itemDisplay);
    setAllPropertiesToLastValues(itemTheme);
    currentInput = new UICodePluginItem(manager, itemInput, CHANGE, this::onInputChange, editorUI, allItems, 0, "inputPlugin");
    currentInput.getStyleClass().add("uiCodeGen");
    centerPane.getChildren().add(currentInput);
    addTitleLabel(centerPane, "Select the display type:");
    currentDisplay = new UICodePluginItem(manager, itemDisplay, CHANGE, this::onDisplayChange, editorUI, allItems, 0, "displayPlugin");
    currentDisplay.getStyleClass().add("uiCodeGen");
    centerPane.getChildren().add(currentDisplay);
    if (itemTheme != null) {
        themeTitle = addTitleLabel(centerPane, "Select a theme:");
        currentTheme = new UICodePluginItem(manager, itemTheme, CHANGE, this::onThemeChange, editorUI, allItems, 0, "themePlugin");
        currentTheme.setId("currentThemeUI");
        currentTheme.getStyleClass().add("uiCodeGen");
        if (!currentDisplay.getItem().isThemeNeeded()) {
            currentTheme.setVisible(false);
            currentTheme.setManaged(false);
            themeTitle.setVisible(false);
            themeTitle.setManaged(false);
        }
        centerPane.getChildren().add(currentTheme);
    } else
        currentTheme = null;
    BorderPane remoteLabelPane = new BorderPane();
    Label titleLbl = new Label("Select IoT/remote capabilities:");
    titleLbl.setStyle("-fx-font-size: 16px; -fx-opacity: 0.6; -fx-font-weight: bold;");
    remoteLabelPane.setLeft(titleLbl);
    Button addRemoteCapabilityButton = new Button("Add another IoT/remote");
    remoteLabelPane.setRight(addRemoteCapabilityButton);
    addRemoteCapabilityButton.setOnAction(this::produceAnotherRemoteCapability);
    centerPane.getChildren().add(remoteLabelPane);
    List<String> remoteIds = genOptions.getLastRemoteCapabilitiesUuids();
    if (remoteIds != null && !remoteIds.isEmpty()) {
        int count = 0;
        for (var remoteId : remoteIds) {
            CodePluginItem itemRemote = findItemByUuidOrDefault(remotesSupported, remoteId, Optional.of(CoreCodeGenerator.NO_REMOTE_ID));
            initialPlugins.add(itemRemote.getId());
            setAllPropertiesToLastValues(itemRemote);
            String pluginId = "remotePlugin" + count;
            var currentRemote = new UICodePluginItem(manager, itemRemote, CHANGE, this::onRemoteChange, editorUI, allItems, count, pluginId);
            currentRemote.getStyleClass().add("uiCodeGen");
            centerPane.getChildren().add(currentRemote);
            count++;
            currentRemotes.add(currentRemote);
        }
    } else {
        // did not exist before this, must be first run.
        CodePluginItem itemRemote = findItemByUuidOrDefault(remotesSupported, "", Optional.empty());
        String pluginId = "remotePlugin0";
        var currentRemote = new UICodePluginItem(manager, itemRemote, CHANGE, this::onRemoteChange, editorUI, allItems, 0, pluginId);
        currentRemote.getStyleClass().add("uiCodeGen");
        centerPane.getChildren().add(currentRemote);
    }
    filterChoicesByPlatform(platformCombo.getValue());
    ButtonBar buttonBar = new ButtonBar();
    Button generateButton = new Button("Generate Code");
    generateButton.setDefaultButton(true);
    generateButton.setOnAction(this::onGenerateCode);
    generateButton.setId("generateButton");
    Button cancelButton = new Button("Cancel");
    cancelButton.setCancelButton(true);
    cancelButton.setOnAction(this::onCancel);
    buttonBar.getButtons().addAll(cancelButton, generateButton);
    ScrollPane scrollPane = new ScrollPane(centerPane);
    scrollPane.setFitToWidth(true);
    scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
    scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);
    pane.setCenter(scrollPane);
    pane.setOpaqueInsets(new Insets(5));
    pane.setBottom(buttonBar);
    pane.setPrefSize(800, 750);
    BorderPane.setMargin(buttonBar, new Insets(5));
    BorderPane.setMargin(pane.getTop(), new Insets(5));
    var title = "Code Generator:" + project.getFileName();
    createDialogStateAndShow(stage, pane, title, modal);
}
Also used : CodeGeneratorOptions(com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptions) Insets(javafx.geometry.Insets) CodePluginItem(com.thecoderscorner.menu.editorui.generator.plugin.CodePluginItem)

Example 2 with CodeGeneratorOptions

use of com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptions in project tcMenu by davetcc.

the class CodeParameterTest method InitTest.

@BeforeEach
public void InitTest() {
    CodeGeneratorOptions opts = mock(CodeGeneratorOptions.class);
    when(opts.getApplicationName()).thenReturn("MyAppName");
    when(opts.getApplicationUUID()).thenReturn(APPUUID);
    when(opts.getPackageNamespace()).thenReturn("my.namespace");
    context = new CodeConversionContext(EmbeddedPlatform.ARDUINO_AVR, "volumeMenuItem", opts, props);
}
Also used : CodeConversionContext(com.thecoderscorner.menu.editorui.generator.core.CodeConversionContext) CodeGeneratorOptions(com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptions) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with CodeGeneratorOptions

use of com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptions in project tcMenu by davetcc.

the class PluginEmbeddedPlatformsImplTest method testEmbeddedPlatforms.

@Test
void testEmbeddedPlatforms() {
    PluginEmbeddedPlatformsImpl platforms = new PluginEmbeddedPlatformsImpl();
    platforms.setInstallerConfiguration(mock(ArduinoLibraryInstaller.class), mock(ConfigurationStorage.class));
    assertThat(platforms.getEmbeddedPlatforms()).containsExactly(ARDUINO_AVR, ARDUINO32, ARDUINO_ESP8266, ARDUINO_ESP32, STM32DUINO, RASPBERRY_PIJ, MBED_RTOS);
    assertEquals(ARDUINO_AVR, platforms.getEmbeddedPlatformFromId(ARDUINO_AVR.getBoardId()));
    assertEquals(ARDUINO32, platforms.getEmbeddedPlatformFromId(ARDUINO32.getBoardId()));
    assertEquals(ARDUINO_ESP8266, platforms.getEmbeddedPlatformFromId(ARDUINO_ESP8266.getBoardId()));
    assertEquals(ARDUINO_ESP32, platforms.getEmbeddedPlatformFromId(ARDUINO_ESP32.getBoardId()));
    assertEquals(MBED_RTOS, platforms.getEmbeddedPlatformFromId(MBED_RTOS.getBoardId()));
    assertEquals(STM32DUINO, platforms.getEmbeddedPlatformFromId(STM32DUINO.getBoardId()));
    assertEquals(RASPBERRY_PIJ, platforms.getEmbeddedPlatformFromId(RASPBERRY_PIJ.getBoardId()));
    assertThrows(IllegalArgumentException.class, () -> platforms.getEmbeddedPlatformFromId("invalidId"));
    assertTrue(ARDUINO_AVR.isUsesProgmem());
    assertFalse(ARDUINO32.isUsesProgmem());
    assertTrue(ARDUINO_ESP32.isUsesProgmem());
    assertTrue(ARDUINO_ESP8266.isUsesProgmem());
    assertFalse(STM32DUINO.isUsesProgmem());
    assertFalse(MBED_RTOS.isUsesProgmem());
    assertFalse(RASPBERRY_PIJ.isUsesProgmem());
    assertTrue(platforms.isJava(RASPBERRY_PIJ));
    assertFalse(platforms.isJava(ARDUINO_ESP32));
    assertTrue(platforms.isArduino(ARDUINO_ESP32));
    assertTrue(platforms.isArduino(ARDUINO_ESP8266));
    assertTrue(platforms.isArduino(STM32DUINO));
    assertTrue(platforms.isArduino(ARDUINO_AVR));
    assertFalse(platforms.isArduino(MBED_RTOS));
    assertTrue(platforms.isMbed(MBED_RTOS));
    CodeGeneratorOptions standardOptions = new CodeGeneratorOptions();
    var generator = platforms.getCodeGeneratorFor(ARDUINO_AVR, standardOptions);
    assertThat(generator).isOfAnyClassIn(ArduinoGenerator.class);
    assertThrows(IllegalArgumentException.class, () -> {
        EmbeddedPlatform invalidPlatform = new EmbeddedPlatform("", "Invalid", false);
        platforms.getCodeGeneratorFor(invalidPlatform, standardOptions);
    });
}
Also used : EmbeddedPlatform(com.thecoderscorner.menu.editorui.generator.plugin.EmbeddedPlatform) CodeGeneratorOptions(com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptions) ConfigurationStorage(com.thecoderscorner.menu.editorui.storage.ConfigurationStorage) ArduinoLibraryInstaller(com.thecoderscorner.menu.editorui.generator.arduino.ArduinoLibraryInstaller) Test(org.junit.jupiter.api.Test)

Example 4 with CodeGeneratorOptions

use of com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptions in project tcMenu by davetcc.

the class ArduinoSketchFileAdjusterTest method setUp.

@SuppressWarnings("unchecked")
@BeforeEach
public void setUp() throws Exception {
    dir = Files.createTempDirectory("tcmenu");
    tree = TestUtils.buildCompleteTree();
    inoFile = dir.resolve("superProject.ino");
    emptyLogger = Mockito.mock(BiConsumer.class);
    adjuster = new ArduinoSketchFileAdjuster(new CodeGeneratorOptions());
    MenuItem itemId6 = tree.getMenuById(6).orElseThrow();
    MenuItem itemId8 = tree.getMenuById(8).orElseThrow();
    MenuItem itemId9 = tree.getMenuById(9).orElseThrow();
    MenuItem itemId10 = tree.getMenuById(10).orElseThrow();
    VariableNameGenerator generator = Mockito.mock(VariableNameGenerator.class);
    when(generator.makeRtFunctionName(any())).thenReturn("fnListRtCall");
    when(generator.makeNameToVar(itemId8)).thenReturn("ActionTest");
    when(generator.makeNameToVar(itemId9)).thenReturn("SubnetMask");
    when(generator.makeNameToVar(itemId10)).thenReturn("List");
    callbacks = List.of(new CallbackRequirement(generator, "callback", itemId8), new CallbackRequirement(generator, "fnListRtCall", itemId10), new CallbackRequirement(generator, "onIpChange", itemId9), new CallbackRequirement(generator, "@includeOnly", itemId6));
}
Also used : CodeGeneratorOptions(com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptions) MenuItem(com.thecoderscorner.menu.domain.MenuItem) VariableNameGenerator(com.thecoderscorner.menu.editorui.generator.core.VariableNameGenerator) BiConsumer(java.util.function.BiConsumer) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

CodeGeneratorOptions (com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptions)4 BeforeEach (org.junit.jupiter.api.BeforeEach)2 MenuItem (com.thecoderscorner.menu.domain.MenuItem)1 ArduinoLibraryInstaller (com.thecoderscorner.menu.editorui.generator.arduino.ArduinoLibraryInstaller)1 CodeConversionContext (com.thecoderscorner.menu.editorui.generator.core.CodeConversionContext)1 VariableNameGenerator (com.thecoderscorner.menu.editorui.generator.core.VariableNameGenerator)1 CodePluginItem (com.thecoderscorner.menu.editorui.generator.plugin.CodePluginItem)1 EmbeddedPlatform (com.thecoderscorner.menu.editorui.generator.plugin.EmbeddedPlatform)1 ConfigurationStorage (com.thecoderscorner.menu.editorui.storage.ConfigurationStorage)1 BiConsumer (java.util.function.BiConsumer)1 Insets (javafx.geometry.Insets)1 Test (org.junit.jupiter.api.Test)1