Search in sources :

Example 6 with ViewDefinitionParserNodeException

use of com.qcadoo.view.internal.xml.ViewDefinitionParserNodeException in project qcadoo by qcadoo.

the class ViewRibbonModule method enable.

@Override
public void enable() {
    addedGroups = new HashMap<WindowComponentPattern, RibbonGroupsPack>();
    InternalViewDefinition viewDefinition = viewDefinitionService.getWithoutSession(viewExtension.getPluginName(), viewExtension.getViewName());
    if (viewDefinition == null) {
        throw new ModuleException(pluginIdentifier, "view", "reference to view which not exists");
    }
    try {
        for (Node groupNode : viewDefinitionParser.geElementChildren(viewExtension.getExtesionNode())) {
            try {
                InternalRibbonGroup group = viewDefinitionParser.parseRibbonGroup(groupNode, viewDefinition);
                group.setExtensionPluginIdentifier(pluginIdentifier);
                RibbonGroupsPack groupsPack = new SingleRibbonGroupPack(group);
                WindowComponentPattern window = viewDefinition.getRootWindow();
                window.getRibbon().addGroupsPack(groupsPack);
                addedGroups.put(window, groupsPack);
            } catch (ViewDefinitionParserNodeException e) {
                throw ViewDefinitionParserException.forFileAndNode(fileName, e);
            }
        }
    } catch (Exception e) {
        throw new ModuleException(pluginIdentifier, "view-ribbon-group", e);
    }
}
Also used : WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) Node(org.w3c.dom.Node) SingleRibbonGroupPack(com.qcadoo.view.internal.ribbon.model.SingleRibbonGroupPack) ViewDefinitionParserNodeException(com.qcadoo.view.internal.xml.ViewDefinitionParserNodeException) RibbonGroupsPack(com.qcadoo.view.internal.ribbon.model.RibbonGroupsPack) ModuleException(com.qcadoo.plugin.api.ModuleException) InternalRibbonGroup(com.qcadoo.view.internal.ribbon.model.InternalRibbonGroup) ViewDefinitionParserNodeException(com.qcadoo.view.internal.xml.ViewDefinitionParserNodeException) IOException(java.io.IOException) ModuleException(com.qcadoo.plugin.api.ModuleException) ViewDefinitionParserException(com.qcadoo.view.internal.xml.ViewDefinitionParserException)

Example 7 with ViewDefinitionParserNodeException

use of com.qcadoo.view.internal.xml.ViewDefinitionParserNodeException 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 8 with ViewDefinitionParserNodeException

use of com.qcadoo.view.internal.xml.ViewDefinitionParserNodeException in project qcadoo by qcadoo.

the class GridComponentPattern method parsePredefinedFilterChildNodes.

private void parsePredefinedFilterChildNodes(final NodeList componentNodes, final ViewDefinitionParser parser) throws ViewDefinitionParserNodeException {
    for (int i = 0; i < componentNodes.getLength(); i++) {
        Node child = componentNodes.item(i);
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            if ("predefinedFilter".equals(child.getNodeName())) {
                PredefinedFilter predefinedFilter = new PredefinedFilter();
                String predefinedFilterName = parser.getStringAttribute(child, "name");
                predefinedFilter.setName(predefinedFilterName);
                NodeList restrictionNodes = child.getChildNodes();
                for (int restrictionNodesIndex = 0; restrictionNodesIndex < restrictionNodes.getLength(); restrictionNodesIndex++) {
                    Node restrictionNode = restrictionNodes.item(restrictionNodesIndex);
                    if (restrictionNode.getNodeType() == Node.ELEMENT_NODE) {
                        if ("filterRestriction".equals(restrictionNode.getNodeName())) {
                            predefinedFilter.addFilterRestriction(parser.getStringAttribute(restrictionNode, L_COLUMN), parser.getStringAttribute(restrictionNode, "value"));
                        } else if ("filterOrder".equals(restrictionNode.getNodeName())) {
                            String column = parser.getStringAttribute(restrictionNode, L_COLUMN);
                            String direction = parser.getStringAttribute(restrictionNode, "direction");
                            if (Objects.isNull(column)) {
                                throw new ViewDefinitionParserNodeException(restrictionNode, "'filterOrder' tag must contain 'column' attribute");
                            }
                            if (Objects.isNull(direction)) {
                                direction = "asc";
                            } else {
                                if (!("asc".equals(direction) || "desc".equals(direction))) {
                                    throw new ViewDefinitionParserNodeException(restrictionNode, "unknown order direction: " + direction);
                                }
                            }
                            predefinedFilter.setOrderColumn(column);
                            predefinedFilter.setOrderDirection(direction);
                        } else {
                            throw new ViewDefinitionParserNodeException(restrictionNode, "predefinedFilter can only contain 'filterRestriction' or 'filterOrder' tag");
                        }
                    }
                }
                if (Objects.isNull(predefinedFilter.getOrderColumn()) && Objects.nonNull(defaultOrderColumn)) {
                    predefinedFilter.setOrderColumn(defaultOrderColumn);
                    predefinedFilter.setOrderDirection(defaultOrderDirection);
                }
                predefinedFilters.put(predefinedFilterName, predefinedFilter);
            } else {
                throwIllegalStateException("predefinedFilters can only contain 'predefinedFilter' tag");
                throw new ViewDefinitionParserNodeException(child, "predefinedFilters can only contain 'predefinedFilter' tag");
            }
        }
    }
}
Also used : Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) ViewDefinitionParserNodeException(com.qcadoo.view.internal.xml.ViewDefinitionParserNodeException)

