Search in sources :

Example 1 with EntityTree

use of com.qcadoo.model.api.EntityTree in project qcadoo by qcadoo.

the class FormComponentState method copyEntityToFields.

private void copyEntityToFields(final Entity entity, final boolean requestUpdateState) {
    for (Map.Entry<String, FieldComponentState> field : getFieldComponents().entrySet()) {
        ErrorMessage message = entity.getError(field.getKey());
        copyMessage(field.getValue(), message);
        if (fieldIsGridCorrespondingLookup(field.getValue(), field.getKey(), entity)) {
            continue;
        }
        if (fieldIsDetachedEntityTree(field.getValue(), field.getKey(), entity)) {
            EntityTree tree = entity.getTreeField(field.getKey());
            if (tree != null) {
                ((TreeComponentState) field.getValue()).setRootNode(tree.getRoot());
            }
        }
        field.getValue().setFieldValue(convertFieldToString(entity.getField(field.getKey()), field.getKey()));
        if (requestUpdateState) {
            field.getValue().requestComponentUpdateState();
        }
    }
}
Also used : FieldComponentState(com.qcadoo.view.internal.components.FieldComponentState) TreeComponentState(com.qcadoo.view.internal.components.tree.TreeComponentState) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) HashMap(java.util.HashMap) Map(java.util.Map) EntityTree(com.qcadoo.model.api.EntityTree)

Example 2 with EntityTree

use of com.qcadoo.model.api.EntityTree in project qcadoo by qcadoo.

the class DetachedEntityTreeImplTest method shouldReturnTreeItem.

@Test
public final void shouldReturnTreeItem() throws Exception {
    // given
    Entity entity1 = mock(Entity.class);
    Entity entity2 = mock(Entity.class);
    Entity entity3 = mock(Entity.class);
    when(entity1.getId()).thenReturn(1L);
    when(entity2.getId()).thenReturn(2L);
    when(entity3.getId()).thenReturn(3L);
    when(entity1.getField("parent")).thenReturn(null);
    when(entity2.getField("parent")).thenReturn(1L);
    when(entity3.getField("parent")).thenReturn(2L);
    when(entity1.getBelongsToField("parent")).thenReturn(null);
    when(entity2.getBelongsToField("parent")).thenReturn(entity1);
    when(entity3.getBelongsToField("parent")).thenReturn(entity2);
    EntityTree tree = new DetachedEntityTreeImpl(Lists.newArrayList(entity1, entity2, entity3));
    // when
    Entity res1 = tree.get(0);
    Entity res2 = tree.get(1);
    Entity res3 = tree.get(2);
    // then
    Assert.assertEquals(entity1, res1);
    Assert.assertEquals(entity2, res2);
    Assert.assertEquals(entity3, res3);
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityTree(com.qcadoo.model.api.EntityTree) Test(org.junit.Test)

Example 3 with EntityTree

use of com.qcadoo.model.api.EntityTree in project qcadoo by qcadoo.

the class DetachedEntityTreeImplTest method shouldBeEmptyIfEntitiesIsEmpty.

@Test
public void shouldBeEmptyIfEntitiesIsEmpty() throws Exception {
    // when
    EntityTree tree = new DetachedEntityTreeImpl(new ArrayList<Entity>());
    // then
    assertTrue(tree.isEmpty());
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityTree(com.qcadoo.model.api.EntityTree) Test(org.junit.Test)

Example 4 with EntityTree

use of com.qcadoo.model.api.EntityTree in project qcadoo by qcadoo.

the class EntityTreeUtilsServiceTest method shouldReturnDetachedEntityTree.

@Test
public final void shouldReturnDetachedEntityTree() throws Exception {
    // given
    Entity rootEntity = mockEntityTreeNode(null, 1, "1");
    // when
    EntityTree entityTree = EntityTreeUtilsService.getDetachedEntityTree(Lists.newArrayList(rootEntity));
    // then
    Assert.assertEquals(entityTree.getRoot(), rootEntity);
    Assert.assertEquals(1, entityTree.size());
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityTree(com.qcadoo.model.api.EntityTree) Test(org.junit.Test)

Example 5 with EntityTree

use of com.qcadoo.model.api.EntityTree in project qcadoo by qcadoo.

the class TreeComponentState method reload.

private void reload() {
    if (belongsToEntityId == null) {
        return;
    }
    Entity entity = belongsToFieldDefinition.getDataDefinition().get(belongsToEntityId);
    EntityTree tree = entity.getTreeField(belongsToFieldDefinition.getName());
    if (tree == null || tree.getRoot() == null) {
        return;
    }
    rootNode = createNode(tree.getRoot(), Lists.newLinkedList(Lists.newArrayList(INITIAL_NODE_NUMBER_VALUE)));
    if (openedNodes == null) {
        addOpenedNode(rootNode.getId());
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityTree(com.qcadoo.model.api.EntityTree)

Aggregations

EntityTree (com.qcadoo.model.api.EntityTree)52 Entity (com.qcadoo.model.api.Entity)44 Test (org.junit.Test)14 DataDefinition (com.qcadoo.model.api.DataDefinition)10 FormComponent (com.qcadoo.view.api.components.FormComponent)10 BigDecimal (java.math.BigDecimal)8 Map (java.util.Map)7 EntityList (com.qcadoo.model.api.EntityList)6 List (java.util.List)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 Service (org.springframework.stereotype.Service)6 EntityTreeNode (com.qcadoo.model.api.EntityTreeNode)5 WindowComponent (com.qcadoo.view.api.components.WindowComponent)4 Set (java.util.Set)4 Sets (com.google.common.collect.Sets)3 ProductQuantitiesService (com.qcadoo.mes.technologies.ProductQuantitiesService)3 Date (java.util.Date)3 Locale (java.util.Locale)3 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2