Search in sources :

Example 16 with MetaPropertyPath

use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.

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();
    Object 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
            EntityValues.setValue(option, inverseProperty.getName(), masterEntity);
        } else {
            Entity ref = EntityValues.getValue(option, inverseProperty.getName());
            if (ref == null) {
                continue;
            }
            // remove ref to the master entity if option is not in value
            if (Objects.equals(EntityValues.getId(ref), EntityValues.getId(masterEntity))) {
                EntityValues.setValue(option, inverseProperty.getName(), null);
            }
        }
    }
}
Also used : ContainerValueSource(io.jmix.ui.component.data.value.ContainerValueSource) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) ListEntityOptions(io.jmix.ui.component.data.options.ListEntityOptions) EntityOptions(io.jmix.ui.component.data.meta.EntityOptions) MapEntityOptions(io.jmix.ui.component.data.options.MapEntityOptions)

Example 17 with MetaPropertyPath

use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.

the class PivotScreenBuilder method removeNonExistingProperties.

protected List<String> removeNonExistingProperties(List<String> properties, MetaClass metaClass, FetchPlan fetchPlan) {
    if (!metadataTools.isJpaEntity(metaClass)) {
        return properties.stream().filter(s -> metaClass.getPropertyPath(s) != null).collect(Collectors.toList());
    }
    List<String> result = new ArrayList<>();
    fetchPlan = fetchPlan == null ? getBaseFetchPlan(metaClass) : fetchPlan;
    for (String property : properties) {
        MetaPropertyPath mpp = metaClass.getPropertyPath(property);
        if (mpp != null && metadataTools.fetchPlanContainsProperty(fetchPlan, mpp)) {
            result.add(property);
        // simple property
        } else if (fetchPlan.containsProperty(property)) {
            result.add(property);
        // id property
        } else if (isIdProperty(property, metaClass)) {
            result.add(property);
        // EmbeddedId's property
        } else if (hasEmbeddedId(metaClass) && isEmbeddedIdProperty(property, metaClass)) {
            result.add(property);
        // if metaClass contains property path, we need to check nested entities in fetch plan
        } else if (mpp != null) {
            for (MetaProperty metaProperty : mpp.getMetaProperties()) {
                MetaClass propertyMetaClass = getPropertyMetaClass(metaProperty);
                if (propertyMetaClass == null) {
                    propertyMetaClass = metaClass;
                }
                // EmbeddedId's property
                if (isEmbeddedIdProperty(property, propertyMetaClass)) {
                    result.add(property);
                // Id property
                } else if (isIdProperty(metaProperty.getName(), propertyMetaClass)) {
                    result.add(property);
                }
            }
        }
    }
    return result;
}
Also used : ListComponent(io.jmix.ui.component.ListComponent) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit) MetaClass(io.jmix.core.metamodel.model.MetaClass) java.util(java.util) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) FrameOwner(io.jmix.ui.screen.FrameOwner) Autowired(org.springframework.beans.factory.annotation.Autowired) io.jmix.core(io.jmix.core) ParamsMap(io.jmix.core.common.util.ParamsMap) Frame(io.jmix.ui.component.Frame) JsonParser(com.google.gson.JsonParser) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Scope(org.springframework.context.annotation.Scope) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) UiEntityAttributeContext(io.jmix.ui.accesscontext.UiEntityAttributeContext) MapScreenOptions(io.jmix.ui.screen.MapScreenOptions) UiControllerUtils.getScreenContext(io.jmix.ui.screen.UiControllerUtils.getScreenContext) JsonSyntaxException(com.google.gson.JsonSyntaxException) Screen(io.jmix.ui.screen.Screen) Collectors(java.util.stream.Collectors) OpenMode(io.jmix.ui.screen.OpenMode) Component(org.springframework.stereotype.Component) EntityDataItem(io.jmix.ui.data.impl.EntityDataItem) DataItem(io.jmix.ui.data.DataItem) Screens(io.jmix.ui.Screens) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 18 with MetaPropertyPath

use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.

the class LookupBuilderProcessor method getFetchPlanForField.

/**
 * The method evaluates the fetch plan that is used for the entity in the given {@code field}
 * <p>
 * If the value for a component (e.g. {@link EntityPicker}) 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.
 *
 * @return a view or {@code null} if the fetch plan cannot be evaluated
 */
