Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2012-04-10 08:38:03 +0000
committercletavernie2012-04-10 08:38:03 +0000
commita7e1204951c3624b00b7fcc6b5d236f98532ba3f (patch)
tree848c2e801250de71823075dca81642908cd7e767 /plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.xtext
parent0a63672273d85165cd40832bad87eba2783610d6 (diff)
downloadorg.eclipse.papyrus-a7e1204951c3624b00b7fcc6b5d236f98532ba3f.tar.gz
org.eclipse.papyrus-a7e1204951c3624b00b7fcc6b5d236f98532ba3f.tar.xz
org.eclipse.papyrus-a7e1204951c3624b00b7fcc6b5d236f98532ba3f.zip
370797: [Theme] Papyrus should provide a support for CSS files on its diagrams
https://bugs.eclipse.org/bugs/show_bug.cgi?id=370797
Diffstat (limited to 'plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.xtext')
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.xtext/src/org/eclipse/papyrus/infra/gmfdiag/validation/CSSJavaValidator.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.xtext/src/org/eclipse/papyrus/infra/gmfdiag/validation/CSSJavaValidator.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.xtext/src/org/eclipse/papyrus/infra/gmfdiag/validation/CSSJavaValidator.java
index e03031f3cea..a3f23360674 100644
--- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.xtext/src/org/eclipse/papyrus/infra/gmfdiag/validation/CSSJavaValidator.java
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.xtext/src/org/eclipse/papyrus/infra/gmfdiag/validation/CSSJavaValidator.java
@@ -11,10 +11,18 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.validation;
+
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.papyrus.infra.gmfdiag.css.Attribute;
import org.eclipse.papyrus.infra.gmfdiag.css.CssPackage;
+import org.eclipse.papyrus.infra.gmfdiag.css.Expression;
+import org.eclipse.papyrus.infra.gmfdiag.css.Function;
import org.eclipse.papyrus.infra.gmfdiag.css.HexColor;
+import org.eclipse.papyrus.infra.gmfdiag.css.Number;
import org.eclipse.papyrus.infra.gmfdiag.css.SimpleSelector;
+import org.eclipse.papyrus.infra.gmfdiag.css.Subterm;
+import org.eclipse.papyrus.infra.gmfdiag.css.Term;
+import org.eclipse.papyrus.infra.gmfdiag.css.UNARY;
import org.eclipse.xtext.validation.Check;
@@ -34,6 +42,59 @@ public class CSSJavaValidator extends AbstractCSSJavaValidator {
}
}
+ @Check
+ public void checkRGBColor(Function function) {
+ if("rgb".equals(function.getName().toLowerCase())) {
+ if(function.getArgs().getSubterms().size() != 2) { //3 Args: 1 Term + 2 Subterms
+ warning("Invalid color. The RGB color must have exactly 3 arguments", CssPackage.Literals.FUNCTION__ARGS);
+ }
+
+
+ }
+ }
+
+ @Check
+ public void checkRGBTerm(Term term) {
+ Expression owningExpression = findExpression(term);
+ if(owningExpression == null) {
+ return;
+ }
+
+ if(owningExpression.eContainer() instanceof Function) {
+ if("rgb".equals(((Function)owningExpression.eContainer()).getName().toLowerCase())) {
+ if(!(term instanceof Number)) {
+ warning("The RGB color arguments must be integers. Actual type: " + term.eClass().getName(), term.eClass().getEStructuralFeature("value"));
+ } else {
+ Number number = (Number)term;
+
+ boolean validValue = true;
+ try {
+ int absoluteValue = Integer.parseInt(number.getValue());
+ validValue = (number.getOp() == null || number.getOp().getOperator() == UNARY.PLUS) && absoluteValue <= 255;
+ } catch (NumberFormatException ex) {
+ validValue = false;
+ }
+
+ if(!validValue) {
+ warning("The RGB color arguments must be integers between 0 and 255", term.eClass().getEStructuralFeature("value"));
+ }
+ }
+ }
+ }
+ }
+
+ protected Expression findExpression(EObject term) {
+ if(term.eContainer() instanceof Expression) {
+ return (Expression)term.eContainer();
+ }
+
+ if(term.eContainer() instanceof Subterm) {
+ return findExpression(term.eContainer());
+ }
+
+ return null;
+ }
+
//////////////////////////
// EMF Only //
//////////////////////////

Back to the top