From 31d4bf94b67763b77d45a2a23a3196b244e4224d Mon Sep 17 00:00:00 2001 From: lempinen Date: Tue, 14 Sep 2010 13:18:58 +0000 Subject: [PATCH] ExpressionField shows if the expression contains unsupported characters and doesn't crash git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@17910 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../widgets/expressions/ExpressionField.java | 9 ++++++--- .../widgets/expressions/ExpressionValidation.java | 11 +++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionField.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionField.java index d564d062..f2a4e7a9 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionField.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionField.java @@ -148,10 +148,13 @@ public class ExpressionField extends Composite { e.printStackTrace(); } } - + setSyntaxError(start, offset, "MissingLink", "Syntax error"); + } + + public void setSyntaxError(int start, int offset, String type, String text) { Annotation annotation = new Annotation(false); - annotation.setType("MissingLink"); - annotation.setText("Syntax error"); + annotation.setType(type); + annotation.setText(text); Position p = new Position(start, offset); _annotationModel.addAnnotation(annotation, p); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionValidation.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionValidation.java index 72936620..2c844005 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionValidation.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionValidation.java @@ -16,6 +16,7 @@ import org.simantics.db.exception.DatabaseException; import org.simantics.sysdyn.expressionParser.ExpressionParser; import org.simantics.sysdyn.expressionParser.ParseException; import org.simantics.sysdyn.expressionParser.Token; +import org.simantics.sysdyn.expressionParser.TokenMgrError; import org.simantics.sysdyn.manager.SysdynModel; import org.simantics.sysdyn.manager.SysdynModelManager; import org.simantics.sysdyn.representation.Configuration; @@ -39,13 +40,15 @@ public class ExpressionValidation { parser.ReInit(new StringReader(textString)); try { parser.expr(); + HashMap> cr = parser.getReferences(); + references.put(ef, cr); + for(String t : cr.keySet()) + variables.add(t); } catch (ParseException e1) { ef.setSyntaxError(e1.currentToken); + } catch (TokenMgrError err) { + ef.setSyntaxError(0, textString.length(), "MissingLink", "Expression contains unsupported characters"); } - HashMap> cr = parser.getReferences(); - references.put(ef, cr); - for(String t : cr.keySet()) - variables.add(t); } // Remove variables from variable array that don't exist in the model. Create annotations -- 2.47.1