Search in sources :

Example 91 with Entity

use of io.jmix.core.Entity in project jmix by jmix-framework.

the class CaptionAdapter method apply.

@Override
public String apply(Object entity) {
    if (!(entity instanceof Entity)) {
        return "";
    }
    if (captionProperty != null) {
        MetaClass entityMetaClass;
        if (entity instanceof KeyValueEntity) {
            entityMetaClass = ((KeyValueEntity) entity).getInstanceMetaClass();
        } else {
            entityMetaClass = metadata.getClass(entity);
        }
        if (entityMetaClass.getPropertyPath(captionProperty) == null) {
            throw new IllegalArgumentException(String.format("Couldn't find property with name '%s'", captionProperty));
        }
        Object propertyValue = EntityValues.getValueEx(entity, captionProperty);
        return propertyValue != null ? propertyValue.toString() : " ";
    }
    return metadataTools.getInstanceName(entity);
}
Also used : KeyValueEntity(io.jmix.core.entity.KeyValueEntity) Entity(io.jmix.core.Entity) MetaClass(io.jmix.core.metamodel.model.MetaClass) KeyValueEntity(io.jmix.core.entity.KeyValueEntity)

Example 92 with Entity

use of io.jmix.core.Entity in project jmix by jmix-framework.

the class ContainerDataProvider method fireCollectionChangeListener.

protected void fireCollectionChangeListener(DataChangeOperation operation, Collection changedItems) {
    List<DataItem> dataItems;
    if (!changedItems.isEmpty()) {
        dataItems = new ArrayList<>();
        for (Object object : changedItems) {
            Entity entity = (Entity) object;
            dataItems.add(new EntityDataItem(entity));
        }
    } else {
        dataItems = Collections.emptyList();
    }
    DataItemsChangeEvent dataItemsChangeEvent = new DataItemsChangeEvent(operation, dataItems);
    for (DataChangeListener listener : new ArrayList<>(changeListeners)) {
        listener.dataItemsChanged(dataItemsChangeEvent);
    }
}
Also used : Entity(io.jmix.core.Entity) ArrayList(java.util.ArrayList)

Example 93 with Entity

use of io.jmix.core.Entity in project jmix by jmix-framework.

the class ContainerDataProvider method getItems.

@Override
public List<DataItem> getItems() {
    List<DataItem> dataItems = new ArrayList<>(dataContainer.getItems().size());
    for (Object object : dataContainer.getItems()) {
        Entity entity = (Entity) object;
        dataItems.add(new EntityDataItem(entity));
    }
    return dataItems;
}
Also used : Entity(io.jmix.core.Entity) ArrayList(java.util.ArrayList)

Example 94 with Entity

use of io.jmix.core.Entity in project jmix by jmix-framework.

the class AbstractComparator method compareAsc.

protected int compareAsc(@Nullable Object o1, @Nullable Object o2) {
    int c;
    if (o1 instanceof String && o2 instanceof String) {
        c = ((String) o1).compareToIgnoreCase((String) o2);
    } else if (o1 instanceof Comparable && o2 instanceof Comparable) {
        c = ((Comparable) o1).compareTo(o2);
    } else if (o1 instanceof Entity && o2 instanceof Entity) {
        MetaClass metaClass = metadata.getClass(o1.getClass());
        Collection<MetaProperty> namePatternProperties = metadataTools.getInstanceNameRelatedProperties(metaClass, true);
        if (namePatternProperties.isEmpty()) {
            String instanceName1 = metadataTools.getInstanceName(o1);
            String instanceName2 = metadataTools.getInstanceName(o2);
            c = instanceName1.compareToIgnoreCase(instanceName2);
        } else {
            c = 0;
            for (MetaProperty property : namePatternProperties) {
                Object v1 = EntityValues.getValue(o1, property.getName());
                Object v2 = EntityValues.getValue(o2, property.getName());
                c = compareAsc(v1, v2);
                if (c != 0)
                    break;
            }
        }
    } else if (Objects.equals(o1, o2)) {
        c = 0;
    } else if (o1 == null && o2 != null) {
        c = nullsLast;
    } else {
        c = -nullsLast;
    }
    return c;
}
Also used : Entity(io.jmix.core.Entity) MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Aggregations

Entity (io.jmix.core.Entity)94 MetaClass (io.jmix.core.metamodel.model.MetaClass)20 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)18 CommitContext (com.haulmont.cuba.core.global.CommitContext)10 CoreTest (com.haulmont.cuba.core.testsupport.CoreTest)10 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)10 Test (org.junit.jupiter.api.Test)10 Server (com.haulmont.cuba.core.model.common.Server)8 Datasource (com.haulmont.cuba.gui.data.Datasource)8 Collectors (java.util.stream.Collectors)8 Autowired (org.springframework.beans.factory.annotation.Autowired)8 FetchPlan (io.jmix.core.FetchPlan)7 Logger (org.slf4j.Logger)7 Metadata (io.jmix.core.Metadata)6 MetadataTools (io.jmix.core.MetadataTools)6 EntityValues (io.jmix.core.entity.EntityValues)6 java.util (java.util)6 ArrayList (java.util.ArrayList)6 Nullable (javax.annotation.Nullable)6 LoggerFactory (org.slf4j.LoggerFactory)6