Search in sources :

Example 11 with ComponentDefinition

use of com.qcadoo.view.internal.ComponentDefinition in project qcadoo by qcadoo.

the class ViewTabModule method enable.

@Override
public void enable() {
    addedTabs = ArrayListMultimap.create();
    InternalViewDefinition viewDefinition = viewDefinitionService.getWithoutSession(viewExtension.getPluginName(), viewExtension.getViewName());
    if (viewDefinition == null) {
        throw new ModuleException(pluginIdentifier, "view", String.format("Reference to view which not exists: %s[%s]", viewExtension.getPluginName(), viewExtension.getViewName()));
    }
    try {
        for (Node tabNode : viewDefinitionParser.geElementChildren(viewExtension.getExtesionNode())) {
            WindowComponentPattern window = viewDefinition.getRootWindow();
            ComponentDefinition tabDefinition = viewDefinitionParser.getComponentDefinition(tabNode, window, viewDefinition);
            tabDefinition.setExtensionPluginIdentifier(pluginIdentifier);
            ComponentPattern tabPattern = new WindowTabComponentPattern(tabDefinition);
            try {
                tabPattern.parse(tabNode, viewDefinitionParser);
            } catch (ViewDefinitionParserNodeException e) {
                throw ViewDefinitionParserException.forFileAndNode(fileName, e);
            }
            window.addChild(tabPattern);
            addedTabs.put(window, tabPattern);
            tabPattern.initializeAll();
            tabPattern.registerViews(viewDefinitionService);
        }
    } catch (Exception e) {
        throw new ModuleException(pluginIdentifier, "view-tab", e);
    }
}
Also used : WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) Node(org.w3c.dom.Node) ViewDefinitionParserNodeException(com.qcadoo.view.internal.xml.ViewDefinitionParserNodeException) WindowTabComponentPattern(com.qcadoo.view.internal.components.window.WindowTabComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) ModuleException(com.qcadoo.plugin.api.ModuleException) WindowTabComponentPattern(com.qcadoo.view.internal.components.window.WindowTabComponentPattern) ViewDefinitionParserNodeException(com.qcadoo.view.internal.xml.ViewDefinitionParserNodeException) IOException(java.io.IOException) ModuleException(com.qcadoo.plugin.api.ModuleException) ViewDefinitionParserException(com.qcadoo.view.internal.xml.ViewDefinitionParserException) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition)

Example 12 with ComponentDefinition

use of com.qcadoo.view.internal.ComponentDefinition in project qcadoo by qcadoo.

the class AwesomeDynamicListPattern 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 ("components".equals(child.getNodeName())) {
            innerFormPattern.parse(child, parser);
        } else if ("header".equals(child.getNodeName())) {
            ComponentDefinition formComponentDefinition = new ComponentDefinition();
            formComponentDefinition.setName("header");
            formComponentDefinition.setFieldPath(null);
            formComponentDefinition.setSourceFieldPath(null);
            formComponentDefinition.setTranslationService(getTranslationService());
            formComponentDefinition.setViewDefinition(getViewDefinition());
            formComponentDefinition.setParent(this);
            formComponentDefinition.setContextualHelpService(getContextualHelpService());
            headerFormPattern = new FlowLayoutPattern(formComponentDefinition);
            headerFormPattern.parse(child, parser);
            children.put(headerFormPattern.getName(), headerFormPattern);
        }
    }
}
Also used : FlowLayoutPattern(com.qcadoo.view.internal.components.layout.FlowLayoutPattern) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition)

Example 13 with ComponentDefinition

use of com.qcadoo.view.internal.ComponentDefinition in project qcadoo by qcadoo.

the class SelectComponentStateTest method init.

@Before
public void init() {
    MockitoAnnotations.initMocks(this);
    DictionaryType dictionaryType = new DictionaryType(DICTIONARY_NAME, dictionaryService, false);
    TranslationService translationService = mock(TranslationService.class);
    FieldDefinition fieldDefinition = mock(FieldDefinition.class);
    when(fieldDefinition.getType()).thenReturn(dictionaryType);
    when(fieldDefinition.isRequired()).thenReturn(true);
    when(fieldDefinition.getDefaultValue()).thenReturn("asd");
    ComponentDefinition definition = new ComponentDefinition();
    definition.setName("selectComponent");
    definition.setViewDefinition(mock(InternalViewDefinition.class));
    SelectComponentPattern pattern = new SelectComponentPattern(definition);
    setField(pattern, "fieldDefinition", fieldDefinition);
    setField(pattern, "translationService", translationService);
    componentState = new SelectComponentState(pattern, Lists.newArrayList());
    setField(componentState, "locale", Locale.ENGLISH);
    setField(pattern, "defaultRequired", true);
}
Also used : TranslationService(com.qcadoo.localization.api.TranslationService) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DictionaryType(com.qcadoo.model.internal.types.DictionaryType) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) Before(org.junit.Before)

