use of com.qcadoo.view.internal.components.FieldComponentState in project qcadoo by qcadoo.
the class FormComponentState method copyFieldMessages.
private void copyFieldMessages(final EntityMessagesHolder messagesHolder) {
for (Map.Entry<String, FieldComponentState> fieldComponentEntry : getFieldComponents().entrySet()) {
ErrorMessage message = messagesHolder.getError(fieldComponentEntry.getKey());
copyMessage(fieldComponentEntry.getValue(), message);
}
}
use of com.qcadoo.view.internal.components.FieldComponentState 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.view.internal.components.FieldComponentState in project qcadoo by qcadoo.
the class FormComponentStateTest method init.
@Before
public void init() throws Exception {
entity = mock(Entity.class);
given(entity.getField("name")).willReturn("text");
viewDefinitionState = mock(ViewDefinitionState.class);
translationService = mock(TranslationService.class);
fieldDefinition = mock(FieldDefinition.class);
given(fieldDefinition.getType()).willReturn(new StringType());
given(fieldDefinition.getName()).willReturn("name");
dataDefinition = mock(DataDefinition.class, RETURNS_DEEP_STUBS);
given(dataDefinition.get(12L)).willReturn(null);
given(dataDefinition.get(13L)).willReturn(entity);
given(dataDefinition.getPluginIdentifier()).willReturn("plugin");
given(dataDefinition.getName()).willReturn("name");
given(dataDefinition.getField("name")).willReturn(fieldDefinition);
given(dataDefinition.delete(any(Long.class))).willReturn(EntityOpResult.successfull());
given(dataDefinition.create(anyLong())).willAnswer(new Answer<Entity>() {
@Override
public Entity answer(final InvocationOnMock invocation) throws Throwable {
Long id = (Long) invocation.getArguments()[0];
return new DefaultEntity(dataDefinition, id);
}
});
FieldComponentPattern namePattern = mock(FieldComponentPattern.class);
given(namePattern.isRequired()).willReturn(false);
given(namePattern.isPersistent()).willReturn(true);
name = new FieldComponentState(namePattern);
name.setTranslationService(translationService);
name.setName("name");
name.initialize(new JSONObject(), Locale.ENGLISH);
FormComponentPattern pattern = mock(FormComponentPattern.class);
given(pattern.getExpressionNew()).willReturn(null);
given(pattern.getExpressionEdit()).willReturn("'static expression'");
applicationContext = mock(ApplicationContext.class);
setField(pattern, "applicationContext", applicationContext);
SecurityRolesService securityRolesService = mock(SecurityRolesService.class);
given(applicationContext.getBean(SecurityRolesService.class)).willReturn(securityRolesService);
form = new FormComponentState(pattern);
form.setDataDefinition(dataDefinition);
form.setTranslationService(translationService);
form.addFieldEntityIdChangeListener("name", name);
form.initialize(new JSONObject(ImmutableMap.of("components", new JSONObject())), Locale.ENGLISH);
new ExpressionServiceImpl().init();
}
use of com.qcadoo.view.internal.components.FieldComponentState in project qcadoo by qcadoo.
the class FormComponentState method setFormEnabled.
@Override
public void setFormEnabled(final boolean enabled) {
for (Map.Entry<String, FieldComponentState> field : getFieldComponents().entrySet()) {
FieldDefinition fieldDefinition = getDataDefinition().getField(field.getKey());
if (!(fieldDefinition.isReadOnly())) {
field.getValue().setEnabled(enabled);
field.getValue().requestComponentUpdateState();
}
}
setEnabled(enabled);
}
Aggregations