From: Miro Richard Eklund Date: Wed, 18 Jul 2018 11:12:05 +0000 (+0300) Subject: Spreadsheet Fixes X-Git-Tag: v1.43.0~136^2~438 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=dfa52ccefe2e4c36965ad3ccf5e19b778cae0d99;p=simantics%2Fplatform.git Spreadsheet Fixes -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 --- diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/CellValueVisitor.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/CellValueVisitor.java index 652659ce0..8150b4dba 100644 --- a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/CellValueVisitor.java +++ b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/CellValueVisitor.java @@ -247,7 +247,12 @@ public class CellValueVisitor implements AstValueVisitor { 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 { 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(); diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/function/All.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/function/All.java index 1439a941d..39e5778f9 100644 --- a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/function/All.java +++ b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/function/All.java @@ -620,20 +620,21 @@ public class All { private CellEditor getPossibleCellEditor(WriteGraph graph, String location, Variant value) throws DatabaseException { SpreadsheetResource SHEET = SpreadsheetResource.getInstance(graph); - Range range = SpreadsheetUtils.decodeCellAbsolute(location); - - List 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 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 diff --git a/bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/TextTableCellEditor.java b/bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/TextTableCellEditor.java index b9920415f..2c84b6ad1 100644 --- a/bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/TextTableCellEditor.java +++ b/bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/TextTableCellEditor.java @@ -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 } }