Wizard: do not show drop down component if it has <= 1 possible values

This commit is contained in:
Ilya Kirillov
2020-03-20 12:51:08 +03:00
parent 1cc86b9c89
commit 67034546ae
2 changed files with 6 additions and 5 deletions
@@ -19,7 +19,7 @@ class DropDownComponent<T : DisplayableSettingItem>(
initialValues: List<T> = emptyList(), initialValues: List<T> = emptyList(),
initiallySelectedValue: T? = null, initiallySelectedValue: T? = null,
labelText: String? = null, labelText: String? = null,
private val filter: (T) -> Boolean = { true }, filter: (T) -> Boolean = { true },
private val validator: SettingValidator<T> = settingValidator { ValidationResult.OK }, private val validator: SettingValidator<T> = settingValidator { ValidationResult.OK },
private val iconProvider: (T) -> Icon? = { null }, private val iconProvider: (T) -> Icon? = { null },
onValueUpdate: (T) -> Unit = {} onValueUpdate: (T) -> Unit = {}
@@ -68,10 +68,8 @@ class DropDownComponent<T : DisplayableSettingItem>(
} }
} }
fun setValues(newValues: List<T>) { val valuesCount
@Suppress("UNCHECKED_CAST") get() = uiComponent.model.size
uiComponent.model = DefaultComboBoxModel(newValues.filter(filter).toTypedArray<DisplayableSettingItem>() as Array<T>)
}
override fun updateUiValue(newValue: T) = safeUpdateUi { override fun updateUiValue(newValue: T) = safeUpdateUi {
uiComponent.selectedItem = newValue uiComponent.selectedItem = newValue
@@ -118,6 +118,9 @@ class DropdownSettingComponent(
labelText = setting.title.takeIf { needLabel }, labelText = setting.title.takeIf { needLabel },
onValueUpdate = { newValue -> value = newValue } onValueUpdate = { newValue -> value = newValue }
).asSubComponent() ).asSubComponent()
override fun shouldBeShow(): Boolean =
uiComponent.valuesCount > 1
} }
class BooleanSettingComponent( class BooleanSettingComponent(