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