Search in sources :

Example 11 with EntityValueSource

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

the class AbstractSelectList 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 12 with EntityValueSource

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

the class GuiActionSupport method createActionsByMetaAnnotations.

public boolean createActionsByMetaAnnotations(PickerField pickerField) {
    ValueSource valueSource = pickerField.getValueSource();
    if (!(valueSource instanceof EntityValueSource)) {
        return false;
    }
    EntityValueSource entityValueSource = (EntityValueSource) pickerField.getValueSource();
    MetaPropertyPath mpp = entityValueSource.getMetaPropertyPath();
    if (mpp == null) {
        return false;
    }
    String[] actionIds = (String[]) metadataTools.getMetaAnnotationAttributes(mpp.getMetaProperty().getAnnotations(), Lookup.class).get("actions");
    if (actionIds != null && actionIds.length > 0) {
        for (String actionId : actionIds) {
            createActionById(pickerField, actionId);
        }
        return true;
    }
    return false;
}
Also used : EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) DatasourceValueSource(com.haulmont.cuba.gui.components.data.value.DatasourceValueSource) ValueSource(io.jmix.ui.component.data.ValueSource) EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath)

Example 13 with EntityValueSource

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

the class MaskedFieldImpl method convertToPresentation.

@Override
protected String convertToPresentation(@Nullable V modelValue) throws ConversionException {
    if (datatype != null) {
        return nullToEmpty(datatype.format(modelValue, locale));
    }
    if (valueBinding != null && valueBinding.getSource() instanceof EntityValueSource) {
        EntityValueSource entityValueSource = (EntityValueSource) valueBinding.getSource();
        Range range = entityValueSource.getMetaPropertyPath().getRange();
        if (range.isDatatype()) {
            Datatype<V> propertyDataType = range.asDatatype();
            return nullToEmpty(propertyDataType.format(modelValue, locale));
        }
    }
    return nullToEmpty(super.convertToPresentation(modelValue));
}
Also used : EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) Range(io.jmix.core.metamodel.model.Range)

Example 14 with EntityValueSource

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

the class MaskedFieldImpl method convertToModel.

@Nullable
@Override
protected V convertToModel(@Nullable String componentRawValue) throws ConversionException {
    String value = emptyToNull(componentRawValue);
    if (datatype != null) {
        try {
            return datatype.parse(value, locale);
        } catch (ValueConversionException e) {
            throw new ConversionException(e.getLocalizedMessage(), e);
        } catch (ParseException e) {
            throw new ConversionException(getConversionErrorMessage(), e);
        }
    }
    if (valueBinding != null && valueBinding.getSource() instanceof EntityValueSource) {
        EntityValueSource entityValueSource = (EntityValueSource) valueBinding.getSource();
        Datatype<V> propertyDataType = entityValueSource.getMetaPropertyPath().getRange().asDatatype();
        try {
            return propertyDataType.parse(value, locale);
        } catch (ValueConversionException e) {
            throw new ConversionException(e.getLocalizedMessage(), e);
        } catch (ParseException e) {
            throw new ConversionException(getConversionErrorMessage(), e);
        }
    }
    return super.convertToModel(value);
}
Also used : ConversionException(io.jmix.ui.component.data.ConversionException) ValueConversionException(io.jmix.ui.component.data.ValueConversionException) EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) ParseException(java.text.ParseException) ValueConversionException(io.jmix.ui.component.data.ValueConversionException) Nullable(javax.annotation.Nullable)

Example 15 with EntityValueSource

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

the class TextFieldImpl method convertToPresentation.

@SuppressWarnings("unchecked")
@Override
protected String convertToPresentation(@Nullable V modelValue) throws ConversionException {
    if (formatter != null) {
        return nullToEmpty(formatter.apply(modelValue));
    }
    if (datatype != null) {
        return nullToEmpty(datatype.format(modelValue, locale));
    }
    if (valueBinding != null && valueBinding.getSource() instanceof EntityValueSource) {
        EntityValueSource entityValueSource = (EntityValueSource) valueBinding.getSource();
        Range range = entityValueSource.getMetaPropertyPath().getRange();
        if (range.isDatatype()) {
            Datatype<V> propertyDataType = range.asDatatype();
            return nullToEmpty(propertyDataType.format(modelValue, locale));
        } else {
            setEditable(false);
            if (modelValue == null)
                return "";
            if (range.isClass()) {
                MetadataTools metadataTools = applicationContext.getBean(MetadataTools.class);
                if (range.getCardinality().isMany()) {
                    return ((Collection<Object>) modelValue).stream().map(metadataTools::getInstanceName).collect(Collectors.joining(", "));
                } else {
                    return metadataTools.getInstanceName(modelValue);
                }
            } else if (range.isEnum()) {
                Messages messages = applicationContext.getBean(Messages.class);
                return messages.getMessage((Enum) modelValue);
            }
        }
    }
    return nullToEmpty(super.convertToPresentation(modelValue));
}
Also used : EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) MetadataTools(io.jmix.core.MetadataTools) Messages(io.jmix.core.Messages) Collection(java.util.Collection) Range(io.jmix.core.metamodel.model.Range)

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