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;
}
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);
}
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);
}
}
}
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()));
}
}
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;
}
Aggregations