use of io.jmix.ui.component.data.options.ListOptions in project jmix by jmix-framework.
the class DynAttrComponentGenerationStrategy method setComboBoxOptionsLoader.
protected void setComboBoxOptionsLoader(ComboBox lookupField, AttributeDefinition attribute, ContainerValueSource valueSource) {
InstanceContainer<?> container = valueSource.getContainer();
Object entity = container.getItemOrNull();
if (entity != null) {
List options = optionsLoader.loadOptions(entity, attribute);
// noinspection unchecked
lookupField.setOptions(new ListOptions(options));
}
container.addItemChangeListener(e -> {
List options = optionsLoader.loadOptions(e.getItem(), attribute);
// noinspection unchecked
lookupField.setOptions(new ListOptions(options));
});
List<String> dependsOnAttributeCodes = attribute.getConfiguration().getDependsOnAttributeCodes();
if (dependsOnAttributeCodes != null && !dependsOnAttributeCodes.isEmpty()) {
container.addItemPropertyChangeListener(e -> {
if (dependsOnAttributeCodes.contains(e.getProperty())) {
List options = optionsLoader.loadOptions(e.getItem(), attribute);
// noinspection unchecked
lookupField.setOptions(new ListOptions(options));
if (!options.contains(lookupField.getValue())) {
// noinspection unchecked
lookupField.setValue(null);
}
}
});
}
}
use of io.jmix.ui.component.data.options.ListOptions in project jmix by jmix-framework.
the class DynAttrComponentGenerationStrategy method setValuesPickerOptionsLoader.
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void setValuesPickerOptionsLoader(ValuesPicker valuesPicker, AttributeDefinition attribute, ContainerValueSource valueSource) {
InstanceContainer<?> container = valueSource.getContainer();
Object entity = container.getItemOrNull();
if (entity != null) {
List options = optionsLoader.loadOptions(entity, attribute);
((ValuesSelectAction) valuesPicker.getActionNN(ValuesSelectAction.ID)).setOptions(new ListOptions(options));
}
container.addItemChangeListener(e -> {
List options = optionsLoader.loadOptions(e.getItem(), attribute);
((ValuesSelectAction) valuesPicker.getActionNN(ValuesSelectAction.ID)).setOptions(new ListOptions(options));
});
List<String> dependsOnAttributeCodes = attribute.getConfiguration().getDependsOnAttributeCodes();
if (dependsOnAttributeCodes != null && !dependsOnAttributeCodes.isEmpty()) {
container.addItemPropertyChangeListener(e -> {
if (dependsOnAttributeCodes.contains(e.getProperty())) {
List options = optionsLoader.loadOptions(e.getItem(), attribute);
((ValuesSelectAction) valuesPicker.getActionNN(ValuesSelectAction.ID)).setOptions(new ListOptions(options));
if (!options.contains(valuesPicker.getValue())) {
valuesPicker.setValue(null);
}
}
});
}
}
Aggregations