Search in sources :

Example 6 with GridComponentPattern

use of com.qcadoo.view.internal.components.grid.GridComponentPattern 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 GridComponentPattern

use of com.qcadoo.view.internal.components.grid.GridComponentPattern in project qcadoo by qcadoo.

the class LookupComponentPattern method createGridComponentPattern.

private GridComponentPattern createGridComponentPattern(final ViewDefinition lookupViewDefinition, final WindowComponentPattern window) {
    final ComponentDefinition gridComponentDefinition = new ComponentDefinition();
    gridComponentDefinition.setName(QcadooViewConstants.L_GRID);
    gridComponentDefinition.setTranslationService(getTranslationService());
    gridComponentDefinition.setApplicationContext(getApplicationContext());
    gridComponentDefinition.setViewDefinition(lookupViewDefinition);
    gridComponentDefinition.setParent(window);
    gridComponentDefinition.setContextualHelpService(getContextualHelpService());
    gridComponentDefinition.setReference(QcadooViewConstants.L_GRID);
    if (getScopeFieldDefinition() != null) {
        gridComponentDefinition.setSourceFieldPath(getScopeFieldDefinition().getName());
    }
    final GridComponentPattern grid = new GridComponentPattern(gridComponentDefinition);
    grid.setRowStyleResolver(rowStyleResolver);
    grid.setCriteriaModifier(criteriaModifier);
    grid.addOption(new ComponentOption("lookup", ImmutableMap.of(L_VALUE, L_TRUE)));
    grid.addOption(new ComponentOption("fullscreen", ImmutableMap.of(L_VALUE, L_TRUE)));
    grid.addOption(new ComponentOption("orderable", ImmutableMap.of(L_VALUE, L_LOOKUP_CODE)));
    grid.addOption(new ComponentOption("order", ImmutableMap.of("column", L_LOOKUP_CODE, "direction", "asc")));
    grid.addOption(new ComponentOption("searchable", ImmutableMap.of(L_VALUE, L_LOOKUP_CODE)));
    grid.addOption(new ComponentOption("prioritizable", ImmutableMap.of(L_VALUE, Boolean.toString(prioritizable))));
    grid.addOption(new ComponentOption("onlyActive", ImmutableMap.of(L_VALUE, Boolean.toString(onlyActive))));
    grid.addOption(createLookupCodeColumn());
    grid.addOption(createLookupValueColumn());
    return grid;
}
Also used : GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern)

Example 8 with GridComponentPattern

use of com.qcadoo.view.internal.components.grid.GridComponentPattern in project qcadoo by qcadoo.

the class GridComponentStateTest method init.

@Before
public void init() throws Exception {
    JSONObject jsonContent = new JSONObject();
    jsonContent.put(GridComponentState.JSON_SELECTED_ENTITY_ID, 13L);
    jsonContent.put(GridComponentState.JSON_MULTISELECT_MODE, false);
    JSONObject jsonSelected = new JSONObject();
    jsonSelected.put("13", true);
    jsonContent.put(GridComponentState.JSON_SELECTED_ENTITIES, jsonSelected);
    jsonContent.put(GridComponentState.JSON_BELONGS_TO_ENTITY_ID, 1L);
    jsonContent.put(GridComponentState.JSON_FIRST_ENTITY, 60);
    jsonContent.put(GridComponentState.JSON_MAX_ENTITIES, 30);
    jsonContent.put(GridComponentState.JSON_FILTERS_ENABLED, true);
    JSONArray jsonOrder = new JSONArray();
    jsonOrder.put(ImmutableMap.of("column", "asd", "direction", "asc"));
    jsonContent.put(GridComponentState.JSON_ORDER, jsonOrder);
    JSONObject jsonFilters = new JSONObject();
    jsonFilters.put("asd", "test");
    jsonFilters.put("qwe", "test2");
    jsonContent.put(GridComponentState.JSON_FILTERS, jsonFilters);
    json = new JSONObject(Collections.singletonMap(AbstractComponentState.JSON_CONTENT, jsonContent));
    Entity entity = mock(Entity.class);
    given(entity.getField("name")).willReturn("text");
    viewDefinitionState = mock(ViewDefinitionState.class);
    productDataDefinition = mock(DataDefinition.class, RETURNS_DEEP_STUBS);
    substituteDataDefinition = mock(DataDefinition.class, "substituteDataDefinition");
    HasManyType substitutesFieldType = mock(HasManyType.class);
    given(substitutesFieldType.getDataDefinition()).willReturn(substituteDataDefinition);
    given(substitutesFieldType.getJoinFieldName()).willReturn("product");
    substitutesFieldDefinition = mock(FieldDefinition.class);
    given(substitutesFieldDefinition.getType()).willReturn(substitutesFieldType);
    given(substitutesFieldDefinition.getName()).willReturn("substitutes");
    given(substitutesFieldDefinition.getDataDefinition()).willReturn(substituteDataDefinition);
    substituteCriteria = mock(SearchCriteriaBuilder.class);
    given(substituteDataDefinition.getPluginIdentifier()).willReturn("plugin");
    given(substituteDataDefinition.getName()).willReturn("substitute");
    given(substituteDataDefinition.find()).willReturn(substituteCriteria);
    given(productDataDefinition.getPluginIdentifier()).willReturn("plugin");
    given(productDataDefinition.getName()).willReturn("product");
    given(productDataDefinition.getField("substitutes")).willReturn(substitutesFieldDefinition);
    columns = new LinkedHashMap<String, GridComponentColumn>();
    TranslationService translationService = mock(TranslationService.class);
    given(translationService.translate(Mockito.anyString(), Mockito.any(Locale.class))).willReturn("i18n");
    given(translationService.translate(Mockito.anyString(), Mockito.anyString(), Mockito.any(Locale.class))).willReturn("i18n");
    given(translationService.translate(Mockito.anyString(), Mockito.any(Locale.class))).willReturn("i18n");
    GridComponentPattern pattern = mock(GridComponentPattern.class);
    given(pattern.getColumns()).willReturn(columns);
    given(pattern.getBelongsToFieldDefinition()).willReturn(substitutesFieldDefinition);
    given(pattern.isActivable()).willReturn(false);
    given(pattern.isWeakRelation()).willReturn(false);
    ApplicationContext applicationContext = mock(ApplicationContext.class);
    setField(pattern, "applicationContext", applicationContext);
    SecurityRolesService securityRolesService = mock(SecurityRolesService.class);
    given(applicationContext.getBean(SecurityRolesService.class)).willReturn(securityRolesService);
    grid = new GridComponentState(productDataDefinition, pattern);
    grid.setDataDefinition(substituteDataDefinition);
    grid.setTranslationService(translationService);
    new ExpressionServiceImpl().init();
}
Also used : Locale(java.util.Locale) Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) FieldDefinition(com.qcadoo.model.api.FieldDefinition) JSONArray(org.json.JSONArray) GridComponentColumn(com.qcadoo.view.internal.components.grid.GridComponentColumn) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) Matchers.anyString(org.mockito.Matchers.anyString) DataDefinition(com.qcadoo.model.api.DataDefinition) HasManyType(com.qcadoo.model.api.types.HasManyType) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) ApplicationContext(org.springframework.context.ApplicationContext) GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) JSONObject(org.json.JSONObject) TranslationService(com.qcadoo.localization.api.TranslationService) GridComponentState(com.qcadoo.view.internal.components.grid.GridComponentState) SecurityRolesService(com.qcadoo.security.api.SecurityRolesService) ExpressionServiceImpl(com.qcadoo.model.internal.ExpressionServiceImpl) Before(org.junit.Before)

