Search in sources :

Example 1 with PersistenceManagerService

use of com.haulmont.cuba.core.app.PersistenceManagerService in project cuba by cuba-platform.

the class UniqueConstraintViolationPatternFactory method build.

@Override
public Object build(String value) {
    Messages messages = AppBeans.get(Messages.NAME);
    PersistenceManagerService pmService = AppBeans.get(PersistenceManagerService.NAME);
    String defaultConstraintViolationPattern = pmService.getUniqueConstraintViolationPattern();
    Pattern constraintViolationPattern;
    if (StringUtils.isBlank(value)) {
        constraintViolationPattern = Pattern.compile(defaultConstraintViolationPattern);
    } else {
        try {
            constraintViolationPattern = Pattern.compile(value);
        } catch (PatternSyntaxException e) {
            constraintViolationPattern = Pattern.compile(defaultConstraintViolationPattern);
            Logger log = LoggerFactory.getLogger(UniqueConstraintViolationPatternFactory.class);
            log.warn(String.format(messages.getMainMessage("incorrectRegexp"), "cuba.uniqueConstraintViolationPattern"), e);
        }
    }
    return constraintViolationPattern;
}
Also used : Pattern(java.util.regex.Pattern) Messages(com.haulmont.cuba.core.global.Messages) PersistenceManagerService(com.haulmont.cuba.core.app.PersistenceManagerService) Logger(org.slf4j.Logger) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 2 with PersistenceManagerService

use of com.haulmont.cuba.core.app.PersistenceManagerService in project cuba by cuba-platform.

the class WebAbstractTable method addColumn.

@Override
public void addColumn(Table.Column column) {
    checkNotNullArgument(column, "Column must be non null");
    Object columnId = column.getId();
    component.addContainerProperty(columnId, column.getType(), null);
    if (StringUtils.isNotBlank(column.getDescription())) {
        component.setColumnDescription(columnId, column.getDescription());
    }
    if (StringUtils.isNotBlank(column.getValueDescription())) {
        component.setAggregationDescription(columnId, column.getValueDescription());
    } else if (column.getAggregation() != null && column.getAggregation().getType() != AggregationInfo.Type.CUSTOM) {
        Messages messages = AppBeans.get(Messages.NAME);
        String aggregationTypeLabel;
        switch(column.getAggregation().getType()) {
            case AVG:
                aggregationTypeLabel = "aggreagtion.avg";
                break;
            case COUNT:
                aggregationTypeLabel = "aggreagtion.count";
                break;
            case SUM:
                aggregationTypeLabel = "aggreagtion.sum";
                break;
            case MIN:
                aggregationTypeLabel = "aggreagtion.min";
                break;
            case MAX:
                aggregationTypeLabel = "aggreagtion.max";
                break;
            default:
                throw new IllegalArgumentException(String.format("AggregationType %s is not supported", column.getAggregation().getType().toString()));
        }
        component.setAggregationDescription(columnId, messages.getMainMessage(aggregationTypeLabel));
    }
    if (!column.isSortable()) {
        component.setColumnSortable(columnId, column.isSortable());
    }
    columns.put(columnId, column);
    columnsOrder.add(column);
    if (column.getWidth() != null) {
        component.setColumnWidth(columnId, column.getWidth());
    }
    if (column.getAlignment() != null) {
        component.setColumnAlignment(columnId, WebComponentsHelper.convertColumnAlignment(column.getAlignment()));
    }
    final String caption = getColumnCaption(columnId, column);
    setColumnHeader(columnId, caption);
    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);
        }
    }
    if (columnId instanceof MetaPropertyPath) {
        PersistenceManagerService persistenceManagerService = AppBeans.get(PersistenceManagerClient.NAME);
        MetaPropertyPath propertyPath = (MetaPropertyPath) columnId;
        MetaProperty metaProperty = propertyPath.getMetaProperty();
        MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(propertyPath);
        String storeName = metadataTools.getStoreName(propertyMetaClass);
        if (metadataTools.isLob(metaProperty) && !persistenceManagerService.supportsLobSortingAndFiltering(storeName)) {
            component.setColumnSortable(columnId, false);
        }
    }
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) CollectionFormatter(com.haulmont.cuba.gui.components.formatters.CollectionFormatter) Formatter(com.haulmont.cuba.gui.components.Formatter) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) PersistenceManagerService(com.haulmont.cuba.core.app.PersistenceManagerService) MetaProperty(com.haulmont.chile.core.model.MetaProperty) CollectionFormatter(com.haulmont.cuba.gui.components.formatters.CollectionFormatter)

