use of com.qcadoo.view.internal.components.form.FormComponentState in project qcadoo by qcadoo.
the class AwesomeDynamicListState method setFieldValue.
@SuppressWarnings("unchecked")
@Override
public void setFieldValue(final Object value) {
requestRender();
forms = new LinkedList<>();
if (value instanceof List) {
List<Entity> entities = (List<Entity>) value;
for (Entity entity : entities) {
InternalViewDefinitionState innerFormState = new ViewDefinitionStateImpl();
FormComponentState formState = (FormComponentState) innerFormPattern.createComponentState(innerFormState);
innerFormPattern.updateComponentStateListeners(innerFormState);
try {
formState.initialize(new JSONObject(), getLocale());
} catch (JSONException e) {
throw new IllegalStateException(e);
}
formState.setEntity(entity);
forms.add(formState);
}
}
}
use of com.qcadoo.view.internal.components.form.FormComponentState in project qcadoo by qcadoo.
the class AwesomeDynamicListState method initializeContent.
@Override
protected void initializeContent(final JSONObject json) throws JSONException {
if (json.has(JSON_FORM_VALUES)) {
forms = new LinkedList<>();
JSONArray formValues = json.getJSONArray(JSON_FORM_VALUES);
for (int i = 0; i < formValues.length(); i++) {
JSONObject value = formValues.getJSONObject(i);
String formName = value.getString("name");
JSONObject formValue = value.getJSONObject("value");
InternalViewDefinitionState innerFormState = new ViewDefinitionStateImpl();
FormComponentState formState = (FormComponentState) innerFormPattern.createComponentState(innerFormState);
formState.setName(formName);
innerFormPattern.updateComponentStateListeners(innerFormState);
formState.initialize(formValue, getLocale());
forms.add(formState);
}
}
}
use of com.qcadoo.view.internal.components.form.FormComponentState in project qcadoo by qcadoo.
the class ComponentStateTest method shouldHaveRequestUpdateStateFlag.
@Test
public void shouldHaveRequestUpdateStateFlag() throws Exception {
// given
new ExpressionServiceImpl().init();
TranslationService translationService = mock(TranslationService.class);
DataDefinition dataDefinition = mock(DataDefinition.class);
FormComponentPattern pattern = mock(FormComponentPattern.class);
given(pattern.getExpressionNew()).willReturn(null);
given(pattern.getExpressionEdit()).willReturn("2");
ApplicationContext applicationContext = mock(ApplicationContext.class);
setField(pattern, "applicationContext", applicationContext);
AbstractComponentState componentState = new FormComponentState(pattern);
componentState.setTranslationService(translationService);
componentState.setDataDefinition(dataDefinition);
componentState.setFieldValue(13L);
componentState.initialize(new JSONObject(ImmutableMap.of("components", new JSONObject())), Locale.ENGLISH);
// when
JSONObject json = componentState.render();
// then
assertTrue(json.getBoolean(AbstractComponentState.JSON_UPDATE_STATE));
}
use of com.qcadoo.view.internal.components.form.FormComponentState in project qcadoo by qcadoo.
the class ContainerStateTest method shouldReturnNullIfChildNotExist.
@Test
public void shouldReturnNullIfChildNotExist() throws Exception {
// given
FormComponentPattern pattern = mock(FormComponentPattern.class);
given(pattern.getExpressionNew()).willReturn(null);
given(pattern.getExpressionEdit()).willReturn(null);
setField(pattern, "applicationContext", applicationContext);
FormComponentState container = new FormComponentState(pattern);
// when
ComponentState child = container.getChild("component");
// then
assertNull(child);
}
use of com.qcadoo.view.internal.components.form.FormComponentState in project qcadoo by qcadoo.
the class ContainerStateTest method shouldHaveNoChildren.
@Test
public void shouldHaveNoChildren() throws Exception {
// given
FormComponentPattern pattern = mock(FormComponentPattern.class);
given(pattern.getExpressionNew()).willReturn(null);
given(pattern.getExpressionEdit()).willReturn(null);
setField(pattern, "applicationContext", applicationContext);
FormComponentState container = new FormComponentState(pattern);
// when
Map<String, InternalComponentState> children = container.getChildren();
// then
assertNotNull(children);
assertEquals(0, children.size());
}
Aggregations