use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.
the class WebDataGrid method addInitialColumns.
protected void addInitialColumns(CollectionDatasource datasource) {
if (this.columns.isEmpty()) {
MessageTools messageTools = AppBeans.get(MessageTools.NAME);
MetaClass metaClass = datasource.getMetaClass();
Collection<MetaPropertyPath> paths = datasource.getView() != null ? // if a view is specified - use view properties
metadataTools.getViewPropertyPaths(datasource.getView(), metaClass) : // otherwise use all properties from meta-class
metadataTools.getPropertyPaths(metaClass);
for (MetaPropertyPath metaPropertyPath : paths) {
MetaProperty property = metaPropertyPath.getMetaProperty();
if (!property.getRange().getCardinality().isMany() && !metadataTools.isSystem(property)) {
String propertyName = property.getName();
ColumnImpl column = new ColumnImpl(propertyName, metaPropertyPath, this);
MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(metaPropertyPath);
column.setCaption(messageTools.getPropertyCaption(propertyMetaClass, propertyName));
addColumn(column);
}
}
}
}
use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.
the class EntityLogBrowser method fillAttributes.
protected void fillAttributes(String metaClassName, LoggedEntity item, boolean editable) {
clearAttributes();
setSelectAllCheckBox(false);
if (metaClassName != null) {
MetaClass metaClass = metadata.getExtendedEntities().getEffectiveMetaClass(metadata.getClassNN(metaClassName));
List<MetaProperty> metaProperties = new ArrayList<>(metaClass.getProperties());
selectAllCheckBox.setEditable(editable);
Set<LoggedAttribute> enabledAttr = null;
if (item != null)
enabledAttr = item.getAttributes();
for (MetaProperty property : metaProperties) {
if (allowLogProperty(property, null)) {
if (metadata.getTools().isEmbedded(property)) {
MetaClass embeddedMetaClass = property.getRange().asClass();
for (MetaProperty embeddedProperty : embeddedMetaClass.getProperties()) {
if (allowLogProperty(embeddedProperty, null)) {
addAttribute(enabledAttr, String.format("%s.%s", property.getName(), embeddedProperty.getName()), editable);
}
}
} else {
addAttribute(enabledAttr, property.getName(), editable);
}
}
}
Collection<CategoryAttribute> attributes = dynamicAttributes.getAttributesForMetaClass(metaClass);
if (attributes != null) {
for (CategoryAttribute categoryAttribute : attributes) {
MetaPropertyPath propertyPath = DynamicAttributesUtils.getMetaPropertyPath(metaClass, categoryAttribute);
MetaProperty property = propertyPath.getMetaProperty();
if (allowLogProperty(property, categoryAttribute)) {
addAttribute(enabledAttr, property.getName(), editable);
}
}
}
}
}
use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.
the class DesktopAbstractTable method addColumn.
@Override
public void addColumn(Column column) {
checkNotNullArgument(column, "Column must be non null");
Object columnId = column.getId();
columns.put(columnId, column);
columnsOrder.add(column);
if (tableModel != null) {
tableModel.addColumn(column);
}
if (datasource != null && column.isEditable() && columnId instanceof MetaPropertyPath) {
if (!editableColumns.contains(columnId)) {
editableColumns.add((MetaPropertyPath) columnId);
}
}
setColumnIdentifiers();
refresh();
column.setOwner(this);
if (column.getFormatter() == null && columnId instanceof MetaPropertyPath) {
MetaProperty metaProperty = ((MetaPropertyPath) columnId).getMetaProperty();
if (Collection.class.isAssignableFrom(metaProperty.getJavaType())) {
final Formatter collectionFormatter = new CollectionFormatter();
column.setFormatter(collectionFormatter);
}
}
}
use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.
the class DesktopAbstractTable method getColumnEditor.
protected TableCellEditor getColumnEditor(int column) {
TableColumn tableColumn = impl.getColumnModel().getColumn(column);
if (tableColumn.getIdentifier() instanceof Table.Column) {
Table.Column columnConf = (Table.Column) tableColumn.getIdentifier();
if (columnConf.getId() instanceof MetaPropertyPath && !(isEditable() && columnConf.isEditable()) && !getTableModel().isGeneratedColumn(columnConf)) {
MetaPropertyPath propertyPath = (MetaPropertyPath) columnConf.getId();
final CellProvider cellProvider = getCustomCellEditor(propertyPath);
if (cellProvider != null) {
return new CellProviderEditor(cellProvider);
}
}
}
return null;
}
use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.
the class BulkEditorWindow method ensureEmbeddedPropertyCreated.
protected void ensureEmbeddedPropertyCreated(Entity item, String propertyPath) {
if (!StringUtils.contains(propertyPath, ".")) {
return;
}
MetaPropertyPath path = metaClass.getPropertyPath(propertyPath);
if (path != null) {
Entity currentItem = item;
for (MetaProperty property : path.getMetaProperties()) {
if (metadataTools.isEmbedded(property)) {
Object currentItemValue = currentItem.getValue(property.getName());
if (currentItemValue == null) {
Entity newItem = metadata.create(property.getRange().asClass());
currentItem.setValue(property.getName(), newItem);
currentItem = newItem;
} else {
currentItem = (Entity) currentItemValue;
}
} else {
break;
}
}
}
}
Aggregations