Search in sources :

Example 1 with ListOptions

use of com.haulmont.cuba.gui.components.data.options.ListOptions in project cuba by cuba-platform.

the class AbstractComponentGenerationStrategy method setOptionsLoader.

protected void setOptionsLoader(CategoryAttribute categoryAttribute, LookupField lookupField, ContainerValueSource valueSource) {
    InstanceContainer<?> container = valueSource.getContainer();
    Entity entity = container.getItemOrNull();
    if (entity != null) {
        List options = dynamicAttributesTools.loadOptions((BaseGenericIdEntity) entity, categoryAttribute);
        // noinspection unchecked
        lookupField.setOptions(new ListOptions(options));
    }
    container.addItemChangeListener(e -> {
        List options = dynamicAttributesTools.loadOptions((BaseGenericIdEntity) e.getItem(), categoryAttribute);
        // noinspection unchecked
        lookupField.setOptions(new ListOptions(options));
    });
    List<CategoryAttribute> dependsOnAttributes = categoryAttribute.getConfiguration().getDependsOnAttributes();
    if (dependsOnAttributes != null && !dependsOnAttributes.isEmpty()) {
        List<String> dependsOnAttributesCodes = dependsOnAttributes.stream().map(a -> DynamicAttributesUtils.encodeAttributeCode(a.getCode())).collect(Collectors.toList());
        container.addItemPropertyChangeListener(e -> {
            if (dependsOnAttributesCodes.contains(e.getProperty())) {
                List options = dynamicAttributesTools.loadOptions((BaseGenericIdEntity) e.getItem(), categoryAttribute);
                // noinspection unchecked
                lookupField.setOptions(new ListOptions(options));
                if (!options.contains(lookupField.getValue())) {
                    // noinspection unchecked
                    lookupField.setValue(null);
                }
            }
        });
    }
}
Also used : Resolution(com.haulmont.cuba.gui.components.DateField.Resolution) DynamicAttributesGuiTools(com.haulmont.cuba.gui.dynamicattributes.DynamicAttributesGuiTools) Time(java.sql.Time) Date(java.util.Date) ContainerValueSource(com.haulmont.cuba.gui.components.data.value.ContainerValueSource) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) BooleanUtils(org.apache.commons.lang3.BooleanUtils) InstanceContainer(com.haulmont.cuba.gui.model.InstanceContainer) AppBeans(com.haulmont.cuba.core.global.AppBeans) StringUtils(org.apache.commons.lang3.StringUtils) MetaClass(com.haulmont.chile.core.model.MetaClass) java.time(java.time) Datatype(com.haulmont.chile.core.datatypes.Datatype) ListOptions(com.haulmont.cuba.gui.components.data.options.ListOptions) com.haulmont.cuba.core.entity(com.haulmont.cuba.core.entity) com.haulmont.cuba.core.app.dynamicattributes(com.haulmont.cuba.core.app.dynamicattributes) Method(java.lang.reflect.Method) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) Nullable(javax.annotation.Nullable) OpenType(com.haulmont.cuba.gui.WindowManager.OpenType) Range(com.haulmont.chile.core.model.Range) MetaProperty(com.haulmont.chile.core.model.MetaProperty) Collection(java.util.Collection) Options(com.haulmont.cuba.gui.components.data.Options) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) ValueSource(com.haulmont.cuba.gui.components.data.ValueSource) Messages(com.haulmont.cuba.core.global.Messages) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) CurrencyValue(com.haulmont.cuba.core.entity.annotation.CurrencyValue) GuiActionSupport(com.haulmont.cuba.gui.components.actions.GuiActionSupport) Consumer(java.util.function.Consumer) List(java.util.List) ComponentsHelper(com.haulmont.cuba.gui.ComponentsHelper) Element(org.dom4j.Element) UiComponents(com.haulmont.cuba.gui.UiComponents) ListOptions(com.haulmont.cuba.gui.components.data.options.ListOptions) List(java.util.List)

Aggregations

Datatype (com.haulmont.chile.core.datatypes.Datatype)1 MetaClass (com.haulmont.chile.core.model.MetaClass)1 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)1 Range (com.haulmont.chile.core.model.Range)1 com.haulmont.cuba.core.app.dynamicattributes (com.haulmont.cuba.core.app.dynamicattributes)1 com.haulmont.cuba.core.entity (com.haulmont.cuba.core.entity)1 CurrencyValue (com.haulmont.cuba.core.entity.annotation.CurrencyValue)1 AppBeans (com.haulmont.cuba.core.global.AppBeans)1 Messages (com.haulmont.cuba.core.global.Messages)1 ComponentsHelper (com.haulmont.cuba.gui.ComponentsHelper)1 UiComponents (com.haulmont.cuba.gui.UiComponents)1 OpenType (com.haulmont.cuba.gui.WindowManager.OpenType)1 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)1 Resolution (com.haulmont.cuba.gui.components.DateField.Resolution)1 GuiActionSupport (com.haulmont.cuba.gui.components.actions.GuiActionSupport)1 Options (com.haulmont.cuba.gui.components.data.Options)1 ValueSource (com.haulmont.cuba.gui.components.data.ValueSource)1 ListOptions (com.haulmont.cuba.gui.components.data.options.ListOptions)1 ContainerValueSource (com.haulmont.cuba.gui.components.data.value.ContainerValueSource)1