Search in sources :

Example 1 with AbstractComponentPattern

use of com.qcadoo.view.internal.patterns.AbstractComponentPattern in project qcadoo by qcadoo.

the class ViewDefinitionImpl method performEvent.

@Override
public ViewDefinitionState performEvent(final JSONObject jsonObject, final Locale locale) throws JSONException {
    viewHooksHolder.callConstructionHooks(this, jsonObject, locale);
    ViewDefinitionStateImpl viewDefinitionState = new ViewDefinitionStateImpl();
    viewDefinitionState.setTranslationService(translationService);
    viewDefinitionState.setJsonContext(getJsonContext());
    JSONObject eventJson = jsonObject.getJSONObject(JSON_EVENT);
    String eventName = eventJson.getString(JSON_EVENT_NAME);
    viewDefinitionState.setViewAfterReload(!(eventName.startsWith("initialize") || "reset".equals(eventName)));
    viewDefinitionState.setViewAfterRedirect(eventName.startsWith("redirect") || eventName.startsWith("initialize"));
    for (ComponentPattern cp : patterns.values()) {
        viewDefinitionState.addChild(cp.createComponentState(viewDefinitionState));
    }
    viewHooksHolder.callLifecycleHooks(HookType.BEFORE_INITIALIZE, viewDefinitionState);
    if (permanentlyDisabled) {
        jsonObject.put(AbstractComponentState.JSON_PERMANENTLY_DISABLED, true);
    }
    viewDefinitionState.initialize(jsonObject, locale);
    for (ComponentPattern cp : patterns.values()) {
        ((AbstractComponentPattern) cp).updateComponentStateListeners(viewDefinitionState);
    }
    viewHooksHolder.callLifecycleHooks(HookType.AFTER_INITIALIZE, viewDefinitionState);
    String eventComponent = eventJson.has(JSON_EVENT_COMPONENT) ? eventJson.getString(JSON_EVENT_COMPONENT) : null;
    JSONArray eventArgsArray = eventJson.has(JSON_EVENT_ARGS) ? eventJson.getJSONArray(JSON_EVENT_ARGS) : new JSONArray();
    String[] eventArgs = new String[eventArgsArray.length()];
    for (int i = 0; i < eventArgsArray.length(); i++) {
        eventArgs[i] = eventArgsArray.getString(i);
    }
    viewDefinitionState.performEvent(eventComponent, eventName, eventArgs);
    viewHooksHolder.callLifecycleHooks(HookType.BEFORE_RENDER, viewDefinitionState);
    return viewDefinitionState;
}
Also used : JSONObject(org.json.JSONObject) AbstractComponentPattern(com.qcadoo.view.internal.patterns.AbstractComponentPattern) JSONArray(org.json.JSONArray) AbstractComponentPattern(com.qcadoo.view.internal.patterns.AbstractComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern)

Example 2 with AbstractComponentPattern

use of com.qcadoo.view.internal.patterns.AbstractComponentPattern in project qcadoo by qcadoo.

the class AbstractLayoutPattern method addFieldEntityIdChangeListener.

public final void addFieldEntityIdChangeListener(final String field, final ComponentPattern listener) {
    AbstractComponentPattern parent = (AbstractComponentPattern) this.getParent();
    parent.addFieldEntityIdChangeListener(field, listener);
}
Also used : AbstractComponentPattern(com.qcadoo.view.internal.patterns.AbstractComponentPattern)

Example 3 with AbstractComponentPattern

use of com.qcadoo.view.internal.patterns.AbstractComponentPattern in project qcadoo by qcadoo.

the class AbstractLayoutPattern method addScopeEntityIdChangeListener.

public final void addScopeEntityIdChangeListener(final String field, final ComponentPattern listener) {
    AbstractComponentPattern parent = (AbstractComponentPattern) this.getParent();
    parent.addScopeEntityIdChangeListener(field, listener);
}
Also used : AbstractComponentPattern(com.qcadoo.view.internal.patterns.AbstractComponentPattern)

Example 4 with AbstractComponentPattern

use of com.qcadoo.view.internal.patterns.AbstractComponentPattern in project qcadoo by qcadoo.

the class GridComponentPatternTest method shouldHaveScopeFieldName.

@Test
public void shouldHaveScopeFieldName() throws Exception {
    // given
    DataDefinition dataDefinition = mock(DataDefinition.class);
    BelongsToType belongsToFieldType = mock(BelongsToType.class);
    FieldDefinition belongsToFieldDefinition = mock(FieldDefinition.class);
    given(belongsToFieldDefinition.getName()).willReturn("joinName");
    given(belongsToFieldDefinition.getType()).willReturn(belongsToFieldType);
    given(belongsToFieldDefinition.getDataDefinition()).willReturn(dataDefinition);
    HasManyType hasManyFieldType = mock(HasManyType.class);
    given(hasManyFieldType.getJoinFieldName()).willReturn("joinName");
    given(hasManyFieldType.getDataDefinition()).willReturn(dataDefinition);
    FieldDefinition hasManyFieldDefinition = mock(FieldDefinition.class);
    given(hasManyFieldDefinition.getName()).willReturn("fieldName");
    given(hasManyFieldDefinition.getType()).willReturn(hasManyFieldType);
    given(hasManyFieldDefinition.getDataDefinition()).willReturn(dataDefinition);
    given(dataDefinition.getField("field")).willReturn(hasManyFieldDefinition);
    given(dataDefinition.getField("joinName")).willReturn(belongsToFieldDefinition);
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    AbstractComponentPattern sourceComponent = new TextInputComponentPattern(getComponentDefinition("component", viewDefinition));
    setField(sourceComponent, "dataDefinition", dataDefinition);
    setField(sourceComponent, "initialized", true);
    given(viewDefinition.getComponentByReference("component")).willReturn(sourceComponent);
    ComponentDefinition componentDefinition = getComponentDefinition(QcadooViewConstants.L_GRID, null, "#{component}.field", null, viewDefinition);
    componentDefinition.setTranslationService(translationService);
    componentDefinition.setApplicationContext(applicationContext);
    GridComponentPattern pattern = new GridComponentPattern(componentDefinition);
    pattern.addOption(new ComponentOption("order", ImmutableMap.of("column", "name", "direction", "asc")));
    // when
    pattern.initialize();
    // then
    JSONObject options = getJsOptions(pattern);
    assertEquals("joinName", options.getString("belongsToFieldName"));
}
Also used : HasManyType(com.qcadoo.model.api.types.HasManyType) BelongsToType(com.qcadoo.model.api.types.BelongsToType) GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) JSONObject(org.json.JSONObject) AbstractComponentPattern(com.qcadoo.view.internal.patterns.AbstractComponentPattern) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ComponentOption(com.qcadoo.view.internal.ComponentOption) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest) Test(org.junit.Test)

