From: miettinen Date: Thu, 28 Feb 2013 11:15:56 +0000 (+0000) Subject: Validate the user defined function before saving it (refs #4133). X-Git-Tag: simantics-1.10.1~16 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=6521b3d2d1bfb88ed09485f09e5b26ed83c2f5d5;p=simantics%2Fsysdyn.git Validate the user defined function before saving it (refs #4133). git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@26940 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/FunctionCodeWidget.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/FunctionCodeWidget.java index bf51ebe7..078490c3 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/FunctionCodeWidget.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/FunctionCodeWidget.java @@ -183,18 +183,6 @@ public class FunctionCodeWidget implements Widget { inputs = modelParser.getInputs(); outputs = modelParser.getOutputs(); - - /*for (Parameter input : inputs) { - System.out.print("input " + input.type + " " + input.name); - if (input.optional) System.out.print(" [optional]"); - if (input.description != null) System.out.print(" [Description: " + input.description + "]"); - System.out.println(); - } - for (Parameter output : outputs) { - System.out.print("output " + output.type + " " + output.name); - if (output.description != null) System.out.print(" [Description: " + output.description + "]"); - System.out.println(); - }^*/ } catch (ParseException e1) { Token token = e1.currentToken; @@ -219,8 +207,33 @@ public class FunctionCodeWidget implements Widget { private void save() { final String code = modelicaCode.getExpression(); + + // Update input and output lists. + validate(); + SimanticsUI.getSession().asyncRequest(new WriteRequest() { - + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + + // Remove the existing input list + removeInputList(graph); + // Create the new input list + createInputList(graph); + + // Remove the existing output list + removeOutputList(graph); + // Create the new output list + createOutputList(graph); + + // Update the function code + graph.claimLiteral( + function, + sr.SysdynModelicaFunction_modelicaFunctionCode, + code); + } + private void removeInputList(WriteGraph graph) throws DatabaseException { SysdynResource sr = SysdynResource.getInstance(graph); @@ -310,27 +323,7 @@ public class FunctionCodeWidget implements Widget { ListUtils.create(graph, outputResources)); } - - @Override - public void perform(WriteGraph graph) throws DatabaseException { - SysdynResource sr = SysdynResource.getInstance(graph); - // Remove the existing input list - removeInputList(graph); - // Create the new input list - createInputList(graph); - - // Remove the existing output list - removeOutputList(graph); - // Create the new output list - createOutputList(graph); - - // Update the function code - graph.claimLiteral( - function, - sr.SysdynModelicaFunction_modelicaFunctionCode, - code); - } }); }