Search in sources :

Example 76 with MetaProperty

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);
    }
}
Also used : CurrencyValue(com.haulmont.cuba.core.entity.annotation.CurrencyValue) MetaProperty(com.haulmont.chile.core.model.MetaProperty) Map(java.util.Map)

Example 77 with MetaProperty

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);
            }
        }
    }
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 78 with MetaProperty

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;
}
Also used : NestedDatasource(com.haulmont.cuba.gui.data.NestedDatasource) MetaProperty(com.haulmont.chile.core.model.MetaProperty) Nullable(javax.annotation.Nullable)

Example 79 with MetaProperty

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();
    }
}
Also used : WeakItemChangeListener(com.haulmont.cuba.gui.data.impl.WeakItemChangeListener) WeakItemPropertyChangeListener(com.haulmont.cuba.gui.data.impl.WeakItemPropertyChangeListener) Property(com.vaadin.data.Property) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 80 with MetaProperty

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);
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Aggregations

MetaProperty (com.haulmont.chile.core.model.MetaProperty)157 MetaClass (com.haulmont.chile.core.model.MetaClass)102 Entity (com.haulmont.cuba.core.entity.Entity)44 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)26 BaseGenericIdEntity (com.haulmont.cuba.core.entity.BaseGenericIdEntity)21 Range (com.haulmont.chile.core.model.Range)13 Nullable (javax.annotation.Nullable)11 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)10 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)9 java.util (java.util)9 Element (org.dom4j.Element)9 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)8 Collectors (java.util.stream.Collectors)6 Inject (javax.inject.Inject)6 Query (com.haulmont.cuba.core.Query)5 SoftDelete (com.haulmont.cuba.core.entity.SoftDelete)5 Collection (java.util.Collection)5 MessageTools (com.haulmont.cuba.core.global.MessageTools)4 PropertyDatasource (com.haulmont.cuba.gui.data.PropertyDatasource)4 Logger (org.slf4j.Logger)4