Search in sources :

Example 1 with ViewDefinitionStateImpl

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);
        }
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) JSONObject(org.json.JSONObject) InternalViewDefinitionState(com.qcadoo.view.internal.api.InternalViewDefinitionState) JSONException(org.json.JSONException) List(java.util.List) LinkedList(java.util.LinkedList) ViewDefinitionStateImpl(com.qcadoo.view.internal.internal.ViewDefinitionStateImpl) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState)

Example 2 with ViewDefinitionStateImpl

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);
        }
    }
}
Also used : JSONObject(org.json.JSONObject) InternalViewDefinitionState(com.qcadoo.view.internal.api.InternalViewDefinitionState) JSONArray(org.json.JSONArray) ViewDefinitionStateImpl(com.qcadoo.view.internal.internal.ViewDefinitionStateImpl) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState)

Example 3 with ViewDefinitionStateImpl

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);
}
Also used : InternalViewDefinitionState(com.qcadoo.view.internal.api.InternalViewDefinitionState) ViewDefinitionStateImpl(com.qcadoo.view.internal.internal.ViewDefinitionStateImpl) ContainerState(com.qcadoo.view.internal.api.ContainerState) ComponentState(com.qcadoo.view.api.ComponentState) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) Test(org.junit.Test) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest)

Example 4 with ViewDefinitionStateImpl

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");
}
Also used : ViewDefinitionStateImpl(com.qcadoo.view.internal.internal.ViewDefinitionStateImpl) ContainerState(com.qcadoo.view.internal.api.ContainerState) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) Test(org.junit.Test) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest)

Example 5 with ViewDefinitionStateImpl

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);
}
Also used : ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) InternalViewDefinitionState(com.qcadoo.view.internal.api.InternalViewDefinitionState) ViewDefinitionStateImpl(com.qcadoo.view.internal.internal.ViewDefinitionStateImpl) ComponentState(com.qcadoo.view.api.ComponentState) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) Test(org.junit.Test) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest)

Aggregations

ViewDefinitionStateImpl (com.qcadoo.view.internal.internal.ViewDefinitionStateImpl)6 InternalComponentState (com.qcadoo.view.internal.api.InternalComponentState)4 InternalViewDefinitionState (com.qcadoo.view.internal.api.InternalViewDefinitionState)4 AbstractStateTest (com.qcadoo.view.internal.states.AbstractStateTest)4 Test (org.junit.Test)4 ContainerState (com.qcadoo.view.internal.api.ContainerState)3 ComponentState (com.qcadoo.view.api.ComponentState)2 FormComponentState (com.qcadoo.view.internal.components.form.FormComponentState)2 JSONObject (org.json.JSONObject)2 Entity (com.qcadoo.model.api.Entity)1 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1