Example 3 with PersistenceManagerService

use of com.haulmont.cuba.core.app.PersistenceManagerService in project cuba by cuba-platform.

the class Param method createEntityLookup.

protected Component createEntityLookup(final ValueProperty valueProperty) {
    Metadata metadata = AppBeans.get(Metadata.NAME);
    MetaClass metaClass = metadata.getSession().getClassNN(javaClass);
    ThemeConstants theme = AppBeans.get(ThemeConstantsManager.class).getConstants();
    PersistenceManagerService persistenceManager = AppBeans.get(PersistenceManagerService.NAME);
    LookupType type = null;
    if (property != null && property.getRange().isClass()) {
        type = (LookupType) metadata.getTools().getMetaAnnotationAttributes(property.getAnnotations(), Lookup.class).get("type");
    }
    boolean useLookupScreen = type != null ? type == LookupType.SCREEN : persistenceManager.useLookupScreen(metaClass.getName());
    if (useLookupScreen) {
        if (inExpr) {
            ListEditor listEditor = componentsFactory.createComponent(ListEditor.class);
            listEditor.setItemType(ListEditor.ItemType.ENTITY);
            listEditor.setEntityName(metaClass.getName());
            initListEditor(listEditor, valueProperty);
            return listEditor;
        } else {
            PickerField picker = componentsFactory.createComponent(PickerField.class);
            picker.setMetaClass(metaClass);
            picker.setWidth(theme.get("cuba.gui.filter.Param.textComponent.width"));
            picker.setFrame(datasource.getDsContext().getFrameContext().getFrame());
            picker.addLookupAction();
            picker.addClearAction();
            picker.addValueChangeListener(e -> _setValue(e.getValue(), valueProperty));
            picker.setValue(_getValue(valueProperty));
            return picker;
        }
    } else {
        CollectionDatasource<Entity<Object>, Object> optionsDataSource = createOptionsDataSource(metaClass);
        if (inExpr) {
            ListEditor listEditor = componentsFactory.createComponent(ListEditor.class);
            listEditor.setItemType(ListEditor.ItemType.ENTITY);
            listEditor.setEntityName(metaClass.getName());
            listEditor.setUseLookupField(true);
            listEditor.setEntityWhereClause(entityWhere);
            initListEditor(listEditor, valueProperty);
            return listEditor;
        } else {
            final LookupPickerField lookup = componentsFactory.createComponent(LookupPickerField.class);
            lookup.addClearAction();
            lookup.setWidth(theme.get("cuba.gui.filter.Param.textComponent.width"));
            lookup.setOptionsDatasource(optionsDataSource);
            // noinspection unchecked
            optionsDataSource.addCollectionChangeListener(e -> lookup.setValue(null));
            lookup.addValueChangeListener(e -> _setValue(e.getValue(), valueProperty));
            lookup.setValue(_getValue(valueProperty));
            return lookup;
        }
    }
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) ThemeConstantsManager(com.haulmont.cuba.gui.theme.ThemeConstantsManager) LookupType(com.haulmont.cuba.core.entity.annotation.LookupType) PersistenceManagerService(com.haulmont.cuba.core.app.PersistenceManagerService) ThemeConstants(com.haulmont.cuba.gui.theme.ThemeConstants) MetaClass(com.haulmont.chile.core.model.MetaClass) Lookup(com.haulmont.cuba.core.entity.annotation.Lookup)

Example 4 with PersistenceManagerService

