]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
SpreadsheetCells with Circular References support iterations.
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 29 Aug 2016 10:15:21 +0000 (13:15 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 29 Aug 2016 10:15:21 +0000 (13:15 +0300)
Default number of iterations is 100 times.
Previously, AstIdentifier visits in CellValueVisitor would throw
IllegalStateException. Now, a FormulaError is returned instead.

refs #6659

bundles/org.simantics.scl.runtime/build.properties
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/CellValueVisitor.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/GraphUI.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetBook.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetCell.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/SpreadsheetEvaluationEnvironment.java
bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/SpreadsheetModel.java

index cd7bc40446f1a1d29395145bcef3bfe25fa61cc2..cbbb8252da9b540f127d71c919d632dd206ff4d7 100755 (executable)
@@ -3,4 +3,4 @@ output.. = bin/
 bin.includes = META-INF/,\\r
                .,\\r
                scl/,\\r
-               schema/\r
+               schema/
\ No newline at end of file
index b0abb61b15627f3d828fd5404ccb6fd27a533797..385af993847c9d2b44393cdbc92386c19c0c18aa 100644 (file)
@@ -434,7 +434,8 @@ public class CellValueVisitor implements AstValueVisitor<Object> {
 \r
        @Override\r
        public Object visit(AstIdentifier id) {\r
-               throw new IllegalStateException();\r
+               return FormulaError2.NAME.getString();\r
+               //throw new IllegalStateException();\r
        }\r
        \r
        @Override\r
index 80e9656e33db8e451cc737d7b69f1aa5d6431854..9a3e8732679d284b4a30abfdbcfc274da9a708e7 100644 (file)
@@ -495,7 +495,13 @@ public class GraphUI implements Adaptable, ListenerSupport, AsyncListenerSupport
                                public <T> void edit(Transaction<Write> transaction, String location, String property, T value, Binding binding, Consumer<?> callback) {\r
                                        \r
                                    if (ClientModel.ITERATION_ENABLED.equals(location)) {\r
-                                       \r
+                                       Simantics.getSession().asyncRequest(new ReadRequest() {\r
+                                                       @Override\r
+                                                       public void run(ReadGraph graph) throws DatabaseException {\r
+                                                               getBook(graph).setIterationEnabled((boolean)value);\r
+                                                       }\r
+                                               });\r
+                                       return;\r
                                    }\r
                                    \r
                                    if (ClientModel.MODE.equals(location)) {\r
index caf3cd98473b38d5e5cb1e33c0e3ecea0e7ea6d7..e292fd91848659bcc4822dbc01604715f8a34212 100644 (file)
@@ -57,6 +57,8 @@ public class SpreadsheetBook implements SpreadsheetElement<SpreadsheetElement, S
        \r
        public Map<Integer, SpreadsheetElement> children = new HashMap<>();\r
 \r
+       private boolean iterationEnabled;\r
+\r
        public int getNewId(SpreadsheetElement element) {\r
                int result = idCounter++;\r
                children.put(result, element);\r
@@ -401,4 +403,12 @@ public class SpreadsheetBook implements SpreadsheetElement<SpreadsheetElement, S
         \r
     }\r
 \r
+       public void setIterationEnabled(boolean value) {\r
+               this.iterationEnabled = value;\r
+       }\r
+       \r
+       public boolean isIterationEnabled() {\r
+               return iterationEnabled;\r
+       }\r
+\r
 }\r
index 7d04e9b6e21c607bb80b30bce98ed10ac8a5489c..b7536f83aa906eed9457356d387ff44336408997 100644 (file)
@@ -101,22 +101,26 @@ public class SpreadsheetCell implements SpreadsheetElement, SheetNode {
                                AstValue value = ((SpreadsheetFormula)content).value;\r
                                if(this.inProgress == true) this.iterations++;\r
                                \r
-                               if(env.iterationEnabled == false){\r
+                               if(!env.getBook().isIterationEnabled()){\r
                                        if(this.inProgress == false){\r
                                                this.inProgress = true;\r
                                                f.result = value.accept(visitor);\r
                                        }\r
                                        else f.result = FormulaError2.CIRCULAR_REF.getString();\r
                                }\r
-                               else if(iterations<env.iterationLimit){\r
+                               else if(this.iterations<env.iterationLimit){\r
                                        this.inProgress = true;\r
                                        f.result = value.accept(visitor);\r
                                }\r
-                               else f.result = 0.0;\r
+                               else {\r
+                                       if(f.result==null)\r
+                                               f.result = 0.0;\r
+                               }\r
                                \r
                                env.getBook().registerReferences(makeReferenceKey(), visitor.getReferences());\r
                        }\r
                        this.inProgress = false;\r
+                       this.iterations = 0;\r
                        return (T)f.result;\r
                } else if (content instanceof SpreadsheetSCLConstant) {\r
                    SpreadsheetSCLConstant sclConstant = (SpreadsheetSCLConstant) content;\r
index bb5a5d71bd38935e65ac7a4d3cfce37029ddb262..b1b9ad0c60fc2a23897af8ddbc2516bc8313b662 100644 (file)
@@ -11,8 +11,6 @@ public class SpreadsheetEvaluationEnvironment {
     final private SpreadsheetBook book;\r
     private Map<String, CellFormulaFunction<?>> functions = new HashMap<>();\r
     public int iterationLimit = 100;\r
-    public boolean iterationEnabled = false;\r
-    \r
 \r
     public SpreadsheetEvaluationEnvironment(SpreadsheetBook book) {\r
         this.book = book;\r
index 9b4ef34e34bf3051a1b4f4e507eef83b4f33c0a3..d534c9488a395dbfb46ceb3093bc0f4063fb73e5 100644 (file)
@@ -753,6 +753,10 @@ public class SpreadsheetModel {
                            @Override\r
                            public void actionPerformed(ActionEvent e) {\r
                                System.out.println("state is " + iterationEnabled.isSelected());\r
+                               CellEditor editor = serverInterface.getAdapter(CellEditor.class);\r
+                               if(editor != null) {\r
+                                   editor.edit(null, ClientModel.ITERATION_ENABLED, ClientModel.ITERATION_ENABLED, iterationEnabled.isSelected(), null, null);\r
+                               }\r
                            }\r
                        });\r
                        \r