use of com.qcadoo.view.internal.internal.ViewDefinitionImpl in project qcadoo by qcadoo.
the class LookupComponentPattern method initializeComponent.
@Override
protected void initializeComponent() throws JSONException {
super.initializeComponent();
for (ComponentOption option : getOptions()) {
if ("expression".equals(option.getType())) {
expression = option.getValue();
} else if ("fieldCode".equals(option.getType())) {
fieldCode = option.getValue();
} else if ("header".equals(option.getType())) {
header = Boolean.parseBoolean(option.getValue());
} else if ("prioritizable".equals(option.getType())) {
prioritizable = Boolean.parseBoolean(option.getValue());
} else if ("onlyActive".equals(option.getType())) {
onlyActive = Boolean.parseBoolean(option.getValue());
} else if ("textRepresentationOnDisabled".equals(option.getType())) {
textRepresentationOnDisabled = Boolean.parseBoolean(option.getValue());
} else if ("boldTextRepresentationOnDisabled".equals(option.getType())) {
Boolean optionValue = Boolean.parseBoolean(option.getValue());
textRepresentationOnDisabled = optionValue;
boldTextRepresentationOnDisabled = optionValue;
}
}
modalDimensions = ModalDimensions.parseFromOptions(getOptions());
checkState(hasText(fieldCode), "Missing fieldCode for lookup");
checkState(hasText(expression), "Missing expression for lookup");
String viewName = getViewName();
DataDefinition dataDefinition = getDataDefinition();
if (getScopeFieldDefinition() != null) {
dataDefinition = getScopeFieldDefinition().getDataDefinition();
}
lookupViewDefinition = new ViewDefinitionImpl(viewName, getViewDefinition().getPluginIdentifier(), dataDefinition, false, getTranslationService());
WindowComponentPattern window = createWindowComponentPattern(lookupViewDefinition);
GridComponentPattern grid = createGridComponentPattern(lookupViewDefinition, window);
for (ComponentOption option : getOptions()) {
if ("orderable".equals(option.getType())) {
Map<String, String> newAttributes = new HashMap<>();
newAttributes.put(L_VALUE, option.getValue() + ",lookupCode");
option = new ComponentOption("orderable", newAttributes);
grid.addOption(option);
} else if ("searchable".equals(option.getType())) {
Map<String, String> newAttributes = new HashMap<>();
newAttributes.put(L_VALUE, option.getValue() + ",lookupCode");
option = new ComponentOption("searchable", newAttributes);
grid.addOption(option);
} else if (!"expression".equals(option.getType()) && !"fieldCode".equals(option.getType()) && !"textRepresentationOnDisabled".equals(option.getType()) && !"labelWidth".equals(option.getType())) {
grid.addOption(option);
}
}
grid.addOption(new ComponentOption("lookup", Collections.singletonMap(L_VALUE, L_TRUE)));
window.addChild(grid);
lookupViewDefinition.addComponentPattern(window);
lookupViewDefinition.initialize();
}
use of com.qcadoo.view.internal.internal.ViewDefinitionImpl in project qcadoo by qcadoo.
the class InitializationTest method shouldInitializeAllComponents.
@Test
public void shouldInitializeAllComponents() throws Exception {
// given
DataDefinition dataDefinition = mock(DataDefinition.class);
DataDefinition hasManyDataDefinition = mock(DataDefinition.class);
DataDefinition belongsToDataDefinition = mock(DataDefinition.class);
FieldDefinition fieldDefinition = mock(FieldDefinition.class);
FieldDefinition hasManyFieldDefinition = mock(FieldDefinition.class);
FieldDefinition belongsToFieldDefinition = mock(FieldDefinition.class);
FieldType fieldType = mock(FieldType.class);
BelongsToType belongsToType = mock(BelongsToType.class);
HasManyType hasManyType = mock(HasManyType.class);
given(dataDefinition.getField("hasMany")).willReturn(hasManyFieldDefinition);
given(belongsToDataDefinition.getField("hasMany")).willReturn(hasManyFieldDefinition);
given(dataDefinition.getField("belongsTo")).willReturn(belongsToFieldDefinition);
given(dataDefinition.getField("field")).willReturn(fieldDefinition);
given(fieldDefinition.getType()).willReturn(fieldType);
given(hasManyFieldDefinition.getType()).willReturn(hasManyType);
given(belongsToFieldDefinition.getType()).willReturn(belongsToType);
given(hasManyType.getDataDefinition()).willReturn(hasManyDataDefinition);
given(belongsToType.getDataDefinition()).willReturn(belongsToDataDefinition);
InternalViewDefinition viewDefinition = new ViewDefinitionImpl("view", "plugin", dataDefinition, true, null);
AbstractContainerPattern parent = new FormComponentPattern(getComponentDefinition("parent", viewDefinition));
AbstractContainerPattern form = new FormComponentPattern(getComponentDefinition(QcadooViewConstants.L_FORM, null, null, parent, viewDefinition));
AbstractComponentPattern input = new TextInputComponentPattern(getComponentDefinition("input", "field", null, form, viewDefinition));
AbstractComponentPattern select = new TextInputComponentPattern(getComponentDefinition("select", "belongsTo", null, form, viewDefinition));
AbstractComponentPattern subselect = new TextInputComponentPattern(getComponentDefinition("subselect", "#{parent.form}.hasMany", "#{parent.form.select}.hasMany", form, viewDefinition));
AbstractComponentPattern grid = new TextInputComponentPattern(getComponentDefinition(QcadooViewConstants.L_GRID, null, "#{parent.form}.hasMany", parent, viewDefinition));
parent.addChild(form);
parent.addChild(grid);
form.addChild(input);
form.addChild(select);
form.addChild(subselect);
viewDefinition.addComponentPattern(parent);
// when
viewDefinition.initialize();
// then
assertEquals(dataDefinition, getField(parent, "dataDefinition"));
assertEquals(dataDefinition, getField(form, "dataDefinition"));
assertEquals(dataDefinition, getField(input, "dataDefinition"));
assertEquals(belongsToDataDefinition, getField(select, "dataDefinition"));
assertEquals(hasManyDataDefinition, getField(subselect, "dataDefinition"));
assertEquals(hasManyDataDefinition, getField(grid, "dataDefinition"));
assertNull(getField(parent, "scopeFieldDefinition"));
assertNull(getField(form, "scopeFieldDefinition"));
assertNull(getField(input, "scopeFieldDefinition"));
assertNull(getField(select, "scopeFieldDefinition"));
assertEquals(hasManyFieldDefinition, getField(subselect, "scopeFieldDefinition"));
assertEquals(hasManyFieldDefinition, getField(grid, "scopeFieldDefinition"));
assertNull(getField(parent, "fieldDefinition"));
assertNull(getField(form, "fieldDefinition"));
assertEquals(fieldDefinition, getField(input, "fieldDefinition"));
assertEquals(belongsToFieldDefinition, getField(select, "fieldDefinition"));
assertEquals(hasManyFieldDefinition, getField(subselect, "fieldDefinition"));
assertNull(getField(grid, "fieldDefinition"));
}
use of com.qcadoo.view.internal.internal.ViewDefinitionImpl in project qcadoo by qcadoo.
the class ViewDefinitionTest method shouldCallInitializeOnChildren.
@Test
public void shouldCallInitializeOnChildren() throws Exception {
// given
InternalViewDefinition viewDefinition = new ViewDefinitionImpl("name", "plugin", mock(DataDefinition.class), true, null);
ComponentPattern pattern1 = Mockito.mock(ComponentPattern.class);
given(pattern1.getName()).willReturn("test1");
given(pattern1.initialize()).willReturn(false, true);
ComponentPattern pattern2 = Mockito.mock(ComponentPattern.class);
given(pattern2.getName()).willReturn("test2");
given(pattern2.initialize()).willReturn(true);
viewDefinition.addComponentPattern(pattern1);
viewDefinition.addComponentPattern(pattern2);
// when
viewDefinition.initialize();
// then
Mockito.verify(pattern1, times(2)).initialize();
Mockito.verify(pattern2, times(2)).initialize();
}
use of com.qcadoo.view.internal.internal.ViewDefinitionImpl in project qcadoo by qcadoo.
the class ViewDefinitionTest method shouldCallHooks.
@Test
public void shouldCallHooks() throws Exception {
// given
ViewDefinitionImpl viewDefinition = new ViewDefinitionImpl("name", "plugin", mock(DataDefinition.class), true, null);
ViewLifecycleHook preInitializeHook = mockLifecycleHook(HookType.BEFORE_INITIALIZE);
viewDefinition.addHook(preInitializeHook);
ViewLifecycleHook postInitializeHook1 = mockLifecycleHook(HookType.AFTER_INITIALIZE);
viewDefinition.addHook(postInitializeHook1);
ViewLifecycleHook postInitializeHook2 = mockLifecycleHook(HookType.AFTER_INITIALIZE);
viewDefinition.addHook(postInitializeHook2);
ViewLifecycleHook preRenderHook = mockLifecycleHook(HookType.BEFORE_RENDER);
viewDefinition.addHook(preRenderHook);
JSONObject eventJson = new JSONObject();
eventJson.put(InternalViewDefinition.JSON_EVENT_NAME, "eventName");
eventJson.put(InternalViewDefinition.JSON_EVENT_ARGS, new JSONArray(newArrayList("arg1", "arg2")));
JSONObject json = new JSONObject();
json.put(InternalViewDefinition.JSON_EVENT, eventJson);
json.put(InternalViewDefinition.JSON_COMPONENTS, new JSONObject());
// when
viewDefinition.performEvent(json, Locale.ENGLISH);
// then
verify(preInitializeHook).callWithViewState(any(ViewDefinitionState.class));
verify(postInitializeHook1).callWithViewState(any(ViewDefinitionState.class));
verify(postInitializeHook2).callWithViewState(any(ViewDefinitionState.class));
verify(preRenderHook).callWithViewState(any(ViewDefinitionState.class));
}
use of com.qcadoo.view.internal.internal.ViewDefinitionImpl in project qcadoo by qcadoo.
the class ViewDefinitionTest method shouldHaveBasicInformation.
@Test
public void shouldHaveBasicInformation() throws Exception {
// given
DataDefinition dataDefinition = mock(DataDefinition.class);
InternalViewDefinition viewDefinition = new ViewDefinitionImpl("name", "plugin", dataDefinition, true, null);
// then
assertEquals("name", viewDefinition.getName());
assertEquals("plugin", viewDefinition.getPluginIdentifier());
assertEquals(dataDefinition, viewDefinition.getDataDefinition());
assertTrue(viewDefinition.isMenuAccessible());
}
Aggregations