import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.procedure.Listener;\r
import org.simantics.db.request.Read;\r
+import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.expressionParser.ExpressionParser;\r
import org.simantics.sysdyn.expressionParser.ParseException;\r
import org.simantics.sysdyn.expressionParser.Token;\r
static class Auxiliary {\r
String name;\r
Resource configuration;\r
+ boolean isVariable;\r
}\r
\r
class UpdateViewRequest implements Read<Auxiliary> {\r
@Override\r
public Auxiliary perform(ReadGraph graph) throws DatabaseException {\r
Builtins b = graph.getBuiltins();\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
Auxiliary a = new Auxiliary();\r
variable = resource;\r
a.configuration = graph.getPossibleObject(variable, b.PartOf);\r
a.name = graph.getPossibleRelatedValue(resource, b.HasName);\r
+ a.isVariable = graph.isInstanceOf(variable, sr.Auxiliary) ||\r
+ graph.isInstanceOf(variable, sr.Stock) ||\r
+ graph.isInstanceOf(variable, sr.Valve);\r
if(a.name == null)\r
a.name = "";\r
return a;\r
expressionComposite.getDisplay().asyncExec(new Runnable() {\r
\r
@Override\r
- public void run(){ \r
- if(configuration == null || !configuration.equals(result.configuration)) {\r
- configuration = result.configuration;\r
- if(unitSelector!= null) {\r
- unitSelector.dispose();\r
- unitSelector = new UnitSelector(unitComposite, SWT.NONE);\r
+ public void run(){ \r
+ if(result.isVariable) {\r
+ unitSelector.setEnabled(true);\r
+ expressionController.setEnabled(true);\r
+ expressionComposite.setEnabled(true);\r
+ nameComposite.setEnabled(true);\r
+ if(configuration == null || !configuration.equals(result.configuration)) {\r
+ configuration = result.configuration;\r
+ if(unitSelector!= null) {\r
+ unitSelector.dispose();\r
+ unitSelector = new UnitSelector(unitComposite, SWT.NONE);\r
+ }\r
+ } else {\r
+ unitSelector.updateUnits(variable);\r
}\r
+\r
+ if(shortcutTabs != null) shortcutTabs.updateTables(variable);\r
+ String expressionType = expressionComposite.resetExpressionView(variable);\r
+ addExpressionFieldListeners();\r
+ validateExpressionFields();\r
+ expressionController.setExpressionTypes(expressionComposite.getExpressionTypes()); \r
+ expressionController.select(expressionType);\r
+ nameComposite.setName(result.name);\r
} else {\r
- unitSelector.updateUnits(variable);\r
+ unitSelector.setEnabled(false);\r
+ expressionController.setEnabled(false);\r
+ expressionComposite.setEnabled(false);\r
+ nameComposite.setEnabled(false);\r
+ unitSelector.clear(); // empty units\r
+ expressionController.setExpressionTypes(null); \r
+ nameComposite.setName(result.name);\r
+ expressionComposite.resetExpressionView(variable);\r
}\r
-\r
- if(shortcutTabs != null) shortcutTabs.updateTables(variable);\r
-\r
- String expressionType = expressionComposite.resetExpressionView(variable);\r
- addExpressionFieldListeners();\r
- validateExpressionFields();\r
- expressionController.setExpressionTypes(expressionComposite.getExpressionTypes()); \r
- expressionController.select(expressionType);\r
-\r
- nameComposite.setName(result.name);\r
}\r
- }); \r
+ }); \r
\r
}\r
\r
ef.setSyntaxError(e1.currentToken);\r
}\r
}\r
- \r
+\r
// Remove variables from variable array that don't exist in the model. Create annotations\r
if(!variables.isEmpty()) {\r
ArrayList<String> modelVariables = new ArrayList<String>();\r
modelVariables.add(v.getName());\r
}\r
}\r
- \r
+\r
\r
for(String v : variables) {\r
if(!modelVariables.contains(v)) {\r
noSuchVariables.add(v);\r
}\r
}\r
- \r
+\r
if(!noSuchVariables.isEmpty()) {\r
// remove no such variables from variable list\r
for(String s : noSuchVariables)\r
}\r
} \r
}\r
- \r
+\r
// Check that the variables that exist have connections and the connected variables have references in the expressions\r
if(!(expressionComposite.getExpressionViewFactor() instanceof StockExpressionViewFactor)) { \r
for(TableItem ti : this.shortcutTabs.getVariableTable().getItems()) {\r
import org.simantics.sysdyn.ui.equation.expressions.AuxiliaryExpressionViewFactor;\r
import org.simantics.sysdyn.ui.equation.expressions.ConstantExpressionViewFactor;\r
import org.simantics.sysdyn.ui.equation.expressions.DelayExpressionViewFactor;\r
+import org.simantics.sysdyn.ui.equation.expressions.EmptyExpressionViewFactor;\r
import org.simantics.sysdyn.ui.equation.expressions.IExpressionViewFactor;\r
import org.simantics.sysdyn.ui.equation.expressions.LookupExpressionViewFactor;\r
import org.simantics.sysdyn.ui.equation.expressions.ParameterExpressionViewFactor;\r
\r
public class ExpressionComposite extends Composite {\r
\r
- static enum ExpressionType {Auxiliary, Parameter, Constant, Lookup, WithLookup, Stock, Delay};\r
+ static enum ExpressionType {Auxiliary, Parameter, Constant, Lookup, WithLookup, Stock, Delay, Empty};\r
\r
ExpressionType[] auxiliaryExpressions = new ExpressionType[] {\r
ExpressionType.Parameter, \r
evf = new StockExpressionViewFactor(); break;\r
case Delay: \r
evf = new DelayExpressionViewFactor(); break;\r
- default: ;\r
+ default: \r
+ evf = new EmptyExpressionViewFactor();\r
}\r
\r
if (evf != null) {\r
}\r
else if(graph.isInstanceOf(variable, sr.Stock)) {\r
et = ExpressionType.Stock;\r
- }\r
+ } else\r
+ et = ExpressionType.Empty;\r
} else {\r
\r
if(graph.isInstanceOf(expression, sr.NormalExpression)) {\r
} else if (graph.isInstanceOf(expression, sr.WithLookupExpression)) {\r
et = ExpressionType.WithLookup;\r
} else {\r
- et = ExpressionType.Auxiliary;\r
+ et = ExpressionType.Empty;\r
}\r
}\r
return et;\r
--- /dev/null
+package org.simantics.sysdyn.ui.equation.expressions;\r
+\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.simantics.db.Resource;\r
+\r
+public class EmptyExpressionViewFactor implements IExpressionViewFactor {\r
+\r
+ @Override\r
+ public void createView(Composite parent, Map<String, Object> data) {\r
+ // TODO Auto-generated method stub\r
+ \r
+ }\r
+\r
+ @Override\r
+ public void focus() {\r
+ // TODO Auto-generated method stub\r
+ \r
+ }\r
+\r
+ @Override\r
+ public List<ExpressionField> getExpressionFields() {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public void readData(Resource variable, Map<String, Object> data) {\r
+ // TODO Auto-generated method stub\r
+ \r
+ }\r
+\r
+ @Override\r
+ public void replaceSelection(String var) {\r
+ // TODO Auto-generated method stub\r
+ \r
+ }\r
+\r
+ @Override\r
+ public void updateData(Map<String, Object> data) {\r
+ // TODO Auto-generated method stub\r
+ \r
+ }\r
+\r
+ @Override\r
+ public void writeData(Resource variable, Map<String, Object> data) {\r
+ // TODO Auto-generated method stub\r
+ \r
+ }\r
+\r
+}\r