Search in sources :

Example 6 with ComponentPattern

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

the class ViewDefinitionTest method shouldThrowCyclicDependencyOnInitialize.

@Test(expected = IllegalStateException.class)
public void shouldThrowCyclicDependencyOnInitialize() throws Exception {
    // given
    InternalViewDefinition viewDefinition = new ViewDefinitionImpl("name", "plugin", mock(DataDefinition.class), true, null);
    ComponentPattern pattern1 = Mockito.mock(ComponentPattern.class);
    given(pattern1.getName()).willReturn("test1");
    given(pattern1.initialize()).willReturn(false, false, false);
    ComponentPattern pattern2 = Mockito.mock(ComponentPattern.class);
    given(pattern2.getName()).willReturn("test2");
    given(pattern2.initialize()).willReturn(false, false, false);
    ComponentPattern pattern3 = Mockito.mock(ComponentPattern.class);
    given(pattern3.getName()).willReturn("test3");
    given(pattern3.initialize()).willReturn(false, true);
    ComponentPattern pattern4 = Mockito.mock(ComponentPattern.class);
    given(pattern3.getName()).willReturn("test4");
    given(pattern3.initialize()).willReturn(true);
    viewDefinition.addComponentPattern(pattern1);
    viewDefinition.addComponentPattern(pattern2);
    viewDefinition.addComponentPattern(pattern3);
    viewDefinition.addComponentPattern(pattern4);
    // when
    viewDefinition.initialize();
}
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)

Example 7 with ComponentPattern

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

the class ViewDefinitionTest method shouldReturnNullWhenPatternNotExists.

@Test
public void shouldReturnNullWhenPatternNotExists() throws Exception {
    // given
    InternalViewDefinition viewDefinition = new ViewDefinitionImpl("name", "plugin", mock(DataDefinition.class), true, null);
    // when
    ComponentPattern actualPattern = viewDefinition.getComponentByReference("xxx");
    // then
    assertNull(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)

Example 8 with ComponentPattern

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

the class ViewGridColumnModule method getGrid.

private GridComponentPattern getGrid() {
    InternalViewDefinition viewDefinition = viewDefinitionService.getWithoutSession(extendsViewPlugin, extendsViewName);
    if (viewDefinition == null) {
        throw new ModuleException(pluginIdentifier, "view", "reference to view which not exists");
    }
    ComponentPattern component = viewDefinition.getComponentByReference(extendsComponentName);
    if (component == null) {
        throw new ModuleException(pluginIdentifier, "view", "reference to component which not exists in " + extendsViewPlugin + "/" + extendsViewName);
    }
    if (!(component instanceof GridComponentPattern)) {
        throw new ModuleException(pluginIdentifier, "view", "component '" + extendsComponentName + "' in " + extendsViewPlugin + "/" + extendsViewName + " is not a grid");
    }
    return (GridComponentPattern) component;
}
Also used : GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) ModuleException(com.qcadoo.plugin.api.ModuleException)

Example 9 with ComponentPattern

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

the class AbstractContainerPattern method prepareView.

@Override
public Map<String, Object> prepareView(final Locale locale) {
    Map<String, Object> model = super.prepareView(locale);
    Map<String, Object> childrenModels = new LinkedHashMap<String, Object>();
    for (ComponentPattern child : children.values()) {
        if (isComponentEnabled(child)) {
            childrenModels.put(child.getName(), child.prepareView(locale));
        }
    }
    model.put("children", childrenModels);
    return model;
}
Also used : ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) LinkedHashMap(java.util.LinkedHashMap)

Example 10 with ComponentPattern

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

the class RibbonUtils method translateRibbonAction.

public static String translateRibbonAction(final String action, final ViewDefinition viewDefinition) {
    if (action == null) {
        return null;
    }
    if (viewDefinition == null) {
        return action;
    }
    Pattern p = Pattern.compile("#\\{([^\\}]+)\\}");
    Matcher m = p.matcher(action);
    String translateAction = action;
    while (m.find()) {
        ComponentPattern actionComponentPattern = ((InternalViewDefinition) viewDefinition).getComponentByReference(m.group(1));
        if (actionComponentPattern == null) {
            throw new IllegalStateException("Cannot find component '" + m.group(1) + "' for action: " + action);
        }
        translateAction = translateAction.replace("#{" + m.group(1) + "}", "#{" + actionComponentPattern.getPath() + "}");
    }
    return translateAction;
}
Also used : AbstractComponentPattern(com.qcadoo.view.internal.patterns.AbstractComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) AbstractComponentPattern(com.qcadoo.view.internal.patterns.AbstractComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern)

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