Search in sources :

Example 36 with EntityValueSource

use of io.jmix.ui.component.data.meta.EntityValueSource in project jmix by jmix-framework.

the class RadioButtonGroupImpl method valueBindingConnected.

@Override
protected void valueBindingConnected(ValueSource<V> valueSource) {
    super.valueBindingConnected(valueSource);
    if (valueSource instanceof EntityValueSource) {
        DataAwareComponentsTools dataAwareComponentsTools = applicationContext.getBean(DataAwareComponentsTools.class);
        dataAwareComponentsTools.setupOptions(this, (EntityValueSource) valueSource);
    }
}
Also used : EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) DataAwareComponentsTools(io.jmix.ui.component.data.DataAwareComponentsTools)

Example 37 with EntityValueSource

use of io.jmix.ui.component.data.meta.EntityValueSource in project jmix by jmix-framework.

the class TableFieldFactoryImpl method applyPermissions.

protected void applyPermissions(io.jmix.ui.component.Component columnComponent) {
    if (columnComponent instanceof HasValueSource && columnComponent instanceof io.jmix.ui.component.Component.Editable) {
        HasValueSource component = (HasValueSource) columnComponent;
        MetaPropertyPath propertyPath = ((EntityValueSource) component.getValueSource()).getMetaPropertyPath();
        if (propertyPath != null) {
            io.jmix.ui.component.Component.Editable editable = (io.jmix.ui.component.Component.Editable) component;
            UiEntityAttributeContext attributeContext = new UiEntityAttributeContext(propertyPath);
            accessManager.applyRegisteredConstraints(attributeContext);
            editable.setEditable(editable.isEditable() && attributeContext.canModify());
        }
    }
}
Also used : EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) io.jmix.ui.component(io.jmix.ui.component) UiEntityAttributeContext(io.jmix.ui.accesscontext.UiEntityAttributeContext) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) HasValueSource(io.jmix.ui.component.data.HasValueSource) Component(com.vaadin.ui.Component)

Example 38 with EntityValueSource

use of io.jmix.ui.component.data.meta.EntityValueSource in project jmix by jmix-framework.

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(io.jmix.ui.component.data.meta.EntityValueSource) ValueSource(io.jmix.ui.component.data.ValueSource) EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) Datatype(io.jmix.core.metamodel.datatype.Datatype)

Example 39 with EntityValueSource

use of io.jmix.ui.component.data.meta.EntityValueSource in project jmix by jmix-framework.

the class FormLoader method loadComponent.

protected ComponentPosition loadComponent(Element element, @Nullable String columnWidth, @Nullable Float flex) {
    Component component;
    if ("field".equals(element.getName())) {
        component = loadField(element);
    } else {
        LayoutLoader loader = getLayoutLoader();
        ComponentLoader childComponentLoader = loader.createComponent(element);
        childComponentLoader.loadComponent();
        component = childComponentLoader.getResultComponent();
    }
    // Set default width
    String componentWidth = element.attributeValue("width");
    if (Strings.isNullOrEmpty(componentWidth)) {
        if (columnWidth != null) {
            component.setWidth(columnWidth);
        } else if (flex != null) {
            component.setWidthFull();
        }
    }
    // Set default caption
    if (component instanceof HasValueSource && ((HasValueSource) component).getValueSource() instanceof EntityValueSource && component instanceof Component.HasCaption && ((Component.HasCaption) component).getCaption() == null) {
        EntityValueSource valueSource = ((EntityValueSource) ((HasValueSource) component).getValueSource());
        MetaPropertyPath metaPropertyPath = valueSource.getMetaPropertyPath();
        String propertyName = metaPropertyPath != null ? metaPropertyPath.getMetaProperty().getName() : null;
        if (metaPropertyPath != null) {
            MetaClass propertyMetaClass = getMetadataTools().getPropertyEnclosingMetaClass(metaPropertyPath);
            String propertyCaption = getMessageTools().getPropertyCaption(propertyMetaClass, propertyName);
            ((Component.HasCaption) component).setCaption(propertyCaption);
        }
    }
    int colspan = loadSpan(element, "colspan");
    int rowspan = loadSpan(element, "rowspan");
    return new ComponentPosition(component, colspan, rowspan);
}
Also used : ComponentPosition(io.jmix.ui.component.form.ComponentPosition) EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) HasValueSource(io.jmix.ui.component.data.HasValueSource) ComponentLoader(io.jmix.ui.xml.layout.ComponentLoader)

Example 40 with EntityValueSource

use of io.jmix.ui.component.data.meta.EntityValueSource in project jmix by jmix-framework.

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();
            UiEntityAttributeContext attributeContext = new UiEntityAttributeContext(metaPropertyPath);
            accessManager.applyRegisteredConstraints(attributeContext);
            if (!attributeContext.canModify() || !attributeContext.canView()) {
                shouldBeEditable = false;
            }
        }
    }
    return editable && shouldBeEditable;
}
Also used : EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) ValueSource(io.jmix.ui.component.data.ValueSource) EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) HasValueSource(io.jmix.ui.component.data.HasValueSource) UiEntityAttributeContext(io.jmix.ui.accesscontext.UiEntityAttributeContext) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) HasValueSource(io.jmix.ui.component.data.HasValueSource)

Aggregations

EntityValueSource (io.jmix.ui.component.data.meta.EntityValueSource)40 DataAwareComponentsTools (io.jmix.ui.component.data.DataAwareComponentsTools)11 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)10 ValueSource (io.jmix.ui.component.data.ValueSource)9 Nullable (javax.annotation.Nullable)9 MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)8 Messages (io.jmix.core.Messages)5 ConversionException (io.jmix.ui.component.data.ConversionException)5 HasValueSource (io.jmix.ui.component.data.HasValueSource)5 Datatype (io.jmix.core.metamodel.datatype.Datatype)4 MetaClass (io.jmix.core.metamodel.model.MetaClass)4 ValueConversionException (io.jmix.ui.component.data.ValueConversionException)4 ParseException (java.text.ParseException)4 UiEntityAttributeContext (io.jmix.ui.accesscontext.UiEntityAttributeContext)3 io.jmix.ui.component (io.jmix.ui.component)3 Nested (io.jmix.ui.model.Nested)3 Range (io.jmix.core.metamodel.model.Range)2 DataContext (io.jmix.ui.model.DataContext)2 DatasourceValueSource (com.haulmont.cuba.gui.components.data.value.DatasourceValueSource)1 LegacyCollectionDsValueSource (com.haulmont.cuba.gui.components.data.value.LegacyCollectionDsValueSource)1