feat(converter): 实现通用枚举转换器和供应商类型转换器
添加EnumEntityStringConverter作为通用枚举转换基类 实现VendorTypeStringConverter用于供应商类型本地化转换 在VendorTypeService中添加findByLocaleAndValue方法支持转换器 优化ComboBoxUtils的绑定逻辑使其支持可选属性 新增VendorCatalogService提供供应商目录CRUD功能
This commit is contained in:
@@ -124,29 +124,34 @@ public class ComboBoxUtils {
|
||||
}
|
||||
list.addAll(queryService.findAll());
|
||||
comboBox.setItems(list);
|
||||
// 从ComboBox选择到property的单向绑定
|
||||
comboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
|
||||
property.setValue(newValue != null ? newValue.getId() : null);
|
||||
});
|
||||
// 从property到ComboBox的单向绑定
|
||||
property.addListener((observable, oldValue, newValue) -> {
|
||||
if (newValue == null) {
|
||||
comboBox.getSelectionModel().clearSelection();
|
||||
return;
|
||||
}
|
||||
list.stream()
|
||||
.filter(item -> item != null && newValue.equals(item.getId()))
|
||||
.findFirst()
|
||||
.ifPresent(comboBox.getSelectionModel()::select);
|
||||
});
|
||||
|
||||
EntityStringConverter<T> converter = new EntityStringConverter<>(list);
|
||||
comboBox.setConverter(converter);
|
||||
// 初始化ComboBox的值
|
||||
if (property.getValue() != null) {
|
||||
list.stream()
|
||||
.filter(item -> item != null && property.getValue().equals(item.getId()))
|
||||
.findFirst()
|
||||
.ifPresent(comboBox.getSelectionModel()::select);
|
||||
|
||||
if (property != null) {
|
||||
// 从ComboBox选择到property的单向绑定
|
||||
comboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
|
||||
property.setValue(newValue != null ? newValue.getId() : null);
|
||||
});
|
||||
// 从property到ComboBox的单向绑定
|
||||
property.addListener((observable, oldValue, newValue) -> {
|
||||
if (newValue == null) {
|
||||
comboBox.getSelectionModel().clearSelection();
|
||||
return;
|
||||
}
|
||||
list.stream()
|
||||
.filter(item -> item != null && newValue.equals(item.getId()))
|
||||
.findFirst()
|
||||
.ifPresent(comboBox.getSelectionModel()::select);
|
||||
});
|
||||
|
||||
// 初始化ComboBox的值
|
||||
if (property.getValue() != null) {
|
||||
list.stream()
|
||||
.filter(item -> item != null && property.getValue().equals(item.getId()))
|
||||
.findFirst()
|
||||
.ifPresent(comboBox.getSelectionModel()::select);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,7 +188,7 @@ public class ComboBoxUtils {
|
||||
}
|
||||
|
||||
public static <K extends Enum<?>, T extends BaseEnumEntity<K>> void bindComboBox(ComboBox<T> comboBox,
|
||||
Property<K> property, List<T> dataSet) {
|
||||
Property<K> property, List<T> dataSet) {
|
||||
property.addListener((observable, oldValue, newValue) -> {
|
||||
dataSet.stream().filter(l -> l.getType() == newValue).findFirst().ifPresent(comboBox::setValue);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user