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;
}
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);
}
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);
}
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"));
}
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"));
}
Aggregations