Search in sources :

Example 6 with ContainerValueSource

use of com.haulmont.cuba.gui.components.data.value.ContainerValueSource in project cuba by cuba-platform.

the class LookupBuilderProcessor method getViewForField.

/**
 * If the value for a component (e.g. {@link com.haulmont.cuba.gui.components.PickerField}) is selected from lookup screen then there may be cases
 * when in entities in lookup screen some attributes required in the editor are not loaded.
 * <p>
 * The method evaluates the view that is used for the entity in the given {@code field}
 *
 * @return a view or null if the view cannot be evaluated
 */
@Nullable
protected <E extends Entity> View getViewForField(HasValue<E> field) {
    if (field instanceof HasValueSource) {
        ValueSource valueSource = ((HasValueSource) field).getValueSource();
        if (valueSource instanceof ContainerValueSource) {
            ContainerValueSource containerValueSource = (ContainerValueSource) valueSource;
            InstanceContainer<E> container = containerValueSource.getContainer();
            View view = container.getView();
            if (view != null) {
                MetaPropertyPath metaPropertyPath = containerValueSource.getMetaPropertyPath();
                View curView = view;
                for (MetaProperty metaProperty : metaPropertyPath.getMetaProperties()) {
                    ViewProperty viewProperty = curView.getProperty(metaProperty.getName());
                    if (viewProperty != null) {
                        curView = viewProperty.getView();
                    }
                    if (curView == null)
                        break;
                }
                if (curView != view) {
                    return curView;
                }
            }
        }
    }
    return null;
}
Also used : ContainerValueSource(com.haulmont.cuba.gui.components.data.value.ContainerValueSource) ContainerValueSource(com.haulmont.cuba.gui.components.data.value.ContainerValueSource) HasValueSource(com.haulmont.cuba.gui.components.data.HasValueSource) ValueSource(com.haulmont.cuba.gui.components.data.ValueSource) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) HasValueSource(com.haulmont.cuba.gui.components.data.HasValueSource) MetaProperty(com.haulmont.chile.core.model.MetaProperty) Nullable(javax.annotation.Nullable)

Example 7 with ContainerValueSource

use of com.haulmont.cuba.gui.components.data.value.ContainerValueSource in project cuba by cuba-platform.

the class AbstractComponentGenerationStrategy method createLookupField.

protected Component createLookupField(ComponentGenerationContext context, CategoryAttribute categoryAttribute) {
    LookupField lookupField = uiComponents.create(LookupField.class);
    ValueSource valueSource = context.getValueSource();
    if (valueSource instanceof ContainerValueSource) {
        setOptionsLoader(categoryAttribute, lookupField, (ContainerValueSource) valueSource);
    }
    setValueSource(lookupField, context);
    setValidators(lookupField, context);
    return lookupField;
}
Also used : ContainerValueSource(com.haulmont.cuba.gui.components.data.value.ContainerValueSource) ContainerValueSource(com.haulmont.cuba.gui.components.data.value.ContainerValueSource) ValueSource(com.haulmont.cuba.gui.components.data.ValueSource)

Example 8 with ContainerValueSource

use of com.haulmont.cuba.gui.components.data.value.ContainerValueSource in project cuba by cuba-platform.

the class WebTokenList method updateMasterRefIfOptionsRefreshed.

/**
 * Sets master-entity reference to the value and remove master-entity reference
 * from options if they are not in nested container.
 *
 * @param value value items
 */
