Search in sources :

Example 11 with InternalRibbonActionItem

use of com.qcadoo.view.internal.ribbon.model.InternalRibbonActionItem 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)

Example 12 with InternalRibbonActionItem

use of com.qcadoo.view.internal.ribbon.model.InternalRibbonActionItem in project qcadoo by qcadoo.

the class RibbonTemplates method createGridDeactivateAction.

private InternalRibbonActionItem createGridDeactivateAction(final ViewDefinition viewDefinition) {
    InternalRibbonActionItem ribbonDeactivateAction = new RibbonActionItemImpl();
    ribbonDeactivateAction.setAction(RibbonUtils.translateRibbonAction("#{grid}.performDeactivate;", viewDefinition));
    ribbonDeactivateAction.setIcon("unactiveNotVisibleIcon.png");
    ribbonDeactivateAction.setName("deactivate");
    ribbonDeactivateAction.setEnabled(false);
    ribbonDeactivateAction.setScript("var listener = {onChange: function(selectedArray) {if (selectedArray.length == 0) {" + "this.disable();} else {this.enable();}}}; #{grid}.addOnChangeListener(listener);");
    ribbonDeactivateAction.setType(RibbonActionItem.Type.SMALL_BUTTON);
    return ribbonDeactivateAction;
}
Also used : RibbonActionItemImpl(com.qcadoo.view.internal.ribbon.model.RibbonActionItemImpl) InternalRibbonActionItem(com.qcadoo.view.internal.ribbon.model.InternalRibbonActionItem)

Example 13 with InternalRibbonActionItem

use of com.qcadoo.view.internal.ribbon.model.InternalRibbonActionItem in project qcadoo by qcadoo.

the class RibbonTemplates method createGridNewAction.

private InternalRibbonActionItem createGridNewAction(final ViewDefinition viewDefinition) {
    InternalRibbonActionItem ribbonNewAction = new RibbonActionItemImpl();
    ribbonNewAction.setAction(RibbonUtils.translateRibbonAction("#{grid}.performNew;", viewDefinition));
    ribbonNewAction.setIcon("newIcon24.png");
    ribbonNewAction.setName("new");
    ribbonNewAction.setEnabled(true);
    ribbonNewAction.setType(RibbonActionItem.Type.BIG_BUTTON);
    return ribbonNewAction;
}
Also used : RibbonActionItemImpl(com.qcadoo.view.internal.ribbon.model.RibbonActionItemImpl) InternalRibbonActionItem(com.qcadoo.view.internal.ribbon.model.InternalRibbonActionItem)

Example 14 with InternalRibbonActionItem

use of com.qcadoo.view.internal.ribbon.model.InternalRibbonActionItem in project qcadoo by qcadoo.

the class RibbonTemplates method createNavigationTemplate.

private InternalRibbonGroup createNavigationTemplate(final ViewDefinition viewDefinition, final SecurityRole role) {
    InternalRibbonActionItem ribbonBackAction = new RibbonActionItemImpl();
    ribbonBackAction.setAction(RibbonUtils.translateRibbonAction("#{window}.performBack", viewDefinition));
    ribbonBackAction.setIcon("backIcon24.png");
    ribbonBackAction.setName("back");
    ribbonBackAction.setEnabled(true);
    ribbonBackAction.setType(RibbonActionItem.Type.BIG_BUTTON);
    InternalRibbonGroup ribbonGroup = new RibbonGroupImpl("navigation", role);
    ribbonGroup.addItem(ribbonBackAction);
    return ribbonGroup;
}
Also used : RibbonGroupImpl(com.qcadoo.view.internal.ribbon.model.RibbonGroupImpl) RibbonActionItemImpl(com.qcadoo.view.internal.ribbon.model.RibbonActionItemImpl) InternalRibbonActionItem(com.qcadoo.view.internal.ribbon.model.InternalRibbonActionItem) InternalRibbonGroup(com.qcadoo.view.internal.ribbon.model.InternalRibbonGroup)

Example 15 with InternalRibbonActionItem

use of com.qcadoo.view.internal.ribbon.model.InternalRibbonActionItem in project qcadoo by qcadoo.

the class RibbonTemplates method createGridDeleteAction.

private InternalRibbonActionItem createGridDeleteAction(final ViewDefinition viewDefinition) {
    InternalRibbonActionItem ribbonDeleteAction = new RibbonActionItemImpl();
    ribbonDeleteAction.setAction(RibbonUtils.translateRibbonAction("#{grid}.performDelete;", viewDefinition));
    ribbonDeleteAction.setIcon("deleteIcon16.png");
    ribbonDeleteAction.setName("delete");
    ribbonDeleteAction.setType(RibbonActionItem.Type.SMALL_BUTTON);
    ribbonDeleteAction.setEnabled(false);
    ribbonDeleteAction.setDefaultEnabled(false);
    ribbonDeleteAction.setScript("var listener = {onChange: function(selectedArray) {if (selectedArray.length == 0) {" + "this.disable();} else {this.enable();}}}; #{grid}.addOnChangeListener(listener);");
    return ribbonDeleteAction;
}
Also used : RibbonActionItemImpl(com.qcadoo.view.internal.ribbon.model.RibbonActionItemImpl) InternalRibbonActionItem(com.qcadoo.view.internal.ribbon.model.InternalRibbonActionItem)

Aggregations

InternalRibbonActionItem (com.qcadoo.view.internal.ribbon.model.InternalRibbonActionItem)21 RibbonActionItemImpl (com.qcadoo.view.internal.ribbon.model.RibbonActionItemImpl)18 InternalRibbonGroup (com.qcadoo.view.internal.ribbon.model.InternalRibbonGroup)4 RibbonGroupImpl (com.qcadoo.view.internal.ribbon.model.RibbonGroupImpl)4 RibbonActionItem (com.qcadoo.view.api.ribbon.RibbonActionItem)3 RibbonComboItem (com.qcadoo.view.api.ribbon.RibbonComboItem)2 RibbonComboBox (com.qcadoo.view.api.ribbon.RibbonComboBox)1 InternalRibbonComboItem (com.qcadoo.view.internal.ribbon.model.InternalRibbonComboItem)1 RibbonComboBoxImpl (com.qcadoo.view.internal.ribbon.model.RibbonComboBoxImpl)1 RibbonComboItemImpl (com.qcadoo.view.internal.ribbon.model.RibbonComboItemImpl)1 ViewDefinitionParserNodeException (com.qcadoo.view.internal.xml.ViewDefinitionParserNodeException)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1