Example 14 with ComponentDefinition

use of com.qcadoo.view.internal.ComponentDefinition in project qcadoo by qcadoo.

the class GridComponentPatternTest method shouldHaveScopeFieldName.

@Test
public void shouldHaveScopeFieldName() throws Exception {
    // given
    DataDefinition dataDefinition = mock(DataDefinition.class);
    BelongsToType belongsToFieldType = mock(BelongsToType.class);
    FieldDefinition belongsToFieldDefinition = mock(FieldDefinition.class);
    given(belongsToFieldDefinition.getName()).willReturn("joinName");
    given(belongsToFieldDefinition.getType()).willReturn(belongsToFieldType);
    given(belongsToFieldDefinition.getDataDefinition()).willReturn(dataDefinition);
    HasManyType hasManyFieldType = mock(HasManyType.class);
    given(hasManyFieldType.getJoinFieldName()).willReturn("joinName");
    given(hasManyFieldType.getDataDefinition()).willReturn(dataDefinition);
    FieldDefinition hasManyFieldDefinition = mock(FieldDefinition.class);
    given(hasManyFieldDefinition.getName()).willReturn("fieldName");
    given(hasManyFieldDefinition.getType()).willReturn(hasManyFieldType);
    given(hasManyFieldDefinition.getDataDefinition()).willReturn(dataDefinition);
    given(dataDefinition.getField("field")).willReturn(hasManyFieldDefinition);
    given(dataDefinition.getField("joinName")).willReturn(belongsToFieldDefinition);
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    AbstractComponentPattern sourceComponent = new TextInputComponentPattern(getComponentDefinition("component", viewDefinition));
    setField(sourceComponent, "dataDefinition", dataDefinition);
    setField(sourceComponent, "initialized", true);
    given(viewDefinition.getComponentByReference("component")).willReturn(sourceComponent);
    ComponentDefinition componentDefinition = getComponentDefinition(QcadooViewConstants.L_GRID, null, "#{component}.field", null, viewDefinition);
    componentDefinition.setTranslationService(translationService);
    componentDefinition.setApplicationContext(applicationContext);
    GridComponentPattern pattern = new GridComponentPattern(componentDefinition);
    pattern.addOption(new ComponentOption("order", ImmutableMap.of("column", "name", "direction", "asc")));
    // when
    pattern.initialize();
    // then
    JSONObject options = getJsOptions(pattern);
    assertEquals("joinName", options.getString("belongsToFieldName"));
}
Also used : HasManyType(com.qcadoo.model.api.types.HasManyType) BelongsToType(com.qcadoo.model.api.types.BelongsToType) GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) JSONObject(org.json.JSONObject) AbstractComponentPattern(com.qcadoo.view.internal.patterns.AbstractComponentPattern) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ComponentOption(com.qcadoo.view.internal.ComponentOption) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest) Test(org.junit.Test)

Example 15 with ComponentDefinition

use of com.qcadoo.view.internal.ComponentDefinition in project qcadoo by qcadoo.

the class GridComponentPatternTest method shouldBeFullscreen.

@Test
public void shouldBeFullscreen() throws Exception {
    // given
    DataDefinition dataDefinition = mock(DataDefinition.class);
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    given(viewDefinition.getDataDefinition()).willReturn(dataDefinition);
    ComponentDefinition componentDefinition = getComponentDefinition(QcadooViewConstants.L_GRID, viewDefinition);
    componentDefinition.setTranslationService(translationService);
    componentDefinition.setApplicationContext(applicationContext);
    GridComponentPattern pattern = new GridComponentPattern(componentDefinition);
    pattern.addOption(new ComponentOption("fullscreen", ImmutableMap.of("value", "true")));
    pattern.addOption(new ComponentOption("order", ImmutableMap.of("column", "name", "direction", "asc")));
    // when
    pattern.initialize();
    // then
    JSONObject options = getJsOptions(pattern);
    assertTrue(options.getBoolean("fullscreen"));
    assertEquals(0, options.getInt("width"));
    assertEquals(0, options.getInt("height"));
}
Also used : GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) JSONObject(org.json.JSONObject) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ComponentOption(com.qcadoo.view.internal.ComponentOption) DataDefinition(com.qcadoo.model.api.DataDefinition) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest) Test(org.junit.Test)

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