protected void updateMasterRefIfOptionsRefreshed(Collection<V> value) {
    if (!isRefreshOptionsEnabled()) {
        return;
    }
    if (!(getValueSource() instanceof ContainerValueSource)) {
        return;
    }
    EntityOptions<V> options = (EntityOptions<V>) getOptions();
    if (options == null) {
        return;
    }
    ContainerValueSource valueSource = (ContainerValueSource) getValueSource();
    MetaPropertyPath mpp = valueSource.getMetaPropertyPath();
    MetaProperty inverseProperty = mpp.getMetaProperty().getInverse();
    Entity masterEntity = valueSource.getItem();
    if (inverseProperty == null || masterEntity == null) {
        return;
    }
    List<V> optionItems = getOptions().getOptions().collect(Collectors.toList());
    for (V option : optionItems) {
        // skip all options that did not load master-reference
        if (!entityStates.isLoaded(option, inverseProperty.getName())) {
            continue;
        }
        if (value.contains(option)) {
            // reset master-entity reference
            option.setValue(inverseProperty.getName(), masterEntity);
        } else {
            Entity ref = option.getValue(inverseProperty.getName());
            if (ref == null) {
                continue;
            }
            // remove ref to the master entity if option is not in value
            if (Objects.equals(ref.getId(), masterEntity.getId())) {
                option.setValue(inverseProperty.getName(), null);
            }
        }
    }
}
Also used : ContainerValueSource(com.haulmont.cuba.gui.components.data.value.ContainerValueSource) Entity(com.haulmont.cuba.core.entity.Entity) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) MetaProperty(com.haulmont.chile.core.model.MetaProperty) EntityOptions(com.haulmont.cuba.gui.components.data.meta.EntityOptions)

Example 9 with ContainerValueSource

use of com.haulmont.cuba.gui.components.data.value.ContainerValueSource in project cuba by cuba-platform.

the class DynamicAttributesPanel method generateFieldComponent.

protected Component generateFieldComponent(DynamicAttributesMetaProperty property) {
    CategoryAttribute attribute = property.getAttribute();
    ValueSource valueSource = new ContainerValueSource<>(instanceContainer, property.getName());
    ComponentGenerationContext componentGenerationContext = new ComponentGenerationContext(instanceContainer.getEntityMetaClass(), property.getName());
    componentGenerationContext.setValueSource(valueSource);
    Component formField;
    if (Boolean.TRUE.equals(attribute.getIsCollection())) {
        formField = dynamicAttributeComponentsGenerator.generateComponent(valueSource, attribute);
    } else {
        formField = uiComponentsGenerator.generate(componentGenerationContext);
    }
    return formField;
}
Also used : ContainerValueSource(com.haulmont.cuba.gui.components.data.value.ContainerValueSource) CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) ContainerValueSource(com.haulmont.cuba.gui.components.data.value.ContainerValueSource) ValueSource(com.haulmont.cuba.gui.components.data.ValueSource) StudioComponent(com.haulmont.cuba.gui.meta.StudioComponent) CompositeComponent(com.haulmont.cuba.web.gui.components.CompositeComponent)

Aggregations

ContainerValueSource (com.haulmont.cuba.gui.components.data.value.ContainerValueSource)9 ValueSource (com.haulmont.cuba.gui.components.data.ValueSource)6 MetaProperty (com.haulmont.chile.core.model.MetaProperty)4 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)4 InstanceContainer (com.haulmont.cuba.gui.model.InstanceContainer)4 Nullable (javax.annotation.Nullable)4 Datatype (com.haulmont.chile.core.datatypes.Datatype)2 MetaClass (com.haulmont.chile.core.model.MetaClass)2 com.haulmont.cuba.core.entity (com.haulmont.cuba.core.entity)2 Entity (com.haulmont.cuba.core.entity.Entity)2 OpenType (com.haulmont.cuba.gui.WindowManager.OpenType)2 GuiActionSupport (com.haulmont.cuba.gui.components.actions.GuiActionSupport)2 Options (com.haulmont.cuba.gui.components.data.Options)2 ListOptions (com.haulmont.cuba.gui.components.data.options.ListOptions)2 Consumer (java.util.function.Consumer)2 Collectors (java.util.stream.Collectors)2 BooleanUtils (org.apache.commons.lang3.BooleanUtils)2 StringUtils (org.apache.commons.lang3.StringUtils)2 Element (org.dom4j.Element)2 Strings (com.google.common.base.Strings)1