]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Parameter and auxiliary types selected automatically.
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 5 Oct 2010 11:51:42 +0000 (11:51 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 5 Oct 2010 11:51:42 +0000 (11:51 +0000)
Numbers are parameters, non-numbers are auxiliaries.
Constant changed to auxiliary if it is not a number.

Expression saved when focus lost from the whole property view. Expression field can also have their own focus lost listeners like WithLookupExpression has to update Lookup Table tab.

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@18224 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ExpressionWidget.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/BasicExpression.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionUtils.java [moved from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionValidation.java with 90% similarity]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/WithLookupExpression.java

index 8a10b1ccbc92e08d4af1257d874d6a1df6c89ac2..5e61552b2468bd686c798a16d4d8105549ff6472 100644 (file)
@@ -18,7 +18,9 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Label;\r
 import org.eclipse.swt.widgets.Table;\r
 import org.eclipse.swt.widgets.TableItem;\r
+import org.eclipse.ui.IWorkbenchPartReference;\r
 import org.eclipse.ui.IWorkbenchSite;\r
+import org.simantics.browsing.ui.platform.PropertyPageView;\r
 import org.simantics.browsing.ui.swt.PropertyTabContributorImpl;\r
 import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;\r
 import org.simantics.browsing.ui.swt.widgets.TrackedCombo;\r
@@ -47,9 +49,12 @@ public class EquationTab extends PropertyTabContributorImpl {
     TrackedCombo expressionTypeCombo, unitCombo;\r
     ShortcutTabWidget shortcutTabWidget;\r
     ExpressionWidget expressionWidget;\r
+    org.eclipse.ui.IPartListener2 focusLostListener;  \r
+    IWorkbenchSite site;\r
 \r
     @Override\r
     public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) {\r
+       this.site = site;\r
         Composite composite = new Composite(body, SWT.NONE);\r
         GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);\r
         GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(6).applyTo(composite);\r
@@ -124,7 +129,6 @@ public class EquationTab extends PropertyTabContributorImpl {
             \r
             @Override\r
             public void modifyText(TrackedModifyEvent e) {\r
-                System.out.println(e.getText());\r
                 expressionWidget.displayExpression(e.getText(), false);\r
                 expressionWidget.save();                \r
             }\r
@@ -226,18 +230,33 @@ public class EquationTab extends PropertyTabContributorImpl {
                 expressionWidget.validateFields();\r
             }\r
         });\r
-\r
-        expressionWidget.addFocusListener(new FocusListener() {\r
-\r
-            @Override\r
-            public void focusLost(FocusEvent e) {\r
-                expressionWidget.save();\r
-            }\r
-\r
-            @Override\r
-            public void focusGained(FocusEvent e) {\r
-                expressionWidget.validateFields();\r
+        \r
+        focusLostListener = new org.eclipse.ui.IPartListener2()\r
+        {\r
+            public void partInputChanged(IWorkbenchPartReference partRef) {}\r
+            public void partVisible(IWorkbenchPartReference partRef) {}\r
+            public void partHidden(IWorkbenchPartReference partRef) {}\r
+            public void partOpened(IWorkbenchPartReference partRef) {}\r
+            public void partDeactivated(IWorkbenchPartReference partRef)\r
+            {\r
+                if(partRef.getPart(false) instanceof PropertyPageView) {\r
+                    // Save expressions\r
+                    if(expressionWidget != null) {\r
+                       expressionWidget.save();\r
+                    }\r
+                }\r
             }\r
-        });   \r
+            public void partClosed(IWorkbenchPartReference partRef) {}\r
+            public void partBroughtToTop(IWorkbenchPartReference partRef) {}\r
+            public void partActivated(IWorkbenchPartReference partRef) {}\r
+        };\r
+        site.getPage().addPartListener(focusLostListener);\r
+    }\r
+    \r
+    @Override\r
+    public void dispose() {\r
+       if(focusLostListener != null && site != null)\r
+               site.getPage().removePartListener(focusLostListener);\r
+       super.dispose();\r
     }\r
 }\r
index a3ad7704c07ddbcb5dcaf3795529edc2d0e3c5d0..823eb4b796e3079cc73f2149d22728933458c5e6 100644 (file)
@@ -25,7 +25,7 @@ import org.simantics.sysdyn.ui.properties.widgets.expressions.AuxiliaryExpressio
 import org.simantics.sysdyn.ui.properties.widgets.expressions.ConstantExpression;\r
 import org.simantics.sysdyn.ui.properties.widgets.expressions.DelayExpression;\r
 import org.simantics.sysdyn.ui.properties.widgets.expressions.EmptyExpression;\r
