]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Validate the user defined function before saving it (refs #4133).
authormiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 28 Feb 2013 11:15:56 +0000 (11:15 +0000)
committermiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 28 Feb 2013 11:15:56 +0000 (11:15 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@26940 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/FunctionCodeWidget.java

index bf51ebe7d4edb6da26395d8dd3add89cc8ac71c9..078490c34c52d43af16aa51ad5cb1a2907e2000c 100644 (file)
@@ -183,18 +183,6 @@ public class FunctionCodeWidget implements Widget {
                        \r
                        inputs = modelParser.getInputs();\r
                    outputs = modelParser.getOutputs();\r
-                       \r
-            /*for (Parameter input : inputs) {\r
-               System.out.print("input " + input.type + " " + input.name);\r
-               if (input.optional) System.out.print(" [optional]");\r
-               if (input.description != null) System.out.print(" [Description: " + input.description + "]");\r
-               System.out.println();\r
-            }\r
-           for (Parameter output : outputs) {    \r
-               System.out.print("output " + output.type + " " + output.name);\r
-               if (output.description != null) System.out.print(" [Description: " + output.description + "]");\r
-               System.out.println();\r
-           }^*/\r
 \r
                } catch (ParseException e1) {\r
                        Token token = e1.currentToken;\r
@@ -219,8 +207,33 @@ public class FunctionCodeWidget implements Widget {
     \r
     private void save() {\r
        final String code = modelicaCode.getExpression();\r
+       \r
+       // Update input and output lists.\r
+       validate();\r
+       \r
        SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
-        \r
+            \r
+            @Override\r
+            public void perform(WriteGraph graph) throws DatabaseException {\r
+                SysdynResource sr = SysdynResource.getInstance(graph);\r
+\r
+                // Remove the existing input list\r
+                removeInputList(graph);\r
+                // Create the new input list\r
+                createInputList(graph);\r
+\r
+                // Remove the existing output list\r
+                removeOutputList(graph);\r
+                // Create the new output list\r
+                createOutputList(graph);\r
+                \r
+                // Update the function code\r
+                graph.claimLiteral(\r
+                        function, \r
+                        sr.SysdynModelicaFunction_modelicaFunctionCode, \r
+                        code);\r
+            }\r
+            \r
            private void removeInputList(WriteGraph graph) throws DatabaseException {\r
                 SysdynResource sr = SysdynResource.getInstance(graph);\r
                 \r
@@ -310,27 +323,7 @@ public class FunctionCodeWidget implements Widget {
                         ListUtils.create(graph, outputResources));\r
                 \r
            }\r
-           \r
-                       @Override\r
-                       public void perform(WriteGraph graph) throws DatabaseException {\r
-                SysdynResource sr = SysdynResource.getInstance(graph);\r
 \r
-                   // Remove the existing input list\r
-                           removeInputList(graph);\r
-                       // Create the new input list\r
-                           createInputList(graph);\r
-                \r
-                // Remove the existing output list\r
-                           removeOutputList(graph);\r
-                // Create the new output list\r
-                           createOutputList(graph);\r
-                           \r
-                // Update the function code\r
-                               graph.claimLiteral(\r
-                                               function, \r
-                                               sr.SysdynModelicaFunction_modelicaFunctionCode, \r
-                                               code);\r
-                       }\r
                });\r
     }\r
 \r