Search in sources :

Example 1 with ViewDefinitionParserNodeException

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

the class RibbonParserService method parseRibbon.

public InternalRibbon parseRibbon(final Node ribbonNode, final ViewDefinitionParser parser, final ViewDefinition viewDefinition) throws ViewDefinitionParserNodeException {
    InternalRibbon ribbon = new RibbonImpl();
    NodeList childNodes = ribbonNode.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node child = childNodes.item(i);
        if (Node.ELEMENT_NODE != child.getNodeType()) {
            continue;
        }
        if ("group".equals(child.getNodeName())) {
            ribbon.addGroupsPack(new SingleRibbonGroupPack(parseRibbonGroup(child, parser, viewDefinition)));
        } else if ("template".equals(child.getNodeName())) {
            applyTemplate(child, ribbon, parser, viewDefinition);
        } else {
            throw new ViewDefinitionParserNodeException(child, "Wrong node type - 'group' or 'template' expected");
        }
    }
    ribbon.setAlignment(parser.getStringAttribute(ribbonNode, ALIGNMENT));
    return ribbon;
}
Also used : InternalRibbon(com.qcadoo.view.internal.ribbon.model.InternalRibbon) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) SingleRibbonGroupPack(com.qcadoo.view.internal.ribbon.model.SingleRibbonGroupPack) ViewDefinitionParserNodeException(com.qcadoo.view.internal.xml.ViewDefinitionParserNodeException) RibbonImpl(com.qcadoo.view.internal.ribbon.model.RibbonImpl)

Example 2 with ViewDefinitionParserNodeException

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

the class RibbonParserService method applyTemplate.

private void applyTemplate(final Node templateNode, final InternalRibbon ribbon, final ViewDefinitionParser parser, final ViewDefinition viewDefinition) throws ViewDefinitionParserNodeException {
    String name = parser.getStringAttribute(templateNode, NAME);
    parser.checkState(name != null, templateNode, "Name attribute cannot be empty");
    String plugin = parser.getStringAttribute(templateNode, "plugin");
    RibbonTemplateParametersBuilder parametersBuilder = RibbonTemplateParameters.getBuilder(plugin, name);
    try {
        parametersBuilder.usingOnlyGroups(parser.getStringAttribute(templateNode, "includeGroups"));
        parametersBuilder.usingOnlyItems(parser.getStringAttribute(templateNode, "includeItems"));
        parametersBuilder.withoutGroups(parser.getStringAttribute(templateNode, "excludeGroups"));
        parametersBuilder.withoutItems(parser.getStringAttribute(templateNode, "excludeItems"));
    } catch (IllegalStateException e) {
        throw new ViewDefinitionParserNodeException(templateNode, e);
    }
    ribbonTemplatesService.applyTemplate(ribbon, parametersBuilder.build(), viewDefinition);
}
Also used : RibbonTemplateParametersBuilder(com.qcadoo.view.internal.ribbon.templates.RibbonTemplateParameters.RibbonTemplateParametersBuilder) ViewDefinitionParserNodeException(com.qcadoo.view.internal.xml.ViewDefinitionParserNodeException)

Example 3 with ViewDefinitionParserNodeException

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

the class RibbonParserService method parseRibbonGroup.

public InternalRibbonGroup parseRibbonGroup(final Node groupNode, final ViewDefinitionParser parser, final ViewDefinition viewDefinition) throws ViewDefinitionParserNodeException {
    String template = parser.getStringAttribute(groupNode, "template");
    SecurityRole role = parser.getAuthorizationRole(groupNode);
    if (template == null) {
        String groupName = parser.getStringAttribute(groupNode, NAME);
        if (groupName == null) {
            throw new ViewDefinitionParserNodeException(groupNode, "Name attribute cannot be empty");
        }
        InternalRibbonGroup ribbonGroup = new RibbonGroupImpl(groupName, role);
        NodeList childNodes = groupNode.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node child = childNodes.item(i);
            if (child.getNodeType() == Node.ELEMENT_NODE) {
                ribbonGroup.addItem(parseRibbonItem(child, parser, viewDefinition));
            }
        }
        return ribbonGroup;
    } else {
        try {
            return ribbonTemplates.getGroupTemplate(template, viewDefinition, role);
        } catch (IllegalStateException e) {
            throw new ViewDefinitionParserNodeException(groupNode, e);
        }
    }
}
Also used : SecurityRole(com.qcadoo.security.api.SecurityRole) RibbonGroupImpl(com.qcadoo.view.internal.ribbon.model.RibbonGroupImpl) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ViewDefinitionParserNodeException(com.qcadoo.view.internal.xml.ViewDefinitionParserNodeException) InternalRibbonGroup(com.qcadoo.view.internal.ribbon.model.InternalRibbonGroup)

Example 4 with ViewDefinitionParserNodeException

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

