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