Search in sources :

Example 71 with Entity

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));
                    }
                }
            }
        }
    }
}
Also used : java.util(java.util) Datasource(com.haulmont.cuba.gui.data.Datasource) PropertyDatasource(com.haulmont.cuba.gui.data.PropertyDatasource) Preconditions(io.jmix.core.common.util.Preconditions) LinkedMap(org.apache.commons.collections4.map.LinkedMap) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) ArrayUtils(org.apache.commons.lang3.ArrayUtils) Collectors(java.util.stream.Collectors) EntityValues(io.jmix.core.entity.EntityValues) CollectionUtils(org.apache.commons.collections4.CollectionUtils) GroupInfo(io.jmix.ui.component.data.GroupInfo) ImmutableList(com.google.common.collect.ImmutableList) GroupDatasource(com.haulmont.cuba.gui.data.GroupDatasource) Entity(io.jmix.core.Entity) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) GroupInfo(io.jmix.ui.component.data.GroupInfo) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) ImmutableList(com.google.common.collect.ImmutableList) LinkedMap(org.apache.commons.collections4.map.LinkedMap)

Example 72 with 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();
}
Also used : Entity(io.jmix.core.Entity)

Example 73 with Entity

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);
}
Also used : Entity(io.jmix.core.Entity)

Example 74 with Entity

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());
}
Also used : Entity(io.jmix.core.Entity) Server(com.haulmont.cuba.core.model.common.Server) CommitContext(com.haulmont.cuba.core.global.CommitContext) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) Test(org.junit.jupiter.api.Test)

Example 75 with Entity

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);
}
Also used : Entity(io.jmix.core.Entity) Server(com.haulmont.cuba.core.model.common.Server) CommitContext(com.haulmont.cuba.core.global.CommitContext) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) Test(org.junit.jupiter.api.Test)

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