Search in sources :

Example 21 with ComponentPattern

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);
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern)

Example 22 with ComponentPattern

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"));
}
Also used : WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) Test(org.junit.Test)

Example 23 with ComponentPattern

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);
}
Also used : FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) Test(org.junit.Test)

Example 24 with ComponentPattern

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"));
}
Also used : AbstractContainerState(com.qcadoo.view.internal.states.AbstractContainerState) InternalViewDefinitionState(com.qcadoo.view.internal.api.InternalViewDefinitionState) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) EmptyContainerState(com.qcadoo.view.internal.components.EmptyContainerState) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) ComponentState(com.qcadoo.view.api.ComponentState) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) Test(org.junit.Test)

Example 25 with ComponentPattern

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"));
}
Also used : FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) Test(org.junit.Test)

Aggregations

ComponentPattern (com.qcadoo.view.internal.api.ComponentPattern)30 Test (org.junit.Test)15 WindowComponentPattern (com.qcadoo.view.internal.components.window.WindowComponentPattern)14 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)13 FormComponentPattern (com.qcadoo.view.internal.components.form.FormComponentPattern)13 TextInputComponentPattern (com.qcadoo.view.internal.components.TextInputComponentPattern)10 AbstractComponentPattern (com.qcadoo.view.internal.patterns.AbstractComponentPattern)6 DataDefinition (com.qcadoo.model.api.DataDefinition)5 ViewDefinitionImpl (com.qcadoo.view.internal.internal.ViewDefinitionImpl)5 AbstractPatternTest (com.qcadoo.view.internal.patterns.AbstractPatternTest)5 JSONObject (org.json.JSONObject)5 Node (org.w3c.dom.Node)5 JSONException (org.json.JSONException)3 NodeList (org.w3c.dom.NodeList)3 ModuleException (com.qcadoo.plugin.api.ModuleException)2 ComponentState (com.qcadoo.view.api.ComponentState)2 ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)2 ContainerPattern (com.qcadoo.view.internal.api.ContainerPattern)2 InternalComponentState (com.qcadoo.view.internal.api.InternalComponentState)2 AbstractContainerPattern (com.qcadoo.view.internal.patterns.AbstractContainerPattern)2