Search in sources :

Example 6 with ComponentDefinition

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;
}
Also used : TranslationService(com.qcadoo.localization.api.TranslationService) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ContextualHelpService(com.qcadoo.view.internal.api.ContextualHelpService) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition)

Example 7 with 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());
}
Also used : ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) Test(org.junit.Test)

Example 8 with ComponentDefinition

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());
}
Also used : JSONObject(org.json.JSONObject) TranslationService(com.qcadoo.localization.api.TranslationService) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) JSONObject(org.json.JSONObject) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) Test(org.junit.Test)

Example 9 with ComponentDefinition

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

Example 10 with ComponentDefinition

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

Aggregations

ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)22 Test (org.junit.Test)15 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)13 DataDefinition (com.qcadoo.model.api.DataDefinition)9 ComponentOption (com.qcadoo.view.internal.ComponentOption)8 GridComponentPattern (com.qcadoo.view.internal.components.grid.GridComponentPattern)8 AbstractPatternTest (com.qcadoo.view.internal.patterns.AbstractPatternTest)8 TextInputComponentPattern (com.qcadoo.view.internal.components.TextInputComponentPattern)7 FieldDefinition (com.qcadoo.model.api.FieldDefinition)6 JSONObject (org.json.JSONObject)6 TranslationService (com.qcadoo.localization.api.TranslationService)4 ComponentState (com.qcadoo.view.api.ComponentState)4 InternalViewDefinitionState (com.qcadoo.view.internal.api.InternalViewDefinitionState)4 Node (org.w3c.dom.Node)4 EnumType (com.qcadoo.model.internal.types.EnumType)3 GridComponent (com.qcadoo.view.api.components.GridComponent)3 Map (java.util.Map)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 BelongsToType (com.qcadoo.model.api.types.BelongsToType)2 HasManyType (com.qcadoo.model.api.types.HasManyType)2