Search in sources :

Example 16 with Metadata

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;
}
Also used : ComponentsFactory(com.haulmont.cuba.gui.xml.layout.ComponentsFactory) ListEditor(com.haulmont.cuba.gui.components.ListEditor) CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) Metadata(com.haulmont.cuba.core.global.Metadata) Collection(java.util.Collection) Scripting(com.haulmont.cuba.core.global.Scripting)

Example 17 with Metadata

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);
}
Also used : FilterEntity(com.haulmont.cuba.security.entity.FilterEntity) Metadata(com.haulmont.cuba.core.global.Metadata)

Example 18 with Metadata

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();
    }
}
Also used : Metadata(com.haulmont.cuba.core.global.Metadata) EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction) Before(org.junit.Before)

Example 19 with Metadata

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);
}
Also used : ExtendedEntities(com.haulmont.cuba.core.global.ExtendedEntities) Metadata(com.haulmont.cuba.core.global.Metadata)

Example 20 with Metadata

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();
    }
}
Also used : EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction) Metadata(com.haulmont.cuba.core.global.Metadata) CascadeEntity(com.haulmont.cuba.testmodel.cascadedelete.CascadeEntity) Before(org.junit.Before)

Aggregations

Metadata (com.haulmont.cuba.core.global.Metadata)25 MetaClass (com.haulmont.chile.core.model.MetaClass)6 PostConstruct (javax.annotation.PostConstruct)3 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)2 EntityManager (com.haulmont.cuba.core.EntityManager)2 Transaction (com.haulmont.cuba.core.Transaction)2 AppBeans (com.haulmont.cuba.core.global.AppBeans)2 ExtendedEntities (com.haulmont.cuba.core.global.ExtendedEntities)2 MetadataTools (com.haulmont.cuba.core.global.MetadataTools)2 FilterEntity (com.haulmont.cuba.security.entity.FilterEntity)2 Collection (java.util.Collection)2 Before (org.junit.Before)2 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)1 Config (com.haulmont.cuba.core.entity.Config)1 Entity (com.haulmont.cuba.core.entity.Entity)1 ReferenceToEntity (com.haulmont.cuba.core.entity.ReferenceToEntity)1 Messages (com.haulmont.cuba.core.global.Messages)1 Scripting (com.haulmont.cuba.core.global.Scripting)1 View (com.haulmont.cuba.core.global.View)1 ViewRepository (com.haulmont.cuba.core.global.ViewRepository)1