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();
}
}
}
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);
}
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());
}
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());
}
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());
}
}
Aggregations