Search in sources :

Example 11 with ValueSource

use of com.haulmont.cuba.gui.components.data.ValueSource 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 12 with ValueSource

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

the class ReadOnlyScreensSupport method isEditableConsideringDataBinding.

protected boolean isEditableConsideringDataBinding(Component component, boolean editable) {
    boolean shouldBeEditable = true;
    if (component instanceof HasValueSource && ((HasValueSource) component).getValueSource() != null) {
        ValueSource valueSource = ((HasValueSource) component).getValueSource();
        shouldBeEditable = !valueSource.isReadOnly();
        if (valueSource instanceof EntityValueSource && ((EntityValueSource) valueSource).isDataModelSecurityEnabled()) {
            MetaPropertyPath metaPropertyPath = ((EntityValueSource) valueSource).getMetaPropertyPath();
            if (!security.isEntityAttrUpdatePermitted(metaPropertyPath) || !security.isEntityAttrReadPermitted(metaPropertyPath)) {
                shouldBeEditable = false;
            }
        }
    }
    return editable && shouldBeEditable;
}
Also used : EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) ValueSource(com.haulmont.cuba.gui.components.data.ValueSource) HasValueSource(com.haulmont.cuba.gui.components.data.HasValueSource) EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) HasValueSource(com.haulmont.cuba.gui.components.data.HasValueSource)

Example 13 with ValueSource

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

the class DateFieldLoader method getJavaType.

protected Class getJavaType(DateField resultComponent) {
    ValueSource valueSource = resultComponent.getValueSource();
    if (valueSource instanceof EntityValueSource) {
        MetaProperty metaProperty = ((EntityValueSource) valueSource).getMetaPropertyPath().getMetaProperty();
        return metaProperty.getRange().asDatatype().getJavaClass();
    }
    Datatype datatype = resultComponent.getDatatype();
    return datatype == null ? Date.class : datatype.getJavaClass();
}
Also used : EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) ValueSource(com.haulmont.cuba.gui.components.data.ValueSource) EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) MetaProperty(com.haulmont.chile.core.model.MetaProperty) Datatype(com.haulmont.chile.core.datatypes.Datatype)

Example 14 with ValueSource

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

the class ClearAction method execute.

/**
 * Executes the action.
 */
@SuppressWarnings("unchecked")
@Override
public void execute() {
    // remove entity if it is a composition
    Object value = pickerField.getValue();
    ValueSource valueSource = pickerField.getValueSource();
    if (value != null && !value.equals(pickerField.getEmptyValue()) && valueSource instanceof EntityValueSource) {
        EntityValueSource entityValueSource = (EntityValueSource) pickerField.getValueSource();
        Entity entity = (Entity) pickerField.getValue();
        if (entityValueSource.getMetaPropertyPath() != null && entityValueSource.getMetaPropertyPath().getMetaProperty().getType() == MetaProperty.Type.COMPOSITION) {
            FrameOwner screen = pickerField.getFrame().getFrameOwner();
            DataContext dataContext = UiControllerUtils.getScreenData(screen).getDataContext();
            dataContext.remove(entity);
        }
    }
    // Set the value as if the user had set it
    pickerField.setValueFromUser(pickerField.getEmptyValue());
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) DataContext(com.haulmont.cuba.gui.model.DataContext) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) ValueSource(com.haulmont.cuba.gui.components.data.ValueSource) EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource)

Example 15 with ValueSource

use of com.haulmont.cuba.gui.components.data.ValueSource 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

ValueSource (com.haulmont.cuba.gui.components.data.ValueSource)15 EntityValueSource (com.haulmont.cuba.gui.components.data.meta.EntityValueSource)10 MetaProperty (com.haulmont.chile.core.model.MetaProperty)7 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)6 ContainerValueSource (com.haulmont.cuba.gui.components.data.value.ContainerValueSource)6 Datatype (com.haulmont.chile.core.datatypes.Datatype)4 HasValueSource (com.haulmont.cuba.gui.components.data.HasValueSource)4 Entity (com.haulmont.cuba.core.entity.Entity)3 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)3 Options (com.haulmont.cuba.gui.components.data.Options)3 Nullable (javax.annotation.Nullable)3 Messages (com.haulmont.cuba.core.global.Messages)2 ComponentsHelper (com.haulmont.cuba.gui.ComponentsHelper)2 ListOptions (com.haulmont.cuba.gui.components.data.options.ListOptions)2 InstanceContainer (com.haulmont.cuba.gui.model.InstanceContainer)2 java.time (java.time)2 Consumer (java.util.function.Consumer)2 StringUtils (org.apache.commons.lang3.StringUtils)2 Element (org.dom4j.Element)2 Pair (com.haulmont.bali.datastruct.Pair)1