@Nullable
protected FetchPlan getFetchPlanForField(HasValue field) {
    if (field instanceof HasValueSource) {
        ValueSource valueSource = ((HasValueSource) field).getValueSource();
        if (valueSource instanceof ContainerValueSource) {
            ContainerValueSource containerValueSource = (ContainerValueSource) valueSource;
            InstanceContainer container = containerValueSource.getContainer();
            FetchPlan fetchPlan = container.getFetchPlan();
            if (fetchPlan != null) {
                MetaPropertyPath metaPropertyPath = containerValueSource.getMetaPropertyPath();
                FetchPlan curFetchPlan = fetchPlan;
                for (MetaProperty metaProperty : metaPropertyPath.getMetaProperties()) {
                    FetchPlanProperty viewProperty = curFetchPlan.getProperty(metaProperty.getName());
                    if (viewProperty != null) {
                        curFetchPlan = viewProperty.getFetchPlan();
                    }
                    if (curFetchPlan == null)
                        break;
                }
                if (curFetchPlan != fetchPlan) {
                    return curFetchPlan;
                }
            }
        }
    }
    return null;
}
Also used : ContainerValueSource(io.jmix.ui.component.data.value.ContainerValueSource) ContainerValueSource(io.jmix.ui.component.data.value.ContainerValueSource) ValueSource(io.jmix.ui.component.data.ValueSource) HasValueSource(io.jmix.ui.component.data.HasValueSource) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) InstanceContainer(io.jmix.ui.model.InstanceContainer) HasValueSource(io.jmix.ui.component.data.HasValueSource) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) Nullable(javax.annotation.Nullable)

Example 19 with MetaPropertyPath

use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.

the class BaseContainerSorter method createComparator.

protected Comparator<?> createComparator(Sort sort, MetaClass metaClass) {
    if (sort.getOrders().size() > 1) {
        throw new UnsupportedOperationException("Sort by multiple properties is not supported");
    }
    MetaPropertyPath propertyPath = metaClass.getPropertyPath(sort.getOrders().get(0).getProperty());
    if (propertyPath == null) {
        throw new IllegalArgumentException("Property " + sort.getOrders().get(0).getProperty() + " is invalid");
    }
    boolean asc = sort.getOrders().get(0).getDirection() == Sort.Direction.ASC;
    EntityValuesComparator<Object> comparator = new EntityValuesComparator<>(asc, metaClass, beanFactory);
    return Comparator.comparing(e -> EntityValues.getValueEx(e, propertyPath), comparator);
}
Also used : MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath)

Example 20 with MetaPropertyPath

use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.

the class GroupTableSettingsBinder method applyColumnSettings.

@Override
protected void applyColumnSettings(TableSettings tableSettings, Table table) {
    super.applyColumnSettings(tableSettings, table);
    GroupTableSettings groupTableSettings = (GroupTableSettings) tableSettings;
    List<String> groupProperties = groupTableSettings.getGroupProperties();
    if (groupProperties != null) {
        MetaClass metaClass = ((EntityTableItems) table.getItems()).getEntityMetaClass();
        List<MetaPropertyPath> properties = new ArrayList<>(groupProperties.size());
        for (String id : groupProperties) {
            MetaPropertyPath property = metadataTools.resolveMetaPropertyPathOrNull(metaClass, id);
            if (property != null) {
                properties.add(property);
            } else {
                log.warn("Ignored group property '{}'", id);
            }
        }
        ((GroupTable) table).groupBy(properties.toArray());
    } else {
        ((GroupTable) table).ungroup();
    }
}
Also used : GroupTable(io.jmix.ui.component.GroupTable) JmixGroupTable(io.jmix.ui.widget.JmixGroupTable) MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) ArrayList(java.util.ArrayList) EntityTableItems(io.jmix.ui.component.data.meta.EntityTableItems) GroupTableSettings(io.jmix.ui.settings.component.GroupTableSettings)

Aggregations

MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)134 MetaClass (io.jmix.core.metamodel.model.MetaClass)68 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)52 Nullable (javax.annotation.Nullable)19 Table (io.jmix.ui.component.Table)15 KeyValueMetaClass (io.jmix.core.impl.keyvalue.KeyValueMetaClass)12 MetadataTools (io.jmix.core.MetadataTools)10 Element (org.dom4j.Element)10 EntityValueSource (io.jmix.ui.component.data.meta.EntityValueSource)9 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)8 UiEntityAttributeContext (io.jmix.ui.accesscontext.UiEntityAttributeContext)8 JmixEnhancedTable (io.jmix.ui.widget.JmixEnhancedTable)7 EntityTableItems (io.jmix.ui.component.data.meta.EntityTableItems)6 java.util (java.util)6 Collectors (java.util.stream.Collectors)6 Range (io.jmix.core.metamodel.model.Range)5 HasValueSource (io.jmix.ui.component.data.HasValueSource)5 ValueSource (io.jmix.ui.component.data.ValueSource)4 AbstractTable (io.jmix.ui.component.impl.AbstractTable)4 TableSettings (io.jmix.ui.settings.component.TableSettings)4