Search in sources :

Example 6 with ValueSource

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

the class DatePickerLoader method getJavaType.

protected Class getJavaType(DatePicker 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) EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) ValueSource(com.haulmont.cuba.gui.components.data.ValueSource) MetaProperty(com.haulmont.chile.core.model.MetaProperty) Datatype(com.haulmont.chile.core.datatypes.Datatype)

Example 7 with ValueSource

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

the class WebDateField method valueBindingConnected.

@Override
protected void valueBindingConnected(ValueSource<V> valueSource) {
    super.valueBindingConnected(valueSource);
    if (valueSource instanceof EntityValueSource) {
        EntityValueSource entityValueSource = (EntityValueSource) valueSource;
        DataAwareComponentsTools dataAwareComponentsTools = beanLocator.get(DataAwareComponentsTools.class);
        dataAwareComponentsTools.setupDateFormat(this, entityValueSource);
        dataAwareComponentsTools.setupZoneId(this, entityValueSource);
        if (valueSourceStateChangeSubscription != null) {
            valueSourceStateChangeSubscription.remove();
        }
        // setup dateRange after valueSource is activated and value is set because
        // Vaadin dateField rejects value if it is not in range
        valueSourceStateChangeSubscription = valueSource.addStateChangeListener(event -> {
            if (event.getState() == BindingState.ACTIVE) {
                dataAwareComponentsTools.setupDateRange(this, entityValueSource);
            }
        });
    }
}
Also used : CubaCssActionsLayout(com.haulmont.cuba.web.widgets.CubaCssActionsLayout) java.util(java.util) TimeMode(com.haulmont.cuba.gui.components.TimeField.TimeMode) ConversionException(com.haulmont.cuba.gui.components.data.ConversionException) CubaDateField(com.haulmont.cuba.web.widgets.CubaDateField) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) InitializingBean(org.springframework.beans.factory.InitializingBean) Inject(javax.inject.Inject) Pair(com.haulmont.bali.datastruct.Pair) java.time(java.time) Datatype(com.haulmont.chile.core.datatypes.Datatype) HasValue(com.vaadin.data.HasValue) Subscription(com.haulmont.bali.events.Subscription) DataAwareComponentsTools(com.haulmont.cuba.gui.components.data.DataAwareComponentsTools) FormatStringsRegistry(com.haulmont.chile.core.datatypes.FormatStringsRegistry) AppUI(com.haulmont.cuba.web.AppUI) EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) WebWrapperUtils.fromVaadinTimeMode(com.haulmont.cuba.web.gui.components.WebWrapperUtils.fromVaadinTimeMode) DateTimeTransformations(com.haulmont.cuba.core.global.DateTimeTransformations) DateResolution(com.vaadin.shared.ui.datefield.DateResolution) Preconditions.checkNotNullArgument(com.haulmont.bali.util.Preconditions.checkNotNullArgument) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) MetaProperty(com.haulmont.chile.core.model.MetaProperty) WebWrapperUtils.toVaadinTimeMode(com.haulmont.cuba.web.gui.components.WebWrapperUtils.toVaadinTimeMode) ValueSource(com.haulmont.cuba.gui.components.data.ValueSource) App(com.haulmont.cuba.web.App) Messages(com.haulmont.cuba.core.global.Messages) ErrorMessage(com.vaadin.server.ErrorMessage) UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource) Preconditions(com.haulmont.bali.util.Preconditions) CubaTimeFieldWrapper(com.haulmont.cuba.web.widgets.CubaTimeFieldWrapper) TestIdManager(com.haulmont.cuba.gui.sys.TestIdManager) Consumer(java.util.function.Consumer) AbstractComponent(com.vaadin.ui.AbstractComponent) BindingState(com.haulmont.cuba.gui.components.data.BindingState) ThemeConstants(com.haulmont.cuba.gui.theme.ThemeConstants) Notifications(com.haulmont.cuba.gui.Notifications) UserError(com.vaadin.server.UserError) ComponentsHelper(com.haulmont.cuba.gui.ComponentsHelper) EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) DataAwareComponentsTools(com.haulmont.cuba.gui.components.data.DataAwareComponentsTools)

Example 8 with ValueSource

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

the class EditorBuilderProcessor method initEntity.

