use of io.jmix.core.Entity in project jmix by jmix-framework.
the class GroupDelegate method doGroupSort.
protected void doGroupSort(CollectionDatasource.Sortable.SortInfo<MetaPropertyPath>[] sortInfo) {
if (hasGroups()) {
MetaPropertyPath propertyPath = sortInfo[0].getPropertyPath();
int index = ArrayUtils.indexOf(groupProperties, propertyPath);
if (index > -1) {
if (index == 0) {
// Sort roots
groupSortDelegate.sortGroups(roots, sortInfo);
} else {
Object parentProperty = groupProperties[index - 1];
for (Map.Entry<GroupInfo, List<GroupInfo>> entry : children.entrySet()) {
Object property = entry.getKey().getProperty();
if (property.equals(parentProperty)) {
groupSortDelegate.sortGroups(entry.getValue(), sortInfo);
}
}
}
} else {
Set<GroupInfo> groups = parents.keySet();
for (GroupInfo groupInfo : groups) {
List<K> items = groupItems.get(groupInfo);
if (items != null) {
List<T> entities = items.stream().map(item -> datasource.getItem(item)).collect(Collectors.toList());
sortDelegate.sort(entities, sortInfo);
items.clear();
for (T entity : entities) {
items.add((K) EntityValues.getId(entity));
}
}
}
}
}
}
use of io.jmix.core.Entity in project jmix by jmix-framework.
the class DatasourceImpl method committed.
@Override
public void committed(Set<Entity> entities) {
if (!State.VALID.equals(state)) {
return;
}
for (Entity entity : entities) {
if (entity.equals(item)) {
detachListener(item);
T prevItem = item;
item = (T) entity;
attachListener(item);
fireItemChanged(prevItem);
}
}
modified = false;
clearCommitLists();
}
use of io.jmix.core.Entity in project jmix by jmix-framework.
the class DsContextImpl method registerDependency.
@Override
public void registerDependency(Datasource datasource, Datasource dependFrom, String propertyName) {
Datasource ds = dependencies.get(datasource);
if (ds != null) {
if (ds.equals(dependFrom)) {
return;
} else {
throw new UnsupportedOperationException("Datasource couldn't depend from two different sources");
}
}
// noinspection unchecked
dependFrom.addItemChangeListener(e -> {
if (datasource.getState() == Datasource.State.VALID) {
datasource.refresh();
}
});
if (dependFrom instanceof CollectionDatasource) {
// noinspection unchecked
((CollectionDatasource) dependFrom).addCollectionChangeListener(e -> {
if (e.getOperation() == CollectionDatasource.Operation.REFRESH) {
datasource.refresh();
}
});
}
// noinspection unchecked
dependFrom.addItemPropertyChangeListener(e -> {
if (propertyName != null) {
// parameter can use a property path with more than one element, e.g. :ds$driversDs.status.id,
// but we should listen the first level property
String listeningProperty = propertyName.split("\\.")[0];
if (listeningProperty.equals(e.getProperty())) {
final Entity item = Datasource.State.VALID.equals(dependFrom.getState()) ? dependFrom.getItem() : null;
if (Objects.equals(item, e.getItem())) {
datasource.refresh();
}
}
}
});
dependencies.put(datasource, dependFrom);
}
use of io.jmix.core.Entity in project jmix by jmix-framework.
the class DataManagerTest method testLoad.
@Test
public void testLoad() {
Server server = new Server();
UUID id = server.getId();
server.setName("localhost");
server.setRunning(true);
dataManager.commit(new CommitContext(Collections.<Entity>singleton(server)));
LoadContext<Server> loadContext = LoadContext.create(Server.class).setId(id);
server = dataManager.load(loadContext);
assertEquals("localhost", server.getName());
}
use of io.jmix.core.Entity in project jmix by jmix-framework.
the class DataManagerTest method testLoadListCaseInsensitive.
@Test
public void testLoadListCaseInsensitive() {
Server server = new Server();
server.setName("LocalHost");
server.setRunning(true);
dataManager.commit(new CommitContext(Collections.<Entity>singleton(server)));
LoadContext<Server> loadContext = LoadContext.create(Server.class);
loadContext.setQueryString("select s from test$Server s where s.name like :name").setParameter("name", "(?i)%loc%host%");
List<Server> list = dataManager.loadList(loadContext);
assertTrue(list.size() > 0);
}
Aggregations