blob: 82c4225cc6ebd64db237ae5967202d5facceb1b8 [file] [log] [blame]
/**
*
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*
*
* This copyright notice shows up in the generated Java code
*
*/
package org.eclipse.osbp.xtext.gridsource.validation
import java.text.DateFormat
import java.text.DecimalFormat
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Set
import org.eclipse.emf.ecore.EClass
import org.eclipse.xtext.validation.Check
import org.eclipse.osbp.infogrid.model.gridsource.style.CxGridEventTopicAble
import org.eclipse.osbp.infogrid.model.gridsource.style.CxGridPropDateStyle
import org.eclipse.osbp.infogrid.model.gridsource.style.CxGridPropImageStyle
import org.eclipse.osbp.infogrid.model.gridsource.style.CxGridPropNumberStyle
import org.eclipse.osbp.infogrid.model.gridsource.style.CxGridPropPriceStyle
import org.eclipse.osbp.infogrid.model.gridsource.style.CxGridPropQuantityStyle
import org.eclipse.osbp.infogrid.model.gridsource.style.CxGridStylePackage
class GridSourceValidator extends AbstractGridSourceValidator {
@Check
def void checkDateformat(CxGridPropDateStyle style) {
if (style.dateFormat.nullOrEmpty) {
return
}
try {
val DateFormat df = new SimpleDateFormat(style.dateFormat)
df.format(new Date())
} catch (Exception ex) {
error('''«style.dateFormat» is not a valid date format''', style,
CxGridStylePackage.Literals.CX_GRID_PROP_DATE_STYLE__DATE_FORMAT)
}
}
@Check
def void checkMixedStyleConfigs(CxGridPropImageStyle style) {
var index = -1
val Set types = <EClass>newHashSet()
for (config : style.configs) {
index++
types.add(config.eClass)
if (types.length > 1) {
error('''You MUST NOT mix up different types of configs.''', style,
CxGridStylePackage.Literals.CX_GRID_PROP_IMAGE_STYLE__CONFIGS, index)
return
}
}
}
@Check
def void checkNumberformat(CxGridPropNumberStyle style) {
if (style.numberFormat.nullOrEmpty) {
return
}
try {
val df = new DecimalFormat(style.numberFormat)
df.format(1000.123)
} catch (Exception ex) {
error('''«style.numberFormat» is not a valid number format''', style,
CxGridStylePackage.Literals.CX_GRID_PROP_NUMBER_STYLE__NUMBER_FORMAT)
}
}
@Check
def void checkEventTopic(CxGridEventTopicAble topic) {
if (topic.eventTopic.nullOrEmpty) {
return
}
if (topic.eventTopic.startsWith("/")) {
error('''Eventtopic «topic.eventTopic» must not start with "/"''', topic,
CxGridStylePackage.Literals.CX_GRID_EVENT_TOPIC_ABLE__EVENT_TOPIC)
}
}
@Check
def void checkHtmlPattern(CxGridPropPriceStyle style) {
if(style.htmlPattern.nullOrEmpty) {
return
}
if (style.htmlPattern.nullOrEmpty || !style.htmlPattern.contains("{@value}") || !style.htmlPattern.contains("{@currency}")) {
error('''HtmlPattern needs to contain the placeholders {@value} and {@currency}.''', style,
CxGridStylePackage.Literals.CX_GRID_PROP_PRICE_STYLE__HTML_PATTERN)
}
}
@Check
def void checkHtmlPattern(CxGridPropQuantityStyle style) {
if(style.htmlPattern.nullOrEmpty) {
return
}
if (style.htmlPattern.nullOrEmpty || !style.htmlPattern.contains("{@value}") || !style.htmlPattern.contains("{@uom}")) {
error('''HtmlPattern needs to contain the placeholders {@value} and {@uom}.''', style,
CxGridStylePackage.Literals.CX_GRID_PROP_QUANTITY_STYLE__HTML_PATTERN)
}
}
}