Search in sources :

Example 61 with MetaPropertyPath

use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.

the class KeyValueMetaClass method getPropertyPath.

@Override
public MetaPropertyPath getPropertyPath(String propertyPath) {
    MetaProperty currentProperty;
    currentProperty = this.getProperty(propertyPath);
    if (currentProperty == null)
        return null;
    return new MetaPropertyPath(this, currentProperty);
}
Also used : MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 62 with MetaPropertyPath

use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.

the class EntityBasicPropertyDiff method getCollectionString.

private String getCollectionString(Object collection) {
    if (DynamicAttributesUtils.isDynamicAttribute(propertyName)) {
        Metadata metadata = AppBeans.get(Metadata.class);
        com.haulmont.chile.core.model.MetaClass metaClass = metadata.getClassNN(metaClassName);
        MetaPropertyPath path = DynamicAttributesUtils.getMetaPropertyPath(metaClass, propertyName);
        return metadata.getTools().format(collection, path.getMetaProperty());
    }
    return String.valueOf(beforeValue);
}
Also used : Metadata(com.haulmont.cuba.core.global.Metadata) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath)

Example 63 with MetaPropertyPath

use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.

the class MessageTools method getPropertyCaption.

/**
 * Get localized name of an entity property. Messages pack must be located in the same package as entity.
 *
 * @param metaClass    MetaClass containing the property
 * @param propertyName property's name
 * @param locale       locale, if value is null locale of current user is used
 * @return localized name
 */
public String getPropertyCaption(MetaClass metaClass, String propertyName, @Nullable Locale locale) {
    Class originalClass = extendedEntities.getOriginalClass(metaClass);
    Class<?> ownClass = originalClass != null ? originalClass : metaClass.getJavaClass();
    String className = ownClass.getSimpleName();
    String key = className + "." + propertyName;
    String message;
    if (locale == null) {
        message = messages.getMessage(ownClass, key);
    } else {
        message = messages.getMessage(ownClass, key, locale);
    }
    if (!message.equals(key)) {
        return message;
    }
    MetaPropertyPath propertyPath = metaClass.getPropertyPath(propertyName);
    if (propertyPath != null) {
        return getPropertyCaption(propertyPath.getMetaProperty());
    } else {
        return message;
    }
}
Also used : MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) MetaClass(com.haulmont.chile.core.model.MetaClass)

Example 64 with MetaPropertyPath

use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.

the class WebSuggestionField method convertToTextView.

protected String convertToTextView(Object value) {
    if (value == null) {
        return StringUtils.EMPTY;
    }
    if (value instanceof Entity) {
        Entity entity = (Entity) value;
        if (captionMode == CaptionMode.ITEM) {
            return entityConverter.convertToPresentation(entity, String.class, userSession.getLocale());
        }
        if (StringUtils.isNotEmpty(captionProperty)) {
            MetaPropertyPath propertyPath = entity.getMetaClass().getPropertyPath(captionProperty);
            if (propertyPath == null) {
                throw new IllegalArgumentException(String.format("Can't find property for given caption property: %s", captionProperty));
            }
            return metadataTools.format(entity.getValueEx(captionProperty), propertyPath.getMetaProperty());
        }
        log.warn("Using StringToEntityConverter to get entity text presentation. Caption property is not defined " + "while caption mode is \"PROPERTY\"");
        return entityConverter.convertToPresentation(entity, String.class, userSession.getLocale());
    }
    return metadataTools.format(value);
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath)

Example 65 with MetaPropertyPath

use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.

the class WebTimeField method createDatasourceWrapper.

@Override
protected ItemWrapper createDatasourceWrapper(Datasource datasource, Collection<MetaPropertyPath> propertyPaths) {
    return new ItemWrapper(datasource, datasource.getMetaClass(), propertyPaths) {

        private static final long serialVersionUID = 1729450322469573679L;

        @Override
        protected PropertyWrapper createPropertyWrapper(Object item, MetaPropertyPath propertyPath) {
            return new PropertyWrapper(item, propertyPath) {

                private static final long serialVersionUID = -4481934193197224070L;

                @Override
                public String getFormattedValue() {
                    Object value = this.getValue();
                    if (value instanceof Date) {
                        SimpleDateFormat sdf = new SimpleDateFormat(timeFormat);
                        return sdf.format(value);
                    }
                    return super.getFormattedValue();
                }

                @Override
                protected Object valueOf(Object newValue) throws Converter.ConversionException {
                    if (newValue instanceof String) {
                        if (StringUtils.isNotEmpty((String) newValue) && !newValue.equals(placeholder)) {
                            try {
                                SimpleDateFormat sdf = new SimpleDateFormat(timeFormat);
                                Date date = sdf.parse((String) newValue);
                                if (component.getComponentError() != null) {
                                    component.setComponentError(null);
                                }
                                return date;
                            } catch (Exception e) {
                                LoggerFactory.getLogger(WebTimeField.class).debug("Unable to parse value of component " + getId() + "\n" + e.getMessage());
                                component.setComponentError(new UserError("Invalid value"));
                                return null;
                            }
                        } else
                            return null;
                    } else
                        return newValue;
                }
            };
        }
    };
}
Also used : ItemWrapper(com.haulmont.cuba.web.gui.data.ItemWrapper) PropertyWrapper(com.haulmont.cuba.web.gui.data.PropertyWrapper) UserError(com.vaadin.server.UserError) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) Converter(com.vaadin.data.util.converter.Converter) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) ParseException(java.text.ParseException)

Aggregations

MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)84 MetaClass (com.haulmont.chile.core.model.MetaClass)34 MetaProperty (com.haulmont.chile.core.model.MetaProperty)27 Element (org.dom4j.Element)16 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)11 Entity (com.haulmont.cuba.core.entity.Entity)9 MetadataTools (com.haulmont.cuba.core.global.MetadataTools)9 Datasource (com.haulmont.cuba.gui.data.Datasource)6 Table (com.haulmont.cuba.gui.components.Table)5 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)5 MessageTools (com.haulmont.cuba.core.global.MessageTools)4 Instance (com.haulmont.chile.core.model.Instance)3 Op (com.haulmont.cuba.core.global.filter.Op)3 FocusableTable (com.haulmont.cuba.desktop.sys.vcl.FocusableTable)3 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)3 Formatter (com.haulmont.cuba.gui.components.Formatter)3 Window (com.haulmont.cuba.gui.components.Window)3 CollectionFormatter (com.haulmont.cuba.gui.components.formatters.CollectionFormatter)3 GroupInfo (com.haulmont.cuba.gui.data.GroupInfo)3 java.util (java.util)3