-import org.simantics.sysdyn.ui.properties.widgets.expressions.ExpressionValidation;\r
+import org.simantics.sysdyn.ui.properties.widgets.expressions.ExpressionUtils;\r
 import org.simantics.sysdyn.ui.properties.widgets.expressions.IExpression;\r
 import org.simantics.sysdyn.ui.properties.widgets.expressions.LookupExpression;\r
 import org.simantics.sysdyn.ui.properties.widgets.expressions.ParameterExpression;\r
@@ -106,7 +106,8 @@ public class ExpressionWidget implements Widget {
             \r
             exp.createExpressionFields(parent, data);\r
             exp.addModifyListener(modifyListener);\r
-            exp.addFocusListener(focusListener);\r
+            if(focusListener != null)\r
+               exp.addFocusListener(focusListener);\r
             this.expression = exp;\r
             this.parent.layout();\r
             validateFields();\r
@@ -143,7 +144,7 @@ public class ExpressionWidget implements Widget {
                     return null;\r
                 }\r
             });\r
-            ExpressionValidation.validateExpressionFields(expression, connectedVariables, configuration);\r
+            ExpressionUtils.validateExpressionFields(expression, connectedVariables, configuration);\r
         } catch (DatabaseException e1) {\r
             e1.printStackTrace();\r
         }\r
index 01acc49ea6f16e08a11ae691d7e575c0a992aa1f..79acf421cfaf7a0fd06ad5bb24143292634d449c 100644 (file)
@@ -58,7 +58,7 @@ public class BasicExpression implements IExpression {
     @Override\r
     public void readData(final Resource variable, Map<String, Object> data) {\r
         String equation = null;\r
-        if (variable != null && data.get("equation") == null && expressionType != null) {\r
+        if (variable != null && data.get("equation") == null) {\r
             try {\r
                 equation = SimanticsUI.getSession().syncRequest(new Read<String>() {\r
 \r
@@ -66,11 +66,14 @@ public class BasicExpression implements IExpression {
                     public String perform(ReadGraph graph) throws DatabaseException {\r
                         SysdynResource sr = SysdynResource.getInstance(graph);\r
                         Resource expression = graph.getPossibleObject(variable, sr.HasExpression);\r
-                        if (expression != null && graph.isInstanceOf(expression, expressionType)) {\r
-                            return graph.getRelatedValue(expression, sr.HasEquation);\r
-                        } else {\r
-                            return "";\r
+                        if (expression != null) {\r
+                            String equation = graph.getPossibleRelatedValue(expression, sr.HasEquation);\r
+                            if(equation != null)\r
+                               return equation;\r
                         }\r
+                        \r
+                        return "";\r
+                        \r
                     }\r
 \r
                 });\r
@@ -108,6 +111,13 @@ public class BasicExpression implements IExpression {
                 throws DatabaseException {\r
                     SysdynResource sr = SysdynResource.getInstance(g);\r
                     Resource expression = g.getPossibleObject(variable, sr.HasExpression);\r
+                    if(ExpressionUtils.isParameter(currentText)) {\r
+                       System.out.println(expressionType);\r
+                       if(!expressionType.equals(sr.ConstantExpression))\r
+                               expressionType = sr.ParameterExpression;\r
+                    } else {\r
+                       expressionType = sr.NormalExpression;\r
+                    }\r
                     if (oldEquation != null \r
                             && expression != null \r
                             && g.isInstanceOf(expression, expressionType) \r
similarity index 90%
rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionValidation.java
rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionUtils.java
index 2c844005d66d41f39f837de47542e888b3cccf0a..2b11a3026f342dc979e2f2545929139f03f84664 100644 (file)
@@ -25,7 +25,23 @@ import org.simantics.sysdyn.representation.Variable;
 import org.simantics.sysdyn.ui.properties.widgets.expressions.IExpression;\r
 import org.simantics.ui.SimanticsUI;\r
 \r
-public class ExpressionValidation {\r
+public class ExpressionUtils {\r
+       \r
+       /**\r
+        * Determines if the given expression is a parameter expression. Parameters are numbers.\r
+        * If the expression contains anything other than numbers, it is not a parameter.\r
+        * \r
+        * @param expression The expression to be checked\r
+        * @return is the expression a parameter\r
+        */\r
+       static public boolean isParameter(String expression) {\r
+               try {\r
+                       Double.parseDouble(expression);\r
+                       return true;\r
+               } catch (NumberFormatException e) {\r
+                       return false;\r
+               }\r
+       }\r
 \r
     static public void validateExpressionFields(IExpression expression, TableItem[] connectedVariables, Resource configuration) {\r
         ExpressionParser parser = new ExpressionParser(new StringReader(""));\r
index 24b075daf799453efc850d87db9cae242094b64b..a0bcf27acf849328cd5fb6fca0e5783a46fbfba3 100644 (file)
@@ -113,6 +113,7 @@ public class WithLookupExpression implements IExpression {
             @Override\r
             public void focusLost(FocusEvent e) {\r
                 lastSelectedText = lookup;\r
+                save(variable, data);\r
             }\r
         });\r
 \r