From: lempinen Date: Tue, 14 Dec 2010 11:54:46 +0000 (+0000) Subject: Ranges are verified inside expressions. Similar use cases as in expression range... X-Git-Tag: 2011-04-05-db-merge-trunk~52 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=ff46052846e698f9f7d9f82e58aa9d711f3449e4;p=simantics%2Fsysdyn.git Ranges are verified inside expressions. Similar use cases as in expression range (same verify action). git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@19147 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextElementNoBounds.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextElementNoBounds.java index 61deb088..2b583a4a 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextElementNoBounds.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextElementNoBounds.java @@ -30,7 +30,7 @@ import org.simantics.g2d.element.IElement; import org.simantics.g2d.utils.Alignment; import org.simantics.modeling.ModelingResources; import org.simantics.scenegraph.g2d.G2DParentNode; -import org.simantics.sysdyn.ui.properties.VariableNameUtils; +import org.simantics.sysdyn.ui.utils.VariableNameUtils; import org.simantics.ui.SimanticsUI; import org.simantics.utils.datastructures.Callback; import org.simantics.utils.datastructures.hints.IHintListener; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java index 63eb2ce8..377019ab 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java @@ -38,6 +38,7 @@ import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.properties.widgets.factories.ComboStringPropertyModifier; import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory; import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier; +import org.simantics.sysdyn.ui.utils.VariableNameUtils; public class ConfigurationTab extends PropertyTabContributorImpl { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java index a913f9ed..4745bc3f 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java @@ -289,6 +289,14 @@ public class EquationTab extends PropertyTabContributorImpl implements Widget { private void addListeners(ISessionContext context) { + shortcutTabWidget.addDependencyListener(new Runnable() { + + @Override + public void run() { + expressionWidget.validateFields(); + } + }); + deleteExpression.addSelectionListener(new SelectionListenerImpl(context) { @Override diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ArrayExpressionCombo.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ArrayExpressionCombo.java index 2a1f6ab7..0053e4fa 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ArrayExpressionCombo.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ArrayExpressionCombo.java @@ -28,7 +28,7 @@ import org.simantics.db.procedure.Listener; import org.simantics.db.service.VirtualGraphSupport; import org.simantics.layer0.Layer0; import org.simantics.sysdyn.SysdynResource; -import org.simantics.sysdyn.ui.properties.VariableNameUtils; +import org.simantics.sysdyn.ui.utils.VariableNameUtils; public class ArrayExpressionCombo extends TrackedCombo { @@ -119,6 +119,7 @@ public class ArrayExpressionCombo extends TrackedCombo { @Override public void execute(final String result) { + if(getWidget().isDisposed()) return; getWidget().getDisplay().asyncExec(new Runnable() { @Override diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ExpressionWidget.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ExpressionWidget.java index 9aec199d..bb146702 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ExpressionWidget.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ExpressionWidget.java @@ -22,8 +22,13 @@ import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Table; import org.simantics.browsing.ui.swt.widgets.impl.Widget; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.ReadGraph; import org.simantics.db.Resource; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; import org.simantics.db.management.ISessionContext; +import org.simantics.db.request.Read; +import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.properties.widgets.ExpressionTypes.ExpressionType; import org.simantics.sysdyn.ui.properties.widgets.expressions.AuxiliaryExpression; import org.simantics.sysdyn.ui.properties.widgets.expressions.ConstantExpression; @@ -34,136 +39,131 @@ import org.simantics.sysdyn.ui.properties.widgets.expressions.LookupExpression; import org.simantics.sysdyn.ui.properties.widgets.expressions.ParameterExpression; import org.simantics.sysdyn.ui.properties.widgets.expressions.StockExpression; import org.simantics.sysdyn.ui.properties.widgets.expressions.WithLookupExpression; +import org.simantics.sysdyn.ui.utils.ExpressionUtils; +import org.simantics.ui.SimanticsUI; import org.simantics.ui.utils.AdaptionUtils; public class ExpressionWidget implements Widget { - - private Resource expr; - private Composite parent; - private Map data; - private IExpression expression; - private ModifyListener modifyListener; - private FocusListener focusListener; - private Table variableTable; + + private Resource expr; + private Composite parent; + private Map data; + private IExpression expression; + private ModifyListener modifyListener; + private FocusListener focusListener; + private Table variableTable; private VerifyKeyListener verifyKeyListener; - - - public ExpressionWidget(Composite parent, WidgetSupport support, int style) { - support.register(this); - this.parent = parent; - this.data = new HashMap(); - } - - @Override - public void setInput(ISessionContext context, Object input) { - expr = AdaptionUtils.adaptToSingle(input, Resource.class); - ExpressionType et = ExpressionTypes.getExpressionType(expr); - displayExpression(et.toString(), true); - } - - public void displayExpression(String expressionType, boolean original) { - if(expressionType == null) { + + + public ExpressionWidget(Composite parent, WidgetSupport support, int style) { + support.register(this); + this.parent = parent; + this.data = new HashMap(); + } + + @Override + public void setInput(ISessionContext context, Object input) { + expr = AdaptionUtils.adaptToSingle(input, Resource.class); + ExpressionType et = ExpressionTypes.getExpressionType(expr); + displayExpression(et.toString(), true); + } + + public void displayExpression(String expressionType, boolean original) { + if(expressionType == null) { return; - } - - if(this.expression != null) expression.updateData(data); - ExpressionType et = ExpressionType.valueOf(expressionType); - IExpression exp = null; - switch (et) { - case Auxiliary: - exp = new AuxiliaryExpression(); break; - case Parameter: - exp = new ParameterExpression(); break; - case Constant: - exp = new ConstantExpression(); break; - case Lookup: - exp = new LookupExpression(); break; - case WithLookup: - exp = new WithLookupExpression(expr); break; - case Stock: - exp = new StockExpression(); break; - case Delay: - exp = new DelayExpression(); break; - default: - exp = new EmptyExpression(); - } - - if (exp != null) { - for(Control c : parent.getChildren()) { - c.dispose(); - } - - if(original) - exp.readData(expr, data); - - exp.createExpressionFields(parent, data); - if(modifyListener != null) - exp.addModifyListener(modifyListener); - if(focusListener != null) - exp.addFocusListener(focusListener); - if(verifyKeyListener != null) - exp.addVerifyKeyListener(verifyKeyListener); - this.expression = exp; - this.parent.layout(); - validateFields(); - - save(); - } - } - - public IExpression getExpression() { - return expression; - } - - public void setVariableTable(Table table) { - this.variableTable = table; - } - - public void validateFields() { - if(this.variableTable == null) return; - /* - TableItem[] connectedVariables = this.variableTable.getItems(); - try { - final Resource configuration = SimanticsUI.getSession().syncRequest(new Read() { - - @Override - public Resource perform(ReadGraph graph) throws DatabaseException { - SysdynResource sr = SysdynResource.getInstance(graph); - - - - Resource configuration = variable; - - do { - configuration = graph.getSingleObject(configuration, Layer0.getInstance(graph).PartOf); - if(graph.isInstanceOf(configuration, sr.Configuration)) - return configuration; - } while (configuration != null); - - return null; - } - }); - ExpressionUtils.validateExpressionFields(expression, connectedVariables, configuration); - } catch (DatabaseException e1) { - e1.printStackTrace(); - } - */ - } - - public void addModifyListener(ModifyListener listener) { - this.modifyListener = listener; - } - - public void addVerifyKeyListener(VerifyKeyListener listener) { - this.verifyKeyListener = listener; - } - - public void addFocusListener(FocusListener listener) { - this.focusListener = listener; - } - - public void save() { - this.expression.save(expr, data); - } + } + + if(this.expression != null) expression.updateData(data); + ExpressionType et = ExpressionType.valueOf(expressionType); + IExpression exp = null; + switch (et) { + case Auxiliary: + exp = new AuxiliaryExpression(); break; + case Parameter: + exp = new ParameterExpression(); break; + case Constant: + exp = new ConstantExpression(); break; + case Lookup: + exp = new LookupExpression(); break; + case WithLookup: + exp = new WithLookupExpression(expr); break; + case Stock: + exp = new StockExpression(); break; + case Delay: + exp = new DelayExpression(); break; + default: + exp = new EmptyExpression(); + } + + if (exp != null) { + for(Control c : parent.getChildren()) { + c.dispose(); + } + + if(original) + exp.readData(expr, data); + + exp.createExpressionFields(parent, data); + if(modifyListener != null) + exp.addModifyListener(modifyListener); + if(focusListener != null) + exp.addFocusListener(focusListener); + if(verifyKeyListener != null) + exp.addVerifyKeyListener(verifyKeyListener); + this.expression = exp; + this.parent.layout(); + validateFields(); + + save(); + } + } + + public IExpression getExpression() { + return expression; + } + + public void setVariableTable(Table table) { + this.variableTable = table; + } + + public void validateFields() { + if(this.variableTable == null) return; + + try { + Resource variable = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public Resource perform(ReadGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + + Resource expressionList = OrderedSetUtils.getSingleOwnerList(graph, expr); + Resource variable = graph.getPossibleObject(expressionList, sr.HasExpressions_Inverse); + return variable; + } + }); + if(variable != null) + ExpressionUtils.validateExpressionFields(variable, expression, variableTable); + } catch (DatabaseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + public void addModifyListener(ModifyListener listener) { + this.modifyListener = listener; + } + + public void addVerifyKeyListener(VerifyKeyListener listener) { + this.verifyKeyListener = listener; + } + + public void addFocusListener(FocusListener listener) { + this.focusListener = listener; + } + + public void save() { + this.expression.save(expr, data); + } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ShortcutTabWidget.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ShortcutTabWidget.java index ded5da75..cbe8af81 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ShortcutTabWidget.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ShortcutTabWidget.java @@ -11,8 +11,10 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.properties.widgets; +import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; +import java.util.concurrent.CopyOnWriteArrayList; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; @@ -27,15 +29,16 @@ import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableItem; import org.simantics.browsing.ui.swt.widgets.impl.Widget; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.AsyncReadGraph; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; import org.simantics.db.management.ISessionContext; +import org.simantics.db.procedure.AsyncListener; import org.simantics.db.request.Read; import org.simantics.layer0.Layer0; import org.simantics.sysdyn.SysdynResource; import org.simantics.ui.SimanticsUI; -import org.simantics.utils.ui.ExceptionUtils; import org.simantics.utils.ui.ISelectionUtils; public class ShortcutTabWidget implements Widget { @@ -46,6 +49,9 @@ public class ShortcutTabWidget implements Widget { Table variableTable; Table functionTable; Composite composite; + + CopyOnWriteArrayList dependencyListeners = + new CopyOnWriteArrayList(); public ShortcutTabWidget(Composite parent, WidgetSupport support, int style) { if(support!=null) @@ -99,55 +105,93 @@ public class ShortcutTabWidget implements Widget { if(input instanceof IStructuredSelection) { final Resource variable = ISelectionUtils.filterSingleSelection((IStructuredSelection)input, Resource.class); if(variable != null) { - HashSet dependencies = getDependencies(variable); - TableItem item; - for(String d : dependencies) { - item = new TableItem(variableTable, SWT.NONE); - item.setText(d); - item.setData(d); - } + + SimanticsUI.getSession().asyncRequest(new Read>() { + + @Override + public HashSet perform(ReadGraph graph) + throws DatabaseException { + return getDependencies(graph, variable); + } + }, new AsyncListener>() { + + @Override + public void execute(AsyncReadGraph graph, + HashSet result) { + + final HashSet dependencies = result; + variableTable.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + if(variableTable.isDisposed()) return; + + TableItem[] items = variableTable.getItems(); + + // Remove deleted dependencies and create the list of current dependencies (itemStrings) + ArrayList itemStrings = new ArrayList(); + for(TableItem i : items) { + String text = i.getText(); + if(dependencies.contains(text)) + itemStrings.add(text); + else + variableTable.remove(variableTable.indexOf(i)); + } + + // Add all new dependencies + TableItem item; + for(String d : dependencies) { + if(!itemStrings.contains(d)) { + item = new TableItem(variableTable, SWT.NONE); + item.setText(d); + item.setData(d); + } + } + + synchronized(dependencyListeners) { + for(Runnable listener : dependencyListeners) + listener.run(); + } + } + }); + } + + @Override + public void exception(AsyncReadGraph graph, + Throwable throwable) { + throwable.printStackTrace(); + } + + @Override + public boolean isDisposed() { + return variableTable.isDisposed(); + } + }); } } } // Returns the names of the related variables (dependencies) - private HashSet getDependencies(final Resource r){ - HashSet variables = null; - if(r != null) - try { - variables = SimanticsUI.getSession().syncRequest(new Read>() { - - @Override - public HashSet perform(ReadGraph graph) - throws DatabaseException { - HashSet variables = new HashSet(); - SysdynResource sr = SysdynResource.getInstance(graph); - Layer0 l0 = Layer0.getInstance(graph); - - Collection dependencies = graph.getObjects(r, sr.IsHeadOf); - - for(Resource d : dependencies) { - if(graph.isInstanceOf(d, sr.Dependency)) { - Resource tail = graph.getPossibleObject(d, sr.HasTail); - if(tail != null) { - Object name = graph.getPossibleRelatedValue(tail, l0.HasName); - if(name != null) - variables.add((String)name); - } - } - } - - return variables; - - } - - - }); - } catch (DatabaseException ee) { - ExceptionUtils.logAndShowError(ee); - } - - return variables; + private HashSet getDependencies(ReadGraph graph, Resource r) throws DatabaseException { + HashSet variables = new HashSet(); + if(graph != null && r != null) { + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + + Collection dependencies = graph.getObjects(r, sr.IsHeadOf); + + for(Resource d : dependencies) { + if(graph.isInstanceOf(d, sr.Dependency)) { + Resource tail = graph.getPossibleObject(d, sr.HasTail); + if(tail != null) { + Object name = graph.getPossibleRelatedValue(tail, l0.HasName); + if(name != null) + variables.add((String)name); + } + } + } + } + return variables; } public void addFocusListener(FocusListener listener) { @@ -160,6 +204,18 @@ public class ShortcutTabWidget implements Widget { this.variableTable.addMouseListener(listener); } + public void addDependencyListener(Runnable listener) { + synchronized(dependencyListeners) { + dependencyListeners.add(listener); + } + } + + public void removeDependencyListener(Runnable listener) { + synchronized(dependencyListeners) { + dependencyListeners.remove(listener); + } + } + public Table getVariableTable() { return variableTable; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/BasicExpression.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/BasicExpression.java index ebf4d420..66dd8622 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/BasicExpression.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/BasicExpression.java @@ -31,11 +31,11 @@ import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; -import org.simantics.db.common.utils.OrderedSetUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.request.Read; import org.simantics.layer0.Layer0; import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.utils.ExpressionUtils; import org.simantics.ui.SimanticsUI; public class BasicExpression implements IExpression { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionFieldConfiguration.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionFieldConfiguration.java index ffa300d6..000db7be 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionFieldConfiguration.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionFieldConfiguration.java @@ -31,7 +31,7 @@ import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.jface.text.source.SourceViewerConfiguration; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.RGB; -import org.simantics.sysdyn.ui.properties.VariableNameUtils; +import org.simantics.sysdyn.ui.utils.VariableNameUtils; public class ExpressionFieldConfiguration extends SourceViewerConfiguration { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionUtils.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionUtils.java deleted file mode 100644 index 191960cb..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionUtils.java +++ /dev/null @@ -1,172 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.properties.widgets.expressions; - -import java.io.StringReader; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.StringTokenizer; - -import org.eclipse.jface.text.Position; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.widgets.TableItem; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.sysdyn.expressionParser.ExpressionParser; -import org.simantics.sysdyn.expressionParser.ParseException; -import org.simantics.sysdyn.expressionParser.Token; -import org.simantics.sysdyn.expressionParser.TokenMgrError; -import org.simantics.sysdyn.manager.SysdynModel; -import org.simantics.sysdyn.manager.SysdynModelManager; -import org.simantics.sysdyn.representation.Configuration; -import org.simantics.sysdyn.representation.IElement; -import org.simantics.sysdyn.representation.Variable; -import org.simantics.sysdyn.ui.properties.widgets.expressions.IExpression; -import org.simantics.ui.SimanticsUI; - -public class ExpressionUtils { - - /** - * Determines if the given expression is a parameter expression. Parameters are numbers. - * If the expression contains anything other than numbers, it is not a parameter. - * - * @param expression The expression to be checked - * @return is the expression a parameter - */ - static public boolean isParameter(String expression) { - try { - StringTokenizer st = new StringTokenizer(expression, "{}[],;"); - while(st.hasMoreTokens()) { - Double.parseDouble(st.nextToken().trim()); - } - return true; - } catch (NumberFormatException e) { - return false; - } - } - - static public void validateExpressionFields(IExpression expression, TableItem[] connectedVariables, Resource configuration) { - ExpressionParser parser = new ExpressionParser(new StringReader("")); - Set variables = new HashSet(); - HashMap>> references = new HashMap>>(); - - - // Build references and variable array - for(ExpressionField ef : expression.getExpressionFields()) { - ef.resetAnnotations(); - String textString = ef.getExpression(); - parser.ReInit(new StringReader(textString)); - try { - parser.expr(); - HashMap> cr = parser.getReferences(); - references.put(ef, cr); - for(String t : cr.keySet()) - variables.add(t); - } catch (ParseException e1) { - ef.setSyntaxError(e1.currentToken, "Syntax Error"); - } catch (TokenMgrError err) { - ef.setSyntaxError(0, textString.length(), "MissingLink", "Expression contains unsupported characters"); - } - } - - // Remove variables from variable array that don't exist in the model. Create annotations - if(!variables.isEmpty()) { - ArrayList modelVariables = new ArrayList(); - Set noSuchVariables = new HashSet(); - SysdynModelManager sdm = SysdynModelManager.getInstance(SimanticsUI.getSession()); - SysdynModel model = sdm.getModel(configuration); - try { - model.update(); - } catch (DatabaseException e1) { - e1.printStackTrace(); - } - Configuration conf = model.getConfiguration(); - ArrayList elements = conf.getElements(); - for(IElement e : elements) { - if(e instanceof Variable) { - Variable v = (Variable) e; - modelVariables.add(v.getName()); - } - } - - - for(String v : variables) { - if(!modelVariables.contains(v)) { - noSuchVariables.add(v); - } - } - - if(!noSuchVariables.isEmpty()) { - // remove no such variables from variable list - for(String s : noSuchVariables) - variables.remove(s); - // create annotations - HashMap> positions = getPositionsForVariables(references, noSuchVariables); - for(ExpressionField ef : positions.keySet()) { - ef.setNoSuchVariableAnnotations(positions.get(ef)); - } - } - } - - // Check that the variables that exist have connections and the connected variables have references in the expressions - if(!(expression instanceof StockExpression)) { - for(TableItem ti : connectedVariables) { - if(!variables.contains(ti.getText())) { - ti.setForeground(new Color(ti.getDisplay(), 255, 0, 0)); - } else { - ti.setForeground(new Color(ti.getDisplay(), 0, 0, 0)); - variables.remove(ti.getText()); - } - } - - if(!variables.isEmpty()) { - HashMap> positions = getPositionsForVariables(references, variables); - for(ExpressionField ef : positions.keySet()) { - ef.setMissingLinkAnnotations(positions.get(ef)); - } - - } - } - - } - - @SuppressWarnings("unchecked") - static private HashMap> getPositionsForVariables(HashMap>> references, Set variables) { - HashMap> result = new HashMap>(); - for(String s : variables) { - List tlist = new ArrayList(); - for(ExpressionField ef : references.keySet()) { - ArrayList positions = new ArrayList(); - 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)); - } - if(result.keySet().contains(ef)) { - result.get(ef).addAll((ArrayList)positions.clone()); - } else { - result.put(ef, (ArrayList)positions.clone()); - } - } - } - return result; - } -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/VariableNamePropertyModifier.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/VariableNamePropertyModifier.java index c6320dfd..eba5f967 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/VariableNamePropertyModifier.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/VariableNamePropertyModifier.java @@ -18,7 +18,7 @@ import org.simantics.db.WriteGraph; import org.simantics.db.exception.DatabaseException; import org.simantics.db.management.ISessionContext; import org.simantics.layer0.Layer0; -import org.simantics.sysdyn.ui.properties.VariableNameUtils; +import org.simantics.sysdyn.ui.utils.VariableNameUtils; public class VariableNamePropertyModifier extends TextModifyListenerImpl { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/VariableNameValidator.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/VariableNameValidator.java index 879dc8f6..9d635e71 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/VariableNameValidator.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/VariableNameValidator.java @@ -17,7 +17,7 @@ import org.simantics.browsing.ui.swt.widgets.impl.Widget; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; import org.simantics.db.Resource; import org.simantics.db.management.ISessionContext; -import org.simantics.sysdyn.ui.properties.VariableNameUtils; +import org.simantics.sysdyn.ui.utils.VariableNameUtils; import org.simantics.utils.ui.ISelectionUtils; public class VariableNameValidator implements IInputValidator, Widget { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ArrayVariableUtils.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ArrayVariableUtils.java new file mode 100644 index 00000000..137267a9 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ArrayVariableUtils.java @@ -0,0 +1,101 @@ +package org.simantics.sysdyn.ui.utils; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.manager.SysdynModel; +import org.simantics.sysdyn.representation.Enumeration; +import org.simantics.sysdyn.representation.EnumerationIndex; +import org.simantics.sysdyn.representation.IElement; +import org.simantics.sysdyn.representation.Variable; + +public class ArrayVariableUtils { + + + /** + * Checks if the given range elements can be applied to the given variable. + * + * @param graph ReadGraph + * @param variable Resource of the variable + * @param range Range elements in the correct order. Elements are separated in range definition by ',' + * @return true if range is valid, false if not + * @throws DatabaseException + */ + public static Map isRangeValid(ReadGraph graph, Variable variable, String[] elements) throws DatabaseException { + if(variable == null) + return null; + Map result = new HashMap(); + ArrayList enumerations = variable.getArrayIndexes().getEnumerations(); + // Too many elements + if(elements.length > enumerations.size()) { + result.put( enumerations.size(), "Too many elements"); + } else if(elements.length < enumerations.size()) { + result.put( elements.length > 0 ? elements.length - 1 : 0, "Too few elements"); + } + + + for(int i = 0; i < elements.length; i++) { + if(elements[i].trim().equals(":")) + continue; + if(elements[i].indexOf(":") != elements[i].lastIndexOf(":")) { + result.put( i, "Too many ':' elements"); + continue; + } + + String[] rangeComponents = elements[i].split(":"); + if(rangeComponents.length > 2){ + result.put( i, "Too many ':' elements"); + continue; + } + // Single range component, equals to the enumeration at that index + if(rangeComponents.length == 1 && rangeComponents[0].trim().equals(enumerations.get(i).getName())) + continue; + // one or two range components, they all equal to individual indexes in the enumeration + for(String r : rangeComponents) { + r = r.trim(); + boolean componentIsValid = false; + for(EnumerationIndex ei : enumerations.get(i).getEnumerationIndexes()) { + if(ei.getName().equals(r)) { + componentIsValid = true; + break; + } + } + if(!componentIsValid) + result.put( i, "Invalid range"); + } + } + if(result.isEmpty()) + return null; + else + return result; + } + + /** + * Checks if the given range can be applied to the given variable. + * + * @param graph ReadGraph + * @param variable Resource of the variable + * @param range Range WITHOUT [ and ] brackets + * @return true if range is valid, false if not + * @throws DatabaseException + */ + public static boolean isRangeValid(ReadGraph graph, Resource variable, String range) throws DatabaseException { + String[] elements = range.split(","); + SysdynModel model = ModelUtils.getModel(graph, variable); + IElement e = model.getElement(variable); + if(e != null && e instanceof Variable) { + Variable v = (Variable) e; + Map result = isRangeValid(graph, v, elements); + if(result == null) + return true; + else + return false; + } else { + return false; + } + } +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ExpressionUtils.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ExpressionUtils.java new file mode 100644 index 00000000..d7372d5a --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ExpressionUtils.java @@ -0,0 +1,270 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.utils; + +import java.io.StringReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.eclipse.jface.text.Position; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.expressionParser.ExpressionParser; +import org.simantics.sysdyn.expressionParser.ParseException; +import org.simantics.sysdyn.expressionParser.Token; +import org.simantics.sysdyn.expressionParser.TokenMgrError; +import org.simantics.sysdyn.manager.SysdynModel; +import org.simantics.sysdyn.manager.SysdynModelManager; +import org.simantics.sysdyn.representation.Configuration; +import org.simantics.sysdyn.representation.IElement; +import org.simantics.sysdyn.representation.Variable; +import org.simantics.sysdyn.ui.properties.widgets.expressions.ExpressionField; +import org.simantics.sysdyn.ui.properties.widgets.expressions.IExpression; +import org.simantics.sysdyn.ui.properties.widgets.expressions.StockExpression; +import org.simantics.ui.SimanticsUI; + +public class ExpressionUtils { + + /** + * Determines if the given expression is a parameter expression. Parameters are numbers. + * If the expression contains anything other than numbers, it is not a parameter. + * + * @param expression The expression to be checked + * @return is the expression a parameter + */ + static public boolean isParameter(String expression) { + try { + /* + StringTokenizer st = new StringTokenizer(expression, "{}[],;"); + while(st.hasMoreTokens()) { + Double.parseDouble(st.nextToken().trim()); + } + */ + Double.parseDouble(expression.trim()); + return true; + } catch (NumberFormatException e) { + return false; + } + } + + /** + * Validates the expressionfield of a given IExpression + * + * @param expression The expression whose fields are validated + * @param connectedVariables Table items from the shortcut widget. (Items needed so that they can be coloured) + * @param configuration configuration where the variable is located + */ + static public void validateExpressionFields(final Resource variable, IExpression expression, Table variableTable) { + + TableItem[] connectedVariables = variableTable.getItems(); + + + Resource configuration = null; + try { + configuration = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public Resource perform(ReadGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Resource configuration = variable; + while (configuration != null) { + configuration = graph.getPossibleObject(configuration, Layer0.getInstance(graph).PartOf); + + if(configuration == null || graph.isInstanceOf(configuration, sr.Configuration)) { + break; + } + } + return configuration; + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + return; + } + + if(configuration == null) + return; + + ExpressionParser parser = new ExpressionParser(new StringReader("")); + Set variables = new HashSet(); + HashMap>> references = new HashMap>>(); + final HashMap>>> ranges = new HashMap>>>(); + + + // Build references and variable array + for(ExpressionField ef : expression.getExpressionFields()) { + ef.resetAnnotations(); + String textString = ef.getExpression(); + parser.ReInit(new StringReader(textString)); + try { + parser.expr(); + HashMap> refs = parser.getReferences(); + references.put(ef, refs); + variables.addAll(refs.keySet()); + + HashMap>> rangs = parser.getRanges(); + ranges.put(ef, rangs); + } catch (ParseException e1) { + ef.setSyntaxError(e1.currentToken, "Syntax Error"); + } catch (TokenMgrError err) { + ef.setSyntaxError(0, textString.length(), "MissingLink", "Expression contains unsupported characters"); + } + } + + + final HashMap modelVariables = new HashMap(); + + if(!variables.isEmpty()) { + Set noSuchVariables = new HashSet(); + SysdynModelManager sdm = SysdynModelManager.getInstance(SimanticsUI.getSession()); + SysdynModel model = sdm.getModel(configuration); + try { + model.update(); + } catch (DatabaseException e1) { + e1.printStackTrace(); + } + + Configuration conf = model.getConfiguration(); + ArrayList elements = conf.getElements(); + for(IElement e : elements) { + if(e instanceof Variable) { + Variable v = (Variable) e; + modelVariables.put(v.getName(), v); + } + } + + // VARIABLE NAMES + + for(String v : variables) { + if(!modelVariables.keySet().contains(v)) { + noSuchVariables.add(v); + } + } + + if(!noSuchVariables.isEmpty()) { + // remove no such variables from variable list + for(String s : noSuchVariables) + variables.remove(s); + // create annotations + HashMap> positions = getPositionsForVariables(references, noSuchVariables); + for(ExpressionField ef : positions.keySet()) { + ef.setNoSuchVariableAnnotations(positions.get(ef)); + } + } + } + + // Check that the variables that exist have connections and the connected variables have references in the expressions + if(!(expression instanceof StockExpression)) { + for(TableItem ti : connectedVariables) { + if(!variables.contains(ti.getText())) { + ti.setForeground(new Color(ti.getDisplay(), 255, 0, 0)); + } else { + ti.setForeground(new Color(ti.getDisplay(), 0, 0, 0)); + variables.remove(ti.getText()); + } + } + + if(!variables.isEmpty()) { + HashMap> positions = getPositionsForVariables(references, variables); + for(ExpressionField ef : positions.keySet()) { + ef.setMissingLinkAnnotations(positions.get(ef)); + } + + } + } + + + // RANGES + HashMap> errors = new HashMap>(); + HashMap result = null; + + for(final ExpressionField ef : ranges.keySet()) { + try { + result = SimanticsUI.getSession().syncRequest(new Read>() { + + @Override + public HashMap perform(ReadGraph graph) throws DatabaseException { + HashMap result = new HashMap(); + for(String s : ranges.get(ef).keySet()) { + if(ranges.get(ef).containsKey(s)) { + for(List l : ranges.get(ef).get(s)) { + String[] ss = new String[l.size()]; + for(int i = 0; i < l.size(); i++) { + ss[i] = l.get(i).image; + } + Map invalidRanges = ArrayVariableUtils.isRangeValid(graph, modelVariables.get(s), ss); + if(invalidRanges != null && !invalidRanges.isEmpty()) { + for(Integer i : invalidRanges.keySet()) { + result.put(l.get(i), invalidRanges.get(i)); + } + } + } + } + } + return result; + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + errors.put(ef, result); + + } + + for(ExpressionField ef : ranges.keySet()) { + HashMap tokens = errors.get(ef); + if(tokens == null || tokens.isEmpty()) continue; + for(Token t : tokens.keySet()) { + ef.setSyntaxError(t, tokens.get(t)); + } + } + } + + @SuppressWarnings("unchecked") + static private HashMap> getPositionsForVariables(HashMap>> references, Set variables) { + HashMap> result = new HashMap>(); + for(String s : variables) { + List tlist = new ArrayList(); + for(ExpressionField ef : references.keySet()) { + ArrayList positions = new ArrayList(); + 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)); + } + if(result.keySet().contains(ef)) { + result.get(ef).addAll((ArrayList)positions.clone()); + } else { + result.put(ef, (ArrayList)positions.clone()); + } + } + } + return result; + } +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ModelUtils.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ModelUtils.java new file mode 100644 index 00000000..c3092652 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ModelUtils.java @@ -0,0 +1,33 @@ +package org.simantics.sysdyn.ui.utils; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.manager.SysdynModel; +import org.simantics.sysdyn.manager.SysdynModelManager; +import org.simantics.ui.SimanticsUI; + +public class ModelUtils { + + /** + * Returns the SysdynModel where the given variable is located + * + * @param graph ReadGraph + * @param variable Variable whose model is wanted + * @return SysdynModel where variable is located + * @throws DatabaseException + */ + public static SysdynModel getModel(ReadGraph graph, Resource variable) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + Resource configuration = graph.getSingleObject(variable, l0.PartOf); + SysdynModelManager sdm = SysdynModelManager.getInstance(SimanticsUI.getSession()); + SysdynModel model = sdm.getModel(graph, configuration); + try { + model.update(graph); + } catch (DatabaseException e1) { + e1.printStackTrace(); + } + return model; + } +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/VariableNameUtils.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/VariableNameUtils.java similarity index 72% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/VariableNameUtils.java rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/VariableNameUtils.java index 4d1b6ead..2a4f746f 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/VariableNameUtils.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/VariableNameUtils.java @@ -9,9 +9,8 @@ * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ -package org.simantics.sysdyn.ui.properties; +package org.simantics.sysdyn.ui.utils; -import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -28,10 +27,7 @@ import org.simantics.db.request.Read; import org.simantics.layer0.Layer0; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.manager.SysdynModel; -import org.simantics.sysdyn.manager.SysdynModelManager; import org.simantics.sysdyn.representation.Configuration; -import org.simantics.sysdyn.representation.Enumeration; -import org.simantics.sysdyn.representation.EnumerationIndex; import org.simantics.sysdyn.representation.IElement; import org.simantics.sysdyn.representation.Variable; import org.simantics.ui.SimanticsUI; @@ -78,7 +74,7 @@ public class VariableNameUtils { private static String replaceAllWords(String original, String find, String replacement) { if(!original.contains(find)) return original; StringBuilder result = new StringBuilder(original.length()); - String delimiters = "+-*/(){}[],. "; + String delimiters = "+-*/(){}[],.: "; StringTokenizer st = new StringTokenizer(original, delimiters, true); while (st.hasMoreTokens()) { String w = st.nextToken(); @@ -93,7 +89,9 @@ public class VariableNameUtils { private static boolean nameIsTaken(ReadGraph graph, Resource variable, String name) throws DatabaseException { - SysdynModel model = getModel(graph, variable); + if(variable == null) + return false; + SysdynModel model = ModelUtils.getModel(graph, variable); Configuration configuration = model.getConfiguration(); IElement current = model.getElement(variable); for(IElement e : configuration.getElements()) { @@ -107,20 +105,6 @@ public class VariableNameUtils { return false; } - - private static SysdynModel getModel(ReadGraph graph, Resource variable) throws DatabaseException { - Layer0 l0 = Layer0.getInstance(graph); - Resource configuration = graph.getSingleObject(variable, l0.PartOf); - SysdynModelManager sdm = SysdynModelManager.getInstance(SimanticsUI.getSession()); - SysdynModel model = sdm.getModel(graph, configuration); - try { - model.update(graph); - } catch (DatabaseException e1) { - e1.printStackTrace(); - } - return model; - } - /** * Checks that the syntax of the given name is valid and there * are no other variables that have the same name in the configuration @@ -145,61 +129,14 @@ public class VariableNameUtils { range = st.nextToken(); if(!st.nextToken().equals("]")) return false; } - if(range != null && !isRangeValid(graph, variable, range)) return false; + if(range != null && !ArrayVariableUtils.isRangeValid(graph, variable, range)) return false; } if(nameIsTaken(graph, variable, name)) return false; if(!isValid(name)) return false; return true; } - /** - * Checks if the given range can be applied to the given variable. - * - * @param graph ReadGraph - * @param variable Resource of the variable - * @param range Range WITHOUT [ and ] brackets - * @return true if range is valid, false if not - * @throws DatabaseException - */ - private static boolean isRangeValid(ReadGraph graph, Resource variable, String range) throws DatabaseException { - String[] elements = range.split(","); - SysdynModel model = getModel(graph, variable); - IElement e = model.getElement(variable); - if(e != null && e instanceof Variable) { - Variable v = (Variable) e; - ArrayList enumerations = v.getArrayIndexes().getEnumerations(); - if(elements.length != enumerations.size()) return false; - for(int i = 0; i < enumerations.size(); i++) { - if(elements[i].trim().equals(":")) - continue; - if(elements[i].indexOf(":") != elements[i].lastIndexOf(":")) - return false; - - String[] rangeComponents = elements[i].split(":"); - if(rangeComponents.length > 2) - return false; - // Single range component, equals to the enumeration at that index - if(rangeComponents.length == 1 && rangeComponents[0].trim().equals(enumerations.get(i).getName())) - continue; - // one or two range components, they all equal to individual indexes in the enumeration - for(String r : rangeComponents) { - r = r.trim(); - boolean componentIsValid = false; - for(EnumerationIndex ei : enumerations.get(i).getEnumerationIndexes()) { - if(ei.getName().equals(r)) { - componentIsValid = true; - break; - } - } - if(!componentIsValid) - return false; - } - } - return true; - } - - return false; - } + /** * Checks that the syntax of the given name is valid and there * are no other variables that have the same name in the configuration diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.jj b/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.jj index 023d50c1..327d3e6c 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.jj +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.jj @@ -12,12 +12,20 @@ import java.util.List; import java.util.ArrayList; import java.util.HashMap; + public class ExpressionParser { + HashMap> references = new HashMap>(); public HashMap> getReferences() { return references; } + + HashMap>> ranges = new HashMap>>(); + + public HashMap>> getRanges() { + return ranges; + } } @@ -162,16 +170,16 @@ void name() : { void component_reference() : { } { //IDENT [ array_subscripts ] [ "." component_reference ] - { - - if(references.get(token.image) == null) { - references.put(token.image, new ArrayList()); + { + String name = token.image; + if(references.get(name) == null) { + references.put(name, new ArrayList()); + } + List list = references.get(name); + list.add(token); } - List list = references.get(token.image); - list.add(token); - } - ( "." component_reference() )? + ( array_subscripts() )? ( "." component_reference() )? } @@ -208,3 +216,38 @@ void expression_list() : { } { expression() ( "," expression() )* } + +void array_subscripts() : { if(ranges.get(token.image) == null) { + ranges.put(token.image, new ArrayList>()); + } + List> rangesList = ranges.get(token.image); + List currentRange = new ArrayList(); +} { + "[" subscript(currentRange) ( "," subscript(currentRange) )* "]" + { + rangesList.add(currentRange); + } +} + +void subscript(List currentRange) : { + Token rangeToken = new Token(token.kind, ""); + rangeToken.beginColumn = token.beginColumn; + rangeToken.beginLine = token.beginLine; +} { ":" { currentRange.add(token); + } + | rangeIndex(rangeToken, false) ( ":" rangeIndex(rangeToken, true))? { + rangeToken.endColumn = token.endColumn; + rangeToken.endLine = token.endLine; + currentRange.add(rangeToken); + } +} + +void rangeIndex(Token rangeToken, boolean second) : { + if(second) + rangeToken.image = rangeToken.image + ":"; +} { { + rangeToken.image = rangeToken.image + token.image; } + | { rangeToken.image = rangeToken.image + token.image; + } +} + diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynResult.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynResult.java index 3acbccc6..350ff700 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynResult.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynResult.java @@ -97,6 +97,8 @@ public class SysdynResult { for(DataSet ds : datasets){ // Add recording to session Recording recording = createRecording(ds); + System.out.println(recording.nodeId); + System.out.println(recording.nodeId.getBinding()); recordings.put(Bindings.VARIANT, recording.nodeId, Bindings.VARIANT, new Variant(recordingBinding, recording)); } @@ -163,7 +165,7 @@ public class SysdynResult { public static class Recording { public Variant nodeId; public @Arguments({String.class, String.class}) TreeMap labels; - public @Arguments({Double.class, Double.class}) TreeMap[] segments; + public @Arguments({TreeMap.class, Double.class, Double.class}) TreeMap[] segments; } public SysdynDataSet getDataSet(String variable) {