Search in sources :

Example 6 with ViewDefinitionImpl

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();
}
Also used : ViewDefinitionImpl(com.qcadoo.view.internal.internal.ViewDefinitionImpl) GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) HashMap(java.util.HashMap) DataDefinition(com.qcadoo.model.api.DataDefinition) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 7 with ViewDefinitionImpl

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"));
}
Also used : HasManyType(com.qcadoo.model.api.types.HasManyType) ViewDefinitionImpl(com.qcadoo.view.internal.internal.ViewDefinitionImpl) BelongsToType(com.qcadoo.model.api.types.BelongsToType) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) FieldType(com.qcadoo.model.api.types.FieldType) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) Test(org.junit.Test)

Example 8 with ViewDefinitionImpl

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();
}
Also used : ViewDefinitionImpl(com.qcadoo.view.internal.internal.ViewDefinitionImpl) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest)

Example 9 with ViewDefinitionImpl

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));
}
Also used : ViewDefinitionImpl(com.qcadoo.view.internal.internal.ViewDefinitionImpl) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) ViewLifecycleHook(com.qcadoo.view.internal.hooks.ViewLifecycleHook) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest)

Example 10 with ViewDefinitionImpl

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());
}
Also used : ViewDefinitionImpl(com.qcadoo.view.internal.internal.ViewDefinitionImpl) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest)

Aggregations

DataDefinition (com.qcadoo.model.api.DataDefinition)11 ViewDefinitionImpl (com.qcadoo.view.internal.internal.ViewDefinitionImpl)11 Test (org.junit.Test)9 AbstractPatternTest (com.qcadoo.view.internal.patterns.AbstractPatternTest)8 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)7 FormComponentPattern (com.qcadoo.view.internal.components.form.FormComponentPattern)6 WindowComponentPattern (com.qcadoo.view.internal.components.window.WindowComponentPattern)6 ComponentPattern (com.qcadoo.view.internal.api.ComponentPattern)5 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 FieldDefinition (com.qcadoo.model.api.FieldDefinition)1 BelongsToType (com.qcadoo.model.api.types.BelongsToType)1 FieldType (com.qcadoo.model.api.types.FieldType)1 HasManyType (com.qcadoo.model.api.types.HasManyType)1 SecurityRole (com.qcadoo.security.api.SecurityRole)1 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)1 InternalComponentState (com.qcadoo.view.internal.api.InternalComponentState)1 TextInputComponentPattern (com.qcadoo.view.internal.components.TextInputComponentPattern)1 GridComponentPattern (com.qcadoo.view.internal.components.grid.GridComponentPattern)1