use of com.haulmont.cuba.core.app.PersistenceManagerService in project cuba by cuba-platform.

the class AbstractCollectionDatasource method getSortPropertiesForPersistentAttribute.

@Nullable
protected String[] getSortPropertiesForPersistentAttribute(MetaPropertyPath propertyPath) {
    String[] sortProperties = null;
    MetaProperty metaProperty = propertyPath.getMetaProperty();
    Range range = metaProperty.getRange();
    PersistenceManagerService persistenceManagerService = AppBeans.get(PersistenceManagerClient.NAME);
    if (!range.isClass()) {
        // a scalar persistent attribute
        MetaClass propertyMetaClass = metadata.getTools().getPropertyEnclosingMetaClass(propertyPath);
        String storeName = metadata.getTools().getStoreName(propertyMetaClass);
        if (!metadata.getTools().isLob(metaProperty) || persistenceManagerService.supportsLobSortingAndFiltering(storeName)) {
            sortProperties = new String[1];
            sortProperties[0] = propertyPath.toString();
        }
    } else {
        // a reference attribute
        if (!range.getCardinality().isMany()) {
            Collection<MetaProperty> properties = metadata.getTools().getNamePatternProperties(range.asClass());
            if (!properties.isEmpty()) {
                sortProperties = properties.stream().filter(prop -> {
                    if (metadata.getTools().isPersistent(prop)) {
                        String storeName = metadata.getTools().getStoreName(range.asClass());
                        return !metadata.getTools().isLob(prop) || persistenceManagerService.supportsLobSortingAndFiltering(storeName);
                    }
                    return true;
                }).map(MetadataObject::getName).map(propName -> propertyPath.toString().concat(".").concat(propName)).toArray(String[]::new);
            } else {
                sortProperties = new String[1];
                sortProperties[0] = propertyPath.toString();
            }
        }
    }
    return sortProperties;
}
Also used : PersistenceManagerService(com.haulmont.cuba.core.app.PersistenceManagerService) Nullable(javax.annotation.Nullable)

Example 5 with PersistenceManagerService

use of com.haulmont.cuba.core.app.PersistenceManagerService in project cuba by cuba-platform.

the class OpManagerImpl method availableOps.

@Override
public EnumSet<Op> availableOps(MetaClass metaClass, MetaProperty metaProperty) {
    Class javaClass = metaProperty.getJavaType();
    if (String.class.equals(javaClass) && metadataTools.isLob(metaProperty)) {
        String storeName = metadata.getTools().getStoreName(metaClass);
        PersistenceManagerService persistenceManagerService = AppBeans.get(PersistenceManagerService.class);
        if (!persistenceManagerService.supportsLobSortingAndFiltering(storeName)) {
            return EnumSet.of(CONTAINS, DOES_NOT_CONTAIN, NOT_EMPTY, STARTS_WITH, ENDS_WITH);
        }
    }
    return availableOps(javaClass);
}
Also used : PersistenceManagerService(com.haulmont.cuba.core.app.PersistenceManagerService) MetaClass(com.haulmont.chile.core.model.MetaClass)

Aggregations

PersistenceManagerService (com.haulmont.cuba.core.app.PersistenceManagerService)5 MetaClass (com.haulmont.chile.core.model.MetaClass)3 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)1 Entity (com.haulmont.cuba.core.entity.Entity)1 Lookup (com.haulmont.cuba.core.entity.annotation.Lookup)1 LookupType (com.haulmont.cuba.core.entity.annotation.LookupType)1 Messages (com.haulmont.cuba.core.global.Messages)1 Formatter (com.haulmont.cuba.gui.components.Formatter)1 CollectionFormatter (com.haulmont.cuba.gui.components.formatters.CollectionFormatter)1 ThemeConstants (com.haulmont.cuba.gui.theme.ThemeConstants)1 ThemeConstantsManager (com.haulmont.cuba.gui.theme.ThemeConstantsManager)1 Pattern (java.util.regex.Pattern)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 Nullable (javax.annotation.Nullable)1 Logger (org.slf4j.Logger)1