use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class WebCurrencyField method setDatasource.
@Override
public void setDatasource(Datasource datasource, String property) {
textField.setDatasource(datasource, property);
if (datasource != null && !DynamicAttributesUtils.isDynamicAttribute(property)) {
MetaProperty metaProperty = datasource.getMetaClass().getPropertyNN(property);
Object obj = metaProperty.getAnnotations().get(CurrencyValue.class.getName());
if (obj == null)
return;
// noinspection unchecked
Map<String, Object> currencyValue = (Map<String, Object>) obj;
String currencyName = (String) currencyValue.get("currency");
component.setCurrency(currencyName);
}
}
use of com.haulmont.chile.core.model.MetaProperty 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.MetaProperty in project cuba by cuba-platform.
the class WebTokenList method getInverseProperty.
@Nullable
protected MetaProperty getInverseProperty(CollectionDatasource datasource) {
if (datasource instanceof NestedDatasource) {
MetaProperty metaProperty = ((NestedDatasource) datasource).getProperty();
com.google.common.base.Preconditions.checkState(metaProperty != null);
return metaProperty.getInverse();
}
return null;
}
use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class WebPickerField method setDatasource.
@SuppressWarnings("unchecked")
@Override
public void setDatasource(Datasource datasource, String property) {
if ((datasource == null && property != null) || (datasource != null && property == null))
throw new IllegalArgumentException("Datasource and property should be either null or not null at the same time");
if (datasource == this.datasource && ((metaPropertyPath != null && metaPropertyPath.toString().equals(property)) || (metaPropertyPath == null && property == null)))
return;
if (this.datasource != null) {
metaProperty = null;
metaPropertyPath = null;
component.setPropertyDataSource(null);
this.datasource.removeItemChangeListener(securityWeakItemChangeListener);
securityWeakItemChangeListener = null;
this.datasource.removeItemChangeListener(weakItemChangeListener);
weakItemChangeListener = null;
this.datasource.removeItemPropertyChangeListener(weakItemPropertyChangeListener);
weakItemPropertyChangeListener = null;
this.datasource = null;
if (itemWrapper != null) {
itemWrapper.unsubscribe();
}
disableBeanValidator();
}
if (datasource != null) {
checkDatasourceProperty(datasource, property);
// noinspection unchecked
this.datasource = datasource;
metaPropertyPath = getResolvedMetaPropertyPath(datasource.getMetaClass(), property);
metaProperty = metaPropertyPath.getMetaProperty();
itemWrapper = createDatasourceWrapper(datasource, Collections.singleton(metaPropertyPath));
Property itemProperty = itemWrapper.getItemProperty(metaPropertyPath);
component.setPropertyDataSource(itemProperty);
itemChangeListener = e -> {
Object newValue = InstanceUtils.getValueEx(e.getItem(), metaPropertyPath.getPath());
setValue(newValue);
};
weakItemChangeListener = new WeakItemChangeListener(datasource, itemChangeListener);
// noinspection unchecked
datasource.addItemChangeListener(weakItemChangeListener);
itemPropertyChangeListener = e -> {
if (!isBuffered() && e.getProperty().equals(metaPropertyPath.toString())) {
setValue(e.getValue());
}
};
weakItemPropertyChangeListener = new WeakItemPropertyChangeListener(datasource, itemPropertyChangeListener);
// noinspection unchecked
datasource.addItemPropertyChangeListener(weakItemPropertyChangeListener);
if (datasource.getState() == Datasource.State.VALID && datasource.getItem() != null) {
if (property.equals(metaPropertyPath.toString())) {
Object newValue = InstanceUtils.getValueEx(datasource.getItem(), metaPropertyPath.getPath());
setValue(newValue);
}
}
initRequired(metaPropertyPath);
if (metaProperty.isReadOnly()) {
setEditable(false);
}
handleFilteredAttributes(this, this.datasource, metaPropertyPath);
securityItemChangeListener = e -> handleFilteredAttributes(this, this.datasource, metaPropertyPath);
securityWeakItemChangeListener = new WeakItemChangeListener(datasource, securityItemChangeListener);
// noinspection unchecked
this.datasource.addItemChangeListener(securityWeakItemChangeListener);
initBeanValidator();
}
}
use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class EntityInspectorEditor method createDataComponents.
/**
* Creates components representing item data
* (fieldGroup, fieldGroups for embedded properties, tables for the referred entities)
*
* @param metaClass item meta class
*/
protected void createDataComponents(MetaClass metaClass, Entity item) {
FieldGroup fieldGroup = componentsFactory.createComponent(FieldGroup.class);
fieldGroup.setBorderVisible(true);
fieldGroup.setWidth("100%");
contentPane.add(fieldGroup);
fieldGroup.setFrame(frame);
MetadataTools tools = metadata.getTools();
MetaProperty primaryKeyProperty = tools.getPrimaryKeyProperty(metaClass);
LinkedList<FieldGroup.FieldConfig> customFields = new LinkedList<>();
for (MetaProperty metaProperty : metaClass.getProperties()) {
boolean isRequired = isRequired(metaProperty);
boolean isReadonly = metaProperty.isReadOnly();
switch(metaProperty.getType()) {
case DATATYPE:
case ENUM:
boolean includeId = primaryKeyProperty.equals(metaProperty) && String.class.equals(metaProperty.getJavaType());
// skip system properties
if (tools.isSystem(metaProperty) && !showSystemFields && !includeId) {
continue;
}
if (metaProperty.getType() != MetaProperty.Type.ENUM && (isByteArray(metaProperty) || isUuid(metaProperty))) {
continue;
}
if (includeId && !isNew) {
isReadonly = true;
}
addField(metaClass, metaProperty, item, fieldGroup, isRequired, false, isReadonly, customFields);
break;
case COMPOSITION:
case ASSOCIATION:
if (metaProperty.getRange().getCardinality().isMany()) {
addTable(metaClass, metaProperty);
} else {
if (isEmbedded(metaProperty)) {
Entity propertyValue = item.getValue(metaProperty.getName());
addEmbeddedFieldGroup(metaProperty, "", propertyValue);
} else {
addField(metaClass, metaProperty, item, fieldGroup, isRequired, true, isReadonly, customFields);
}
}
break;
default:
break;
}
}
fieldGroup.setDatasource(datasource);
fieldGroup.bind();
createCustomFields(fieldGroup, customFields);
}
Aggregations