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