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
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
\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
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
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
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
// 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
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
\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
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
\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
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
}\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
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
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
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
\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
@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
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
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
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
@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
\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
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
}\r
\r
@Override\r
- public List<Text> getExpressionFields() {\r
+ public List<ExpressionField> getExpressionFields() {\r
// TODO Auto-generated method stub\r
return null;\r
}\r
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
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
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
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
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
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
/**\r
* @return all individual expression fields for modelica validation\r
*/\r
- List<Text> getExpressionFields();\r
+ List<ExpressionField> getExpressionFields();\r
\r
}\r
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
}\r
\r
@Override\r
- public List<Text> getExpressionFields() {\r
+ public List<ExpressionField> getExpressionFields() {\r
// TODO Auto-generated method stub\r
return null;\r
}\r
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
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
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
@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
\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
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
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
\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
@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("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
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
\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
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
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
\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
@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