use of com.qcadoo.view.internal.ComponentDefinition in project qcadoo by qcadoo.
the class FormComponentPattern method getVersionField.
private FieldComponentPattern getVersionField(ComponentPattern parent) {
ComponentDefinition componentDefinition = new ComponentDefinition();
componentDefinition.setName(VersionableConstants.VERSION_FIELD_NAME);
componentDefinition.setFieldPath("#{" + getReference() + "}." + VersionableConstants.VERSION_FIELD_NAME);
componentDefinition.setSourceFieldPath(null);
componentDefinition.setTranslationService(getTranslationService());
componentDefinition.setApplicationContext(getApplicationContext());
componentDefinition.setViewDefinition(getViewDefinition());
componentDefinition.setParent(parent);
componentDefinition.setContextualHelpService(getContextualHelpService());
componentDefinition.setExtensionPluginIdentifier(getExtensionPluginIdentifier());
FieldComponentPattern versionField = new HiddenComponentPattern(componentDefinition);
versionField.setPersistent(true);
return versionField;
}
use of com.qcadoo.view.internal.ComponentDefinition in project qcadoo by qcadoo.
the class GridComponentPatternTest method shouldHaveDefaultValues.
@Test
public void shouldHaveDefaultValues() 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("order", ImmutableMap.of("column", "name", "direction", "asc")));
// when
pattern.initialize();
// then
JSONObject options = getJsOptions(pattern);
assertFalse(options.has("correspondingView"));
assertFalse(options.has("correspondingComponent"));
assertFalse(options.has("belongsToFieldName"));
assertTrue(options.getBoolean("paginable"));
assertFalse(options.getBoolean("lookup"));
assertFalse(options.getBoolean("creatable"));
assertFalse(options.getBoolean("deletable"));
assertFalse(options.getBoolean("prioritizable"));
assertFalse(options.getBoolean("fullscreen"));
assertEquals(300, options.getInt("width"));
assertEquals(300, options.getInt("height"));
assertEquals(0, options.getJSONArray("orderableColumns").length());
assertEquals(0, options.getJSONArray("searchableColumns").length());
assertEquals(0, options.getJSONArray("columns").length());
}
use of com.qcadoo.view.internal.ComponentDefinition in project qcadoo by qcadoo.
the class GridComponentPatternTest method shouldParsePredefinedFilters.
@Test
public void shouldParsePredefinedFilters() throws Exception {
// given
DataDefinition dataDefinition = mock(DataDefinition.class);
InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
SecurityRolesService securityRolesService = mock(SecurityRolesService.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("order", ImmutableMap.of("column", "name", "direction", "asc")));
ViewDefinitionParser parser = new ViewDefinitionParserImpl();
setField(parser, "securityRolesService", securityRolesService);
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.newDocument();
Node componentNode = doc.createElement("root");
Node predefinedFiltersNode = doc.createElement("predefinedFilters");
componentNode.appendChild(predefinedFiltersNode);
Element predefinedFilter1 = doc.createElement("predefinedFilter");
predefinedFilter1.setAttribute("name", "filter1");
predefinedFiltersNode.appendChild(predefinedFilter1);
Element predefinedFilter2 = doc.createElement("predefinedFilter");
predefinedFilter2.setAttribute("name", "filter2");
predefinedFiltersNode.appendChild(predefinedFilter2);
Element orderNode = doc.createElement("filterOrder");
orderNode.setAttribute("column", "testCol");
orderNode.setAttribute("direction", "desc");
predefinedFilter2.appendChild(orderNode);
Element filterNode1 = doc.createElement("filterRestriction");
filterNode1.setAttribute("column", "testCol1");
filterNode1.setAttribute("value", "testVal1");
predefinedFilter2.appendChild(filterNode1);
Element filterNode2 = doc.createElement("filterRestriction");
filterNode2.setAttribute("column", "testCol2");
filterNode2.setAttribute("value", "testVal2");
predefinedFilter2.appendChild(filterNode2);
pattern.initialize();
// when
pattern.parse(componentNode, parser);
// then
JSONObject options = getJsOptions(pattern);
JSONArray filtersArray = options.getJSONArray("predefinedFilters");
assertNotNull(filtersArray);
assertEquals(2, filtersArray.length());
assertEquals("filter1", filtersArray.getJSONObject(0).get("label"));
assertEquals("name", filtersArray.getJSONObject(0).get("orderColumn"));
assertEquals("asc", filtersArray.getJSONObject(0).get("orderDirection"));
assertEquals(0, filtersArray.getJSONObject(0).getJSONObject("filter").length());
assertEquals("filter2", filtersArray.getJSONObject(1).get("label"));
assertEquals("testCol", filtersArray.getJSONObject(1).get("orderColumn"));
assertEquals("desc", filtersArray.getJSONObject(1).get("orderDirection"));
assertEquals(2, filtersArray.getJSONObject(1).getJSONObject("filter").length());
assertEquals("testVal1", filtersArray.getJSONObject(1).getJSONObject("filter").getString("testCol1"));
assertEquals("testVal2", filtersArray.getJSONObject(1).getJSONObject("filter").getString("testCol2"));
}
use of com.qcadoo.view.internal.ComponentDefinition in project qcadoo by qcadoo.
the class GridComponentPatternTest method shouldNotFilterOutColumnsVisibleForTenant.
@Test
public void shouldNotFilterOutColumnsVisibleForTenant() throws Exception {
// given
PluginStateResolver pluginStateResolver = mock(PluginStateResolver.class);
PluginUtilsService pluginUtil = new PluginUtilsService(pluginStateResolver);
pluginUtil.init();
given(pluginStateResolver.isEnabled("disabledPlugin")).willReturn(true);
InternalViewDefinitionState viewDefinitionState = mock(InternalViewDefinitionState.class);
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);
componentDefinition.setDataDefinition(dataDefinition);
GridComponentPattern pattern = new GridComponentPattern(componentDefinition);
FieldDefinition nameFieldDefinition = mock(FieldDefinition.class);
given(nameFieldDefinition.getType()).willReturn(new EnumType(translationService, "", true, "v1", "v2"));
given(dataDefinition.getField("name")).willReturn(nameFieldDefinition);
pattern.addOption(new ComponentOption("column", ImmutableMap.of("name", "name", "fields", "name", "hidden", "true")));
pattern.addOption(new ComponentOption("order", ImmutableMap.of("column", "name", "direction", "asc")));
ViewGridColumnModuleColumnModel columnModel = new ViewGridColumnModuleColumnModel("invisible", "name");
columnModel.setWidth(100);
pattern.addColumn("disabledPlugin", columnModel);
pattern.initialize();
// when
ComponentState state = pattern.createComponentState(viewDefinitionState);
// then
assertTrue(state instanceof GridComponent);
@SuppressWarnings("unchecked") Map<String, GridComponentColumn> patternColumns = (Map<String, GridComponentColumn>) getField(pattern, "columns");
@SuppressWarnings("unchecked") Map<String, GridComponentColumn> stateColumns = (Map<String, GridComponentColumn>) getField(state, "columns");
assertEquals(2, patternColumns.size());
assertEquals(2, stateColumns.size());
assertTrue(patternColumns.keySet().contains("name"));
assertNotNull(patternColumns.get("name"));
assertTrue(patternColumns.keySet().contains("invisible"));
assertNotNull(patternColumns.get("invisible"));
assertTrue(stateColumns.keySet().contains("name"));
assertNotNull(stateColumns.get("name"));
assertTrue(stateColumns.keySet().contains("invisible"));
assertNotNull(stateColumns.get("invisible"));
}
use of com.qcadoo.view.internal.ComponentDefinition in project qcadoo by qcadoo.
the class ViewDefinitionParserImpl method getComponentDefinition.
@Override
public ComponentDefinition getComponentDefinition(final Node componentNode, final ContainerPattern parent, final ViewDefinition viewDefinition) {
String name = getStringAttribute(componentNode, "name");
String fieldPath = getStringAttribute(componentNode, "field");
String sourceFieldPath = getStringAttribute(componentNode, "source");
String plugin = getStringAttribute(componentNode, "plugin");
String model = getStringAttribute(componentNode, "model");
Boolean useDto = getBooleanAttribute(componentNode, "useDto", false);
DataDefinition customDataDefinition = null;
if (model != null) {
String modelPluginIdentifier = plugin == null ? viewDefinition.getPluginIdentifier() : plugin;
customDataDefinition = dataDefinitionService.get(modelPluginIdentifier, model);
}
ComponentDefinition componentDefinition = new ComponentDefinition();
componentDefinition.setName(name);
componentDefinition.setFieldPath(fieldPath);
componentDefinition.setSourceFieldPath(sourceFieldPath);
componentDefinition.setParent(parent);
componentDefinition.setTranslationService(translationService);
componentDefinition.setContextualHelpService(contextualHelpService);
componentDefinition.setViewDefinition(viewDefinition);
componentDefinition.setReference(getStringAttribute(componentNode, "reference"));
componentDefinition.setDefaultVisible(getBooleanAttribute(componentNode, "defaultVisible", true));
componentDefinition.setHasLabel(getBooleanAttribute(componentNode, "hasLabel", true));
componentDefinition.setHasDescription(getBooleanAttribute(componentNode, "hasDescription", false));
componentDefinition.setDataDefinition(customDataDefinition);
componentDefinition.setApplicationContext(applicationContext);
componentDefinition.setUseDto(useDto);
EnabledAttribute enabledAttribute = EnabledAttribute.TRUE;
final String defaultEnabled = getStringAttribute(componentNode, "defaultEnabled");
if (defaultEnabled != null) {
enabledAttribute = EnabledAttribute.parseString(defaultEnabled);
}
componentDefinition.setDefaultEnabled(EnabledAttribute.TRUE.equals(enabledAttribute));
componentDefinition.setPermanentlyDisabled(EnabledAttribute.NEVER.equals(enabledAttribute));
return componentDefinition;
}
Aggregations