]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Expression Field
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 29 Jan 2010 14:16:07 +0000 (14:16 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 29 Jan 2010 14:16:07 +0000 (14:16 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@13778 ac1ea38d-2e2b-0410-8846-a27921b304fc

12 files changed:
org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java
org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/EquationView.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/AuxiliaryExpressionViewFactor.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ConstantExpressionViewFactor.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/DelayExpressionViewFactor.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ExpressionField.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/IExpressionViewFactor.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/LookupExpressionViewFactor.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ParameterExpressionViewFactor.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/StockExpressionViewFactor.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/WithLookupExpressionViewFactor.java

index 5ed419b104fe43cc274835a6bd22cac7bd94ac5f..4c0de3c64f437ce0963c6ee82c1fff4d6996c778 100644 (file)
@@ -12,7 +12,7 @@ import org.simantics.modelica.data.SimulationResult;
 public class ModelicaManager {\r
 \r
     protected static File getOpenModelicaHome() {\r
-        String dir = System.getenv("OPENMODELICAHOMEe");\r
+        String dir = System.getenv("OPENMODELICAHOME");\r
         if(dir == null)\r
             dir = "c:/OpenModelica1.5.0";\r
         return new File(dir);\r
index 7a7185bf593062fd79ceeb4329d574f20a879ffa..123919d6eb4694aba33abf2312cc9ce5adf1b3a3 100644 (file)
             commandId="org.simantics.sysdyn.ui.trend.view.pin">\r
       </handler>\r
    </extension>\r
--  <extension point="org.eclipse.ui.editors.annotationTypes">\r
-      <type markerSeverity="0" name="com.mycompany.element" /> \r
-   </extension>\r
--     <extension point="org.eclipse.ui.editors.markerAnnotationSpecification">\r
-      <specification annotationType="com.mycompany.element" colorPreferenceKey="annotateElemColor" colorPreferenceValue="255,255,0" highlightPreferenceKey="annotateElemHighlight" highlightPreferenceValue="true" includeOnPreferencePage="true" label="Sample Annotation" overviewRulerPreferenceKey="annotateElemOverviewRuler" textPreferenceKey="annotateElemText" verticalRulerPreferenceKey="annotateElemVerticalRuler" verticalRulerPreferenceValue="true" /> \r
-   </extension>\r
 </plugin>\r
index 9ece38b081555ffab87edb2ccd4860620ae69d89..173cbf3153e0cb3020ea15a13139122c46720e8b 100644 (file)
@@ -3,8 +3,6 @@ package org.simantics.sysdyn.ui.equation;
 \r
 import java.io.StringReader;\r
 import java.util.ArrayList;\r
-import java.util.Collections;\r
-import java.util.Comparator;\r
 import java.util.HashMap;\r
 import java.util.HashSet;\r
 import java.util.List;\r
@@ -15,7 +13,6 @@ import org.eclipse.jface.layout.GridLayoutFactory;
 import org.eclipse.jface.viewers.ISelection;\r
 import org.eclipse.jface.viewers.IStructuredSelection;\r
 import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.custom.StyleRange;\r
 import org.eclipse.swt.custom.StyledText;\r
 import org.eclipse.swt.events.FocusEvent;\r
 import org.eclipse.swt.events.FocusListener;\r
@@ -30,7 +27,9 @@ import org.eclipse.swt.events.SelectionListener;
 import org.eclipse.swt.graphics.Color;\r
 import org.eclipse.swt.graphics.Font;\r
 import org.eclipse.swt.graphics.Point;\r
+import org.eclipse.swt.layout.RowLayout;\r
 import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Label;\r
 import org.eclipse.swt.widgets.Table;\r
 import org.eclipse.swt.widgets.TableItem;\r
 import org.eclipse.swt.widgets.Text;\r
@@ -49,6 +48,7 @@ import org.simantics.sysdyn.expressionParser.ParseException;
 import org.simantics.sysdyn.expressionParser.Token;\r
 import org.simantics.sysdyn.ui.equation.expressions.ExpressionField;\r
 import org.simantics.ui.SimanticsUI;\r
+import org.eclipse.jface.text.Position;\r
 \r
 public class EquationView extends ViewPart implements ISelectionListener {\r
 \r
@@ -71,20 +71,6 @@ public class EquationView extends ViewPart implements ISelectionListener {
     // Dummies\r
     Composite unitsAndRange;  \r
     Composite emptyComposite;\r
-    \r
-    ExpressionField ef;\r
-\r
-\r
-    StyledText styledText;\r
-    \r
-    public static final String              ANNO_TYPE          = "org.eclipse.ui.workbench.texteditor.error";\r
-    public static final String              ANNO_KEY_HIGHLIGHT = "annotateElemHighlight";\r
-    public static final String              ANNO_KEY_OVERVIEW  = "annotateElemOverviewRuler";\r
-    public static final String              ANNO_KEY_VERTICAL  = "annotateElemVertialRuler";\r
-    public static final String              ANNO_KEY_TEXT      = "annotateElemText";\r
-    public static final String              ANNO_KEY_COLOR     = "annotateElemColor";\r
\r
-\r
 \r
     @Override    \r
     public void createPartControl(Composite parent) {\r
@@ -151,9 +137,6 @@ public class EquationView extends ViewPart implements ISelectionListener {
         emptyComposite = new Composite(parent, SWT.NONE);\r
         GridDataFactory.fillDefaults().span(1,4).grab(true, true).applyTo(emptyComposite);\r
         GridLayoutFactory.fillDefaults().applyTo(emptyComposite);\r
-        \r
-        ef = new ExpressionField(emptyComposite, SWT.NONE);\r
-        GridDataFactory.fillDefaults().grab(true, true).applyTo(ef);\r
 \r
         // Below variable name: Equation\r
         expressionComposite = new ExpressionComposite(parent, SWT.NONE);\r
@@ -162,42 +145,10 @@ public class EquationView extends ViewPart implements ISelectionListener {
 \r
         // Lower part of the view: Units and Range\r
         unitsAndRange = new Composite(parent, SWT.NONE); \r
-        GridDataFactory.fillDefaults().span(3, 1).grab(true, true).applyTo(unitsAndRange);\r
+        GridDataFactory.fillDefaults().span(3, 1).grab(true, false).applyTo(unitsAndRange);\r
 \r
         GridLayoutFactory.fillDefaults().applyTo(unitsAndRange);\r
 \r
-        styledText = new StyledText(unitsAndRange, SWT.BORDER | SWT.H_SCROLL\r
-                | SWT.V_SCROLL);\r
-\r
-\r
-        GridDataFactory.fillDefaults().grab(true, true).applyTo(styledText);\r
-\r
-        /*\r
-        styledText.addLineStyleListener(new LineStyleListener() {\r
-\r
-            public void lineGetStyle(LineStyleEvent event) {\r
-              // Create a collection to hold the StyleRanges\r
-              java.util.List styles = new java.util.ArrayList();\r
-              // Iterate through the text\r
-              for (int i = 0, n = event.lineText.length(); i < n; i++) {\r
-                // Check for 'e'\r
-                if (event.lineText.charAt(i) == 'e') {\r
-                  // Found an 'e'; combine all subsequent e's into the same StyleRange\r
-                  int start = i;\r
-                  for (; i < n && event.lineText.charAt(i) == 'e'; i++);\r
-\r
-                  // Create the StyleRange and add it to the collection\r
-                  styles.add(new StyleRange(event.lineOffset + start, i - start, styledText.getDisplay().getSystemColor(SWT.COLOR_RED),\r
-                      null));\r
-                }\r
-              }\r
-              // Set the styles for the line\r
-              event.styles = (StyleRange[]) styles.toArray(new StyleRange[0]);\r
-            }\r
-          });\r
-         */\r
-\r
-        /*\r
         RowLayout layout = new RowLayout();\r
         layout.spacing = 3;\r
         unitsAndRange.setLayout(layout);\r
@@ -214,7 +165,7 @@ public class EquationView extends ViewPart implements ISelectionListener {
         text1.setToolTipText("Stop");\r
         text1 = new Text(c, SWT.SINGLE | SWT.BORDER);\r
         text1.setToolTipText("Step");\r
-         */\r
+\r
     }   \r
 \r
     static class Auxiliary {\r
@@ -380,16 +331,17 @@ public class EquationView extends ViewPart implements ISelectionListener {
 \r
     private void addExpressionFieldListeners() {\r
         if(expressionComposite.getExpressionViewFactor() != null)\r
-            for(Text text : expressionComposite.getExpressionViewFactor().getExpressionFields()) {\r
-                final String expression = text.getText();\r
-                text.addModifyListener(new ModifyListener() {\r
+            for(ExpressionField ef : expressionComposite.getExpressionViewFactor().getExpressionFields()) {\r
+                final String expression = ef.getExpression();\r
+                StyledText st = ef.getSourceViewer().getTextWidget();\r
+                st.addModifyListener(new ModifyListener() {\r
 \r
                     @Override\r
                     public void modifyText(ModifyEvent e) {\r
                         validateExpressionFields();\r
                     }\r
                 });\r
-                text.addKeyListener(new KeyListener() {\r
+                st.addKeyListener(new KeyListener() {\r
 \r
                     @Override\r
                     public void keyReleased(KeyEvent e) {\r
@@ -409,35 +361,29 @@ public class EquationView extends ViewPart implements ISelectionListener {
     private void validateExpressionFields() {\r
         ExpressionParser parser = new ExpressionParser(new StringReader(""));\r
         Set<String> variables = new HashSet<String>();\r
-        HashMap<String, List<Token>> references = null;\r
+        HashMap<ExpressionField, HashMap<String, List<Token>>> references = new HashMap<ExpressionField, HashMap<String, List<Token>>>();\r
 \r
 \r
 \r
         if(expressionComposite.getExpressionViewFactor() != null)\r
-            for(Text text : expressionComposite.getExpressionViewFactor().getExpressionFields()) {\r
-\r
-                \r
-                styledText.setText(text.getText());\r
-\r
-                String textString = text.getText();\r
+            for(ExpressionField ef : expressionComposite.getExpressionViewFactor().getExpressionFields()) {\r
+                ef.resetAnnotations();\r
+                String textString = ef.getExpression();\r
                 parser.ReInit(new StringReader(textString));\r
                 try {\r
                     parser.expr();\r
-                    System.out.println(parser.getReferences());\r
-                    references = parser.getReferences();\r
-                    for(String t : references.keySet())\r
+                    HashMap<String, List<Token>> cr = parser.getReferences();\r
+                    references.put(ef, cr);\r
+                    for(String t : cr.keySet())\r
                         variables.add(t);\r
-                    text.setBackground(new Color(text.getDisplay(), 255, 255, 255));\r
                 } catch (ParseException e1) {\r
-                    text.setBackground(new Color(text.getDisplay(), 255, 230, 230));\r
+                    ef.setSyntaxError();\r
                     return;\r
                 }\r
             }\r
 \r
         for(TableItem ti : this.shortcutTabs.getVariableTable().getItems()) {\r
             if(!variables.contains(ti.getText())) {\r
-                for(Text text : expressionComposite.getExpressionViewFactor().getExpressionFields())\r
-                    text.setBackground(new Color(text.getDisplay(), 255, 230, 230)); \r
                 ti.setBackground(new Color(ti.getDisplay(), 255, 230, 230));\r
             } else {\r
                 ti.setBackground(new Color(ti.getDisplay(), 255, 255, 255));\r
@@ -446,39 +392,24 @@ public class EquationView extends ViewPart implements ISelectionListener {
         }\r
 \r
         if(!variables.isEmpty()) {\r
-            ArrayList<StyleRange> ranges = new ArrayList<StyleRange>();\r
-            String no_connections = "No connections for: ";\r
+            ArrayList<Position> positions = new ArrayList<Position>();\r
             for(String s : variables) {\r
-                List<Token> tlist = references.get(s);\r
-                for(Token t : tlist) {\r
-                    no_connections = no_connections + s + "[" + t.beginLine + "," + \r
-                    t.beginColumn + "," + t.endLine + "," + t.endColumn + "]";\r
-                    int start = styledText.getOffsetAtLine(t.beginLine - 1) + t.beginColumn - 1;\r
-                    int length = t.endColumn - t.beginColumn + 1;\r
-                    System.out.println(start + ", " + length);\r
-                    ranges.add(new StyleRange( \r
-                            start,\r
-                            length, \r
-                            new Color(styledText.getDisplay(), 0, 0, 0), \r
-                            new Color(styledText.getDisplay(), 255, 255, 255), \r
-                            SWT.BOLD));\r
+                List<Token> tlist = new ArrayList<Token>();\r
+                for(ExpressionField ef : references.keySet()) {\r
+                    tlist = references.get(ef).get(s);\r
+                    if(tlist != null)\r
+                        for(Token t : tlist) {\r
+                            StyledText st = ef.getSourceViewer().getTextWidget();\r
+                            int start =  st.getOffsetAtLine(t.beginLine - 1) + t.beginColumn - 1;\r
+                            int offset = st.getOffsetAtLine(t.endLine - 1) + t.endColumn - start;\r
+                            positions.add(new Position(\r
+                                    start,\r
+                                    offset));\r
+                        }\r
+                    ef.setMissingLinkAnnotations(positions);\r
                 }\r
             }\r
-            System.out.println(no_connections);\r
-            Collections.sort(ranges, new StyleRangeSorter());\r
-            styledText.setStyleRanges(ranges.toArray(new StyleRange[0]));\r
-        }\r
-    }\r
-\r
-\r
-    class StyleRangeSorter implements Comparator<StyleRange> {\r
-        public int compare(StyleRange a, StyleRange b) {\r
-            Integer ai, bi;\r
-\r
-            ai = a.start;\r
-            bi = b.start;\r
 \r
-            return ai.compareTo(bi);\r
         }\r
     }\r
 }
\ No newline at end of file
index 1ed9a96596b4dd7f39aeed3ce62ce6e93c0be2d4..136ade16ea380c8d4148074a8dde71189134cef4 100644 (file)
@@ -12,7 +12,6 @@ import org.eclipse.swt.events.FocusEvent;
 import org.eclipse.swt.graphics.Point;\r
 import org.eclipse.swt.widgets.Composite;\r
 import org.eclipse.swt.widgets.Label;\r
-import org.eclipse.swt.widgets.Text;\r
 import org.simantics.db.Builtins;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
@@ -26,7 +25,7 @@ import org.simantics.ui.SimanticsUI;
 public class AuxiliaryExpressionViewFactor implements IExpressionViewFactor {\r
     \r
     private Label equationLabel;\r
-    private Text expression;\r
+    private ExpressionField expression;\r
     private Point lastSelection = new Point(0,0);\r
     \r
     @Override\r
@@ -41,9 +40,9 @@ public class AuxiliaryExpressionViewFactor implements IExpressionViewFactor {
         GridDataFactory.fillDefaults().applyTo(equationLabel);\r
 \r
 \r
-        expression = new Text(parent, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);\r
+        expression = new ExpressionField(parent, SWT.BORDER);\r
         expression.setFont(FONT);\r
-        expression.setText(equation);\r
+        expression.setExpression(equation);\r
         GridDataFactory.fillDefaults().grab(true, true).applyTo(expression);\r
 \r
         expression.addFocusListener(new FocusAdapter() {\r
@@ -89,7 +88,7 @@ public class AuxiliaryExpressionViewFactor implements IExpressionViewFactor {
 \r
     @Override\r
     public void writeData(final Resource variable, Map<String, Object> data) {\r
-        final String currentText = expression.getText();\r
+        final String currentText = expression.getExpression();\r
         if(currentText != null) {\r
             data.put("equation", currentText);\r
             SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
@@ -120,23 +119,23 @@ public class AuxiliaryExpressionViewFactor implements IExpressionViewFactor {
     @Override\r
     public void replaceSelection(String var) {\r
         if(this.expression != null) {\r
-            String oldExpression = expression.getText();\r
+            String oldExpression = expression.getExpression();\r
             if(lastSelection == null)\r
                 lastSelection = new Point(0,0);\r
             String newExpression = oldExpression.substring(0, lastSelection.x) + var + oldExpression.substring(lastSelection.y);\r
-            expression.setText(newExpression);\r
+            expression.setExpression(newExpression);\r
             expression.setSelection(lastSelection.x + var.length());\r
         }\r
     }\r
 \r
     @Override\r
     public void updateData(Map<String, Object> data) {\r
-        if(this.expression != null && this.expression.getText() != null)\r
-            data.put("equation", this.expression.getText());\r
+        if(this.expression != null && this.expression.getExpression() != null)\r
+            data.put("equation", this.expression.getExpression());\r
     }\r
 \r
     @Override\r
-    public List<Text> getExpressionFields() {\r
+    public List<ExpressionField> getExpressionFields() {\r
         return Arrays.asList(this.expression);\r
     }\r
 }\r
index 3766a2679938e9c80f2bd1999fcaaac9f9912405..494b7369307ef1ea996d445d67d41eb5e0e2477c 100644 (file)
@@ -12,7 +12,6 @@ import org.eclipse.swt.events.FocusEvent;
 import org.eclipse.swt.graphics.Point;\r
 import org.eclipse.swt.widgets.Composite;\r
 import org.eclipse.swt.widgets.Label;\r
-import org.eclipse.swt.widgets.Text;\r
 import org.simantics.db.Builtins;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
@@ -26,7 +25,7 @@ import org.simantics.ui.SimanticsUI;
 public class ConstantExpressionViewFactor implements IExpressionViewFactor {\r
 \r
     private Label equationLabel;\r
-    private Text expression;\r
+    private ExpressionField expression;\r
     private Point lastSelection = new Point(0,0);\r
 \r
     @Override\r
@@ -41,9 +40,9 @@ public class ConstantExpressionViewFactor implements IExpressionViewFactor {
         GridDataFactory.fillDefaults().applyTo(equationLabel);\r
 \r
 \r
-        expression = new Text(parent, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);\r
+        expression = new ExpressionField(parent, SWT.BORDER);\r
         expression.setFont(FONT);\r
-        expression.setText(equation);\r
+        expression.setExpression(equation);\r
         GridDataFactory.fillDefaults().grab(true, true).applyTo(expression);\r
 \r
         expression.addFocusListener(new FocusAdapter() {\r
@@ -90,18 +89,18 @@ public class ConstantExpressionViewFactor implements IExpressionViewFactor {
     @Override\r
     public void replaceSelection(String var) {\r
         if(this.expression != null) {\r
-            String oldExpression = expression.getText();\r
+            String oldExpression = expression.getExpression();\r
             if(lastSelection == null)\r
                 lastSelection = new Point(0,0);\r
             String newExpression = oldExpression.substring(0, lastSelection.x) + var + oldExpression.substring(lastSelection.y);\r
-            expression.setText(newExpression);\r
+            expression.setExpression(newExpression);\r
             expression.setSelection(lastSelection.x + var.length());\r
         }\r
     }\r
 \r
     @Override\r
     public void writeData(final Resource variable, Map<String, Object> data) {\r
-        final String currentText = expression.getText();\r
+        final String currentText = expression.getExpression();\r
         if(currentText != null) {\r
             SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
 \r
@@ -126,12 +125,12 @@ public class ConstantExpressionViewFactor implements IExpressionViewFactor {
 \r
     @Override\r
     public void updateData(Map<String, Object> data) {\r
-        if(this.expression != null && this.expression.getText() != null)\r
-            data.put("equation", this.expression.getText());        \r
+        if(this.expression != null && this.expression.getExpression() != null)\r
+            data.put("equation", this.expression.getExpression());        \r
     }\r
 \r
     @Override\r
-    public List<Text> getExpressionFields() {\r
+    public List<ExpressionField> getExpressionFields() {\r
         return Arrays.asList(this.expression);\r
     }\r
 \r
index 75abce6548760f8c1465f86c1f316f9c556463b6..74d397dae7138eee237940e7b7506682edf7c4b0 100644 (file)
@@ -4,7 +4,6 @@ import java.util.List;
 import java.util.Map;\r
 \r
 import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Text;\r
 import org.simantics.db.Resource;\r
 \r
 public class DelayExpressionViewFactor implements IExpressionViewFactor {\r
@@ -46,7 +45,7 @@ public class DelayExpressionViewFactor implements IExpressionViewFactor {
     }\r
 \r
     @Override\r
-    public List<Text> getExpressionFields() {\r
+    public List<ExpressionField> getExpressionFields() {\r
         // TODO Auto-generated method stub\r
         return null;\r
     }\r
index 3c97db7b58985f5065474de9e80c1f4b91f2727b..953a76f4e2e01af9930e05669e3731ac20967abd 100644 (file)
@@ -1,5 +1,8 @@
 package org.simantics.sysdyn.ui.equation.expressions;\r
 \r
+import java.util.List;\r
+\r
+import org.eclipse.jface.layout.GridLayoutFactory;\r
 import org.eclipse.jface.text.Document;\r
 import org.eclipse.jface.text.IDocument;\r
 import org.eclipse.jface.text.PaintManager;\r
@@ -21,38 +24,27 @@ import org.eclipse.swt.graphics.RGB;
 import org.eclipse.swt.layout.GridData;\r
 import org.eclipse.swt.widgets.Composite;\r
 import org.eclipse.swt.widgets.Display;\r
-import org.eclipse.ui.PlatformUI;\r
-import org.eclipse.ui.texteditor.AnnotationPreference;\r
 import org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess;\r
-import org.eclipse.ui.texteditor.SourceViewerDecorationSupport;\r
+import org.eclipse.swt.graphics.Point;\r
 \r
 public class ExpressionField extends Composite {\r
-    \r
-    public static final String              ANNO_TYPE          = "com.mycompany.element";\r
-    public static final String              ANNO_KEY_HIGHLIGHT = "annotateElemHighlight";\r
-    public static final String              ANNO_KEY_OVERVIEW  = "annotateElemOverviewRuler";\r
-    public static final String              ANNO_KEY_VERTICAL  = "annotateElemVertialRuler";\r
-    public static final String              ANNO_KEY_TEXT      = "annotateElemText";\r
-    public static final String              ANNO_KEY_COLOR     = "annotateElemColor";\r
\r
+     \r
     protected SourceViewer                  _sourceViewer;\r
-    protected SourceViewerDecorationSupport _sds;\r
     protected IDocument                     _document;\r
     protected AnnotationModel               _annotationModel;\r
  \r
-    protected String                        _docString         = "this\nis\na\ntest\ndocument";\r
-\r
     ColorManager cManager = new ColorManager();\r
     \r
     IAnnotationAccess annotationAccess = new DefaultMarkerAnnotationAccess();\r
 \r
     public ExpressionField(Composite parent, int style) {\r
         super(parent, style);\r
+        \r
+        GridLayoutFactory.fillDefaults().applyTo(this);\r
 \r
         int VERTICAL_RULER_WIDTH = 12;\r
         \r
         int styles = SWT.V_SCROLL\r
-            | SWT.H_SCROLL\r
             | SWT.MULTI\r
             | SWT.BORDER\r
             | SWT.FULL_SELECTION;\r
@@ -62,47 +54,24 @@ public class ExpressionField extends Composite {
         CompositeRuler ruler = new CompositeRuler(VERTICAL_RULER_WIDTH);\r
  \r
         _document = new Document();\r
-        _document.set(_docString);\r
+        _document.set("");\r
  \r
         _annotationModel = new AnnotationModel();\r
         _annotationModel.connect(_document);\r
  \r
-        _sourceViewer = new SourceViewer(parent,\r
+        _sourceViewer = new SourceViewer(this,\r
                                          ruler,\r
                                          overviewRuler,\r
                                          true,\r
                                          styles);\r
         _sourceViewer.configure(new ExpressionFieldConfiguration(cManager));\r
         \r
-        \r
-        // TƤmƤ ei esimerkissƤ \r
         AnnotationPainter painter = new AnnotationPainter(_sourceViewer, annotationAccess);\r
         _sourceViewer.addPainter(painter);\r
         \r
-        _sds = new SourceViewerDecorationSupport(_sourceViewer,\r
-                                                 overviewRuler,\r
-                                                 annotationAccess,\r
-                                                 cManager);\r
-        // ^^^^^^^\r
+        painter.addAnnotationType("MissingLink");\r
+        painter.setAnnotationTypeColor("MissingLink", new Color(this.getDisplay(), 255,0,0));\r
         \r
-        /* EsimerkistƤ:\r
-         _sds = new SourceViewerDecorationSupport(_sourceViewer,\r
-                                                 overviewRuler,\r
-                                                 null,\r
-                                                 cManager);\r
-         */\r
\r
-        AnnotationPreference ap = new AnnotationPreference();\r
-        ap.setColorPreferenceKey(ANNO_KEY_COLOR);\r
-        ap.setHighlightPreferenceKey(ANNO_KEY_HIGHLIGHT);\r
-        ap.setVerticalRulerPreferenceKey(ANNO_KEY_VERTICAL);\r
-        ap.setOverviewRulerPreferenceKey(ANNO_KEY_OVERVIEW);\r
-        ap.setTextPreferenceKey(ANNO_KEY_TEXT);\r
-        ap.setAnnotationType(ANNO_TYPE);\r
-        _sds.setAnnotationPreference(ap);\r
\r
-        _sds.install(PlatformUI.getPreferenceStore());\r
\r
         _sourceViewer.setDocument(_document, _annotationModel);\r
  \r
         _sourceViewer.getControl().setLayoutData(new GridData(SWT.FILL,\r
@@ -113,11 +82,7 @@ public class ExpressionField extends Composite {
         ruler.addDecorator(0, new LineNumberRulerColumn());\r
  \r
         \r
-        Annotation annotation = new Annotation(false);\r
-        annotation.setType(ANNO_TYPE);\r
-        annotation.setText("moro!");\r
-        Position position = new Position(0, 4);\r
-        _annotationModel.addAnnotation(annotation, position);        \r
+\r
 \r
 \r
         \r
@@ -127,18 +92,51 @@ public class ExpressionField extends Composite {
         matchingCharacterPainter.setColor(new Color(Display.getCurrent(), new RGB(160, 160, 160)));\r
         paintManager.addPainter(matchingCharacterPainter);\r
         \r
-        \r
-        \r
-        annotation = new Annotation(false);\r
-        annotation.setType("org.eclipse.ui.workbench.texteditor.error");\r
-        annotation.setText("TekstiƤ!");\r
-        position = new Position(0, 4);\r
-        _sourceViewer.getAnnotationModel().addAnnotation(annotation, position);\r
 \r
     }\r
     \r
     public SourceViewer getSourceViewer() {\r
         return this._sourceViewer;\r
     }\r
+    \r
+    public void setMissingLinkAnnotations(List<Position> positions){\r
+        for(Position p : positions) {\r
+            Annotation annotation = new Annotation(false);\r
+            annotation.setType("MissingLink");\r
+            annotation.setText("No link to this variable");\r
+            _annotationModel.addAnnotation(annotation, p);        \r
+        }\r
+    }\r
+    \r
+    public void setSyntaxError(){\r
+        \r
+        Annotation annotation = new Annotation(false);\r
+        annotation.setType("MissingLink");\r
+        annotation.setText("Syntax error");\r
+        Position p = new Position(0, _document.getLength());\r
+        _annotationModel.addAnnotation(annotation, p);      \r
+    }\r
+    \r
+    public void resetAnnotations() {\r
+        _annotationModel.removeAllAnnotations();\r
+    }\r
+    public void setExpression(String expression) {\r
+        _document.set(expression);\r
+    }\r
+    \r
+    public String getExpression() {\r
+        return this._document.get();\r
+    }\r
+    \r
+    public Point getSelection() {\r
+        return _sourceViewer.getSelectedRange();\r
+    }\r
+    \r
+    public void setSelection(int selection) {\r
+        this._sourceViewer.setSelectedRange(selection, 0);\r
+    }\r
+    \r
+\r
+    \r
 \r
 }\r
index e7d37515ef5a8cabbe269e7f0ff3e4b3e56de9d3..baf07b26ea048c0f4b6ddf09194f1e9d624c4479 100644 (file)
@@ -6,7 +6,6 @@ import java.util.Map;
 import org.eclipse.swt.SWT;\r
 import org.eclipse.swt.graphics.Font;\r
 import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Text;\r
 import org.simantics.db.Resource;\r
 \r
 public interface IExpressionViewFactor {\r
@@ -55,6 +54,6 @@ public interface IExpressionViewFactor {
     /**\r
      * @return all individual expression fields for modelica validation\r
      */\r
-    List<Text> getExpressionFields();\r
+    List<ExpressionField> getExpressionFields();\r
    \r
 }\r
index df077d606e0cb812a2c413cafda2ebee4194d55c..8040305ffaf4af904a1f673bfd1da22f2c275191 100644 (file)
@@ -4,7 +4,6 @@ import java.util.List;
 import java.util.Map;\r
 \r
 import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Text;\r
 import org.simantics.db.Resource;\r
 \r
 public class LookupExpressionViewFactor implements IExpressionViewFactor {\r
@@ -46,7 +45,7 @@ public class LookupExpressionViewFactor implements IExpressionViewFactor {
     }\r
 \r
     @Override\r
-    public List<Text> getExpressionFields() {\r
+    public List<ExpressionField> getExpressionFields() {\r
         // TODO Auto-generated method stub\r
         return null;\r
     }\r
index 0f8967105f8621d73cafa1f6204c2f6bbba82505..74d1cdd24855354799d6b4079254b8f7244c589e 100644 (file)
@@ -12,7 +12,6 @@ import org.eclipse.swt.events.FocusEvent;
 import org.eclipse.swt.graphics.Point;\r
 import org.eclipse.swt.widgets.Composite;\r
 import org.eclipse.swt.widgets.Label;\r
-import org.eclipse.swt.widgets.Text;\r
 import org.simantics.db.Builtins;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
@@ -26,7 +25,7 @@ import org.simantics.ui.SimanticsUI;
 public class ParameterExpressionViewFactor implements IExpressionViewFactor {\r
     \r
     private Label equationLabel;\r
-    private Text expression;\r
+    private ExpressionField expression;\r
     private Point lastSelection = new Point(0,0);\r
     \r
     @Override\r
@@ -42,9 +41,9 @@ public class ParameterExpressionViewFactor implements IExpressionViewFactor {
         GridDataFactory.fillDefaults().applyTo(equationLabel);\r
 \r
 \r
-        expression = new Text(parent, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);\r
+        expression = new ExpressionField(parent, SWT.BORDER);\r
         expression.setFont(FONT);\r
-        expression.setText(equation);\r
+        expression.setExpression(equation);\r
         GridDataFactory.fillDefaults().grab(true, true).applyTo(expression);\r
 \r
         expression.addFocusListener(new FocusAdapter() {\r
@@ -91,18 +90,18 @@ public class ParameterExpressionViewFactor implements IExpressionViewFactor {
     @Override\r
     public void replaceSelection(String var) {\r
         if(this.expression != null) {\r
-            String oldExpression = expression.getText();\r
+            String oldExpression = expression.getExpression();\r
             if(lastSelection == null)\r
                 lastSelection = new Point(0,0);\r
             String newExpression = oldExpression.substring(0, lastSelection.x) + var + oldExpression.substring(lastSelection.y);\r
-            expression.setText(newExpression);\r
+            expression.setExpression(newExpression);\r
             expression.setSelection(lastSelection.x + var.length());\r
         }\r
     }\r
 \r
     @Override\r
     public void writeData(final Resource variable, Map<String, Object> data) {\r
-        final String currentText = expression.getText();\r
+        final String currentText = expression.getExpression();\r
         if(currentText != null) {\r
             SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
 \r
@@ -127,12 +126,12 @@ public class ParameterExpressionViewFactor implements IExpressionViewFactor {
 \r
     @Override\r
     public void updateData(Map<String, Object> data) {\r
-        if(this.expression != null && this.expression.getText() != null)\r
-            data.put("equation", this.expression.getText());        \r
+        if(this.expression != null && this.expression.getExpression() != null)\r
+            data.put("equation", this.expression.getExpression());        \r
     }\r
 \r
     @Override\r
-    public List<Text> getExpressionFields() {\r
+    public List<ExpressionField> getExpressionFields() {\r
         return Arrays.asList(this.expression);\r
     }\r
 \r
index ac483c0b0850cd54dcf8c2181e464a7a90b7b953..b10ceee922abc6e3ccb4bcd919a5eadb32eb28b6 100644 (file)
@@ -29,7 +29,7 @@ public class StockExpressionViewFactor implements IExpressionViewFactor {
     private Label integralLabel;\r
     private Text integral;\r
     private Label equationLabel;\r
-    private Text expression;\r
+    private ExpressionField expression;\r
     private Point lastSelection = new Point(0,0);\r
 \r
     @Override\r
@@ -57,9 +57,9 @@ public class StockExpressionViewFactor implements IExpressionViewFactor {
         GridDataFactory.fillDefaults().applyTo(equationLabel);\r
 \r
 \r
-        expression = new Text(parent, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);\r
+        expression = new ExpressionField(parent, SWT.BORDER);\r
         expression.setFont(FONT);\r
-        expression.setText(initialEquation);\r
+        expression.setExpression(initialEquation);\r
         GridDataFactory.fillDefaults().grab(true, true).applyTo(expression);\r
 \r
         expression.addFocusListener(new FocusAdapter() {\r
@@ -103,7 +103,7 @@ public class StockExpressionViewFactor implements IExpressionViewFactor {
 \r
     @Override\r
     public void writeData(final Resource variable, Map<String, Object> data) {\r
-        final String currentText = expression.getText();\r
+        final String currentText = expression.getExpression();\r
         if(currentText != null) {\r
             SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
 \r
@@ -180,11 +180,11 @@ public class StockExpressionViewFactor implements IExpressionViewFactor {
     @Override\r
     public void replaceSelection(String var) {\r
         if(this.expression != null) {\r
-            String oldExpression = expression.getText();\r
+            String oldExpression = expression.getExpression();\r
             if(lastSelection == null)\r
                 lastSelection = new Point(0,0);\r
             String newExpression = oldExpression.substring(0, lastSelection.x) + var + oldExpression.substring(lastSelection.y);\r
-            expression.setText(newExpression);      \r
+            expression.setExpression(newExpression);      \r
             expression.setSelection(lastSelection.x + var.length());\r
         }\r
 \r
@@ -192,14 +192,14 @@ public class StockExpressionViewFactor implements IExpressionViewFactor {
 \r
     @Override\r
     public void updateData(Map<String, Object> data) {\r
-        if(this.expression != null && this.expression.getText() != null)\r
-            data.put("initialEquation", this.expression.getText());   \r
+        if(this.expression != null && this.expression.getExpression() != null)\r
+            data.put("initialEquation", this.expression.getExpression());   \r
         if(this.integral != null && this.integral.getText() != null)\r
             data.put("integral", this.integral.getText());\r
     }\r
 \r
     @Override\r
-    public List<Text> getExpressionFields() {\r
+    public List<ExpressionField> getExpressionFields() {\r
         return Arrays.asList(this.expression);\r
     }\r
 }\r
index 80e934fc5a5a392a36c68e7e95dc0ab41e26d5b5..8eb0359d30a243e8f01299cce011774786f3849c 100644 (file)
@@ -12,7 +12,6 @@ import org.eclipse.swt.events.FocusEvent;
 import org.eclipse.swt.graphics.Point;\r
 import org.eclipse.swt.widgets.Composite;\r
 import org.eclipse.swt.widgets.Label;\r
-import org.eclipse.swt.widgets.Text;\r
 import org.simantics.db.Builtins;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
@@ -27,11 +26,11 @@ public class WithLookupExpressionViewFactor implements IExpressionViewFactor {
 \r
     \r
     private Label expressionLabel;\r
-    private Text expression;\r
+    private ExpressionField expression;\r
     private Label lookupLabel;\r
-    private Text lookup;\r
+    private ExpressionField lookup;\r
     private Point lastSelection = new Point(0,0);\r
-    private Text lastSelectedText = expression;\r
+    private ExpressionField lastSelectedText = expression;\r
     \r
     @Override\r
     public void createView(Composite parent, Map<String, Object> data) {\r
@@ -46,9 +45,9 @@ public class WithLookupExpressionViewFactor implements IExpressionViewFactor {
         expressionLabel.setText("With\nLookup");\r
         GridDataFactory.fillDefaults().applyTo(expressionLabel);\r
 \r
-        expression = new Text(parent, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);\r
+        expression = new ExpressionField(parent, SWT.BORDER);\r
         expression.setFont(FONT);\r
-        expression.setText(equation);\r
+        expression.setExpression(equation);\r
         GridDataFactory.fillDefaults().grab(true, true).applyTo(expression);\r
         \r
         \r
@@ -67,9 +66,9 @@ public class WithLookupExpressionViewFactor implements IExpressionViewFactor {
         GridDataFactory.fillDefaults().applyTo(lookupLabel);\r
 \r
 \r
-        lookup = new Text(parent, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);\r
+        lookup = new ExpressionField(parent, SWT.BORDER);\r
         lookup.setFont(FONT);\r
-        lookup.setText(lookupTable);\r
+        lookup.setExpression(lookupTable);\r
         GridDataFactory.fillDefaults().grab(true, true).applyTo(lookup);\r
 \r
         lookup.addFocusListener(new FocusAdapter() {\r
@@ -116,8 +115,8 @@ public class WithLookupExpressionViewFactor implements IExpressionViewFactor {
 \r
     @Override\r
     public void writeData(final Resource variable, Map<String, Object> data) {\r
-        final String currentExpression = expression.getText();\r
-        final String currentLookupTable = lookup.getText();\r
+        final String currentExpression = expression.getExpression();\r
+        final String currentLookupTable = lookup.getExpression();\r
         \r
         if(currentExpression != null && currentLookupTable != null) {\r
             data.put("equation", currentExpression);\r
@@ -151,25 +150,25 @@ public class WithLookupExpressionViewFactor implements IExpressionViewFactor {
     @Override\r
     public void replaceSelection(String var) {\r
         if(this.lastSelectedText != null) {\r
-            String oldExpression = lastSelectedText.getText();\r
+            String oldExpression = lastSelectedText.getExpression();\r
             if(lastSelection == null)\r
                 lastSelection = new Point(0,0);\r
             String newExpression = oldExpression.substring(0, lastSelection.x) + var + oldExpression.substring(lastSelection.y);\r
-            lastSelectedText.setText(newExpression);\r
+            lastSelectedText.setExpression(newExpression);\r
             lastSelectedText.setSelection(lastSelection.x + var.length());\r
         }\r
     }\r
 \r
     @Override\r
     public void updateData(Map<String, Object> data) {\r
-        if(this.expression != null && this.expression.getText() != null)\r
-            data.put("equation", this.expression.getText());   \r
-        if(this.lookup != null && this.lookup.getText() != null)\r
-            data.put("lookup", this.lookup.getText());        \r
+        if(this.expression != null && this.expression.getExpression() != null)\r
+            data.put("equation", this.expression.getExpression());   \r
+        if(this.lookup != null && this.lookup.getExpression() != null)\r
+            data.put("lookup", this.lookup.getExpression());        \r
     }\r
 \r
     @Override\r
-    public List<Text> getExpressionFields() {\r
+    public List<ExpressionField> getExpressionFields() {\r
         return Arrays.asList(this.expression, this.lookup);\r
     }\r
 }
\ No newline at end of file