Example 9 with GridComponentPattern

use of com.qcadoo.view.internal.components.grid.GridComponentPattern 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 10 with GridComponentPattern

use of com.qcadoo.view.internal.components.grid.GridComponentPattern in project qcadoo by qcadoo.

the class GridComponentPatternTest method shouldBeFullscreen.

@Test
public void shouldBeFullscreen() throws Exception {
    // given
    DataDefinition dataDefinition = mock(DataDefinition.class);
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    given(viewDefinition.getDataDefinition()).willReturn(dataDefinition);
    ComponentDefinition componentDefinition = getComponentDefinition(QcadooViewConstants.L_GRID, viewDefinition);
    componentDefinition.setTranslationService(translationService);
    componentDefinition.setApplicationContext(applicationContext);
    GridComponentPattern pattern = new GridComponentPattern(componentDefinition);
    pattern.addOption(new ComponentOption("fullscreen", ImmutableMap.of("value", "true")));
    pattern.addOption(new ComponentOption("order", ImmutableMap.of("column", "name", "direction", "asc")));
    // when
    pattern.initialize();
    // then
    JSONObject options = getJsOptions(pattern);
    assertTrue(options.getBoolean("fullscreen"));
    assertEquals(0, options.getInt("width"));
    assertEquals(0, options.getInt("height"));
}
Also used : GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) JSONObject(org.json.JSONObject) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ComponentOption(com.qcadoo.view.internal.ComponentOption) DataDefinition(com.qcadoo.model.api.DataDefinition) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest) Test(org.junit.Test)

Aggregations

GridComponentPattern (com.qcadoo.view.internal.components.grid.GridComponentPattern)13 DataDefinition (com.qcadoo.model.api.DataDefinition)10 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)9 Test (org.junit.Test)9 ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)8 ComponentOption (com.qcadoo.view.internal.ComponentOption)8 AbstractPatternTest (com.qcadoo.view.internal.patterns.AbstractPatternTest)8 JSONObject (org.json.JSONObject)7 FieldDefinition (com.qcadoo.model.api.FieldDefinition)6 ImmutableMap (com.google.common.collect.ImmutableMap)4 Map (java.util.Map)4 HasManyType (com.qcadoo.model.api.types.HasManyType)3 EnumType (com.qcadoo.model.internal.types.EnumType)3 SecurityRolesService (com.qcadoo.security.api.SecurityRolesService)3 ComponentState (com.qcadoo.view.api.ComponentState)3 GridComponent (com.qcadoo.view.api.components.GridComponent)3 InternalViewDefinitionState (com.qcadoo.view.internal.api.InternalViewDefinitionState)3 GridComponentColumn (com.qcadoo.view.internal.components.grid.GridComponentColumn)3 BelongsToType (com.qcadoo.model.api.types.BelongsToType)2 PluginStateResolver (com.qcadoo.plugin.api.PluginStateResolver)2