Example 5 with ViewDefinitionParserNodeException

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

the class RibbonParserService method parseRibbonItem.

public InternalRibbonActionItem parseRibbonItem(final Node itemNode, final ViewDefinitionParser parser, final ViewDefinition viewDefinition) throws ViewDefinitionParserNodeException {
    String stringType = itemNode.getNodeName();
    RibbonActionItem.Type type = null;
    if ("bigButtons".equals(stringType) || "bigButton".equals(stringType)) {
        type = RibbonActionItem.Type.BIG_BUTTON;
    } else if ("smallButtons".equals(stringType) || "smallButton".equals(stringType)) {
        type = RibbonActionItem.Type.SMALL_BUTTON;
    } else if ("combobox".equals(stringType)) {
        type = RibbonActionItem.Type.COMBOBOX;
    } else if ("smallEmptySpace".equals(stringType)) {
        type = RibbonActionItem.Type.SMALL_EMPTY_SPACE;
    } else {
        throw new ViewDefinitionParserNodeException(itemNode, "Unsupported ribbon item type '" + stringType + "'");
    }
    InternalRibbonActionItem item = null;
    if ("bigButtons".equals(stringType) || "smallButtons".equals(stringType)) {
        item = new RibbonComboItemImpl();
    } else if ("combobox".equals(stringType)) {
        item = new RibbonComboBoxImpl();
    } else {
        item = new RibbonActionItemImpl();
    }
    item.setIcon(parser.getStringAttribute(itemNode, "icon"));
    item.setName(parser.getStringAttribute(itemNode, NAME));
    String accesskey = parser.getStringAttribute(itemNode, "accesskey");
    if (accesskey != null) {
        item.setAccesskey(accesskey);
    }
    item.setAction(RibbonUtils.translateRibbonAction(parser.getStringAttribute(itemNode, "action"), viewDefinition));
    item.setType(type);
    String state = parser.getStringAttribute(itemNode, "state");
    if (state == null) {
        item.setEnabled(true);
    } else {
        if ("enabled".equals(state)) {
            item.setEnabled(true);
        } else if ("disabled".equals(state)) {
            item.setEnabled(false);
        } else {
            throw new ViewDefinitionParserNodeException(itemNode, "Unsupported ribbon item state : " + state);
        }
    }
    item.setDefaultEnabled(item.isEnabled());
    String message = parser.getStringAttribute(itemNode, "message");
    if (message != null) {
        item.setMessage(message);
    }
    NodeList childNodes = itemNode.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node child = childNodes.item(i);
        if (child.getNodeType() == Node.ELEMENT_NODE && "script".equals(child.getNodeName())) {
            item.setScript(parser.getStringNodeContent(child));
        }
    }
    if (item instanceof RibbonComboItem) {
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node child = childNodes.item(i);
            if (child.getNodeType() == Node.ELEMENT_NODE && !"script".equals(child.getNodeName())) {
                ((InternalRibbonComboItem) item).addItem(parseRibbonItem(child, parser, viewDefinition));
            }
        }
    } else if (item instanceof RibbonComboBox) {
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node child = childNodes.item(i);
            if (child.getNodeType() == Node.ELEMENT_NODE && !"script".equals(child.getNodeName())) {
                if (!"option".equals(child.getNodeName())) {
                    throw new ViewDefinitionParserNodeException(child, "ribbon combobox can only have 'option' elements");
                }
                ((RibbonComboBox) item).addOption(parser.getStringAttribute(child, NAME));
            }
        }
    } else {
        (item).setAction(RibbonUtils.translateRibbonAction(parser.getStringAttribute(itemNode, "action"), viewDefinition));
    }
    return item;
}
Also used : RibbonComboBox(com.qcadoo.view.api.ribbon.RibbonComboBox) InternalRibbonComboItem(com.qcadoo.view.internal.ribbon.model.InternalRibbonComboItem) RibbonComboItem(com.qcadoo.view.api.ribbon.RibbonComboItem) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) InternalRibbonComboItem(com.qcadoo.view.internal.ribbon.model.InternalRibbonComboItem) ViewDefinitionParserNodeException(com.qcadoo.view.internal.xml.ViewDefinitionParserNodeException) RibbonComboBoxImpl(com.qcadoo.view.internal.ribbon.model.RibbonComboBoxImpl) RibbonActionItemImpl(com.qcadoo.view.internal.ribbon.model.RibbonActionItemImpl) InternalRibbonActionItem(com.qcadoo.view.internal.ribbon.model.InternalRibbonActionItem) RibbonComboItemImpl(com.qcadoo.view.internal.ribbon.model.RibbonComboItemImpl) RibbonActionItem(com.qcadoo.view.api.ribbon.RibbonActionItem) InternalRibbonActionItem(com.qcadoo.view.internal.ribbon.model.InternalRibbonActionItem)

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