Search in sources :

Example 16 with ComponentPattern

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

the class SmallTabLayoutState method renderContent.

@Override
protected JSONObject renderContent() throws JSONException {
    JSONObject state = new JSONObject();
    List<String> errorTabs = new LinkedList<String>();
    for (Map.Entry<String, InternalComponentState> child : getChildren().entrySet()) {
        if (child.getValue().isHasError()) {
            for (SmallTabLayoutPatternTab tab : tabs) {
                boolean found = false;
                for (ComponentPattern tabComponents : tab.getComponents()) {
                    if (tabComponents.getName().equals(child.getValue().getName())) {
                        errorTabs.add(tab.getName());
                        found = true;
                        break;
                    }
                }
                if (found) {
                    break;
                }
            }
        }
    }
    JSONArray errors = new JSONArray();
    for (String tabName : errorTabs) {
        errors.put(tabName);
    }
    state.put("errors", errors);
    return state;
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) Map(java.util.Map) LinkedList(java.util.LinkedList) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState)

Example 17 with ComponentPattern

use of com.qcadoo.view.internal.api.ComponentPattern 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 18 with ComponentPattern

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

the class ViewDefinitionImpl method translateContextReferences.

@Override
@SuppressWarnings("unchecked")
public String translateContextReferences(final String context) {
    if (context == null) {
        return null;
    }
    try {
        JSONObject oldContext = new JSONObject(context);
        JSONObject newContext = new JSONObject();
        Iterator<String> paths = oldContext.keys();
        while (paths.hasNext()) {
            String oldPath = paths.next();
            String[] newPath = oldPath.split("\\.");
            ComponentPattern pattern = getComponentByReference(newPath[0]);
            if (pattern == null) {
                throw new IllegalStateException("Cannot find component for " + getPluginIdentifier() + "." + getName() + ": " + newPath[0]);
            }
            newPath[0] = pattern.getPath();
            newContext.put(StringUtils.arrayToDelimitedString(newPath, "."), oldContext.get(oldPath));
        }
        return newContext.toString();
    } catch (JSONException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) AbstractComponentPattern(com.qcadoo.view.internal.patterns.AbstractComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern)

Example 19 with ComponentPattern

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

the class ViewDefinitionImpl method initialize.

@Override
public void initialize() {
    List<ComponentPattern> list = getPatternsAsList(patterns.values());
    int lastNotInitialized = 0;
    while (true) {
        int notInitialized = 0;
        for (ComponentPattern pattern : list) {
            if (!pattern.initialize()) {
                notInitialized++;
            }
        }
        if (notInitialized == 0) {
            break;
        }
        if (notInitialized == lastNotInitialized) {
            throw new IllegalStateException("There is cyclic dependency between components");
        }
        lastNotInitialized = notInitialized;
    }
    initAdditionalNavigation();
}
Also used : AbstractComponentPattern(com.qcadoo.view.internal.patterns.AbstractComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern)

Example 20 with ComponentPattern

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

the class GridLayoutPattern method createGridLayoutCell.

private GridLayoutCell createGridLayoutCell(final Node child, final ViewDefinitionParser parser) throws ViewDefinitionParserNodeException {
    Integer colspan = getIntAttribute(child, "width", parser);
    Integer rowspan = getIntAttribute(child, "height", parser);
    ComponentPattern elementComponent = null;
    NodeList elementComponentNodes = child.getChildNodes();
    GridLayoutCell cell = new GridLayoutCell();
    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");
        elementComponent = parser.parseComponent(elementComponentNode, this);
        this.addChild(elementComponent);
        cell.addComponent(elementComponent);
    }
    if (colspan != null) {
        cell.setColspan(colspan);
    }
    if (rowspan != null) {
        cell.setRowspan(rowspan);
    }
    return cell;
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) 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