User: kyle wood Date: 19 Jan 26 00:28 Revision: 0ff5c52310324fc559b905ba52aa1496a557ca77 Summary: Add visibility support for property groups TeamCity URL: http://ci.mcdev.io:80/viewModification.html?tab=vcsModificationFiles&modId=10398&personal=false Index: src/main/kotlin/creator/custom/CreatorTemplateProcessor.kt =================================================================== --- src/main/kotlin/creator/custom/CreatorTemplateProcessor.kt (revision ca8e1bd4a9e7e3e4cf27d54ea5d3e4642d24217e) +++ src/main/kotlin/creator/custom/CreatorTemplateProcessor.kt (revision 0ff5c52310324fc559b905ba52aa1496a557ca77) @@ -176,7 +176,7 @@ val factory = Consumer { panel -> val label = descriptor.translatedLabel - if (descriptor.collapsible == false) { + val group = if (descriptor.collapsible == false) { panel.group(label) { for (childFactory in childrenUiFactories) { childFactory.accept(this@group) @@ -190,7 +190,11 @@ } group.expanded = descriptor.default as? Boolean ?: false + group } + + val isVisible = CreatorProperty.setupVisibleProperty(context.graph, context.properties, reporter, descriptor.visible) + group.visibleIf(isVisible) } val order = descriptor.order ?: 0 @@ -202,9 +206,7 @@ } val prop = CreatorPropertyFactory.createFromType(descriptor.type, descriptor, context) - if (prop == null) { - reporter.fatal("Unknown template property type ${descriptor.type}") - } + ?: reporter.fatal("Unknown template property type ${descriptor.type}") prop.setupProperty(reporter) Index: src/main/kotlin/creator/custom/types/CreatorProperty.kt =================================================================== --- src/main/kotlin/creator/custom/types/CreatorProperty.kt (revision ca8e1bd4a9e7e3e4cf27d54ea5d3e4642d24217e) +++ src/main/kotlin/creator/custom/types/CreatorProperty.kt (revision 0ff5c52310324fc559b905ba52aa1496a557ca77) @@ -227,75 +227,86 @@ protected fun Row.propertyVisibility(): Row = this.visibleIf(visibleProperty) - private fun setupVisibleProperty( + fun setupVisibleProperty( reporter: TemplateValidationReporter, visibility: Any? ): GraphProperty { + return setupVisibleProperty(graph, properties, reporter, visibility) + } + + companion object { + fun setupVisibleProperty( + graph: PropertyGraph, + properties: Map>, + reporter: TemplateValidationReporter, + visibility: Any? + ): GraphProperty { - val prop = graph.property(true) - if (visibility == null || visibility is Boolean) { - prop.set(visibility != false) - return prop - } + val prop = graph.property(true) + if (visibility == null || visibility is Boolean) { + prop.set(visibility != false) + return prop + } - if (visibility !is Map<*, *>) { - reporter.error("Visibility can only be a boolean or an object") - return prop - } + if (visibility !is Map<*, *>) { + reporter.error("Visibility can only be a boolean or an object") + return prop + } - var dependsOn = visibility["dependsOn"] + val dependsOn = visibility["dependsOn"] - if (dependsOn !is String && (dependsOn !is List<*> || dependsOn.any { it !is String })) { - reporter.error( - "Expected 'visible' to have a 'dependsOn' value that is either a string or a list of strings" - ) - return prop - } + if (dependsOn !is String && (dependsOn !is List<*> || dependsOn.any { it !is String })) { + reporter.error( + "Expected 'visible' to have a 'dependsOn' value that is either a string or a list of strings" + ) + return prop + } - val dependenciesNames = when (dependsOn) { - is String -> setOf(dependsOn) - is Collection<*> -> dependsOn.filterIsInstance().toSet() - else -> throw IllegalStateException("Should not be reached") - } - val dependencies = dependenciesNames.mapNotNull { + val dependenciesNames = when (dependsOn) { + is String -> setOf(dependsOn) + is Collection<*> -> dependsOn.filterIsInstance().toSet() + else -> throw IllegalStateException("Should not be reached") + } + val dependencies = dependenciesNames.mapNotNull { - val dependency = this.properties[it] + val dependency = properties[it] - if (dependency == null) { - reporter.error("Visibility dependency '$it' does not exist") - } - dependency - } - if (dependencies.size != dependenciesNames.size) { - // Errors have already been reported - return prop - } + if (dependency == null) { + reporter.error("Visibility dependency '$it' does not exist") + } + dependency + } + if (dependencies.size != dependenciesNames.size) { + // Errors have already been reported + return prop + } - val condition = visibility["condition"] - if (condition !is String) { - reporter.error("Expected 'visible' to have a 'condition' string") - return prop - } + val condition = visibility["condition"] + if (condition !is String) { + reporter.error("Expected 'visible' to have a 'condition' string") + return prop + } - var didInitialUpdate = false - val update: () -> Boolean = { - val conditionProperties = dependencies.associate { prop -> prop.descriptor.name to prop.get() } - val result = TemplateEvaluator.condition(conditionProperties, condition) - val exception = result.exceptionOrNull() - if (exception != null) { - if (!didInitialUpdate) { - didInitialUpdate = true - reporter.error("Failed to compute initial visibility: ${exception.message}") - thisLogger().info("Failed to compute initial visibility: ${exception.message}", exception) - } else { - thisLogger().error("Failed to compute initial visibility: ${exception.message}", exception) - } - } + var didInitialUpdate = false + val update: () -> Boolean = { + val conditionProperties = dependencies.associate { prop -> prop.descriptor.name to prop.get() } + val result = TemplateEvaluator.condition(conditionProperties, condition) + val exception = result.exceptionOrNull() + if (exception != null) { + if (!didInitialUpdate) { + didInitialUpdate = true + reporter.error("Failed to compute initial visibility: ${exception.message}") + thisLogger().info("Failed to compute initial visibility: ${exception.message}", exception) + } else { + thisLogger().error("Failed to compute initial visibility: ${exception.message}", exception) + } + } - result.getOrDefault(true) - } + result.getOrDefault(true) + } - prop.set(update()) - for (dependency in dependencies) { - prop.dependsOn(dependency.graphProperty, deleteWhenModified = false, update) - } + prop.set(update()) + for (dependency in dependencies) { + prop.dependsOn(dependency.graphProperty, deleteWhenModified = false, update) + } - return prop - } -} + return prop + } + } +}