use of com.qcadoo.view.internal.internal.ViewDefinitionStateImpl 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.internal.ViewDefinitionStateImpl 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.internal.ViewDefinitionStateImpl in project qcadoo by qcadoo.
the class ViewDefinitionStateTest method shouldReturnStateByFunctionalPath.
@Test
public void shouldReturnStateByFunctionalPath() throws Exception {
// given
InternalViewDefinitionState viewDefinitionState = new ViewDefinitionStateImpl();
ContainerState state = mock(ContainerState.class);
viewDefinitionState.registerComponent("reference", state);
// when
ComponentState actualState = viewDefinitionState.getComponentByReference("reference");
// then
assertEquals(state, actualState);
}
use of com.qcadoo.view.internal.internal.ViewDefinitionStateImpl in project qcadoo by qcadoo.
the class ViewDefinitionStateTest method shouldPerformEventOnAllComponent.
@Test
public void shouldPerformEventOnAllComponent() throws Exception {
// given
ViewDefinitionStateImpl viewDefinitionState = new ViewDefinitionStateImpl();
ContainerState state1 = mock(ContainerState.class);
given(state1.getName()).willReturn("name1");
InternalComponentState state2 = mock(InternalComponentState.class);
viewDefinitionState.addChild(state1);
given(state1.getChildren()).willReturn(Collections.singletonMap("name2", state2));
// when
viewDefinitionState.performEvent((String) null, "event", new String[] { "arg1", "arg2" });
// then
Mockito.verify(state1).performEvent(viewDefinitionState, "event", "arg1", "arg2");
Mockito.verify(state2).performEvent(viewDefinitionState, "event", "arg1", "arg2");
}
use of com.qcadoo.view.internal.internal.ViewDefinitionStateImpl in project qcadoo by qcadoo.
the class ViewDefinitionStateTest method shouldReturnNullWhenStateNoExists.
@Test
public void shouldReturnNullWhenStateNoExists() throws Exception {
// given
ViewDefinitionState viewDefinitionState = new ViewDefinitionStateImpl();
// when
ComponentState actualState = viewDefinitionState.getComponentByReference("xxx");
// then
assertNull(actualState);
}
Aggregations