Search in sources :

Example 1 with ComponentPattern

use of com.qcadoo.view.internal.api.ComponentPattern in project qcadoo by qcadoo.

the class FormComponentPattern method tryAddVersionField.

private void tryAddVersionField() {
    List<ComponentPattern> layouts = getChildren().values().stream().filter(childComponentPattern -> childComponentPattern instanceof GridLayoutPattern).collect(Collectors.toList());
    if (!layouts.isEmpty()) {
        GridLayoutPattern gridLayoutPattern = (GridLayoutPattern) layouts.get(0);
        FieldComponentPattern versionComponentPattern = getVersionField(gridLayoutPattern);
        gridLayoutPattern.addChild(versionComponentPattern);
        GridLayoutCell[][] cells = gridLayoutPattern.getCells();
        if (cells != null && cells[0] != null && cells[0][0] != null) {
            cells[0][0].addComponent(versionComponentPattern);
        }
    }
}
Also used : ViewDefinitionParserNodeException(com.qcadoo.view.internal.xml.ViewDefinitionParserNodeException) VersionableConstants(com.qcadoo.model.constants.VersionableConstants) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) FieldComponentPattern(com.qcadoo.view.internal.components.FieldComponentPattern) ComponentState(com.qcadoo.view.api.ComponentState) SecurityRole(com.qcadoo.security.api.SecurityRole) ViewDefinitionParser(com.qcadoo.view.internal.xml.ViewDefinitionParser) AbstractContainerPattern(com.qcadoo.view.internal.patterns.AbstractContainerPattern) Collectors(java.util.stream.Collectors) GridLayoutPattern(com.qcadoo.view.internal.components.layout.GridLayoutPattern) JSONException(org.json.JSONException) List(java.util.List) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) JSONObject(org.json.JSONObject) HiddenComponentPattern(com.qcadoo.view.internal.components.HiddenComponentPattern) Locale(java.util.Locale) GridLayoutCell(com.qcadoo.view.internal.components.layout.GridLayoutCell) Node(org.w3c.dom.Node) ComponentOption(com.qcadoo.view.internal.ComponentOption) FieldComponentPattern(com.qcadoo.view.internal.components.FieldComponentPattern) GridLayoutPattern(com.qcadoo.view.internal.components.layout.GridLayoutPattern) FieldComponentPattern(com.qcadoo.view.internal.components.FieldComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) HiddenComponentPattern(com.qcadoo.view.internal.components.HiddenComponentPattern)

Example 2 with ComponentPattern

use of com.qcadoo.view.internal.api.ComponentPattern in project qcadoo by qcadoo.

the class ComponentPatternTest method shouldReturnValidPath.

@Test
public void shouldReturnValidPath() throws Exception {
    // given
    ContainerPattern root = new WindowComponentPattern(getComponentDefinition("rootName", null));
    ContainerPattern child1 = new WindowComponentPattern(getComponentDefinition("child1", root, null));
    ComponentPattern child2 = new TextInputComponentPattern(getComponentDefinition("child2", root, null));
    ComponentPattern child11 = new TextInputComponentPattern(getComponentDefinition("child11", child1, null));
    // when
    String rootPathName = root.getPath();
    String child1PathName = child1.getPath();
    String child2PathName = child2.getPath();
    String child11PathName = child11.getPath();
    // then
    Assert.assertEquals("rootName", rootPathName);
    Assert.assertEquals("rootName.child1", child1PathName);
    Assert.assertEquals("rootName.child2", child2PathName);
    Assert.assertEquals("rootName.child1.child11", child11PathName);
}
Also used : ContainerPattern(com.qcadoo.view.internal.api.ContainerPattern) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) 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 3 with ComponentPattern

use of com.qcadoo.view.internal.api.ComponentPattern in project qcadoo by qcadoo.

the class ContainerPatternTest method shouldNotCallInitializeOnChildren.

@Test
public void shouldNotCallInitializeOnChildren() throws Exception {
    // given
    InternalViewDefinition viewDefinition = Mockito.mock(InternalViewDefinition.class);
    ComponentPattern child = Mockito.mock(ComponentPattern.class);
    AbstractContainerPattern parent = new FormComponentPattern(getComponentDefinition("test", viewDefinition));
    parent.addChild(child);
    // when
    parent.initialize();
    // then
    Mockito.verify(child, never()).initialize();
}
Also used : FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) Test(org.junit.Test)

Example 4 with ComponentPattern

use of com.qcadoo.view.internal.api.ComponentPattern in project qcadoo by qcadoo.

the class ContainerPatternTest method shouldReturnChildByName.

@Test
public void shouldReturnChildByName() throws Exception {
    // given
    AbstractContainerPattern parent = new FormComponentPattern(getComponentDefinition("test", null));
    ComponentPattern child1 = new TextInputComponentPattern(getComponentDefinition("test1", parent, null));
    parent.addChild(child1);
    // when
    ComponentPattern child = parent.getChild("test1");
    // then
    Assert.assertEquals(child1, child);
}
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)

Example 5 with ComponentPattern

use of com.qcadoo.view.internal.api.ComponentPattern in project qcadoo by qcadoo.

the class ViewDefinitionTest method shouldReturnPattern.

@Test
public void shouldReturnPattern() throws Exception {
    // given
    InternalViewDefinition viewDefinition = new ViewDefinitionImpl("name", "plugin", mock(DataDefinition.class), true, null);
    ComponentPattern pattern = Mockito.mock(ComponentPattern.class);
    viewDefinition.registerComponent("reference", "path", pattern);
    // when
    ComponentPattern actualPattern = viewDefinition.getComponentByReference("reference");
    // then
    Assert.assertEquals(pattern, actualPattern);
}
Also used : ViewDefinitionImpl(com.qcadoo.view.internal.internal.ViewDefinitionImpl) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest)

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