use of com.qcadoo.view.internal.ComponentDefinition in project qcadoo by qcadoo.
the class AbstractPatternTest method getComponentDefinition.
public ComponentDefinition getComponentDefinition(final String name, final String fieldPath, final String sourceFieldPath, final ContainerPattern parent, final ViewDefinition viewDefinition) {
ComponentDefinition componentDefinition = new ComponentDefinition();
componentDefinition.setName(name);
componentDefinition.setFieldPath(fieldPath);
componentDefinition.setSourceFieldPath(sourceFieldPath);
componentDefinition.setParent(parent);
TranslationService translationService = mock(TranslationService.class);
componentDefinition.setTranslationService(translationService);
ContextualHelpService contextualHelpService = mock(ContextualHelpService.class);
componentDefinition.setContextualHelpService(contextualHelpService);
if (viewDefinition != null) {
componentDefinition.setViewDefinition(viewDefinition);
} else {
componentDefinition.setViewDefinition(mock(InternalViewDefinition.class));
}
return componentDefinition;
}
use of com.qcadoo.view.internal.ComponentDefinition in project qcadoo by qcadoo.
the class ComponentPatternTest method shouldHaveDefaultEnabledFlag.
@Test
public void shouldHaveDefaultEnabledFlag() throws Exception {
// given
ComponentDefinition componentDefinition = getComponentDefinition("testName", null);
componentDefinition.setDefaultEnabled(false);
AbstractComponentPattern pattern = new TextInputComponentPattern(componentDefinition);
// then
assertFalse(pattern.isDefaultEnabled());
}
use of com.qcadoo.view.internal.ComponentDefinition in project qcadoo by qcadoo.
the class ComponentPatternTest method shouldHaveListenersOnEmptyOptions.
@Test
public void shouldHaveListenersOnEmptyOptions() throws Exception {
// given
TranslationService translationService = mock(TranslationService.class);
InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
ComponentDefinition componentDefinition = getComponentDefinition("testName", null);
componentDefinition.setTranslationService(translationService);
componentDefinition.setViewDefinition(viewDefinition);
AbstractComponentPattern pattern = new TextInputComponentPattern(componentDefinition);
// when
Map<String, Object> model = pattern.prepareView(Locale.ENGLISH);
// then
JSONObject options = (JSONObject) model.get("jsOptions");
assertEquals(7, options.length());
}
use of com.qcadoo.view.internal.ComponentDefinition in project qcadoo by qcadoo.
the class ComponentPatternTest method shouldHaveDefaultVisibleFlag.
@Test
public void shouldHaveDefaultVisibleFlag() throws Exception {
// given
ComponentDefinition componentDefinition = getComponentDefinition("testName", null);
componentDefinition.setDefaultVisible(false);
AbstractComponentPattern pattern = new TextInputComponentPattern(componentDefinition);
// then
assertFalse(pattern.isDefaultVisible());
}
use of com.qcadoo.view.internal.ComponentDefinition in project qcadoo by qcadoo.
the class WindowComponentPattern method parse.
@Override
public void parse(final Node componentNode, final ViewDefinitionParser parser) throws ViewDefinitionParserNodeException {
super.parseWithoutChildren(componentNode, parser);
Node ribbonNode = null;
NodeList childNodes = componentNode.getChildNodes();
Boolean tabMode = null;
for (int i = 0; i < childNodes.getLength(); i++) {
Node child = childNodes.item(i);
if (child.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
if ("ribbon".equals(child.getNodeName())) {
if (ribbonNode != null) {
throw new ViewDefinitionParserNodeException(child, "Window can contain only one ribbon");
}
ribbonNode = child;
} else if ("windowTab".equals(child.getNodeName())) {
if (tabMode != null && !tabMode) {
throw new ViewDefinitionParserNodeException(child, "Window cannot have both 'windowTab' and 'component' tags");
}
tabMode = true;
WindowTabComponentPattern tab = new WindowTabComponentPattern(parser.getComponentDefinition(child, this, getViewDefinition()));
tab.parse(child, parser);
addChild(tab);
if (firstTabName == null) {
firstTabName = tab.getName();
}
} else if ("component".equals(child.getNodeName())) {
if (tabMode != null && tabMode) {
throw new ViewDefinitionParserNodeException(child, "Window cannot have both 'windowTab' and 'component' tags");
}
tabMode = false;
if (mainTab == null) {
ComponentDefinition componentDefinition = new ComponentDefinition();
componentDefinition.setName("mainTab");
componentDefinition.setParent(this);
componentDefinition.setTranslationService(getTranslationService());
componentDefinition.setContextualHelpService(getContextualHelpService());
componentDefinition.setViewDefinition(getViewDefinition());
componentDefinition.setReference("mainTab");
componentDefinition.setDataDefinition(null);
mainTab = new WindowTabComponentPattern(componentDefinition);
addChild(mainTab);
firstTabName = mainTab.getName();
}
mainTab.addChild(parser.parseComponent(child, mainTab));
} else if ("option".equals(child.getNodeName())) {
String type = parser.getStringAttribute(child, "type");
String value = parser.getStringAttribute(child, "value");
if (HEADER.equals(type)) {
header = Boolean.parseBoolean(value);
} else if ("fixedHeight".equals(type)) {
fixedHeight = Boolean.parseBoolean(value);
} else {
throw new ViewDefinitionParserNodeException(child, "Unknown option for window: " + type);
}
} else if (!"listener".equals(child.getNodeName()) && !"script".equals(child.getNodeName())) {
throw new ViewDefinitionParserNodeException(child, "Unknown tag for window: " + child.getNodeName());
}
}
if (header == null) {
header = parser.getBooleanAttribute(componentNode, HEADER, true);
}
if (fixedHeight == null) {
fixedHeight = parser.getBooleanAttribute(componentNode, "fixedHeight", false);
}
hasRibbon = parser.getBooleanAttribute(componentNode, "ribbon", true);
if (ribbonNode != null) {
setRibbon(parser.parseRibbon(ribbonNode, getViewDefinition()));
}
}
Aggregations