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();
}
}
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;
}
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);
}
});
}
}
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());
}
}
}
}
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;
}
Aggregations