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