Example 5 with AbstractComponentPattern

use of com.qcadoo.view.internal.patterns.AbstractComponentPattern in project qcadoo by qcadoo.

the class GridComponentPatternTest method shouldReturnState.

@Test
public void shouldReturnState() throws Exception {
    // given
    InternalViewDefinitionState viewDefinitionState = mock(InternalViewDefinitionState.class);
    DataDefinition dataDefinition = mock(DataDefinition.class);
    BelongsToType belongsToFieldType = mock(BelongsToType.class);
    FieldDefinition belongsToFieldDefinition = mock(FieldDefinition.class);
    given(belongsToFieldDefinition.getName()).willReturn("joinName");
    given(belongsToFieldDefinition.getType()).willReturn(belongsToFieldType);
    HasManyType hasManyFieldType = mock(HasManyType.class);
    given(hasManyFieldType.getJoinFieldName()).willReturn("joinName");
    given(hasManyFieldType.getDataDefinition()).willReturn(dataDefinition);
    FieldDefinition hasManyFieldDefinition = mock(FieldDefinition.class);
    given(hasManyFieldDefinition.getName()).willReturn("fieldName");
    given(hasManyFieldDefinition.getType()).willReturn(hasManyFieldType);
    given(dataDefinition.getField("field")).willReturn(hasManyFieldDefinition);
    given(dataDefinition.getField("joinName")).willReturn(belongsToFieldDefinition);
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    AbstractComponentPattern sourceComponent = new TextInputComponentPattern(getComponentDefinition("component", viewDefinition));
    setField(sourceComponent, "dataDefinition", dataDefinition);
    setField(sourceComponent, "initialized", true);
    given(viewDefinition.getComponentByReference("component")).willReturn(sourceComponent);
    ComponentDefinition componentDefinition = getComponentDefinition(QcadooViewConstants.L_GRID, null, "#{component}.field", null, viewDefinition);
    componentDefinition.setTranslationService(translationService);
    componentDefinition.setApplicationContext(applicationContext);
    GridComponentPattern pattern = new GridComponentPattern(componentDefinition);
    pattern.addOption(new ComponentOption("order", ImmutableMap.of("column", "name", "direction", "asc")));
    pattern.initialize();
    // when
    ComponentState state = pattern.createComponentState(viewDefinitionState);
    // then
    assertTrue(state instanceof GridComponent);
    assertEquals(belongsToFieldDefinition, getField(state, "belongsToFieldDefinition"));
    assertEquals(getField(pattern, "columns"), getField(state, "columns"));
}
Also used : InternalViewDefinitionState(com.qcadoo.view.internal.api.InternalViewDefinitionState) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ComponentOption(com.qcadoo.view.internal.ComponentOption) GridComponent(com.qcadoo.view.api.components.GridComponent) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) HasManyType(com.qcadoo.model.api.types.HasManyType) BelongsToType(com.qcadoo.model.api.types.BelongsToType) GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) AbstractComponentPattern(com.qcadoo.view.internal.patterns.AbstractComponentPattern) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) ComponentState(com.qcadoo.view.api.ComponentState) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest) Test(org.junit.Test)

Aggregations

AbstractComponentPattern (com.qcadoo.view.internal.patterns.AbstractComponentPattern)5 DataDefinition (com.qcadoo.model.api.DataDefinition)2 FieldDefinition (com.qcadoo.model.api.FieldDefinition)2 BelongsToType (com.qcadoo.model.api.types.BelongsToType)2 HasManyType (com.qcadoo.model.api.types.HasManyType)2 ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)2 ComponentOption (com.qcadoo.view.internal.ComponentOption)2 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)2 TextInputComponentPattern (com.qcadoo.view.internal.components.TextInputComponentPattern)2 GridComponentPattern (com.qcadoo.view.internal.components.grid.GridComponentPattern)2 AbstractPatternTest (com.qcadoo.view.internal.patterns.AbstractPatternTest)2 JSONObject (org.json.JSONObject)2 Test (org.junit.Test)2 ComponentState (com.qcadoo.view.api.ComponentState)1 GridComponent (com.qcadoo.view.api.components.GridComponent)1 ComponentPattern (com.qcadoo.view.internal.api.ComponentPattern)1 InternalViewDefinitionState (com.qcadoo.view.internal.api.InternalViewDefinitionState)1 WindowComponentPattern (com.qcadoo.view.internal.components.window.WindowComponentPattern)1 JSONArray (org.json.JSONArray)1