Search in sources :

Example 76 with Entity

use of com.haulmont.cuba.core.entity.Entity in project cuba by cuba-platform.

the class TableModelAdapter method setValueAt.

@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
    Table.Column column = columns.get(columnIndex);
    if (!column.isEditable())
        return;
    if (generatedColumns.contains(column))
        return;
    Object id = getItemId(rowIndex);
    Entity item = datasource.getItem(id);
    if (column.getId() instanceof MetaPropertyPath) {
        String property = column.getId().toString();
        item.setValueEx(property, aValue);
    }
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) Table(com.haulmont.cuba.gui.components.Table) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath)

Example 77 with Entity

use of com.haulmont.cuba.core.entity.Entity in project cuba by cuba-platform.

the class TableModelAdapter method getRowIndex.

@Override
public int getRowIndex(Entity entity) {
    int idx = 0;
    if (entity != null) {
        if (datasource instanceof CollectionDatasource.Ordered) {
            Object id = ((CollectionDatasource.Ordered) datasource).firstItemId();
            while (id != null) {
                if (entity.equals(datasource.getItem(id)))
                    return idx;
                id = ((CollectionDatasource.Ordered) datasource).nextItemId(id);
                idx++;
            }
        } else {
            for (Entity item : datasource.getItems()) {
                if (entity.equals(item))
                    return idx;
                idx++;
            }
        }
    }
    return -1;
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource)

Example 78 with Entity

use of com.haulmont.cuba.core.entity.Entity in project cuba by cuba-platform.

the class TreeModelAdapter method isLeaf.

@Override
public boolean isLeaf(Object node) {
    if (node == rootNode) {
        return false;
    } else {
        Entity entity = ((Node) node).getEntity();
        Collection<Object> childrenIds = datasource.getChildren(entity.getId());
        return childrenIds.size() == 0;
    }
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity)

Example 79 with Entity

use of com.haulmont.cuba.core.entity.Entity in project cuba by cuba-platform.

the class TreeModelAdapter method getIndexOfChild.

@Override
public int getIndexOfChild(Object parent, Object child) {
    if (parent == null || child == null)
        return -1;
    Collection<Object> childrenIds;
    if (parent == rootNode) {
        childrenIds = datasource.getRootItemIds();
    } else {
        Entity entity = ((Node) parent).getEntity();
        childrenIds = datasource.getChildren(entity.getId());
    }
    final Entity childEntity = ((Node) child).getEntity();
    return Iterables.indexOf(childrenIds, id -> childEntity.getId().equals(id));
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity)

Example 80 with Entity

use of com.haulmont.cuba.core.entity.Entity in project cuba by cuba-platform.

the class DataManagerTest method testLoadListById.

@Test
public void testLoadListById() {
    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);
    List<Server> list = dataManager.loadList(loadContext);
    assertTrue(list.size() == 1);
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) Server(com.haulmont.cuba.core.entity.Server) Test(org.junit.Test)

Aggregations

Entity (com.haulmont.cuba.core.entity.Entity)203 MetaClass (com.haulmont.chile.core.model.MetaClass)51 MetaProperty (com.haulmont.chile.core.model.MetaProperty)44 BaseGenericIdEntity (com.haulmont.cuba.core.entity.BaseGenericIdEntity)40 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)18 Test (org.junit.Test)15 Inject (javax.inject.Inject)14 java.util (java.util)12 EntityManager (com.haulmont.cuba.core.EntityManager)11 ParseException (java.text.ParseException)11 Element (org.dom4j.Element)11 Logger (org.slf4j.Logger)11 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)10 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)9 LoggerFactory (org.slf4j.LoggerFactory)9 Query (com.haulmont.cuba.core.Query)8 Server (com.haulmont.cuba.core.entity.Server)8 Transaction (com.haulmont.cuba.core.Transaction)7 Datasource (com.haulmont.cuba.gui.data.Datasource)7 Collectors (java.util.stream.Collectors)7