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()));
}
}
}
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;
}
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;
}
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)));
}
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));
}
Aggregations