Spreadsheet Fixes 33/1933/2
authorMiro Richard Eklund <miro.eklund@semantum.fi>
Wed, 18 Jul 2018 11:12:05 +0000 (14:12 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Sat, 21 Jul 2018 06:40:08 +0000 (06:40 +0000)
-Fix ArithmeticExpression + and - String cell value evaluation to check
for number properly.
-decodePossibleCellAbsolute by location rather than decodeCellAbsolute
in "getPossibleCellEditor" to avoid error being thrown unnecessarily
when trying to access cells by ID "Headers" (which is not a proper cell
ID)
-Update cell content expression after change rather than leaving the
default value.

gitlab #43
gitlab #44
gitlab #45

Change-Id: I8a89d86f6cdfd0651a36176a69066b8faa4faeac

bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/CellValueVisitor.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/function/All.java
bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/TextTableCellEditor.java

index 652659ce0349e1b87a4fc2f472d4d7d6efd0eab0..8150b4dbadba87104e927a965c1e963970ea2fd0 100644 (file)
@@ -247,7 +247,12 @@ public class CellValueVisitor implements AstValueVisitor<Object> {
                                        if(err!=null) return err.getString();
                                        
                                        if(result instanceof String && !((String) result).isEmpty()){
-                                               return FormulaError2.VALUE.getString();
+                                               Number num = SpreadsheetGraphUtils.asValidNumber(result);
+                                               if(num == null) {
+                                                       return FormulaError2.VALUE.getString();
+                                               } else {
+                                                       result = num;
+                                               }
                                        } 
                                        else if(result instanceof Variant){
                                                Object val = ((Variant)result).getValue();
@@ -280,7 +285,12 @@ public class CellValueVisitor implements AstValueVisitor<Object> {
                                        if(err!=null) return err.getString();
                                        
                                        if(result instanceof String && !((String) result).isEmpty()){
-                                               return FormulaError2.VALUE.getString();
+                                               Number num = SpreadsheetGraphUtils.asValidNumber(result);
+                                               if(num == null) {
+                                                       return FormulaError2.VALUE.getString();
+                                               } else {
+                                                       result = num;
+                                               }
                                        } 
                                        else if(result instanceof Variant){
                                                Object val = ((Variant)result).getValue();
index 1439a941dcb53d5a023d894a4615cb8924d469d0..39e5778f9ddd5bfef7acee410973dc9f008f61df 100644 (file)
@@ -620,20 +620,21 @@ public class All {
                
             private CellEditor<Write> getPossibleCellEditor(WriteGraph graph, String location, Variant value) throws DatabaseException {
                 SpreadsheetResource SHEET = SpreadsheetResource.getInstance(graph);
-                Range range = SpreadsheetUtils.decodeCellAbsolute(location);
-                
-                List<Variable> cells = SpreadsheetGraphUtils.possibleConfigurationCellVariables(graph, sheet, range);
-                if (cells.isEmpty()) {
-                    if (value == null) {
-                        return null;
-                    } else {
-                        cells = SpreadsheetGraphUtils.getOrCreateConfigurationCellVariables(graph, sheet, range);
-                    }
-                }
-                if (cells.size() != 1)
-                    throw new DatabaseException("Can edit only one cell at a time!");
-                
-                return cells.iterator().next().getPropertyValue(graph, SHEET.cellEditor);
+                   Range range = SpreadsheetUtils.decodePossibleCellAbsolute(location);
+                   if(range == null) return null; //No editor found
+                   
+                   List<Variable> cells = SpreadsheetGraphUtils.possibleConfigurationCellVariables(graph, sheet, range);
+                   if (cells.isEmpty()) {
+                       if (value == null) {
+                           return null;
+                       } else {
+                           cells = SpreadsheetGraphUtils.getOrCreateConfigurationCellVariables(graph, sheet, range);
+                       }
+                   }
+                   if (cells.size() != 1)
+                       throw new DatabaseException("Can edit only one cell at a time!");
+                       
+                   return cells.iterator().next().getPropertyValue(graph, SHEET.cellEditor);
             }
 
                @Override
index b9920415ff31c3b7ef2357633275e60dc439f967..2c84b6ad1d16abc8662e052c67f4bd9f2c394ed6 100644 (file)
@@ -145,14 +145,19 @@ class TextTableCellEditor extends DefaultCellEditor implements SpreadsheetCellEd
                                expression = "";
                } else {
                        expression = "=" + expression;
-               }        
+               }
+               //Don't update if the expression hasn't changed
         if (expression.equals(str))
                return;
         
         if (str.startsWith("=")) {
                        editor.edit(null, SpreadsheetUtils.cellName(row, column), ClientModel.CONTENT_EXPRESSION, str, Bindings.STRING, null);
+               //Update cell expression
+                       clientModel.setProperty(cellName, ClientModel.CONTENT_EXPRESSION, str);
                } else {
                        editor.edit(null, SpreadsheetUtils.cellName(row, column), Variant.ofInstance(str), null);
+                       //Update cell expression
+                       clientModel.setProperty(cellName, ClientModel.CONTENT_EXPRESSION, null); //If not an expression, then the expression property is null
                }
         
     }