use of com.haulmont.cuba.core.global.Metadata in project cuba by cuba-platform.
the class DynamicAttributeCustomFieldGenerator method generateField.
@Override
public Component generateField(Datasource datasource, String propertyId) {
ComponentsFactory componentsFactory = AppBeans.get(ComponentsFactory.class);
ListEditor listEditor = componentsFactory.createComponent(ListEditor.class);
MetaPropertyPath metaPropertyPath = DynamicAttributesUtils.getMetaPropertyPath(datasource.getMetaClass(), propertyId);
if (metaPropertyPath == null) {
log.error("MetaPropertyPath for dynamic attribute {} not found", propertyId);
return null;
}
CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaPropertyPath.getMetaProperty());
if (categoryAttribute == null) {
log.error("Dynamic attribute {} not found", propertyId);
return null;
}
listEditor.setEntityJoinClause(categoryAttribute.getJoinClause());
listEditor.setEntityWhereClause(categoryAttribute.getWhereClause());
ListEditor.ItemType itemType = listEditorItemTypeFromDynamicAttrType(categoryAttribute.getDataType());
listEditor.setItemType(itemType);
Metadata metadata = AppBeans.get(Metadata.class);
Scripting scripting = AppBeans.get(Scripting.class);
if (!Strings.isNullOrEmpty(categoryAttribute.getEntityClass())) {
Class<?> clazz = scripting.loadClass(categoryAttribute.getEntityClass());
if (clazz == null) {
log.error("Unable to find class of entity {} for dynamic attribute {}", categoryAttribute.getEntityClass(), categoryAttribute.getCode());
return null;
}
MetaClass metaClass = metadata.getClassNN(clazz);
listEditor.setEntityName(metaClass.getName());
listEditor.setUseLookupField(BooleanUtils.isTrue(categoryAttribute.getLookup()));
}
// noinspection unchecked
datasource.addStateChangeListener(e -> {
if (e.getState() == Datasource.State.VALID) {
Object value = datasource.getItem().getValue(propertyId);
if (value != null && value instanceof Collection) {
listEditor.setValue(value);
}
}
});
listEditor.addValueChangeListener(e -> {
datasource.getItem().setValue(propertyId, e.getValue());
});
listEditor.setWidthFull();
return listEditor;
}
use of com.haulmont.cuba.core.global.Metadata in project cuba by cuba-platform.
the class FilteringLookupAction method applyFilter.
protected void applyFilter(Filter filterComponent) {
Metadata metadata = AppBeans.get(Metadata.class);
FilterEntity filterEntity = metadata.create(FilterEntity.class);
filterEntity.setComponentId(ComponentsHelper.getFilterComponentPath(filterComponent));
filterEntity.setName(messages.getMainMessage("dynamicAttributes.entity.filter"));
filterEntity.setXml(createFilterXml(filterComponent));
filterEntity.setUser(userSession.getCurrentOrSubstitutedUser());
filterComponent.setFilterEntity(filterEntity);
filterComponent.apply(true);
}
use of com.haulmont.cuba.core.global.Metadata in project cuba by cuba-platform.
the class FetchJoinTest method setUp.
@Before
public void setUp() throws Exception {
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
Metadata metadata = cont.metadata();
joinF = metadata.create(JoinF.class);
joinF.setName("joinF");
em.persist(joinF);
joinD = metadata.create(JoinD.class);
joinD.setName("joinD");
em.persist(joinD);
joinE = metadata.create(JoinE.class);
joinE.setName("joinE");
joinE.setF(joinF);
em.persist(joinE);
joinC = metadata.create(JoinC.class);
joinC.setName("joinC");
joinC.setD(joinD);
joinC.setE(joinE);
em.persist(joinC);
joinB = metadata.create(JoinB.class);
joinB.setName("joinB");
joinB.setC(joinC);
em.persist(joinB);
joinA = metadata.create(JoinA.class);
joinA.setName("joinA");
joinA.setB(joinB);
em.persist(joinA);
product = metadata.create(Product.class);
product.setName("Product");
em.persist(product);
partyCustomer = metadata.create(Party.class);
partyCustomer.setName("Customer");
em.persist(partyCustomer);
partyPerson = metadata.create(Party.class);
partyPerson.setName("Person");
em.persist(partyPerson);
customer = metadata.create(Customer.class);
customer.setParty(partyCustomer);
customer.setCustomerNumber(1);
em.persist(customer);
salesPerson = metadata.create(SalesPerson.class);
salesPerson.setParty(partyPerson);
salesPerson.setSalespersonNumber(1);
em.persist(salesPerson);
order = metadata.create(Order.class);
order.setOrderNumber(1);
order.setOrderAmount(BigDecimal.ONE);
order.setCustomer(customer);
order.setSalesPerson(salesPerson);
em.persist(order);
orderLine = metadata.create(OrderLine.class);
orderLine.setOrder(order);
orderLine.setProduct(product);
orderLine.setQuantity(1);
em.persist(orderLine);
tx.commit();
} finally {
tx.end();
}
}
use of com.haulmont.cuba.core.global.Metadata in project cuba by cuba-platform.
the class DesktopTokenList method isInversePropertyAssignableFromDsClass.
protected boolean isInversePropertyAssignableFromDsClass(MetaProperty inverseProp) {
Metadata metadata = AppBeans.get(Metadata.NAME);
ExtendedEntities extendedEntities = metadata.getExtendedEntities();
Class inversePropClass = extendedEntities.getEffectiveClass(inverseProp.getDomain());
Class dsClass = extendedEntities.getEffectiveClass(datasource.getMetaClass());
// noinspection unchecked
return inversePropClass.isAssignableFrom(dsClass);
}
use of com.haulmont.cuba.core.global.Metadata in project cuba by cuba-platform.
the class CascadeDeleteTest method setUp.
@Before
public void setUp() throws Exception {
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
Metadata metadata = cont.metadata();
root = metadata.create(CascadeEntity.class);
root.setName("root");
em.persist(root);
first = metadata.create(CascadeEntity.class);
first.setName("first");
first.setFather(root);
em.persist(first);
second = metadata.create(CascadeEntity.class);
second.setName("second");
second.setFather(first);
em.persist(second);
third = metadata.create(CascadeEntity.class);
third.setName("third");
third.setFather(second);
em.persist(third);
tx.commit();
} finally {
tx.end();
}
}
Aggregations