Search in sources :

Example 1 with IoExpanderPropertyValidationRules

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

the class GenerateCodeDialog method ensureIoFullyDeclared.

private void ensureIoFullyDeclared(CodePluginItem pluginItem) {
    logger.log(INFO, "Checking for unmapped IO devices: " + pluginItem.getDescription());
    var codeOptions = project.getGeneratorOptions();
    // find any IO device declarations that do not match to an entry in the expanders
    var anyIoWithoutEntries = pluginItem.getProperties().stream().filter(prop -> prop.getValidationRules() instanceof IoExpanderPropertyValidationRules).filter(prop -> codeOptions.getExpanderDefinitions().getDefinitionById(prop.getLatestValue()).isEmpty()).toList();
    // nothing to do if list is empty
    if (anyIoWithoutEntries.isEmpty()) {
        logger.log(INFO, "All IO devices mapped");
        return;
    }
    var allExpanders = new HashSet<>(codeOptions.getExpanderDefinitions().getAllExpanders());
    // now we iterate through the unmapped expanders, which must be from prior to the automated support.
    for (var customIo : anyIoWithoutEntries) {
        if (StringHelper.isStringEmptyOrNull(customIo.getLatestValue())) {
            // for empty strings, the previous assumption was using device IO. This is now explicitly defined
            // as deviceIO
            customIo.setLatestValue(InternalDeviceExpander.DEVICE_ID);
            logger.log(INFO, "Device being mapped as internal: " + customIo.getLatestValue());
        } else {
            // otherwise, previously the assumption was using a custom defined expander in the sketch, now we'll
            // actually add that to the sketch.
            allExpanders.add(new CustomDeviceExpander(customIo.getLatestValue()));
            logger.log(INFO, "Device being mapped as custom: " + customIo.getLatestValue());
        }
    }
    project.setGeneratorOptions(new CodeGeneratorOptionsBuilder().withExisting(codeOptions).withExpanderDefinitions(new IoExpanderDefinitionCollection(allExpanders)).codeOptions());
    logger.log(INFO, "Done mapping all IO devices");
}
Also used : EmbeddedPlatforms(com.thecoderscorner.menu.editorui.generator.plugin.EmbeddedPlatforms) HPos(javafx.geometry.HPos) javafx.scene.layout(javafx.scene.layout) javafx.scene.control(javafx.scene.control) BaseDialogSupport(com.thecoderscorner.menu.editorui.dialog.BaseDialogSupport) CreatorProperty(com.thecoderscorner.menu.editorui.generator.core.CreatorProperty) CHANGE(com.thecoderscorner.menu.editorui.generator.ui.UICodePluginItem.UICodeAction.CHANGE) IoExpanderPropertyValidationRules(com.thecoderscorner.menu.editorui.generator.validation.IoExpanderPropertyValidationRules) FXCollections.observableArrayList(javafx.collections.FXCollections.observableArrayList) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Insets(javafx.geometry.Insets) SelectAuthenticatorTypeDialog(com.thecoderscorner.menu.editorui.dialog.SelectAuthenticatorTypeDialog) BiConsumer(java.util.function.BiConsumer) SELECT(com.thecoderscorner.menu.editorui.generator.ui.UICodePluginItem.UICodeAction.SELECT) CustomDeviceExpander(com.thecoderscorner.menu.editorui.generator.parameters.expander.CustomDeviceExpander) IoExpanderDefinitionCollection(com.thecoderscorner.menu.editorui.generator.parameters.IoExpanderDefinitionCollection) StringHelper(com.thecoderscorner.menu.editorui.util.StringHelper) CodeGeneratorOptionsBuilder(com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptionsBuilder) SelectEepromTypeDialog(com.thecoderscorner.menu.editorui.dialog.SelectEepromTypeDialog) InternalDeviceExpander(com.thecoderscorner.menu.editorui.generator.parameters.expander.InternalDeviceExpander) CurrentProjectEditorUI(com.thecoderscorner.menu.editorui.uimodel.CurrentProjectEditorUI) SubSystem(com.thecoderscorner.menu.editorui.generator.core.SubSystem) INFO(java.lang.System.Logger.Level.INFO) CoreCodeGenerator(com.thecoderscorner.menu.editorui.generator.core.CoreCodeGenerator) EmbeddedPlatform(com.thecoderscorner.menu.editorui.generator.plugin.EmbeddedPlatform) CurrentEditorProject(com.thecoderscorner.menu.editorui.project.CurrentEditorProject) Collectors(java.util.stream.Collectors) BaseDialogSupport.createDialogStateAndShow(com.thecoderscorner.menu.editorui.dialog.BaseDialogSupport.createDialogStateAndShow) Popup(javafx.stage.Popup) ERROR(java.lang.System.Logger.Level.ERROR) ActionEvent(javafx.event.ActionEvent) List(java.util.List) CodePluginItem(com.thecoderscorner.menu.editorui.generator.plugin.CodePluginItem) Stage(javafx.stage.Stage) Paths(java.nio.file.Paths) CodeGeneratorOptions(com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptions) Optional(java.util.Optional) CodePluginManager(com.thecoderscorner.menu.editorui.generator.plugin.CodePluginManager) CustomDeviceExpander(com.thecoderscorner.menu.editorui.generator.parameters.expander.CustomDeviceExpander) IoExpanderPropertyValidationRules(com.thecoderscorner.menu.editorui.generator.validation.IoExpanderPropertyValidationRules) IoExpanderDefinitionCollection(com.thecoderscorner.menu.editorui.generator.parameters.IoExpanderDefinitionCollection) HashSet(java.util.HashSet) CodeGeneratorOptionsBuilder(com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptionsBuilder)

