use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.
the class AbstractComponentLoader method loadVisible.
protected boolean loadVisible(Component component, Element element) {
if (component instanceof DatasourceComponent && ((DatasourceComponent) component).getDatasource() != null) {
DatasourceComponent wiredComponent = (DatasourceComponent) component;
MetaClass metaClass = wiredComponent.getDatasource().getMetaClass();
MetaPropertyPath propertyPath = wiredComponent.getMetaPropertyPath();
if (propertyPath != null && !security.isEntityAttrReadPermitted(metaClass, propertyPath.toString())) {
component.setVisible(false);
return false;
}
}
String visible = element.attributeValue("visible");
if (StringUtils.isNotEmpty(visible)) {
boolean visibleValue = Boolean.parseBoolean(visible);
component.setVisible(visibleValue);
return visibleValue;
}
return true;
}
use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.
the class AbstractComponentLoader method loadEditable.
protected void loadEditable(Component component, Element element) {
if (component instanceof Component.Editable) {
if (component instanceof DatasourceComponent && ((DatasourceComponent) component).getDatasource() != null) {
DatasourceComponent wiredComponent = (DatasourceComponent) component;
MetaClass metaClass = wiredComponent.getDatasource().getMetaClass();
MetaPropertyPath propertyPath = wiredComponent.getMetaPropertyPath();
if (propertyPath != null && !security.isEntityAttrUpdatePermitted(metaClass, propertyPath.toString())) {
((Component.Editable) component).setEditable(false);
return;
}
}
final String editable = element.attributeValue("editable");
if (!StringUtils.isEmpty(editable)) {
((Component.Editable) component).setEditable(Boolean.parseBoolean(editable));
}
}
}
use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.
the class DataGridLoader method loadColumn.
protected Column loadColumn(DataGrid component, Element element, Datasource ds) {
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.getCurrentFrameId(), "DataGrid ID", component.getId());
}
}
Column column;
if (property != null) {
MetaPropertyPath metaPropertyPath = AppBeans.get(MetadataTools.NAME, MetadataTools.class).resolveMetaPropertyPath(ds.getMetaClass(), 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));
}
// Default caption set to columns when it is added to a DataGrid,
// so we need to set caption as null to get caption from
// metaProperty if 'caption' attribute is empty
column.setCaption(null);
String caption = loadCaption(element);
if (caption == null) {
String columnCaption;
if (column.getPropertyPath() != null) {
MetaProperty metaProperty = column.getPropertyPath().getMetaProperty();
String propertyName = metaProperty.getName();
if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty);
columnCaption = LocaleHelper.isLocalizedValueDefined(categoryAttribute.getLocaleNames()) ? categoryAttribute.getLocaleName() : StringUtils.capitalize(categoryAttribute.getName());
} else {
MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(column.getPropertyPath());
columnCaption = messageTools.getPropertyCaption(propertyMetaClass, propertyName);
}
} else {
Class<?> declaringClass = ds.getMetaClass().getJavaClass();
String className = declaringClass.getName();
int i = className.lastIndexOf('.');
if (i > -1) {
className = className.substring(i + 1);
}
columnCaption = messages.getMessage(declaringClass, className + "." + id);
}
column.setCaption(columnCaption);
} else {
column.setCaption(caption);
}
column.setXmlDescriptor(element);
Integer width = loadWidth(element, "width");
if (width != null) {
column.setWidth(width);
}
Integer minimumWidth = loadWidth(element, "minimumWidth");
if (minimumWidth != null) {
column.setMinimumWidth(minimumWidth);
}
Integer maximumWidth = loadWidth(element, "maximumWidth");
if (maximumWidth != null) {
column.setMaximumWidth(maximumWidth);
}
column.setFormatter(loadFormatter(element));
return column;
}
use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.
the class FieldGroupLoader method loadVisible.
protected void loadVisible(FieldGroup resultComponent, FieldGroup.FieldConfig field) {
Element element = field.getXmlDescriptor();
if (element != null) {
String visible = element.attributeValue("visible");
if (StringUtils.isNotEmpty(visible)) {
field.setVisible(Boolean.parseBoolean(visible));
}
}
if (!field.isCustom() && BooleanUtils.isNotFalse(field.isVisible())) {
MetaClass metaClass = getMetaClass(resultComponent, field);
MetaPropertyPath propertyPath = metadataTools.resolveMetaPropertyPath(metaClass, field.getProperty());
checkNotNullArgument(propertyPath, "Could not resolve property path '%s' in '%s'", field.getId(), metaClass);
if (!security.isEntityAttrReadPermitted(metaClass, propertyPath.toString())) {
field.setVisible(false);
}
}
}
use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.
the class FieldGroupLoader method getDefaultCaption.
protected String getDefaultCaption(FieldGroup.FieldConfig fieldConfig, Datasource fieldDatasource) {
String caption = fieldConfig.getCaption();
if (caption == null) {
String propertyId = fieldConfig.getProperty();
MetaPropertyPath propertyPath = fieldDatasource != null ? fieldDatasource.getMetaClass().getPropertyPath(propertyId) : null;
if (propertyPath != null) {
MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(propertyPath);
String propertyName = propertyPath.getMetaProperty().getName();
caption = messageTools.getPropertyCaption(propertyMetaClass, propertyName);
}
}
return caption;
}
Aggregations