Example 9 with ViewDefinitionParserNodeException

use of com.qcadoo.view.internal.xml.ViewDefinitionParserNodeException in project qcadoo by qcadoo.

the class TreeComponentPattern 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 (child.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }
        if ("dataType".equals(child.getNodeName())) {
            String dataTypeName = parser.getStringAttribute(child, "name");
            TreeDataType dataType = new TreeDataType(dataTypeName);
            NodeList dataTypeOptionNodes = child.getChildNodes();
            for (int dton = 0; dton < dataTypeOptionNodes.getLength(); dton++) {
                Node dataTypeOptionNode = dataTypeOptionNodes.item(dton);
                if (dataTypeOptionNode.getNodeType() != Node.ELEMENT_NODE) {
                    continue;
                }
                if (!"option".equals(dataTypeOptionNode.getNodeName())) {
                    throw new ViewDefinitionParserNodeException(dataTypeOptionNode, "Tree 'dataType' node can only contains 'option' nodes");
                }
                String optionType = parser.getStringAttribute(dataTypeOptionNode, "type");
                String optionValue = parser.getStringAttribute(dataTypeOptionNode, "value");
                dataType.setOption(optionType, optionValue);
            }
            try {
                dataType.validate();
            } catch (IllegalStateException e) {
                throw new ViewDefinitionParserNodeException(child, e);
            }
            dataTypes.put(dataTypeName, dataType);
        }
    }
    if (dataTypes.isEmpty()) {
        throw new ViewDefinitionParserNodeException(componentNode, "Tree must contains at least one 'dataType' node");
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ViewDefinitionParserNodeException(com.qcadoo.view.internal.xml.ViewDefinitionParserNodeException)

Example 10 with ViewDefinitionParserNodeException

use of com.qcadoo.view.internal.xml.ViewDefinitionParserNodeException in project qcadoo by qcadoo.

the class FlowGridLayoutPattern method parse.

@Override
public void parse(final Node componentNode, final ViewDefinitionParser parser) throws ViewDefinitionParserNodeException {
    super.parse(componentNode, parser);
    Integer columns = getIntAttribute(componentNode, "columns", parser);
    Integer rows = getIntAttribute(componentNode, "rows", parser);
    parser.checkState(columns != null, componentNode, "columns not definied");
    parser.checkState(rows != null, componentNode, "rows not definied");
    // check again - because sonar is stupid
    if (rows == null) {
        throw new IllegalStateException("rows not definied");
    }
    cells = new FlowGridLayoutCell[rows][];
    for (int row = 0; row < cells.length; row++) {
        cells[row] = new FlowGridLayoutCell[columns];
        for (int col = 0; col < cells[row].length; col++) {
            cells[row][col] = new FlowGridLayoutCell();
        }
    }
    NodeList childNodes = componentNode.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node child = childNodes.item(i);
        if (child.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }
        parser.checkState("layoutElement".equals(child.getNodeName()), child, "flowGridlayout can contains only layoutElements");
        Integer column = getIntAttribute(child, "column", parser);
        Integer row = getIntAttribute(child, "row", parser);
        FlowGridLayoutCell cell = createFlowGridLayoutCell(child, parser);
        try {
            insertCell(cell, column, row);
        } catch (IllegalStateException e) {
            throw new ViewDefinitionParserNodeException(child, e);
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ViewDefinitionParserNodeException(com.qcadoo.view.internal.xml.ViewDefinitionParserNodeException)

Aggregations

ViewDefinitionParserNodeException (com.qcadoo.view.internal.xml.ViewDefinitionParserNodeException)11 Node (org.w3c.dom.Node)10 NodeList (org.w3c.dom.NodeList)8 ModuleException (com.qcadoo.plugin.api.ModuleException)2 ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)2 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)2 WindowComponentPattern (com.qcadoo.view.internal.components.window.WindowComponentPattern)2 InternalRibbonGroup (com.qcadoo.view.internal.ribbon.model.InternalRibbonGroup)2 SingleRibbonGroupPack (com.qcadoo.view.internal.ribbon.model.SingleRibbonGroupPack)2 ViewDefinitionParserException (com.qcadoo.view.internal.xml.ViewDefinitionParserException)2 IOException (java.io.IOException)2 SecurityRole (com.qcadoo.security.api.SecurityRole)1 RibbonActionItem (com.qcadoo.view.api.ribbon.RibbonActionItem)1 RibbonComboBox (com.qcadoo.view.api.ribbon.RibbonComboBox)1 RibbonComboItem (com.qcadoo.view.api.ribbon.RibbonComboItem)1 ComponentPattern (com.qcadoo.view.internal.api.ComponentPattern)1 WindowTabComponentPattern (com.qcadoo.view.internal.components.window.WindowTabComponentPattern)1 InternalRibbon (com.qcadoo.view.internal.ribbon.model.InternalRibbon)1 InternalRibbonActionItem (com.qcadoo.view.internal.ribbon.model.InternalRibbonActionItem)1 InternalRibbonComboItem (com.qcadoo.view.internal.ribbon.model.InternalRibbonComboItem)1