Aggregations

BaseDialogSupport (com.thecoderscorner.menu.editorui.dialog.BaseDialogSupport)1 BaseDialogSupport.createDialogStateAndShow (com.thecoderscorner.menu.editorui.dialog.BaseDialogSupport.createDialogStateAndShow)1 SelectAuthenticatorTypeDialog (com.thecoderscorner.menu.editorui.dialog.SelectAuthenticatorTypeDialog)1 SelectEepromTypeDialog (com.thecoderscorner.menu.editorui.dialog.SelectEepromTypeDialog)1 CodeGeneratorOptions (com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptions)1 CodeGeneratorOptionsBuilder (com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptionsBuilder)1 CoreCodeGenerator (com.thecoderscorner.menu.editorui.generator.core.CoreCodeGenerator)1 CreatorProperty (com.thecoderscorner.menu.editorui.generator.core.CreatorProperty)1 SubSystem (com.thecoderscorner.menu.editorui.generator.core.SubSystem)1 IoExpanderDefinitionCollection (com.thecoderscorner.menu.editorui.generator.parameters.IoExpanderDefinitionCollection)1 CustomDeviceExpander (com.thecoderscorner.menu.editorui.generator.parameters.expander.CustomDeviceExpander)1 InternalDeviceExpander (com.thecoderscorner.menu.editorui.generator.parameters.expander.InternalDeviceExpander)1 CodePluginItem (com.thecoderscorner.menu.editorui.generator.plugin.CodePluginItem)1 CodePluginManager (com.thecoderscorner.menu.editorui.generator.plugin.CodePluginManager)1 EmbeddedPlatform (com.thecoderscorner.menu.editorui.generator.plugin.EmbeddedPlatform)1 EmbeddedPlatforms (com.thecoderscorner.menu.editorui.generator.plugin.EmbeddedPlatforms)1 CHANGE (com.thecoderscorner.menu.editorui.generator.ui.UICodePluginItem.UICodeAction.CHANGE)1 SELECT (com.thecoderscorner.menu.editorui.generator.ui.UICodePluginItem.UICodeAction.SELECT)1 IoExpanderPropertyValidationRules (com.thecoderscorner.menu.editorui.generator.validation.IoExpanderPropertyValidationRules)1 CurrentEditorProject (com.thecoderscorner.menu.editorui.project.CurrentEditorProject)1