Search in sources :

Example 6 with MetadataTools

use of com.haulmont.cuba.core.global.MetadataTools in project cuba by cuba-platform.

the class DesktopAbstractField method initBeanValidator.

protected void initBeanValidator() {
    MetadataTools metadataTools = AppBeans.get(MetadataTools.NAME);
    MetaClass propertyEnclosingMetaClass = metadataTools.getPropertyEnclosingMetaClass(metaPropertyPath);
    Class enclosingJavaClass = propertyEnclosingMetaClass.getJavaClass();
    if (enclosingJavaClass != KeyValueEntity.class && !DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
        BeanValidation beanValidation = AppBeans.get(BeanValidation.NAME);
        javax.validation.Validator validator = beanValidation.getValidator();
        BeanDescriptor beanDescriptor = validator.getConstraintsForClass(enclosingJavaClass);
        if (beanDescriptor.isBeanConstrained()) {
            addValidator(new BeanValidator(enclosingJavaClass, metaProperty.getName()));
        }
    }
}
Also used : MetadataTools(com.haulmont.cuba.core.global.MetadataTools) BeanValidator(com.haulmont.cuba.gui.components.validators.BeanValidator) MetaClass(com.haulmont.chile.core.model.MetaClass) BeanValidation(com.haulmont.cuba.core.global.BeanValidation) BeanDescriptor(javax.validation.metadata.BeanDescriptor) MetaClass(com.haulmont.chile.core.model.MetaClass) KeyValueEntity(com.haulmont.cuba.core.entity.KeyValueEntity)

Example 7 with MetadataTools

use of com.haulmont.cuba.core.global.MetadataTools in project cuba by cuba-platform.

the class PropertyConditionDescriptor method createCondition.

@Override
public AbstractCondition createCondition() {
    OpManager opManager = AppBeans.get(OpManager.class);
    MetadataTools metadataTools = AppBeans.get(MetadataTools.class);
    PropertyCondition propertyCondition = new PropertyCondition(this, entityAlias);
    MetaPropertyPath propertyPath = datasourceMetaClass.getPropertyPath(name);
    if (propertyPath == null) {
        throw new IllegalStateException(String.format("Unable to find property '%s' in entity %s", name, datasourceMetaClass));
    }
    MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(propertyPath);
    EnumSet<Op> ops = opManager.availableOps(propertyMetaClass, propertyPath.getMetaProperty());
    propertyCondition.setOperator(ops.iterator().next());
    return propertyCondition;
}
Also used : Op(com.haulmont.cuba.core.global.filter.Op) MetadataTools(com.haulmont.cuba.core.global.MetadataTools) PropertyCondition(com.haulmont.cuba.gui.components.filter.condition.PropertyCondition) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) OpManager(com.haulmont.cuba.core.global.filter.OpManager)

Example 8 with MetadataTools

use of com.haulmont.cuba.core.global.MetadataTools in project cuba by cuba-platform.

the class PropertyOperationEditor method createComponent.

@Override
protected Component createComponent() {
    OpManager opManager = AppBeans.get(OpManager.class);
    MetadataTools metadataTools = AppBeans.get(MetadataTools.class);
    componentsFactory = AppBeans.get(ComponentsFactory.class);
    popupButton = componentsFactory.createComponent(PopupButton.class);
    MetaClass metaClass = condition.getDatasource().getMetaClass();
    MetaPropertyPath propertyPath = metaClass.getPropertyPath(condition.getName());
    if (propertyPath == null) {
        throw new IllegalStateException(String.format("Unable to find property '%s' in entity %s", condition.getName(), metaClass));
    }
    MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(propertyPath);
    for (Op op : opManager.availableOps(propertyMetaClass, propertyPath.getMetaProperty())) {
        OperatorChangeAction operatorChangeAction = new OperatorChangeAction(op);
        popupButton.addAction(operatorChangeAction);
    }
    popupButton.setCaption(condition.getOperator().getLocCaption());
    popupButton.setStyleName("condition-operation-button");
    return popupButton;
}
Also used : ComponentsFactory(com.haulmont.cuba.gui.xml.layout.ComponentsFactory) Op(com.haulmont.cuba.core.global.filter.Op) MetadataTools(com.haulmont.cuba.core.global.MetadataTools) PopupButton(com.haulmont.cuba.gui.components.PopupButton) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) OpManager(com.haulmont.cuba.core.global.filter.OpManager)

Example 9 with MetadataTools

use of com.haulmont.cuba.core.global.MetadataTools in project cuba by cuba-platform.

the class MetadataTest method testSystemLevel.

@Test
public void testSystemLevel() throws Exception {
    MetadataTools tools = metadata.getTools();
    assertTrue(tools.isSystemLevel(metadata.getClassNN(UserRole.class)));
    assertTrue(tools.isSystemLevel(metadata.getClassNN(AbstractNotPersistentEntity.class)));
    assertFalse(tools.isSystemLevel(metadata.getClassNN(TestNotPersistentEntity.class)));
    MetaClass metaClass = metadata.getClassNN(User.class);
    assertTrue(tools.isSystemLevel(metaClass.getPropertyNN("password")));
    assertTrue(tools.isSystemLevel(metadata.getClassNN(SearchFolder.class)));
}
Also used : MetadataTools(com.haulmont.cuba.core.global.MetadataTools) MetaClass(com.haulmont.chile.core.model.MetaClass) Test(org.junit.Test)

Example 10 with MetadataTools

use of com.haulmont.cuba.core.global.MetadataTools in project cuba by cuba-platform.

the class MetadataTest method testPersistentAndTransientEntities.

@Test
public void testPersistentAndTransientEntities() throws Exception {
    MetadataTools metadataTools = cont.metadata().getTools();
    assertTrue(metadataTools.isPersistent(User.class));
    assertFalse(metadataTools.isTransient(User.class));
    assertFalse(metadataTools.isPersistent(LockInfo.class));
    assertTrue(metadataTools.isTransient(LockInfo.class));
    assertFalse(metadataTools.isPersistent(TestNotPersistentEntity.class));
    assertTrue(metadataTools.isNotPersistent(TestNotPersistentEntity.class));
}
Also used : MetadataTools(com.haulmont.cuba.core.global.MetadataTools) LockInfo(com.haulmont.cuba.core.global.LockInfo) TestNotPersistentEntity(com.haulmont.cuba.testmodel.TestNotPersistentEntity) Test(org.junit.Test)

Aggregations

MetadataTools (com.haulmont.cuba.core.global.MetadataTools)11 MetaClass (com.haulmont.chile.core.model.MetaClass)9 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)3 Test (org.junit.Test)3 KeyValueEntity (com.haulmont.cuba.core.entity.KeyValueEntity)2 AppBeans (com.haulmont.cuba.core.global.AppBeans)2 BeanValidation (com.haulmont.cuba.core.global.BeanValidation)2 Metadata (com.haulmont.cuba.core.global.Metadata)2 Op (com.haulmont.cuba.core.global.filter.Op)2 OpManager (com.haulmont.cuba.core.global.filter.OpManager)2 BeanValidator (com.haulmont.cuba.gui.components.validators.BeanValidator)2 TestNotPersistentEntity (com.haulmont.cuba.testmodel.TestNotPersistentEntity)2 Collection (java.util.Collection)2 BeanDescriptor (javax.validation.metadata.BeanDescriptor)2 Joiner (com.google.common.base.Joiner)1 Datatype (com.haulmont.chile.core.datatypes.Datatype)1 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)1 Entity (com.haulmont.cuba.core.entity.Entity)1 Folder (com.haulmont.cuba.core.entity.Folder)1