use of io.jmix.core.Entity in project jmix by jmix-framework.
the class HierarchicalPropertyDatasourceImpl method getChildren.
@SuppressWarnings("unchecked")
@Override
public Collection<K> getChildren(K itemId) {
if (hierarchyPropertyName != null) {
Entity item = getItem(itemId);
if (item == null) {
return Collections.emptyList();
}
List<K> res = new ArrayList<>();
Collection<K> ids = getItemIds();
for (K id : ids) {
Entity currentItem = getItemNN(id);
Object parentItem = EntityValues.getValue(currentItem, hierarchyPropertyName);
if (parentItem != null && parentItem.equals(item))
res.add((K) EntityValues.getId(currentItem));
}
if (StringUtils.isNotBlank(sortPropertyName)) {
res.sort((o1, o2) -> {
Entity item1 = getItemNN(o1);
Entity item2 = getItemNN(o2);
Object value1 = EntityValues.getValue(item1, sortPropertyName);
Object value2 = EntityValues.getValue(item2, sortPropertyName);
if ((value1 instanceof Comparable) && (value2 instanceof Comparable)) {
return ((Comparable) value1).compareTo(value2);
}
return 0;
});
}
return res;
}
return Collections.emptyList();
}
use of io.jmix.core.Entity in project jmix by jmix-framework.
the class PropertyDatasourceImpl method committed.
@Override
public void committed(Set<Entity> entities) {
Entity parentItem = masterDs.getItem();
T prevItem = getItem();
T newItem = null;
for (Entity entity : entities) {
if (entity.equals(prevItem)) {
// noinspection unchecked
newItem = (T) entity;
break;
}
}
// If committed set contains previousItem
if ((parentItem != null) && newItem != null) {
// Value changed
boolean isModified = masterDs.isModified();
EntityValues.setValue(parentItem, metaProperty.getName(), newItem, false);
detachListener(prevItem);
attachListener(newItem);
fireItemChanged(prevItem);
((DatasourceImplementation) masterDs).setModified(isModified);
} else {
if (parentItem != null) {
Entity newParentItem = null;
Entity previousParentItem = null;
// Find previous and new parent items
Iterator<Entity> commitIter = entities.iterator();
while (commitIter.hasNext() && (previousParentItem == null) && (newParentItem == null)) {
Entity commitItem = commitIter.next();
if (commitItem.equals(parentItem)) {
previousParentItem = parentItem;
newParentItem = commitItem;
}
}
if (previousParentItem != null) {
detachListener(getItem(previousParentItem));
}
if (newParentItem != null) {
attachListener(getItem(newParentItem));
}
}
}
modified = false;
clearCommitLists();
}
use of io.jmix.core.Entity in project jmix by jmix-framework.
the class PropertyDatasourceImpl method initParentDsListeners.
@SuppressWarnings("unchecked")
protected void initParentDsListeners() {
masterDs.addItemChangeListener(e -> {
Entity prevValue = getItem(e.getPrevItem());
Entity newValue = getItem(e.getItem());
reattachListeners(prevValue, newValue);
fireItemChanged((T) prevValue);
});
masterDs.addStateChangeListener(e -> fireStateChanged(e.getPrevState()));
masterDs.addItemPropertyChangeListener(e -> {
if (e.getProperty().equals(metaProperty.getName()) && !Objects.equals(e.getPrevValue(), e.getValue())) {
reattachListeners((Entity) e.getPrevValue(), (Entity) e.getValue());
fireItemChanged((T) e.getPrevValue());
}
});
}
use of io.jmix.core.Entity in project jmix by jmix-framework.
the class PropertyDatasourceImpl method setItem.
@Override
public void setItem(T item) {
if (getItem() != null) {
metadata.getTools().copy(item, getItem());
itemsToUpdate.add(item);
} else {
final Entity parentItem = masterDs.getItem();
EntityValues.setValue(parentItem, metaProperty.getName(), item);
}
setModified(true);
}
use of io.jmix.core.Entity in project jmix by jmix-framework.
the class RuntimePropsDatasourceImpl method committed.
@Override
public void committed(Set<Entity> entities) {
if (!State.VALID.equals(state)) {
return;
}
for (Entity entity : entities) {
if (entity.equals(mainDs.getItem())) {
initMetaClass(entity);
}
}
modified = false;
clearCommitLists();
}
Aggregations