Search in sources :

Example 11 with MetaPropertyPath

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

the class PropertyFilterSupport method getPropertyFilterCaption.

/**
 * Returns default caption for {@link PropertyFilter}.
 *
 * @param metaClass an entity meta class associated with property filter
 * @param property  an entity attribute associated with property filter
 */
public String getPropertyFilterCaption(MetaClass metaClass, String property) {
    MetaPropertyPath mpp = metadataTools.resolveMetaPropertyPathOrNull(metaClass, property);
    if (mpp == null) {
        return property;
    } else {
        MetaProperty[] metaProperties = mpp.getMetaProperties();
        StringBuilder sb = new StringBuilder();
        MetaPropertyPath parentMpp = null;
        MetaClass tempMetaClass;
        for (int i = 0; i < metaProperties.length; i++) {
            if (i == 0) {
                parentMpp = new MetaPropertyPath(metaClass, metaProperties[i]);
                tempMetaClass = metaClass;
            } else {
                parentMpp = new MetaPropertyPath(parentMpp, metaProperties[i]);
                tempMetaClass = metadataTools.getPropertyEnclosingMetaClass(parentMpp);
            }
            sb.append(messageTools.getPropertyCaption(tempMetaClass, metaProperties[i].getName()));
            if (i < metaProperties.length - 1) {
                sb.append(".");
            }
        }
        return sb.toString();
    }
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 12 with MetaPropertyPath

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

the class AbstractDataGridLoader method loadColumn.

protected Column loadColumn(DataGrid component, Element element, MetaClass metaClass) {
    String id = element.attributeValue("id");
    String property = element.attributeValue("property");
    if (id == null) {
        if (property != null) {
            id = property;
        } else {
            throw new GuiDevelopmentException("A column must have whether id or property specified", context, "DataGrid ID", component.getId());
        }
    }
    Column column;
    if (property != null) {
        MetaPropertyPath metaPropertyPath = getMetadataTools().resolveMetaPropertyPathOrNull(metaClass, property);
        column = component.addColumn(id, metaPropertyPath);
    } else {
        column = component.addColumn(id, null);
    }
    String expandRatio = element.attributeValue("expandRatio");
    if (StringUtils.isNotEmpty(expandRatio)) {
        column.setExpandRatio(Integer.parseInt(expandRatio));
    }
    String collapsed = element.attributeValue("collapsed");
    if (StringUtils.isNotEmpty(collapsed)) {
        column.setCollapsed(Boolean.parseBoolean(collapsed));
    }
    String collapsible = element.attributeValue("collapsible");
    if (StringUtils.isNotEmpty(collapsible)) {
        column.setCollapsible(Boolean.parseBoolean(collapsible));
    }
    String collapsingToggleCaption = element.attributeValue("collapsingToggleCaption");
    if (StringUtils.isNotEmpty(collapsingToggleCaption)) {
        collapsingToggleCaption = loadResourceString(collapsingToggleCaption);
        column.setCollapsingToggleCaption(collapsingToggleCaption);
    }
    String sortable = element.attributeValue("sortable");
    if (StringUtils.isNotEmpty(sortable)) {
        column.setSortable(Boolean.parseBoolean(sortable));
    }
    String resizable = element.attributeValue("resizable");
    if (StringUtils.isNotEmpty(resizable)) {
        column.setResizable(Boolean.parseBoolean(resizable));
    }
    String editable = element.attributeValue("editable");
    if (StringUtils.isNotEmpty(editable)) {
        column.setEditable(Boolean.parseBoolean(editable));
    }
    String sort = element.attributeValue("sort");
    if (StringUtils.isNotBlank(sort)) {
        loadColumnSort(component, column, sort);
    }
    String caption = loadCaption(element);
    if (caption == null) {
        String columnCaption;
        if (column.getPropertyPath() != null) {
            MetaProperty metaProperty = column.getPropertyPath().getMetaProperty();
            String propertyName = metaProperty.getName();
            MetaClass propertyMetaClass = getMetadataTools().getPropertyEnclosingMetaClass(column.getPropertyPath());
            columnCaption = getMessageTools().getPropertyCaption(propertyMetaClass, propertyName);
        } else {
            Class<?> declaringClass = metaClass.getJavaClass();
            String className = declaringClass.getName();
            int i = className.lastIndexOf('.');
            if (i > -1) {
                className = className.substring(i + 1);
            }
            columnCaption = getMessages().getMessage(declaringClass, className + "." + id);
        }
        column.setCaption(columnCaption);
    } else {
        column.setCaption(caption);
    }
    ((Component.HasXmlDescriptor) column).setXmlDescriptor(element);
    Integer width = loadSizeInPx(element, "width");
    if (width != null) {
        column.setWidth(width);
    }
    Integer minimumWidth = loadSizeInPx(element, "minimumWidth");
    if (minimumWidth != null) {
        column.setMinimumWidth(minimumWidth);
    }
    Integer maximumWidth = loadSizeInPx(element, "maximumWidth");
    if (maximumWidth != null) {
        column.setMaximumWidth(maximumWidth);
    }
    loadColumnVisualDisplay(column, element);
    loadAggregation(column, element);
    return column;
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) Column(io.jmix.ui.component.DataGrid.Column) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 13 with MetaPropertyPath

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

the class RuntimePropertiesFrame method loadEditable.

protected void loadEditable(FieldGroup fieldGroup, FieldGroup.FieldConfig field) {
    if (fieldGroup.isEditable()) {
        MetaClass metaClass = rds.resolveCategorizedEntityClass();
        getAttributeByPropertyName(metaClass, field.getProperty()).ifPresent(attribute -> {
            MetaProperty metaProperty = attribute.getMetaProperty();
            MetaPropertyPath propertyPath = new MetaPropertyPath(metaClass, metaProperty);
            boolean editableFromPermissions = security.isEntityAttrUpdatePermitted(metaClass, propertyPath.toString());
            if (!editableFromPermissions) {
                field.setEditable(false);
            }
            boolean visibleFromPermissions = security.isEntityAttrReadPermitted(metaClass, propertyPath.toString());
            if (!visibleFromPermissions) {
                field.setVisible(false);
            }
        });
    }
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 14 with MetaPropertyPath

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

the class WebTable method setupAutowiredColumns.

@Override
protected void setupAutowiredColumns(EntityTableItems<E> entityTableSource) {
    Collection<MetaPropertyPath> paths = getAutowiredProperties(entityTableSource);
    for (MetaPropertyPath metaPropertyPath : paths) {
        MetaProperty property = metaPropertyPath.getMetaProperty();
        if (!property.getRange().getCardinality().isMany() && !metadataTools.isSystem(property)) {
            io.jmix.ui.component.Table.Column<E> column = addColumn(metaPropertyPath);
            String propertyName = property.getName();
            MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(metaPropertyPath);
            column.setCaption(messageTools.getPropertyCaption(propertyMetaClass, propertyName));
            if (column instanceof Table.Column) {
                ((Table.Column<E>) column).setType(metaPropertyPath.getRangeJavaClass());
            }
        }
    }
}
Also used : Table(com.haulmont.cuba.gui.components.Table) AbstractTable(io.jmix.ui.component.impl.AbstractTable) JmixEnhancedTable(io.jmix.ui.widget.JmixEnhancedTable) MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 15 with MetaPropertyPath

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

the class WebTokenList method getViewForField.

/**
 * If the value for a component is selected from the lookup screen there may be cases when lookup screen contains a list of entities loaded with a
 * view that doesn't contain all attributes, required by the token list.
 * <p>
 * The method evaluates the view that was is for loading entities in the token list
 *
 * @return a view or null if the view cannot be evaluated
 */
@Nullable
protected FetchPlan getViewForField() {
    ValueSource valueSource = getValueSource();
    if (valueSource instanceof ContainerValueSource) {
        ContainerValueSource containerValueSource = (ContainerValueSource) valueSource;
        InstanceContainer container = containerValueSource.getContainer();
        FetchPlan view = container.getFetchPlan();
        if (view != null) {
            MetaPropertyPath metaPropertyPath = containerValueSource.getMetaPropertyPath();
            FetchPlan curView = view;
            if (metaPropertyPath != null) {
                for (MetaProperty metaProperty : metaPropertyPath.getMetaProperties()) {
                    FetchPlanProperty viewProperty = curView.getProperty(metaProperty.getName());
                    if (viewProperty != null) {
                        curView = viewProperty.getFetchPlan();
                        if (curView == null)
                            return null;
                    }
                }
                MetaProperty inverseMetaProperty = metaPropertyPath.getMetaProperty().getInverse();
                if (inverseMetaProperty != null && !inverseMetaProperty.getRange().getCardinality().isMany()) {
                    curView = fetchPlans.builder(curView).add(inverseMetaProperty.getName()).build();
                }
            }
            if (curView != view) {
                return curView;
            }
        }
    }
    return null;
}
Also used : ContainerValueSource(io.jmix.ui.component.data.value.ContainerValueSource) ContainerValueSource(io.jmix.ui.component.data.value.ContainerValueSource) LegacyCollectionDsValueSource(com.haulmont.cuba.gui.components.data.value.LegacyCollectionDsValueSource) ValueSource(io.jmix.ui.component.data.ValueSource) EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) InstanceContainer(io.jmix.ui.model.InstanceContainer) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) Nullable(javax.annotation.Nullable)

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