From 10fadbd73eb5c55d3904a83ad2c6847577648046 Mon Sep 17 00:00:00 2001 From: lempinen Date: Wed, 10 Mar 2010 14:00:24 +0000 Subject: [PATCH] Show empty equation view when cloud or dependency selected git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@14790 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/ui/equation/EquationView.java | 63 ++++++++++++------- .../ui/equation/ExpressionComposite.java | 11 ++-- .../sysdyn/ui/equation/UnitSelector.java | 4 ++ .../EmptyExpressionViewFactor.java | 53 ++++++++++++++++ 4 files changed, 105 insertions(+), 26 deletions(-) create mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/EmptyExpressionViewFactor.java 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 ff8e7547..4ba9e745 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 @@ -46,6 +46,7 @@ import org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; import org.simantics.db.procedure.Listener; import org.simantics.db.request.Read; +import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.expressionParser.ExpressionParser; import org.simantics.sysdyn.expressionParser.ParseException; import org.simantics.sysdyn.expressionParser.Token; @@ -177,6 +178,7 @@ public class EquationView extends ViewPart implements ISelectionListener { static class Auxiliary { String name; Resource configuration; + boolean isVariable; } class UpdateViewRequest implements Read { @@ -190,10 +192,14 @@ public class EquationView extends ViewPart implements ISelectionListener { @Override public Auxiliary perform(ReadGraph graph) throws DatabaseException { Builtins b = graph.getBuiltins(); + SysdynResource sr = SysdynResource.getInstance(graph); Auxiliary a = new Auxiliary(); variable = resource; a.configuration = graph.getPossibleObject(variable, b.PartOf); a.name = graph.getPossibleRelatedValue(resource, b.HasName); + a.isVariable = graph.isInstanceOf(variable, sr.Auxiliary) || + graph.isInstanceOf(variable, sr.Stock) || + graph.isInstanceOf(variable, sr.Valve); if(a.name == null) a.name = ""; return a; @@ -224,28 +230,41 @@ public class EquationView extends ViewPart implements ISelectionListener { expressionComposite.getDisplay().asyncExec(new Runnable() { @Override - public void run(){ - if(configuration == null || !configuration.equals(result.configuration)) { - configuration = result.configuration; - if(unitSelector!= null) { - unitSelector.dispose(); - unitSelector = new UnitSelector(unitComposite, SWT.NONE); + public void run(){ + if(result.isVariable) { + unitSelector.setEnabled(true); + expressionController.setEnabled(true); + expressionComposite.setEnabled(true); + nameComposite.setEnabled(true); + if(configuration == null || !configuration.equals(result.configuration)) { + configuration = result.configuration; + if(unitSelector!= null) { + unitSelector.dispose(); + unitSelector = new UnitSelector(unitComposite, SWT.NONE); + } + } else { + unitSelector.updateUnits(variable); } + + if(shortcutTabs != null) shortcutTabs.updateTables(variable); + String expressionType = expressionComposite.resetExpressionView(variable); + addExpressionFieldListeners(); + validateExpressionFields(); + expressionController.setExpressionTypes(expressionComposite.getExpressionTypes()); + expressionController.select(expressionType); + nameComposite.setName(result.name); } else { - unitSelector.updateUnits(variable); + unitSelector.setEnabled(false); + expressionController.setEnabled(false); + expressionComposite.setEnabled(false); + nameComposite.setEnabled(false); + unitSelector.clear(); // empty units + expressionController.setExpressionTypes(null); + nameComposite.setName(result.name); + expressionComposite.resetExpressionView(variable); } - - if(shortcutTabs != null) shortcutTabs.updateTables(variable); - - String expressionType = expressionComposite.resetExpressionView(variable); - addExpressionFieldListeners(); - validateExpressionFields(); - expressionController.setExpressionTypes(expressionComposite.getExpressionTypes()); - expressionController.select(expressionType); - - nameComposite.setName(result.name); } - }); + }); } @@ -389,7 +408,7 @@ public class EquationView extends ViewPart implements ISelectionListener { ef.setSyntaxError(e1.currentToken); } } - + // Remove variables from variable array that don't exist in the model. Create annotations if(!variables.isEmpty()) { ArrayList modelVariables = new ArrayList(); @@ -409,14 +428,14 @@ public class EquationView extends ViewPart implements ISelectionListener { 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) @@ -428,7 +447,7 @@ public class EquationView extends ViewPart implements ISelectionListener { } } } - + // Check that the variables that exist have connections and the connected variables have references in the expressions if(!(expressionComposite.getExpressionViewFactor() instanceof StockExpressionViewFactor)) { for(TableItem ti : this.shortcutTabs.getVariableTable().getItems()) { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/ExpressionComposite.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/ExpressionComposite.java index 32bbf6fd..1afb3cea 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/ExpressionComposite.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/ExpressionComposite.java @@ -15,6 +15,7 @@ import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.equation.expressions.AuxiliaryExpressionViewFactor; import org.simantics.sysdyn.ui.equation.expressions.ConstantExpressionViewFactor; import org.simantics.sysdyn.ui.equation.expressions.DelayExpressionViewFactor; +import org.simantics.sysdyn.ui.equation.expressions.EmptyExpressionViewFactor; import org.simantics.sysdyn.ui.equation.expressions.IExpressionViewFactor; import org.simantics.sysdyn.ui.equation.expressions.LookupExpressionViewFactor; import org.simantics.sysdyn.ui.equation.expressions.ParameterExpressionViewFactor; @@ -24,7 +25,7 @@ import org.simantics.ui.SimanticsUI; public class ExpressionComposite extends Composite { - static enum ExpressionType {Auxiliary, Parameter, Constant, Lookup, WithLookup, Stock, Delay}; + static enum ExpressionType {Auxiliary, Parameter, Constant, Lookup, WithLookup, Stock, Delay, Empty}; ExpressionType[] auxiliaryExpressions = new ExpressionType[] { ExpressionType.Parameter, @@ -100,7 +101,8 @@ public class ExpressionComposite extends Composite { evf = new StockExpressionViewFactor(); break; case Delay: evf = new DelayExpressionViewFactor(); break; - default: ; + default: + evf = new EmptyExpressionViewFactor(); } if (evf != null) { @@ -191,7 +193,8 @@ public class ExpressionComposite extends Composite { } else if(graph.isInstanceOf(variable, sr.Stock)) { et = ExpressionType.Stock; - } + } else + et = ExpressionType.Empty; } else { if(graph.isInstanceOf(expression, sr.NormalExpression)) { @@ -209,7 +212,7 @@ public class ExpressionComposite extends Composite { } else if (graph.isInstanceOf(expression, sr.WithLookupExpression)) { et = ExpressionType.WithLookup; } else { - et = ExpressionType.Auxiliary; + et = ExpressionType.Empty; } } return et; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/UnitSelector.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/UnitSelector.java index 4d192b08..38e20c09 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/UnitSelector.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/UnitSelector.java @@ -100,6 +100,10 @@ public class UnitSelector extends Composite { setUnit(); } } + + public void clear() { + this.unitCombo.removeAll(); + } private void setUnit() { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/EmptyExpressionViewFactor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/EmptyExpressionViewFactor.java new file mode 100644 index 00000000..b360a39f --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/EmptyExpressionViewFactor.java @@ -0,0 +1,53 @@ +package org.simantics.sysdyn.ui.equation.expressions; + +import java.util.List; +import java.util.Map; + +import org.eclipse.swt.widgets.Composite; +import org.simantics.db.Resource; + +public class EmptyExpressionViewFactor implements IExpressionViewFactor { + + @Override + public void createView(Composite parent, Map data) { + // TODO Auto-generated method stub + + } + + @Override + public void focus() { + // TODO Auto-generated method stub + + } + + @Override + public List getExpressionFields() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void readData(Resource variable, Map data) { + // TODO Auto-generated method stub + + } + + @Override + public void replaceSelection(String var) { + // TODO Auto-generated method stub + + } + + @Override + public void updateData(Map data) { + // TODO Auto-generated method stub + + } + + @Override + public void writeData(Resource variable, Map data) { + // TODO Auto-generated method stub + + } + +} -- 2.47.1