protected <E extends Entity> E initEntity(EditorBuilder<E> builder, CollectionContainer<E> container) {
    E entity;
    boolean oneToOneComposition = false;
    EntityValueSource entityValueSource = null;
    HasValue<E> field = builder.getField();
    if (field instanceof HasValueSource) {
        ValueSource valueSource = ((HasValueSource) field).getValueSource();
        if (valueSource instanceof EntityValueSource) {
            entityValueSource = (EntityValueSource) valueSource;
            oneToOneComposition = isCompositionProperty(entityValueSource);
        }
    }
    if (builder.getMode() == EditMode.CREATE || (oneToOneComposition && field.getValue() == null)) {
        if (builder.getNewEntity() == null) {
            entity = metadata.create(builder.getEntityClass());
        } else {
            entity = builder.getNewEntity();
        }
        if (container instanceof Nested) {
            initializeNestedEntity(entity, (Nested) container);
        }
        if (oneToOneComposition) {
            Entity ownerEntity = entityValueSource.getItem();
            MetaProperty inverseProp = entityValueSource.getMetaPropertyPath().getMetaProperty().getInverse();
            if (inverseProp != null) {
                entity.setValue(inverseProp.getName(), ownerEntity);
            }
        }
        if (builder.getInitializer() != null) {
            builder.getInitializer().accept(entity);
        }
    } else {
        entity = builder.getEditedEntity();
    }
    return entity;
}
Also used : BaseGenericIdEntity(com.haulmont.cuba.core.entity.BaseGenericIdEntity) Entity(com.haulmont.cuba.core.entity.Entity) EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) HasValueSource(com.haulmont.cuba.gui.components.data.HasValueSource) 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) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 9 with ValueSource

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

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

the class AttributeAccessSupport method visitComponent.

protected void visitComponent(com.haulmont.cuba.gui.components.Component component, boolean reset) {
    if (!(component instanceof HasValueSource)) {
        return;
    }
    ValueSource valueSource = ((HasValueSource) component).getValueSource();
    if (!(valueSource instanceof EntityValueSource)) {
        return;
    }
    EntityValueSource entityValueSource = (EntityValueSource) valueSource;
    MetaPropertyPath propertyPath = entityValueSource.getMetaPropertyPath();
    if (valueSource.getState() != BindingState.ACTIVE || propertyPath == null) {
        return;
    }
    if (reset) {
        component.setVisible(security.isEntityAttrReadPermitted(entityValueSource.getEntityMetaClass(), propertyPath.toString()));
        if (component instanceof Editable) {
            ((Editable) component).setEditable(security.isEntityAttrUpdatePermitted(entityValueSource.getEntityMetaClass(), propertyPath.toString()));
        }
        if (component instanceof Field) {
            ((Field) component).setRequired(propertyPath.getMetaProperty().isMandatory());
        }
    }
    Entity item = entityValueSource.getItem();
    ComponentState componentState = calculateComponentState(item, propertyPath);
    if (metadataTools.isEmbeddable(item.getMetaClass()) && entityValueSource instanceof DatasourceValueSource) {
        Datasource ds = ((DatasourceValueSource) entityValueSource).getDatasource();
        if (ds instanceof EmbeddedDatasource) {
            Datasource masterDs = ((EmbeddedDatasource) ds).getMaster();
            item = masterDs.getItem();
            componentState = calculateComponentState(item, metadataTools.resolveMetaPropertyPath(masterDs.getMetaClass(), ((EmbeddedDatasource) ds).getProperty().getName() + "." + propertyPath));
        }
    }
    if (componentState.hidden) {
        component.setVisible(false);
    }
    if (componentState.readOnly) {
        if (component instanceof Editable) {
            ((Editable) component).setEditable(false);
        }
    }
    if (component instanceof Field) {
        if (componentState.required && ((Field) component).isEditable() && component.isVisibleRecursive()) {
            ((Field) component).setRequired(true);
        }
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) EmbeddedDatasource(com.haulmont.cuba.gui.data.EmbeddedDatasource) EmbeddedDatasource(com.haulmont.cuba.gui.data.EmbeddedDatasource) Field(com.haulmont.cuba.gui.components.Field) Entity(com.haulmont.cuba.core.entity.Entity) EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) DatasourceValueSource(com.haulmont.cuba.gui.components.data.value.DatasourceValueSource) DatasourceValueSource(com.haulmont.cuba.gui.components.data.value.DatasourceValueSource) HasValueSource(com.haulmont.cuba.gui.components.data.HasValueSource) EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) ValueSource(com.haulmont.cuba.gui.components.data.ValueSource) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) Editable(com.haulmont.cuba.gui.components.Component.Editable) HasValueSource(com.haulmont.cuba.gui.components.data.HasValueSource)

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