use of com.qcadoo.view.internal.api.ComponentPattern in project qcadoo by qcadoo.
the class SmallTabLayoutPattern method parse.
@Override
public void parse(final Node componentNode, final ViewDefinitionParser parser) throws ViewDefinitionParserNodeException {
super.parse(componentNode, parser);
NodeList childNodes = componentNode.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node child = childNodes.item(i);
if (child.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
parser.checkState("tabElement".equals(child.getNodeName()), child, "gridlayout can contains only tabElements");
String tabName = parser.getStringAttribute(child, "name");
SmallTabLayoutPatternTab tab = new SmallTabLayoutPatternTab(tabName);
NodeList elementComponentNodes = child.getChildNodes();
for (int elementComponentNodesIter = 0; elementComponentNodesIter < elementComponentNodes.getLength(); elementComponentNodesIter++) {
Node elementComponentNode = elementComponentNodes.item(elementComponentNodesIter);
if (elementComponentNode.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
parser.checkState("component".equals(elementComponentNode.getNodeName()), elementComponentNode, "layoutElement can contains only components");
ComponentPattern elementComponent = parser.parseComponent(elementComponentNode, this);
this.addChild(elementComponent);
tab.addComponent(elementComponent);
}
tabs.add(tab);
}
}
use of com.qcadoo.view.internal.api.ComponentPattern in project qcadoo by qcadoo.
the class ComponentPatternTest method shouldAddItselfToParentOnInitialize.
@Test
public void shouldAddItselfToParentOnInitialize() throws Exception {
// given
InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
AbstractContainerPattern parent = new WindowComponentPattern(getComponentDefinition("test", viewDefinition));
ComponentPattern pattern = new TextInputComponentPattern(getComponentDefinition("testName", "testField", null, parent, viewDefinition));
// when
pattern.initialize();
// then
assertEquals(pattern, parent.getFieldEntityIdChangeListeners().get("testField"));
}
use of com.qcadoo.view.internal.api.ComponentPattern in project qcadoo by qcadoo.
the class ComponentPatternTest method shouldHaveName.
@Test
public void shouldHaveName() throws Exception {
// given
ComponentPattern pattern = new FormComponentPattern(getComponentDefinition("testName", null));
// when
String name = pattern.getName();
// then
Assert.assertEquals("testName", name);
}
use of com.qcadoo.view.internal.api.ComponentPattern in project qcadoo by qcadoo.
the class ContainerPatternTest method shouldCallCreateComponentStateOnChildren.
@Test
public void shouldCallCreateComponentStateOnChildren() throws Exception {
// given
InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
InternalViewDefinitionState viewDefinitionState = mock(InternalViewDefinitionState.class);
AbstractContainerState state = new EmptyContainerState();
InternalComponentState state1 = mock(InternalComponentState.class);
given(state1.getName()).willReturn("name1");
InternalComponentState state2 = mock(InternalComponentState.class);
given(state2.getName()).willReturn("name2");
ComponentPattern pattern1 = mock(ComponentPattern.class);
given(pattern1.getName()).willReturn("name1");
given(pattern1.createComponentState(viewDefinitionState)).willReturn(state1);
ComponentPattern pattern2 = mock(ComponentPattern.class);
given(pattern2.getName()).willReturn("name2");
given(pattern2.createComponentState(viewDefinitionState)).willReturn(state2);
ContainerPatternMock parent = new ContainerPatternMock(getComponentDefinition("name", viewDefinition), state);
parent.addChild(pattern1);
parent.addChild(pattern2);
// when
ComponentState actualState = parent.createComponentState(viewDefinitionState);
// then
assertEquals(state, actualState);
verify(pattern1).createComponentState(viewDefinitionState);
verify(pattern2).createComponentState(viewDefinitionState);
verify(viewDefinitionState).registerComponent("name", actualState);
assertEquals(state1, state.getChild("name1"));
assertEquals(state2, state.getChild("name2"));
}
use of com.qcadoo.view.internal.api.ComponentPattern in project qcadoo by qcadoo.
the class ContainerPatternTest method shouldHaveChildren.
@Test
public void shouldHaveChildren() throws Exception {
// given
AbstractContainerPattern parent = new FormComponentPattern(getComponentDefinition("test", null));
ComponentPattern child1 = new TextInputComponentPattern(getComponentDefinition("test1", parent, null));
ComponentPattern child2 = new TextInputComponentPattern(getComponentDefinition("test2", parent, null));
parent.addChild(child1);
parent.addChild(child2);
// when
Map<String, ComponentPattern> children = parent.getChildren();
// then
Assert.assertEquals(2, children.size());
Assert.assertEquals(child1, children.get("test1"));
Assert.assertEquals(child2, children.get("test2"));
}
Aggregations