]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Show empty equation view when cloud or dependency selected
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 10 Mar 2010 14:00:24 +0000 (14:00 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 10 Mar 2010 14:00:24 +0000 (14:00 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@14790 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/EquationView.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/ExpressionComposite.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/UnitSelector.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/EmptyExpressionViewFactor.java [new file with mode: 0644]

index ff8e7547cf9bdc04dafa6c5e656e5330a40f4841..4ba9e745577e2678d28fc60c7d55fe8110775989 100644 (file)
@@ -46,6 +46,7 @@ import org.simantics.db.Resource;
 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
@@ -177,6 +178,7 @@ public class EquationView extends ViewPart implements ISelectionListener {
     static class Auxiliary {\r
         String name;\r
         Resource configuration;\r
+        boolean isVariable;\r
     }\r
 \r
     class UpdateViewRequest implements Read<Auxiliary> {\r
@@ -190,10 +192,14 @@ public class EquationView extends ViewPart implements ISelectionListener {
         @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
@@ -224,28 +230,41 @@ public class EquationView extends ViewPart implements ISelectionListener {
                                     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
@@ -389,7 +408,7 @@ public class EquationView extends ViewPart implements ISelectionListener {
                     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
@@ -409,14 +428,14 @@ public class EquationView extends ViewPart implements ISelectionListener {
                     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
@@ -428,7 +447,7 @@ public class EquationView extends ViewPart implements ISelectionListener {
                 }\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
index 32bbf6fd8f882e92722cd511c2f60c022ff45ea4..1afb3cead337a88949f297db24e28206aaa55f11 100644 (file)
@@ -15,6 +15,7 @@ import org.simantics.sysdyn.SysdynResource;
 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
@@ -24,7 +25,7 @@ import org.simantics.ui.SimanticsUI;
 \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
@@ -100,7 +101,8 @@ public class ExpressionComposite extends Composite {
                 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
@@ -191,7 +193,8 @@ public class ExpressionComposite extends Composite {
                         }\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
@@ -209,7 +212,7 @@ public class ExpressionComposite extends Composite {
                         } 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
index 4d192b08c0c2a6076fafd9332526c11cf35b7175..38e20c09e44b1520bccf0790d8b99c195393a1c9 100644 (file)
@@ -100,6 +100,10 @@ public class UnitSelector extends Composite {
             setUnit();\r
         }\r
     }\r
+    \r
+    public void clear() {\r
+        this.unitCombo.removeAll();\r
+    }\r
 \r
     private void setUnit() {\r
 \r
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 (file)
index 0000000..b360a39
--- /dev/null
@@ -0,0 +1,53 @@
+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