Adopt spreadsheet changes made in Balas development 33/3633/1
authorAntti Villberg <antti.villberg@semantum.fi>
Thu, 28 Nov 2019 10:55:52 +0000 (12:55 +0200)
committerAntti Villberg <antti.villberg@semantum.fi>
Thu, 28 Nov 2019 10:55:52 +0000 (12:55 +0200)
gitlab #427

Change-Id: Idfcc4da578dcfa03e9e88f88a2e5012f17fc1f1d

168 files changed:
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ProxyVariables.java
bundles/org.simantics.modeling.ontology/graph/ModelingViewpoint.pgraph
bundles/org.simantics.spreadsheet.common/META-INF/MANIFEST.MF
bundles/org.simantics.spreadsheet.common/src/org/simantics/spreadsheet/util/SpreadsheetUtils.java
bundles/org.simantics.spreadsheet.graph/plugin.xml
bundles/org.simantics.spreadsheet.graph/scl/Spreadsheet/All.scl
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/CellFormulaFunction.java [deleted file]
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/CellValueVisitor.java [deleted file]
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/EvaluateAll.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/ExcelArrayFormula.java [deleted file]
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/ExcelFormula.java [deleted file]
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/ExcelImport.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/GraphUI.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/InvalidateAll.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/PrintVisitor.java [deleted file]
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetBook.java [deleted file]
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetCell.java [deleted file]
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetEngine.java [deleted file]
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetGraphUtils.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetLine.java [deleted file]
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetLines.java [deleted file]
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetMapping.java [deleted file]
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetMatrix.java [deleted file]
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetNodeManager.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetRealm.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetReferenceResolver.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetSessionManager.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetTypeNode.java [deleted file]
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetVisitable.java [deleted file]
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetVisitor.java [deleted file]
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/adapter/DoubleArrayCellVariable.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/adapter/DoubleArrayCells.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/adapter/SpreadsheetVariable.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/adapter/StringArrayCells.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/celleditor/GraphCellEditorAdapter.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/AndFormulaFunction.java [deleted file]
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/AverageFormulaFunction.java [deleted file]
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/CountifFormulaFunction.java [deleted file]
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/FormulaError2.java [deleted file]
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/GeomeanFormulaFunction.java [deleted file]
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/HlookupFormulaFunction.java [deleted file]
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/MatchFormulaFunction.java [deleted file]
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/OrFormulaFunction.java [deleted file]
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/VlookupFormulaFunction.java [deleted file]
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/function/All.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/function/SpreadsheetRootVariable.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/request/SpreadsheetExpressionVisitor.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/synchronization/LineCommandBuilder.java [deleted file]
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/synchronization/LineNodeUpdater.java [deleted file]
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/synchronization/LineUpdater.java [deleted file]
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/synchronization/LinesCommandBuilder.java [deleted file]
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/synchronization/NullCommandBuilder.java [deleted file]
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/synchronization/NullUpdater.java [deleted file]
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/synchronization/SheetLineComponent.java [deleted file]
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/synchronization/SpreadsheetSynchronizationEventHandler.java
bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/ClientModelImpl.java
bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/ClientTableModel.java
bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/DeleteHandler.java
bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/ExcelAdapter.java
bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/ExpressionTextListener.java
bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/SelectionListener.java
bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/SpreadsheetModel.java
bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/SpreadsheetTable.java
bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/TextTableCellEditor.java
bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/editor/CommandCellTab.java
bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/editor/ExcelLink.java
bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/editor/SpreadsheetSelectionProcessor.java
bundles/org.simantics.spreadsheet/.classpath
bundles/org.simantics.spreadsheet/META-INF/MANIFEST.MF
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/Adaptable.java
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/CellEditor.java
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/CellModifier.java
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/CellParseException.java [moved from bundles/org.simantics.spreadsheet.common/src/org/simantics/spreadsheet/common/exception/CellParseException.java with 93% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/ClientModel.java
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/CommandCellExecutor.java
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/Disposable.java
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/ExternalRef.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/Matrix.java
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/OperationMode.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/Range.java
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/SheetVariables.java
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/SpreadsheetCellStyle.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetCellStyle.java with 83% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/SpreadsheetMatrix.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/SpreadsheetVisitable.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/SpreadsheetVisitor.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/Spreadsheets.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/Transaction.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/ExternalRefConstant.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/ExternalRefData.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/SheetLineComponent.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/SheetNode.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SheetNode.java with 53% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/SpreadsheetBook.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/SpreadsheetCell.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/SpreadsheetCellContent.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetCellContent.java with 53% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/SpreadsheetCellContentExpression.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetCellContentExpression.java with 61% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/SpreadsheetCellEditable.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetCellEditable.java with 62% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/SpreadsheetElement.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetElement.java with 78% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/SpreadsheetEngine.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/SpreadsheetFormula.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetFormula.java with 62% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/SpreadsheetLine.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/SpreadsheetLines.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/SpreadsheetMapping.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/SpreadsheetSCLConstant.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetSCLConstant.java with 84% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/SpreadsheetStyle.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetStyle.java with 81% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/SpreadsheetTypeNode.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/AndFormulaFunction.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/AverageFormulaFunction.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/CellFormulaFunction.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/CellValueVisitor.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/CountifFormulaFunction.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/FormulaError2.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/GeomeanFormulaFunction.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/HlookupFormulaFunction.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/IfErrorFormulaFunction.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/IfErrorFormulaFunction.java with 63% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/IfFormulaFunction.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/IfFormulaFunction.java with 50% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/IsErrorFormulaFunction.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/IsErrorFormulaFunction.java with 50% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/LinestFormulaFunction.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/LinestFormulaFunction.java with 82% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/MatchFormulaFunction.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/OrFormulaFunction.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/PiFormulaFunction.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/PiFormulaFunction.java with 53% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/PrintVisitor.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/RoundFormulaFunction.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/RoundFormulaFunction.java with 62% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/RoundupFormulaFunction.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/RoundupFormulaFunction.java with 62% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/SpreadsheetEvaluationEnvironment.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/SpreadsheetEvaluationEnvironment.java with 93% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/SqrtFormulaFunction.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/SqrtFormulaFunction.java with 54% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/SumFormulaFunction.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/SumFormulaFunction.java with 52% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/SumifFormulaFunction.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/SumifFormulaFunction.java with 65% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/TodayFormulaFunction.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/TodayFormulaFunction.java with 66% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/VlookupFormulaFunction.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/parser/ParseException.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/parser/ParseException.java with 99% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/parser/SheetFormulaParser.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/parser/SheetFormulaParser.java with 99% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/parser/SheetFormulaParser.jj [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/parser/SheetFormulaParser.jj with 100% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/parser/SheetFormulaParserConstants.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/parser/SheetFormulaParserConstants.java with 97% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/parser/SheetFormulaParserTokenManager.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/parser/SheetFormulaParserTokenManager.java with 99% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/parser/SheetParserUtils.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/parser/SheetParserUtils.java with 96% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/parser/SimpleCharStream.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/parser/SimpleCharStream.java with 99% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/parser/Token.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/parser/Token.java with 98% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/parser/TokenMgrError.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/parser/TokenMgrError.java with 98% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/parser/ast/AstApply.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/parser/ast/AstApply.java with 89% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/parser/ast/AstArgList.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/parser/ast/AstArgList.java with 93% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/parser/ast/AstArithmeticExpression.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/parser/ast/AstArithmeticExpression.java with 90% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/parser/ast/AstArray.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/parser/ast/AstArray.java with 93% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/parser/ast/AstArrayFormulaReference.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/parser/ast/AstArrayFormulaReference.java with 94% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/parser/ast/AstBoolean.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/parser/ast/AstBoolean.java with 93% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/parser/ast/AstDouble.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/parser/ast/AstDouble.java with 93% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/parser/ast/AstFactor.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/parser/ast/AstFactor.java with 88% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/parser/ast/AstIdentifier.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/parser/ast/AstIdentifier.java with 93% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/parser/ast/AstInteger.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/parser/ast/AstInteger.java with 93% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/parser/ast/AstList.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/parser/ast/AstList.java with 92% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/parser/ast/AstNothing.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/parser/ast/AstNothing.java with 94% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/parser/ast/AstNull.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/parser/ast/AstNull.java with 92% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/parser/ast/AstRange.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/parser/ast/AstRange.java with 92% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/parser/ast/AstRelation.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/parser/ast/AstRelation.java with 94% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/parser/ast/AstString.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/parser/ast/AstString.java with 93% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/parser/ast/AstTerm.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/parser/ast/AstTerm.java with 88% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/parser/ast/AstValue.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/parser/ast/AstValue.java with 92% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/parser/ast/AstValueVisitor.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/parser/ast/AstValueVisitor.java with 94% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/synchronization/ExcelArrayFormula.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/synchronization/ExcelFormula.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/synchronization/LineCommandBuilder.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/synchronization/LineContentBean.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/function/LineContentBean.java with 66% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/synchronization/LineContentBeanCell.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/function/LineContentBeanCell.java with 78% similarity]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/synchronization/LineNodeUpdater.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/synchronization/LineUpdater.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/synchronization/LinesCommandBuilder.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/synchronization/NullCommandBuilder.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/synchronization/NullUpdater.java [new file with mode: 0644]
bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/synchronization/StyleUpdater.java [moved from bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/synchronization/StyleUpdater.java with 96% similarity]

index ddfe108cb713a409f1da67df7e688748bdb94606..cd38064a89be00e83c4cf085ad8e83eaa2102c4b 100644 (file)
@@ -52,25 +52,9 @@ public class ProxyVariables {
        }
        
     public static Variable proxySessionVariable(ReadGraph graph, Variable variable) throws DatabaseException {
-       
-       try {
-               
-               Variable child = variable.getParent(graph);
-               Variable parent = child.getParent(graph);
 
-               if(parent instanceof ProxyChildVariable) {
-                       Variable var = ((ProxyChildVariable)parent).other();
-                       if(var.getParent(graph) == null) {
-                               return null;
-                       }
-                       return var;
-               } else {
-                       Variable input = parent.getPossiblePropertyValue(graph, "session");
-                       if(input == null) {
-                           System.out.println("null input for: " + parent.getURI(graph));
-                       }
-                       return input;
-               }
+        try {
+            return proxyVariableInput(graph, variable);
         } catch (Throwable t) {
             LOGGER.error("proxySessionVariable failed", t);
             return null;
@@ -109,7 +93,7 @@ public class ProxyVariables {
                } else {
                        Variable parent = variable.getParent(graph);
                        if(parent == null) return null;
-                       else return proxyVariableBase(graph, parent);
+                       else return proxyVariableInput(graph, parent);
                }
        
     }
index b97753e5fc5c920061de1be78cd1f8b7adde20d9..10e9146d0a2db9fac04151aecb84be8494b35f21 100644 (file)
@@ -450,6 +450,13 @@ MOD.Contributions.NewSheetBook : VP.ActionContribution
     VP.ActionContribution.HasNodeType L0.Library
     VP.ActionContribution.HasAction ACTIONS.NewSheetBook
 
+MOD.Contributions.ImportSheetBook : VP.ActionContribution
+    L0.HasLabel "Spreadsheet"
+    VP.ActionContribution.HasImage SILK.star
+    VP.ActionContribution.HasCategory VP.ImportActionCategory
+    VP.ActionContribution.HasNodeType L0.Library
+    VP.ActionContribution.HasAction ACTIONS.ImportSheetBook
+
 MOD.Contributions.ActivateModel : VP.ActionContribution
     L0.HasLabel "Activate"
     VP.ActionContribution.HasImage SILK.bullet_go
@@ -693,6 +700,7 @@ MAC
     VP.BrowseContext.SupportsRenamingOf MBC.Symbol
     VP.BrowseContext.HasActionContribution
         MOD.Contributions.NewSheetBook
+        MOD.Contributions.ImportSheetBook
 
     @VP.renamingTestContribution
         L0.SharedOntology
@@ -732,6 +740,8 @@ ACTIONS.NewSCLQueryType
   @MOD.sclAction "createSCLQueryTypeAction"
 ACTIONS.NewSheetBook
   @MOD.sclAction "createSpreadsheetBookAction"
+ACTIONS.ImportSheetBook
+  @MOD.sclAction "importSpreadsheetBookAction"
 ACTIONS.ActivateModel
   @MOD.sclAction "activateModelAction"
 ACTIONS.ActivateExperiment
index eab319b3a0419348ecdfe24c5c466cccb71f43ed..8d195df0cd1206f9d2a764b41c37899566783365 100644 (file)
@@ -18,7 +18,6 @@ Export-Package: org.simantics.spreadsheet.common,
  org.simantics.spreadsheet.common.cell,
  org.simantics.spreadsheet.common.cell.handler,
  org.simantics.spreadsheet.common.client,
- org.simantics.spreadsheet.common.exception,
  org.simantics.spreadsheet.common.expression.analysis,
  org.simantics.spreadsheet.common.expression.lexer,
  org.simantics.spreadsheet.common.expression.node,
index 4d6715dc5d57fd0635ed27e7cccd7d9f3db58767..a784ccf9efaf340dd4834107a5dfd51e5e0cf5c9 100644 (file)
@@ -46,291 +46,17 @@ import org.simantics.document.server.io.SimpleFont;
 import org.simantics.layer0.Layer0;
 import org.simantics.scl.runtime.function.Function1;
 import org.simantics.scl.runtime.tuple.Tuple;
-import org.simantics.spreadsheet.CellEditor;
-import org.simantics.spreadsheet.CellEditor.Transaction;
 import org.simantics.spreadsheet.ClientModel;
-import org.simantics.spreadsheet.ClientModel.OperationMode;
+import org.simantics.spreadsheet.OperationMode;
 import org.simantics.spreadsheet.Range;
+import org.simantics.spreadsheet.Spreadsheets;
+import org.simantics.spreadsheet.Transaction;
 import org.simantics.spreadsheet.common.TableCell;
 import org.simantics.spreadsheet.common.cell.StringCellParser;
-import org.simantics.spreadsheet.common.exception.CellParseException;
 import org.simantics.spreadsheet.resource.SpreadsheetResource;
 import org.simantics.utils.datastructures.Pair;
 
 public class SpreadsheetUtils {
-    
-    public static final int SPREADSHEET_BTREE_SIZE = 100;
-       
-       public static String offset(String location, int rowOffset, int columnOffset) {
-
-               Range range = decodeCellAbsolute(location);
-               String result = cellName(range.startRow + rowOffset, range.startColumn + columnOffset); 
-               //      System.err.println("offset " + location + "(" + rowOffset + " " + columnOffset + ") = >" + result);
-               return result;
-
-       }
-
-       public static Object extract(Object object, int row, int column) {
-               if(object instanceof List) {
-                       List list = (List)object;
-                       if(list.size() <= row) return null;
-                       Object item = list.get(row);
-                       if(item instanceof Tuple) {
-                               Tuple tuple = (Tuple)item;
-                               if(tuple.length() <= column) return null;
-                               return tuple.get(column);
-                       }
-               }
-               return null;
-       }
-
-       //      1 kirjain, 'A' + column
-       //      2 kirjainta, 'A' + column % 26 , 'A' + int((column-26)/26)
-       //      3 kirjainta 'A' + column % 26 , 'A' + int(column-(26*(26+1)) / 26) % 26
-
-       //    0              26
-       //    26             26 + 26*26
-       //    26 + 26*26     26 + 26*26 + 26*26*26
-
-       public static String columnName(int column, int current, int limit, int chars) {
-
-               if(column < limit) {
-
-                       char[] buf = new char[chars];
-                       column -= current;
-                       for(int i=chars-1;i>=0;i--) {
-                               char rem = (char)(column % 26);
-                               column = (column / 26);
-                               buf[i] = (char)('A' + rem); 
-                       }
-                       return new String(buf);
-
-               } else return columnName(column, limit, 26*(limit+1), chars+1);
-
-       }
-
-       public static String columnName(int column) {
-               return columnName(column, 0, 26, 1);
-       }    
-
-       public static String cellName(int row, int column) {
-
-               String result = columnName(column);
-               result += (row+1);
-               return result;
-
-       }    
-
-       public static Range decodeCellAbsolute(String identifier) {
-               long l = decodeCellCoded(identifier);
-               int row = (int)(l & 0xffffffff) - 1;
-               int column = (int)((l>>32) & 0xffffffff);
-               return new Range(row, row, column, column);
-       }
-
-       public static Range decodePossibleCellAbsolute(String identifier) {
-           try {
-               return decodeCellAbsolute(identifier);
-           } catch (CellParseException e) {
-               return null;
-           }
-       }
-
-       public static long decodeCellCoded(String identifier) {
-
-           //        System.out.println("decodecellabsolute " + identifier);
-
-           int row = 0;
-               int column = 0;
-               
-//             identifier.
-               
-               int position = 0;
-               
-               // We skip $ here
-               if(identifier.charAt(position) == '$') position++;
-               
-               int length = identifier.length();
-               
-               while(position < length) {
-                       char b = identifier.charAt(position);
-                       if(b >= 'A' && b <= 'Z') column = column * 26 + (b-'A' + 1);
-                       else break;
-                       position++;
-               }
-
-               // We skip $ here
-               if(position < length)
-                       if(identifier.charAt(position) == '$')
-                               position++;
-
-               while(position < length) {
-                       char b = identifier.charAt(position);
-                       if(b >= '0' && b <= '9'){
-                               row = row * 10 + b-'0';
-                       }
-                       else if(b=='-' && position < (length-1)){//identify use of full row range here.
-                               position++;
-                               char b2 = identifier.charAt(position);
-                               if(b2=='1'){
-                                       row = 0;
-                                       position++;
-                                       break;
-                               }
-                       }
-                       else {
-                               break;
-                       }
-                       position++;
-               }
-
-               if(position == length) {
-
-                       // We need to be able to express -1 in row => report row + 1 here
-                       column--;
-                       //            System.err.println("ra " + identifier + " => " + row + " " + column);
-                       return row + (((long)column)<<32);
-
-               } else {
-
-                       throw new CellParseException("Cell identifier '" + identifier + "' is not a valid cell reference.");
-
-               }
-
-       }
-
-       public static Range decodeCellRelative(String identifier, int row, int column) {
-
-               int offset = Integer.valueOf(identifier.substring(1).trim());
-               //        System.out.println("offset=" + offset);
-
-               if(identifier.startsWith("L") || identifier.startsWith("l")) {
-                       return new Range(row, row, column-offset, column-offset);
-               } else if(identifier.startsWith("R") || identifier.startsWith("r")) {
-                       return new Range(row, row, column+offset, column+offset);
-               } else if(identifier.startsWith("U") || identifier.startsWith("u")) {
-                       return new Range(row-offset, row-offset, column, column);
-               } else if(identifier.startsWith("D") || identifier.startsWith("d")) {
-                       return new Range(row+offset, row+offset, column, column);
-               } else {
-                       throw new CellParseException("Relative cell syntax must begin with L|R|U|D.");
-               }
-
-       }
-
-       public static Range decodeCell(String identifier, int row, int column) {
-
-               if(identifier.startsWith("_")) {
-                       return decodeCellRelative(identifier.substring(1), row, column);
-               } else {
-                       return decodeCellAbsolute(identifier);
-               }
-
-       }
-
-       public static Range decodeReference(String identifier, int row, int column) {
-               if(!identifier.startsWith("&")) throw new CellParseException("A reference cell was expected.");
-               return decodeRange(identifier.substring(1), row, column);
-       }
-
-       public static List<Range> decodeRanges(String ranges){
-               String[] splitted = ranges.split(",");
-               List<Range> result = new ArrayList<>();
-               for(String split : splitted){
-                       result.add(decodeRange(split));
-               }
-               return result;
-       }
-       
-       public static int startRow(List<Range> ranges){
-               int s = -1;
-               for(Range r : ranges){
-                       if(r.startRow<s || s==-1){
-                               s = r.startRow;
-                       }
-               }
-               return s;
-       }
-       
-       public static int startColumn(List<Range> ranges){
-               int s = -1;
-               for(Range r : ranges){
-                       if(r.startColumn<s || s==-1){
-                               s = r.startColumn;
-                       }
-               }
-               return s;
-       }
-       
-       public static int amountOfRows(Range r){
-               int endRow = -2;
-               int startRow = -2;
-               if(r.isFullRows()){
-                       return Range.MAXROWSPEC;
-               }
-               if(endRow == -2 && startRow == -2){
-                       endRow = r.endRow;
-                       startRow = r.startRow;
-               }
-               if(r.startRow<startRow){
-                       startRow = r.startRow;
-               }
-               if(r.endRow>endRow){
-                       endRow = r.endRow;
-               }
-               return endRow - startRow +1;
-       }
-       
-       public static int amountOfColumns(Range r){
-               int endColumn = -2;
-               int startColumn = -2;
-               if(r.isFullColumns()){
-                       return Range.MAXCOLUMNSPEC;
-               }
-               if(endColumn == -2 && startColumn == -2){
-                       endColumn = r.endColumn; 
-                       startColumn = r.startColumn;
-               }
-               if(r.startColumn<startColumn){
-                       startColumn = r.startColumn;
-               }
-               if(r.endColumn>endColumn){
-                       endColumn = r.endColumn;
-               }
-               return endColumn - startColumn +1;
-       }
-       
-       public static Range decodeRange(String rangeOrCell) {
-               if(rangeOrCell.isEmpty()) return fullRange();
-               return decodeRange(rangeOrCell, 0, 0);
-       }
-       
-       public static Range fullRange() {
-               return new Range(0, -1, 0, -1);
-       }
-
-       public static Range decodeRange(String rangeOrCell, int row, int column) {
-       
-               String[] parts = rangeOrCell.split(":");
-               if(parts.length == 1) {
-
-                       return decodeCell(rangeOrCell, row, column);
-
-               } else if (parts.length == 2) {
-
-                       Range from = decodeCell(parts[0].trim(), row, column);
-                       //            System.out.println("decodefrom=" + from);
-                       Range to = decodeCell(parts[1].trim(), row, column);
-                       //            System.out.println("decodeto=" + to);
-                       return Range.combine(from, to);
-
-               } else {
-
-                       throw new CellParseException("The reference cell syntax was invalid. At most 1 occurrence of ':' is expected.");
-
-               }
-
-       }
 
        public static Pair<String, Collection<PropertyCreationData>> parse(String text, StringCellParser[] parsers) {
 
@@ -410,15 +136,15 @@ public class SpreadsheetUtils {
 
        public static void main(String[] args) {
                for(int i=0;i<16384;i++) {
-                       String name = columnName(i);
-                       Range r = decodeCellAbsolute(name + "1");
+                       String name = Spreadsheets.columnName(i);
+                       Range r = Spreadsheets.decodeCellAbsolute(name + "1");
                        System.err.println(i + " " + name + " " + r);
                }
        }
 
        public static String getLabel(ClientModel model, int row, int column) {
                try {
-                       String location = SpreadsheetUtils.cellName(row, column);
+                       String location = Spreadsheets.cellName(row, column);
                        String label = model.getPropertyAt(location, ClientModel.LABEL);
                        if(label != null) return label;
                        Variant content = SpreadsheetUtils.getSafeClientVariant(model, location, ClientModel.CONTENT);
@@ -435,8 +161,8 @@ public class SpreadsheetUtils {
        }
 
        public static boolean isInBounds(String base, String location, int wBounds, int hBounds) {
-               Range baseRange = decodeCellAbsolute(base);
-               Range locationRange = decodeCellAbsolute(location);
+               Range baseRange = Spreadsheets.decodeCellAbsolute(base);
+               Range locationRange = Spreadsheets.decodeCellAbsolute(location);
                if(locationRange.startColumn < baseRange.startColumn) return false;
                if(locationRange.startRow < baseRange.startRow) return false;
                int wb = wBounds == -1 ? (Integer.MAX_VALUE / 3) : wBounds;
@@ -446,7 +172,7 @@ public class SpreadsheetUtils {
                return true;
        }
 
-       public static void schedule(CellEditor.Transaction<?> transaction, Write write) {
+       public static void schedule(Transaction<?> transaction, Write write) {
 
                if(transaction == null) {
 
@@ -471,7 +197,7 @@ public class SpreadsheetUtils {
                return new TransactionImpl(mode);
        }       
 
-       static class TransactionImpl implements CellEditor.Transaction<Write> {
+       static class TransactionImpl implements Transaction<Write> {
 
                private ArrayList<Write> writes = new ArrayList<>();
                private final OperationMode mode;
@@ -577,7 +303,7 @@ public class SpreadsheetUtils {
 //            graph.claim(result, L0.ConsistsOf, L0.PartOf, newCell);
 //            BTree bt = new BTree(graph, SpreadsheetUtils.SPREADSHEET_BTREE_SIZE, SR.Lines, SR.LineNode, L0.PartOf, true);
         
-        BTree bt = new BTree(graph, SpreadsheetUtils.SPREADSHEET_BTREE_SIZE, sr.Lines, sr.LineNode, L0.PartOf, false);
+        BTree bt = new BTree(graph, Spreadsheets.SPREADSHEET_BTREE_SIZE, sr.Lines, sr.LineNode, L0.PartOf, false);
 //        BTree bt = BTreeUtils.create(graph, sr.Lines, sr.LineNode, L0.PartOf, SpreadsheetUtils.SPREADSHEET_BTREE_SIZE, false);
         Resource lines = bt.rootOfBTree();
         
@@ -807,7 +533,7 @@ public class SpreadsheetUtils {
         if (formatString == null)
             return getLabel(model, row, column); 
         try {
-            String location = SpreadsheetUtils.cellName(row, column);
+            String location = Spreadsheets.cellName(row, column);
             Variant content = SpreadsheetUtils.getSafeClientVariant(model, location, ClientModel.CONTENT);
             if(content != null) {
                 
@@ -830,5 +556,78 @@ public class SpreadsheetUtils {
             return null;
         }
     }
+
+    /*
+     *  Please use Spreadsheets.cellName instead
+     */
+    @Deprecated
+    public static String cellName(int row, int column) {
+        return Spreadsheets.cellName(row, column);
+    }
+
+    /*
+     *  Please use Spreadsheets.columnName instead
+     */
+    @Deprecated
+    public static String columnName(int column) {
+        return Spreadsheets.columnName(column);
+    }
+
+    /*
+     *  Please use Spreadsheets.decodeCellAbsolute instead
+     */
+    @Deprecated
+    public static Range decodeCellAbsolute(String identifier) {
+        return Spreadsheets.decodeCellAbsolute(identifier);
+    }
+    
+    /*
+     *  Please use Spreadsheets.decodePossibleCellAbsolute instead
+     */
+    @Deprecated
+    public static Range decodePossibleCellAbsolute(String identifier) {
+        return Spreadsheets.decodePossibleCellAbsolute(identifier);
+    }
+
+    /*
+     *  Please use Spreadsheets.decodeRange instead
+     */
+    @Deprecated
+    public static Range decodeRange(String rangeOrCell) {
+        return Spreadsheets.decodeRange(rangeOrCell);
+    }
+
+    /*
+     *  Please use Spreadsheets.decodeRanges instead
+     */
+    @Deprecated
+    public static List<Range> decodeRanges(String ranges) {
+        return Spreadsheets.decodeRanges(ranges);
+    }
+    
+    /*
+     *  Please use Spreadsheets.startColumn instead
+     */
+    @Deprecated
+    public static int startColumn(List<Range> ranges) {
+        return Spreadsheets.startColumn(ranges);
+    }
+
+    /*
+     *  Please use Spreadsheets.startRow instead
+     */
+    @Deprecated
+    public static int startRow(List<Range> ranges) {
+        return Spreadsheets.startRow(ranges);
+    }
+    
+    /*
+     *  Please use Spreadsheets.offset instead
+     */
+    @Deprecated
+    public static String offset(String location, int rowOffset, int columnOffset) {
+        return Spreadsheets.offset(location, rowOffset, columnOffset);
+    }
+
     
 }
index 18738892970d05ecb16e5538d46bdf1f73263e03..6088f678d02e649376f456b10a670dca2cd9aeac 100644 (file)
@@ -12,7 +12,7 @@
          <externalClass className="org.simantics.db.layer0.variable.ValueAccessor"/>
          <externalClass className="org.simantics.db.layer0.variable.VariableMap"/>
          <externalClass className="org.simantics.spreadsheet.CellEditor"/>
-         <externalClass className="org.simantics.spreadsheet.graph.function.LineContentBean"/>
+         <externalClass className="org.simantics.spreadsheet.synchronization.LineContentBean"/>
          <class className="org.simantics.spreadsheet.graph.function.All"/>
       </namespace>
    </extension>
index 8898ce10a9a306d58b0ea796e6d96653987fd132..aa58a7f73c2f5654dffac51ce7e81accd1eee6be 100644 (file)
@@ -1,12 +1,45 @@
 include "Simantics/DB"
 include "Simantics/Ontologies"
 include "Simantics/SCL"
+include "Simantics/UI"
 include "Document/All"
 include "File"
 
+
+effect SpreadsheetTransaction 
+    "spreadsheetTransaction" 
+    "org.simantics.spreadsheet.Transaction"
+
+importJava "org.simantics.spreadsheet.graph.ExternalRef" where
+    data ExternalRef
+
 importJava "org.simantics.spreadsheet.common.TableCell" where
     data TableCell
 
+importJava "java.util.function.Consumer" where
+    data Consumer
+
+importJava "org.simantics.spreadsheet.CellEditor" where
+    data CellEditor
+    startTransaction :: CellEditor -> OperationMode -> <Proc> Transaction
+    @JavaName "edit"
+    editProperty_ :: CellEditor -> String -> String -> a -> Binding a -> Maybe Consumer -> <SpreadsheetTransaction> () 
+    @JavaName "edit"
+    editContent :: CellEditor -> String -> Variant -> Maybe Consumer -> <SpreadsheetTransaction> () 
+
+@inline
+editProperty :: Serializable a => CellEditor -> String -> String -> a -> Maybe Consumer -> <SpreadsheetTransaction> ()
+editProperty editor location property value consumer = editProperty_ editor location property value binding consumer
+
+importJava "org.simantics.spreadsheet.OperationMode" where
+    data OperationMode
+    OPERATION :: OperationMode
+    EDIT_MODE :: OperationMode
+
+importJava "org.simantics.spreadsheet.Transaction" where
+    data Transaction
+    commit :: Transaction -> <Proc> ()
+
 importJava "org.simantics.spreadsheet.common.TreeTableCell" where
     data TreeTableCell
 
@@ -41,6 +74,14 @@ importJava "org.simantics.spreadsheet.graph.SpreadsheetGraphUtils" where
     saveInitialCondition :: Variable -> Resource -> String -> <WriteGraph> Resource
     findCell :: Variable -> String -> <ReadGraph> Maybe Variable
     invalidateAll :: Variable -> <ReadGraph> ()
+    extRefVariable :: Variable -> <ReadGraph> Variant
+    extRefActiveVariable :: Variable -> <ReadGraph> Variant
+    cellEditor :: Resource -> <ReadGraph> CellEditor
+    syncExec :: CellEditor -> OperationMode -> (<SpreadsheetTransaction, Proc> a) -> <Proc> a
+    cellColumn :: Variable -> <ReadGraph> Integer
+
+importJava "org.simantics.spreadsheet.Spreadsheets" where
+     cellName :: Integer -> Integer -> String
 
 importJava "org.simantics.spreadsheet.util.SpreadsheetUtils" where
     createSheet :: Resource -> String -> <WriteGraph> Resource
@@ -58,6 +99,11 @@ importJava "org.simantics.spreadsheet.util.SpreadsheetUtils" where
     selectColumn :: Integer -> TableCell -> Boolean
     setSCLLine :: Resource -> Integer -> String -> <WriteGraph> ()
     sheetRun :: Resource -> Variable -> <ReadGraph> Variable
+    @JavaName "sheetRun"
+    bookRun :: Resource -> Variable -> <ReadGraph> Variable
+
+sheetRunDefault :: Resource -> <ReadGraph> Variable
+sheetRunDefault sheet = sheetRun sheet (resourceVariable sheet)
 
 importJava "org.simantics.spreadsheet.graph.SpreadsheetSessionManager" where
     removeSpreadsheetSession :: Variable -> <Proc, WriteGraph> ()
@@ -65,6 +111,11 @@ importJava "org.simantics.spreadsheet.graph.SpreadsheetSessionManager" where
 importJava "org.simantics.spreadsheet.graph.ExcelImport" where
     importBook :: Resource -> File -> <Proc> ()
 
+importSpreadsheetBookAction :: Resource -> <Proc> ()
+importSpreadsheetBookAction res = match fileDialog "foo" [("Excel file", "*.xls"), ("Excel File", "*.xlsx")] with
+  Nothing -> ()
+  Just file -> importBook res file
+
 createSpreadsheetBookAction :: Resource -> <Proc> ()
 createSpreadsheetBookAction res = do
   syncWrite (\() -> createSpreadsheetBookDefault res)
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/CellFormulaFunction.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/CellFormulaFunction.java
deleted file mode 100644 (file)
index 8880085..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-package org.simantics.spreadsheet.graph;
-
-import org.simantics.spreadsheet.graph.parser.ast.AstArgList;
-
-public interface CellFormulaFunction<T> {
-
-       T evaluate(CellValueVisitor visitor, AstArgList args);
-       
-}
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
deleted file mode 100644 (file)
index 8150b4d..0000000
+++ /dev/null
@@ -1,478 +0,0 @@
-package org.simantics.spreadsheet.graph;
-
-import org.simantics.databoard.binding.mutable.Variant;
-import org.simantics.spreadsheet.Range;
-import org.simantics.spreadsheet.graph.formula.FormulaError2;
-import org.simantics.spreadsheet.graph.formula.SpreadsheetEvaluationEnvironment;
-import org.simantics.spreadsheet.graph.parser.ast.AstApply;
-import org.simantics.spreadsheet.graph.parser.ast.AstArgList;
-import org.simantics.spreadsheet.graph.parser.ast.AstArithmeticExpression;
-import org.simantics.spreadsheet.graph.parser.ast.AstArray;
-import org.simantics.spreadsheet.graph.parser.ast.AstArrayFormulaReference;
-import org.simantics.spreadsheet.graph.parser.ast.AstBoolean;
-import org.simantics.spreadsheet.graph.parser.ast.AstDouble;
-import org.simantics.spreadsheet.graph.parser.ast.AstFactor;
-import org.simantics.spreadsheet.graph.parser.ast.AstIdentifier;
-import org.simantics.spreadsheet.graph.parser.ast.AstInteger;
-import org.simantics.spreadsheet.graph.parser.ast.AstNothing;
-import org.simantics.spreadsheet.graph.parser.ast.AstNull;
-import org.simantics.spreadsheet.graph.parser.ast.AstRange;
-import org.simantics.spreadsheet.graph.parser.ast.AstRelation;
-import org.simantics.spreadsheet.graph.parser.ast.AstString;
-import org.simantics.spreadsheet.graph.parser.ast.AstTerm;
-import org.simantics.spreadsheet.graph.parser.ast.AstValue;
-import org.simantics.spreadsheet.graph.parser.ast.AstValueVisitor;
-import org.simantics.spreadsheet.util.SpreadsheetUtils;
-
-import it.unimi.dsi.fastutil.longs.AbstractLongList;
-import it.unimi.dsi.fastutil.longs.LongArrayList;
-
-public class CellValueVisitor implements AstValueVisitor<Object> {
-
-       final public SpreadsheetBook book;
-       final private SpreadsheetEvaluationEnvironment env;
-       final private SpreadsheetCell thisCell;
-       final private LongArrayList references = new LongArrayList();
-       
-       public CellValueVisitor(SpreadsheetEvaluationEnvironment env, SpreadsheetCell thisCell) {
-               this.book = env.getBook();
-               this.env = env;
-               this.thisCell = thisCell;
-       }
-       
-       public void addReference(long ref) {
-               references.add(ref);
-       }
-       
-       public AbstractLongList getReferences() {
-               return references;
-       }
-       
-       @Override
-       public Object visit(AstBoolean astBoolean) {
-               return astBoolean.value;
-       }
-
-       @Override
-       public Object visit(AstDouble astFloat) {
-               return astFloat.value;
-       }
-
-       @Override
-       public Object visit(AstInteger astInteger) {
-               return astInteger.value;
-       }
-
-       @Override
-       public Object visit(AstNull astNull) {
-               throw new IllegalStateException();
-       }
-
-       @Override
-       public Object visit(AstString astString) {
-               return astString.value;
-       }
-
-       @Override
-       public Object visit(AstRange astRange) {
-               
-               if(astRange.isRef()){
-                       return FormulaError2.REF.getString();
-               }
-               
-               if(astRange.isCell()) {
-                       String ref = astRange.first;
-                       Range r = SpreadsheetUtils.decodeCell(ref, 0, 0);
-                       String sheetName = astRange.sheetName != null ? astRange.sheetName : thisCell.getEngine().getName();
-                       SpreadsheetCell cell = thisCell.getBook().get(sheetName, r.startRow, r.startColumn);
-                       if(cell == null) {
-                           SpreadsheetEngine eng = thisCell.getBook().getEngine(sheetName);
-                           SpreadsheetLine line = eng.getLine(r.startRow);
-                           
-                           if (line == null) {
-                               line = new SpreadsheetLine(eng.lines, r.startRow);
-                               eng.lines.lines.put(-r.startRow, line);
-                           }
-                           cell = SpreadsheetCell.empty(line, r.startColumn);
-                       }
-                       return cell.evaluate(env, this);
-                       
-               } else {
-                       
-                       Object cached = thisCell.getEngine().getCachedRange(astRange);
-                       if(cached != null) {
-                               
-                               Range r_ = SpreadsheetUtils.decodeRange(astRange.first + ":" + astRange.second);
-                               String sheetName = astRange.sheetName != null ? astRange.sheetName : thisCell.getEngine().getName();
-                               SpreadsheetEngine eng = thisCell.getBook().getEngine(sheetName);
-                               Range r = eng.actualRange(r_);
-                               for(int row=0; row < r.height();row++) {
-                                       SpreadsheetLine line = eng.getLine(r.startRow + row);
-                                       if(line != null) {
-                                               for(int column=0; column < r.width();column++) {
-                                                       int col = r.startColumn + column;
-                                                       if(line.cells.size() > col) {
-                                                               SpreadsheetCell cell = line.cells.get(r.startColumn + column);
-                                                               //Add references, but do not evaluate if there exists a cached range.
-                                                               addReference(cell.makeReferenceKey());
-                                                       }
-                                               }
-                                       }
-                               }       
-                               return cached;
-                       }
-                       
-                       Range r_ = SpreadsheetUtils.decodeRange(astRange.first + ":" + astRange.second);
-                       String sheetName = astRange.sheetName != null ? astRange.sheetName : thisCell.getEngine().getName();
-                       SpreadsheetEngine eng = thisCell.getBook().getEngine(sheetName);
-                       // Full ranges are resolved here
-                       Range r = eng.actualRange(r_);
-                       SpreadsheetMatrix result = new SpreadsheetMatrix(r.width(), r.height());
-                       for(int row=0; row < r.height();row++) {
-                               SpreadsheetLine line = eng.getLine(r.startRow + row);
-                               if(line != null) {
-                                       for(int column=0; column < r.width();column++) {
-                                               int col = r.startColumn + column;
-                                               if(line.cells.size() > col) {
-                                                       SpreadsheetCell cell = line.cells.get(r.startColumn + column);
-                                                       result.values[r.width()*row + column] = cell.evaluate(env, this);
-                                               }
-                                       }
-                               }
-                       }
-                       thisCell.getEngine().cacheRange(astRange, result);
-                       return result;
-               }
-       }
-
-       @Override
-       public Object visit(AstArgList astArgList) {
-               throw new IllegalStateException();
-       }
-
-       @Override
-       public Object visit(AstApply astApply) {
-               CellFormulaFunction<?> fn = env.getFunction(astApply.value);
-               if(fn != null) {
-                       return fn.evaluate(this, astApply.args);
-               } else {
-                       return FormulaError2.NAME.getString();
-               }
-       }
-
-       @Override
-       public Object visit(AstRelation astRelation) {
-
-               Object leftResult = astRelation.left.accept(this);
-               Object rightResult = astRelation.right.accept(this);
-               
-               FormulaError2 err = FormulaError2.forObject(leftResult);
-               if(err!=null) return err.getString();
-               FormulaError2 err2 = FormulaError2.forObject(rightResult);
-               if(err2!=null) return err2.getString();
-               
-               if(leftResult instanceof Variant){
-                       Object leftTemp = ((Variant)leftResult).getValue();
-                       Double leftVal = SpreadsheetGraphUtils.asDoubleWhereEmptyStringIsZero(leftTemp);
-                       if(leftVal==null) leftResult = leftTemp.toString();
-                       else leftResult = leftVal;
-               }
-               if(rightResult instanceof Variant){
-                       Object rightTemp = ((Variant)rightResult).getValue();
-                       Double rightVal = SpreadsheetGraphUtils.asDoubleWhereEmptyStringIsZero(rightTemp);
-                       if(rightVal==null) rightResult = rightTemp.toString();
-                       else rightResult = rightVal;
-               }
-               if ((leftResult instanceof String) && (rightResult instanceof String)) {
-                       String leftString = (leftResult.toString()).toLowerCase();
-                       String rightString = (rightResult.toString()).toLowerCase();
-                       if("<".equals(astRelation.op.trim())) return leftString.compareTo(rightString) < 0;
-                       else if(">".equals(astRelation.op.trim())) return leftString.compareTo(rightString) > 0;
-                       else if("=".equals(astRelation.op.trim())) return leftString.compareTo(rightString) == 0;
-                       else if("<>".equals(astRelation.op.trim())) return leftString.compareTo(rightString) != 0 ;
-                       else if("<=".equals(astRelation.op.trim())) return leftString.compareTo(rightString) <= 0 ;
-                       else if(">=".equals(astRelation.op.trim())) return leftString.compareTo(rightString) >= 0 ;
-                       else throw new IllegalStateException();
-               } else {
-                       Number leftNumber = SpreadsheetGraphUtils.asDoubleWhereEmptyStringIsZero(leftResult);
-                       Number rightNumber = SpreadsheetGraphUtils.asDoubleWhereEmptyStringIsZero(rightResult);
-                       if(leftNumber==null || rightNumber==null) return false;
-                       if("<".equals(astRelation.op.trim())) return leftNumber.doubleValue() < rightNumber.doubleValue();
-                       else if(">".equals(astRelation.op.trim())) return leftNumber.doubleValue() > rightNumber.doubleValue();
-                       else if("=".equals(astRelation.op.trim())) return leftNumber.doubleValue() == rightNumber.doubleValue();
-                       else if("<>".equals(astRelation.op.trim())) return leftNumber.doubleValue() != rightNumber.doubleValue();
-                       else if("<=".equals(astRelation.op.trim())) return leftNumber.doubleValue() <= rightNumber.doubleValue();
-                       else if(">=".equals(astRelation.op.trim())) return leftNumber.doubleValue() >= rightNumber.doubleValue();
-                       else throw new IllegalStateException();
-               }
-       }
-       
-       Object leftValueWithPrefix(Object result, AstValue value, String prefix, boolean forceNumber) {
-               if(result == null) {
-                       Object obj = value.accept(this);
-                       FormulaError2 err = FormulaError2.forObject(obj);
-                       if(err!=null) return err.getString();
-                       
-                       if("-".equals(prefix)) {
-                               result = SpreadsheetGraphUtils.asNumber(obj);
-                               return -((Number)result).doubleValue();
-                       } else {
-                               if(forceNumber) return SpreadsheetGraphUtils.asNumber(obj);
-                               else return obj;
-                       }
-               }
-               try{
-                       return (Number)Double.parseDouble(result.toString());
-               } catch (NumberFormatException e){
-                       return result;
-               }
-       }
-
-       @Override
-       public Object visit(AstArithmeticExpression exp) {
-               Object result = null;
-               Object other = null;
-               AstValue value = null;
-               Object acceptedValue = null;
-               
-               for(int i=0;i<exp.rightCount();i++) {
-                       String op = exp.rightOp(i);
-                       value = exp.rightValue(i);
-                       acceptedValue = value.accept(this);
-                       if("+".equals(op)) {
-                               result = leftValueWithPrefix(result, exp.left, exp.prefix, false);
-                               
-                               if(!(result instanceof Number)) {
-                                       FormulaError2 err = FormulaError2.forObject(result);
-                                       if(err!=null) return err.getString();
-                                       
-                                       if(result instanceof String && !((String) result).isEmpty()){
-                                               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();
-                                               if(val instanceof String && (val.toString().isEmpty())){
-                                                       result = 0.0;
-                                               } else {
-                                                       Number resNum = SpreadsheetGraphUtils.asDoubleWhereEmptyStringIsZero(val);
-                                                       if(resNum==null) return FormulaError2.VALUE.getString();
-                                                       else result = resNum;
-                                               }
-                                       } else {
-                                               result = 0.0;
-                                       }
-                               }
-                               
-                               FormulaError2 err2 = FormulaError2.forObject(acceptedValue);
-                               if(err2!=null) return err2.getString();
-                               
-                               other = SpreadsheetGraphUtils.asDoubleWhereEmptyStringIsZero(acceptedValue);
-                               if(other==null)
-                                       return FormulaError2.handleErrorCall(acceptedValue);
-                               
-                               result = ((Number)result).doubleValue() + ((Number)other).doubleValue();
-                               
-                       } else if("-".equals(op)) {
-                               result = leftValueWithPrefix(result, exp.left, exp.prefix, false);
-                               
-                               if(!(result instanceof Number)) {
-                                       FormulaError2 err = FormulaError2.forObject(result);
-                                       if(err!=null) return err.getString();
-                                       
-                                       if(result instanceof String && !((String) result).isEmpty()){
-                                               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();
-                                               if(val instanceof String && (val.toString().isEmpty())){
-                                                       result = 0.0;
-                                               } else {
-                                                       Number resNum = SpreadsheetGraphUtils.asDoubleWhereEmptyStringIsZero(val);
-                                                       if(resNum==null)
-                                                               return FormulaError2.VALUE.getString();
-                                                       else result = resNum;
-                                               }
-                                       } else {
-                                               result = 0.0;
-                                       }
-                               }
-                               FormulaError2 err2 = FormulaError2.forObject(acceptedValue);
-                               if(err2!=null) return err2.getString();
-                               
-                               other = SpreadsheetGraphUtils.asDoubleWhereEmptyStringIsZero(acceptedValue);
-                               if(other==null)
-                                       return FormulaError2.handleErrorCall(acceptedValue);
-                               
-                               result = ((Number)result).doubleValue() - ((Number)other).doubleValue();
-                               
-                       } else if("&".equals(op)) {
-                               result = leftValueWithPrefix(result, exp.left, exp.prefix, false);
-                               FormulaError2 err = FormulaError2.forObject(result);
-                               if(err!=null) return err.getString();
-                               FormulaError2 err2 = FormulaError2.forObject(acceptedValue);
-                               if(err2!=null) return err2.getString();
-                               
-                               result = SpreadsheetGraphUtils.asString(result);
-                               other = SpreadsheetGraphUtils.asString(acceptedValue);
-
-                               result += (String)other;
-                       }
-               }
-               return leftValueWithPrefix(result, exp.left, exp.prefix, false);
-               
-       }
-
-       @Override
-       public Object visit(AstTerm exp) {
-               Number result = null;
-               for(int i=0;i<exp.rightCount();i++) {
-                       String op = exp.rightOp(i);
-                       AstValue value = exp.rightValue(i);
-                       Object leftValue = exp.left.accept(this);
-                       Object rightValue = value.accept(this);
-                       if("*".equals(op)) {
-                               if(result == null) {
-                                       result = SpreadsheetGraphUtils.asDoubleWhereEmptyStringIsZero(leftValue);
-                                       if(result == null)
-                                               return FormulaError2.handleErrorCall(leftValue);
-                               }
-                               Number other = SpreadsheetGraphUtils.asDoubleWhereEmptyStringIsZero(rightValue);
-                               if(other==null) return FormulaError2.handleErrorCall(rightValue);
-                               
-                               result = new Double(result.doubleValue() * other.doubleValue());
-                               
-                       } else if("/".equals(op)) {
-                               if(result == null) {
-                                       result = SpreadsheetGraphUtils.asDoubleWhereEmptyStringIsZero(leftValue);
-                                       if(result == null)
-                                               return FormulaError2.handleErrorCall(leftValue);
-                               }
-                               Number other = SpreadsheetGraphUtils.asDoubleWhereEmptyStringIsZero(rightValue);
-                               if(other==null) return FormulaError2.handleErrorCall(rightValue);
-                               if(other.doubleValue()==0.0) return FormulaError2.DIV0.getString();
-                               
-                               result = new Double(result.doubleValue() / other.doubleValue());        
-                       }
-               }
-               if(result == null) result = SpreadsheetGraphUtils.asNumber(exp.left.accept(this));
-               return result;
-       }
-
-       @Override
-       public Object visit(AstFactor exp) {
-               Object result = null;
-               for(int i=0;i<exp.rightCount();i++) {
-                       String op = exp.rightOp(i);
-                       AstValue value = exp.rightValue(i);
-                       if("^".equals(op)) {
-                               if(result == null) {
-                                       Object leftValue = exp.left.accept(this);
-
-                                       FormulaError2 err = FormulaError2.forObject(leftValue);
-                                       if(err!=null) return err.getString();
-                                       
-                                       if(leftValue instanceof Variant){
-                                               Object leftTemp = ((Variant)leftValue).getValue();
-                                               Double leftV = SpreadsheetGraphUtils.asDoubleWhereEmptyStringIsZero(leftTemp);
-                                               if(leftV==null) leftValue = leftTemp.toString();
-                                               else leftValue = leftV;
-                                       }
-                                       
-                                       if(leftValue instanceof String){
-                                               if((leftValue.toString()).isEmpty())
-                                                       result = 0;
-                                                else 
-                                                       return FormulaError2.VALUE.getString();
-                                       }
-                                       else if(leftValue instanceof SpreadsheetMatrix) 
-                                               result = leftValue;
-                                       else 
-                                               result = SpreadsheetGraphUtils.asNumber(leftValue);
-                               }
-                               Object otherValue = value.accept(this);
-                               
-                               FormulaError2 err2 = FormulaError2.forObject(otherValue);
-                               if(err2!=null) return err2.getString();
-                               
-                               if(otherValue instanceof Variant){
-                                       Object otherTemp = ((Variant)otherValue).getValue();
-                                       Double otherV = SpreadsheetGraphUtils.asDoubleWhereEmptyStringIsZero(otherTemp);
-                                       if(otherV==null) otherValue = otherTemp.toString();
-                                       else otherValue = otherV;
-                               }
-                               
-                               if(otherValue instanceof String){
-                                       if((otherValue.toString()).isEmpty())
-                                               otherValue = 0;
-                                       else 
-                                               return FormulaError2.VALUE.getString();
-                               }
-                               
-                               if(result instanceof SpreadsheetMatrix) {
-                                       result = ((SpreadsheetMatrix)result).pow(otherValue);
-                               } else {
-                                       if(otherValue instanceof SpreadsheetMatrix) {
-                                               throw new IllegalStateException();
-                                       } else {
-                                               Double base = ((Number)result).doubleValue();
-                                               Double exponent = SpreadsheetGraphUtils.asNumber(otherValue);
-                                               if(exponent==0 && base==0)
-                                                       return FormulaError2.NUM.getString();
-                                               if(exponent<0 && base==0)
-                                                       return FormulaError2.DIV0.getString();
-                                               result = Math.pow(base, exponent);
-                                               if(result instanceof Double && Double.isInfinite((Double)result)){
-                                                       return FormulaError2.NUM.getString();
-                                               }
-                                       }
-                               }
-                       }
-               }
-               if(result == null) result = SpreadsheetGraphUtils.asNumber(exp.left.accept(this));
-               return result;
-       }
-
-       @Override
-       public Object visit(AstIdentifier id) {
-               return FormulaError2.NAME.getString();
-               //throw new IllegalStateException();
-       }
-       
-       @Override
-       public Object visit(AstArray array) {
-               SpreadsheetMatrix m = new SpreadsheetMatrix(array.values.size(), 1);
-               for(int i=0;i<array.values.size();i++) {
-                       m.values[i] = array.values.get(i).accept(this);
-               }
-               return m; 
-       }
-       
-       @Override
-       public Object visit(AstNothing array) {
-               return AstNothing.NOTHING;
-       }
-       
-       @Override
-       public Object visit(AstArrayFormulaReference ref) {
-               
-               Range thisRange = SpreadsheetUtils.decodeRange(thisCell.getName());
-               Range arrayRange = SpreadsheetUtils.decodeRange(ref.range);
-               int x = thisRange.startColumn - arrayRange.startColumn;
-               int y = thisRange.startRow - arrayRange.startRow;
-               
-               SpreadsheetMatrix m = (SpreadsheetMatrix)ref.value.accept(this);
-               return m.get(y, x);
-               
-       }
-
-}
index fa629bbc4ecb0aaa938a2c64aa94fc7940858f6a..1d55203ff2da5ac1c0222c2b1bf7a1c4b4681f3b 100644 (file)
@@ -1,6 +1,12 @@
 package org.simantics.spreadsheet.graph;
 
-import org.simantics.spreadsheet.graph.formula.SpreadsheetEvaluationEnvironment;
+import org.simantics.spreadsheet.SpreadsheetVisitor;
+import org.simantics.spreadsheet.solver.SpreadsheetBook;
+import org.simantics.spreadsheet.solver.SpreadsheetCell;
+import org.simantics.spreadsheet.solver.SpreadsheetEngine;
+import org.simantics.spreadsheet.solver.SpreadsheetLine;
+import org.simantics.spreadsheet.solver.SpreadsheetLines;
+import org.simantics.spreadsheet.solver.formula.SpreadsheetEvaluationEnvironment;
 
 public class EvaluateAll implements SpreadsheetVisitor {
        
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/ExcelArrayFormula.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/ExcelArrayFormula.java
deleted file mode 100644 (file)
index da9dd5f..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-package org.simantics.spreadsheet.graph;
-
-import org.simantics.databoard.Bindings;
-import org.simantics.databoard.binding.Binding;
-
-public class ExcelArrayFormula {
-       
-       public static final Binding BINDING = Bindings.getBindingUnchecked(ExcelArrayFormula.class);
-
-       public String range;
-       public String expression;
-       
-       public ExcelArrayFormula(String range, String expression) {
-               this.range = range;
-               this.expression = expression;
-       }
-       
-}
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/ExcelFormula.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/ExcelFormula.java
deleted file mode 100644 (file)
index bad4fd0..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-package org.simantics.spreadsheet.graph;
-
-import org.simantics.databoard.Bindings;
-import org.simantics.databoard.binding.Binding;
-
-public class ExcelFormula {
-       
-       public static final Binding BINDING = Bindings.getBindingUnchecked(ExcelFormula.class);
-
-       public String expression;
-       
-       public ExcelFormula(String expression) {
-               this.expression = expression;
-       }
-       
-}
index 8b2d9af4f520530f2686ee34dadf6b2415ce4233..24a0a85d0ce15c204e14da3eb7b9ddef85daba48 100644 (file)
@@ -39,12 +39,17 @@ import org.simantics.db.layer0.util.Layer0Utils;
 import org.simantics.db.service.XSupport;
 import org.simantics.layer0.Layer0;
 import org.simantics.operation.Layer0X;
-import org.simantics.spreadsheet.graph.SpreadsheetStyle.SpreadsheetStyleBuilder;
-import org.simantics.spreadsheet.graph.formula.SpreadsheetEvaluationEnvironment;
-import org.simantics.spreadsheet.graph.parser.SheetFormulaParser;
-import org.simantics.spreadsheet.graph.parser.ast.AstValue;
+import org.simantics.spreadsheet.Spreadsheets;
 import org.simantics.spreadsheet.resource.SpreadsheetResource;
-import org.simantics.spreadsheet.util.SpreadsheetUtils;
+import org.simantics.spreadsheet.solver.SpreadsheetBook;
+import org.simantics.spreadsheet.solver.SpreadsheetStyle;
+import org.simantics.spreadsheet.solver.SpreadsheetStyle.SpreadsheetStyleBuilder;
+import org.simantics.spreadsheet.solver.formula.CellValueVisitor;
+import org.simantics.spreadsheet.solver.formula.SpreadsheetEvaluationEnvironment;
+import org.simantics.spreadsheet.solver.formula.parser.SheetFormulaParser;
+import org.simantics.spreadsheet.solver.formula.parser.ast.AstValue;
+import org.simantics.spreadsheet.synchronization.ExcelArrayFormula;
+import org.simantics.spreadsheet.synchronization.ExcelFormula;
 import org.simantics.utils.DataContainer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -124,7 +129,7 @@ public class ExcelImport {
                                 graph.claim(sheet, L0.ConsistsOf, L0.PartOf, newCell);
                             }
 
-                            BTree bt = new BTree(graph, SpreadsheetUtils.SPREADSHEET_BTREE_SIZE, SR.Lines, SR.LineNode, L0.PartOf, true);
+                            BTree bt = new BTree(graph, Spreadsheets.SPREADSHEET_BTREE_SIZE, SR.Lines, SR.LineNode, L0.PartOf, true);
                             result.add(bt);
                             Resource lines = bt.rootOfBTree();
 
@@ -172,7 +177,7 @@ public class ExcelImport {
                                     Cell val = row.getCell(i, Row.RETURN_BLANK_AS_NULL);
                                     if(val != null) {
                                        
-                                        String cellName = SpreadsheetUtils.cellName(rowN, i);
+                                        String cellName = Spreadsheets.cellName(rowN, i);
                                         
                                         int ccIndx = val.getColumnIndex();
                                         if(columnWidths.size()<=ccIndx){
@@ -590,7 +595,7 @@ public class ExcelImport {
             SheetFormulaParser p = new SheetFormulaParser(new StringReader("(-(0.2/2)+SQRT((0.2/2)^2-4*((0.2/2)^2-(3*0.17625)/(PI()*4.7))))"));
             AstValue v = p.relation();
             System.err.println("v="+v);
-            SpreadsheetBook book = new SpreadsheetBook();
+            SpreadsheetBook book = new SpreadsheetBook("http:/");
             Object o = v.accept(new CellValueVisitor(SpreadsheetEvaluationEnvironment.getInstance(book), null));
             System.err.println("o="+o);
         }
index 03df2dd0a8eb8f99af62ee7d6cfb31b012dfd660..5717aa80744c4c90589799367ae4aa8d196ce675 100644 (file)
@@ -59,10 +59,13 @@ import org.simantics.simulator.toolkit.StandardRealm;
 import org.simantics.spreadsheet.Adaptable;
 import org.simantics.spreadsheet.CellEditor;
 import org.simantics.spreadsheet.ClientModel;
-import org.simantics.spreadsheet.ClientModel.OperationMode;
+import org.simantics.spreadsheet.OperationMode;
 import org.simantics.spreadsheet.SheetCommands;
+import org.simantics.spreadsheet.Transaction;
 import org.simantics.spreadsheet.event.model.RemoveCellHandler;
 import org.simantics.spreadsheet.resource.SpreadsheetResource;
+import org.simantics.spreadsheet.solver.SheetNode;
+import org.simantics.spreadsheet.solver.SpreadsheetBook;
 import org.simantics.ui.selection.WorkbenchSelectionUtils;
 import org.simantics.utils.datastructures.Pair;
 import org.simantics.utils.strings.AlphanumComparator;
index 97290dacbf38b5491df247757179d0ae814749d0..9a7a23703e094507f7ce4d04bf8f69ec15f278f2 100644 (file)
@@ -1,5 +1,12 @@
 package org.simantics.spreadsheet.graph;
 
+import org.simantics.spreadsheet.SpreadsheetVisitor;
+import org.simantics.spreadsheet.solver.SpreadsheetBook;
+import org.simantics.spreadsheet.solver.SpreadsheetCell;
+import org.simantics.spreadsheet.solver.SpreadsheetEngine;
+import org.simantics.spreadsheet.solver.SpreadsheetLine;
+import org.simantics.spreadsheet.solver.SpreadsheetLines;
+
 public class InvalidateAll implements SpreadsheetVisitor {
        
        public InvalidateAll() {
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/PrintVisitor.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/PrintVisitor.java
deleted file mode 100644 (file)
index 1e36a69..0000000
+++ /dev/null
@@ -1,173 +0,0 @@
-package org.simantics.spreadsheet.graph;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import org.simantics.spreadsheet.Range;
-import org.simantics.spreadsheet.graph.parser.ast.AstApply;
-import org.simantics.spreadsheet.graph.parser.ast.AstArgList;
-import org.simantics.spreadsheet.graph.parser.ast.AstArithmeticExpression;
-import org.simantics.spreadsheet.graph.parser.ast.AstArray;
-import org.simantics.spreadsheet.graph.parser.ast.AstArrayFormulaReference;
-import org.simantics.spreadsheet.graph.parser.ast.AstBoolean;
-import org.simantics.spreadsheet.graph.parser.ast.AstDouble;
-import org.simantics.spreadsheet.graph.parser.ast.AstFactor;
-import org.simantics.spreadsheet.graph.parser.ast.AstIdentifier;
-import org.simantics.spreadsheet.graph.parser.ast.AstInteger;
-import org.simantics.spreadsheet.graph.parser.ast.AstNothing;
-import org.simantics.spreadsheet.graph.parser.ast.AstNull;
-import org.simantics.spreadsheet.graph.parser.ast.AstRange;
-import org.simantics.spreadsheet.graph.parser.ast.AstRelation;
-import org.simantics.spreadsheet.graph.parser.ast.AstString;
-import org.simantics.spreadsheet.graph.parser.ast.AstTerm;
-import org.simantics.spreadsheet.graph.parser.ast.AstValue;
-import org.simantics.spreadsheet.graph.parser.ast.AstValueVisitor;
-import org.simantics.spreadsheet.util.SpreadsheetUtils;
-
-public class PrintVisitor implements AstValueVisitor<String> {
-
-       @Override
-       public String visit(AstBoolean astBoolean) {
-               return "" + astBoolean.value;
-       }
-
-       @Override
-       public String visit(AstDouble astFloat) {
-               return "" + astFloat.value;
-       }
-
-       @Override
-       public String visit(AstInteger astInteger) {
-               return "" + astInteger.value;
-       }
-
-       @Override
-       public String visit(AstNull astNull) {
-               return "AstNull";
-       }
-
-       @Override
-       public String visit(AstString astString) {
-               return "\"" + astString.value + "\"";  
-       }
-
-       @Override
-       public String visit(AstRange astRange) {
-               if(astRange.isCell()) {
-                       return astRange.first;
-               } else {
-                       return astRange.first + ":" + astRange.second;
-               }
-       }
-
-       @Override
-       public String visit(AstArgList astArgList) {
-               StringBuilder b = new StringBuilder();
-               for(int i=0;i<astArgList.values.size();i++) {
-                       if(i > 0) b.append(";");
-                       b.append(astArgList.values.get(i).accept(this));
-               }
-               return b.toString();
-       }
-
-       @Override
-       public String visit(AstApply astApply) {
-               if(astApply.args == null) {
-                       return astApply.value + "()";
-               } else {
-                       return astApply.value + "(" + astApply.args.accept(this) + ")";
-               }
-       }
-
-       @Override
-       public String visit(AstRelation astRelation) {
-
-               StringBuilder b = new StringBuilder();
-               b.append(astRelation.left.accept(this));
-               b.append(astRelation.op.trim());
-               b.append(astRelation.right.accept(this));
-               return b.toString();
-               
-       }
-       
-       @Override
-       public String visit(AstArithmeticExpression exp) {
-               
-               StringBuilder b = new StringBuilder();
-               if(exp.prefix != null) b.append(exp.prefix);
-               
-               b.append(exp.left.accept(this));
-
-               for(int i=0;i<exp.rightCount();i++) {
-                       String op = exp.rightOp(i);
-                       b.append(op);
-                       AstValue value = exp.rightValue(i);
-                       b.append(value.accept(this));
-               }
-               
-               return b.toString();
-               
-       }
-
-       @Override
-       public String visit(AstTerm exp) {
-               
-               StringBuilder b = new StringBuilder();
-               
-               b.append(exp.left.accept(this));
-
-               for(int i=0;i<exp.rightCount();i++) {
-                       String op = exp.rightOp(i);
-                       b.append(op);
-                       AstValue value = exp.rightValue(i);
-                       b.append(value.accept(this));
-               }
-               
-               return b.toString();
-               
-       }
-
-       @Override
-       public String visit(AstFactor exp) {
-               
-               StringBuilder b = new StringBuilder();
-               
-               b.append(exp.left.accept(this));
-
-               for(int i=0;i<exp.rightCount();i++) {
-                       String op = exp.rightOp(i);
-                       b.append(op);
-                       AstValue value = exp.rightValue(i);
-                       b.append(value.accept(this));
-               }
-               
-               return b.toString();
-               
-       }
-
-       @Override
-       public String visit(AstIdentifier id) {
-               return "AstIdentifier";
-       }
-       
-       @Override
-       public String visit(AstArray array) {
-               StringBuilder b = new StringBuilder();
-               for(int i=0;i<array.values.size();i++) {
-                       if(i > 0) b.append(";");
-                       b.append(array.values.get(i).accept(this));
-               }
-               return b.toString();
-       }
-       
-       @Override
-       public String visit(AstNothing array) {
-               return "AstNothing";
-       }
-       
-       @Override
-       public String visit(AstArrayFormulaReference ref) {
-               return "{" + ref.value.accept(this) + "}";
-       }
-
-}
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetBook.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetBook.java
deleted file mode 100644 (file)
index d741d4c..0000000
+++ /dev/null
@@ -1,450 +0,0 @@
-package org.simantics.spreadsheet.graph;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-
-import org.simantics.databoard.Bindings;
-import org.simantics.databoard.binding.Binding;
-import org.simantics.databoard.binding.mutable.Variant;
-import org.simantics.db.exception.DatabaseException;
-import org.simantics.simulator.toolkit.StandardNodeManagerSupport;
-import org.simantics.simulator.variable.exceptions.NodeManagerException;
-import org.simantics.spreadsheet.graph.formula.SpreadsheetEvaluationEnvironment;
-import org.simantics.spreadsheet.graph.synchronization.LineNodeUpdater;
-import org.simantics.spreadsheet.graph.synchronization.LineUpdater;
-import org.simantics.spreadsheet.graph.synchronization.NullUpdater;
-import org.simantics.spreadsheet.graph.synchronization.SheetLineComponent;
-import org.simantics.spreadsheet.graph.synchronization.StyleUpdater;
-import org.simantics.structural.synchronization.base.ModuleUpdaterBase;
-import org.simantics.structural.synchronization.base.ModuleUpdaterFactoryBase;
-import org.simantics.structural.synchronization.base.SolverNameUtil;
-import org.simantics.structural.synchronization.utils.ComponentFactory;
-import org.simantics.structural.synchronization.utils.MappingBase;
-import org.simantics.structural.synchronization.utils.Solver;
-
-import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
-import it.unimi.dsi.fastutil.longs.AbstractLongList;
-import it.unimi.dsi.fastutil.longs.AbstractLongSet;
-import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
-import it.unimi.dsi.fastutil.longs.LongArraySet;
-import it.unimi.dsi.fastutil.longs.LongLinkedOpenHashSet;
-
-public class SpreadsheetBook implements StandardNodeManagerSupport<SheetNode>, SpreadsheetElement<SpreadsheetElement, SpreadsheetElement>, Serializable, SheetNode<SpreadsheetEngine, SheetNode>, Solver, SolverNameUtil, ComponentFactory<SheetLineComponent>, ModuleUpdaterFactoryBase<SheetLineComponent> {
-
-       private static final long serialVersionUID = 7417208688311691396L;
-       
-       public Serializable NotAvailableError = new Serializable() {
-               private static final long serialVersionUID = 2535371785498129460L;
-       };
-       
-       public Long2ObjectOpenHashMap<AbstractLongSet> referenceMap = new Long2ObjectOpenHashMap<>();
-       
-       private Int2ObjectArrayMap<SpreadsheetStyle> styles = new Int2ObjectArrayMap<>();
-//     public ObjectArrayList<SpreadsheetStyle> styles = new ObjectArrayList<SpreadsheetStyle>();
-       public ArrayList<SpreadsheetEngine> sheets = new ArrayList<SpreadsheetEngine>();
-       
-       private SpreadsheetMapping mapping;
-       
-       
-       private int idCounter = 1;
-       
-       public SpreadsheetBook() {
-               getNewId(this);
-               mapping = new SpreadsheetMapping(new SheetLineComponent(""));
-       }
-       
-       public Map<Integer, SpreadsheetElement> children = new HashMap<>();
-
-       private boolean iterationEnabled;
-
-       public int getNewId(SpreadsheetElement element) {
-               int result = idCounter++;
-               children.put(result, element);
-               return result; 
-       }
-       
-       public long getEngineIndex(SpreadsheetEngine engine) {
-               for(int i=0;i<sheets.size();i++)
-                       if(sheets.get(i) == engine) return i;
-               throw new IllegalStateException("Did not find sheet " + engine.getName());
-       }
-       
-       public void registerReferences(long cell, AbstractLongList refs) {
-               for(int i=0;i<refs.size();i++) {
-                       long key = refs.getLong(i);
-                       AbstractLongSet set = referenceMap.get(key);
-                       if(set == null) {
-                               set = new LongArraySet();
-                               referenceMap.put(key, set);
-                       }
-                       if(set.size() == 5) {
-                               AbstractLongSet newSet = new LongLinkedOpenHashSet();
-                               newSet.addAll(set);
-                               set = newSet;
-                               referenceMap.put(key, set);
-                       }
-                       set.add(cell);
-               }
-       }
-       
-       @Override
-       public Binding getEngineBinding(SheetNode node) throws NodeManagerException {
-               Object value = getEngineValue(node);
-               if(value instanceof Variant) return Bindings.VARIANT;
-               if(value instanceof String) return Bindings.STRING;
-               if(value instanceof Boolean) return Bindings.BOOLEAN;
-               else return Bindings.VOID;
-               
-       }
-       
-       @Override
-       public Object getEngineValue(SheetNode node) {
-               if(node instanceof SpreadsheetCellContent) {
-                       try {
-                               SpreadsheetCellContent scc = (SpreadsheetCellContent)node;
-                               Object content = scc.cell.evaluate(SpreadsheetEvaluationEnvironment.getInstance(this));
-                               if(content == null) return Variant.ofInstance("");
-                               if(content instanceof Variant) return content;
-                               else return Variant.ofInstance(content);
-                       } catch (Throwable t) {
-                               t.printStackTrace();
-                               return Variant.ofInstance(t.toString());
-                       }
-               } else if (node instanceof SpreadsheetCellContentExpression) {
-                       SpreadsheetCellContentExpression scce = (SpreadsheetCellContentExpression)node;
-                       if (scce.cell.content instanceof SpreadsheetFormula) {
-                       SpreadsheetFormula formula = (SpreadsheetFormula)scce.cell.content; 
-                       return formula.expression;
-                       } else if (scce.cell.content instanceof SpreadsheetSCLConstant) {
-                           SpreadsheetSCLConstant sclConstant = (SpreadsheetSCLConstant) scce.cell.content;
-                           return "=" + sclConstant.expression;
-                       } else {
-                           System.out.println("Broken SpreadsheetCellContentExpression possibly due to overwriting an existing expression with a constant or something else (current content is " + scce.cell.content + ")");
-                           if (scce.cell.content instanceof Variant) {
-                               return scce.cell.content;
-                           } else {
-                               return Variant.ofInstance(scce.cell.content);
-                           }
-                       }
-               } else if (node instanceof SpreadsheetTypeNode) {
-                       SpreadsheetTypeNode stn = (SpreadsheetTypeNode)node;
-                       return stn.uri;
-               } else if (node instanceof SpreadsheetCellStyle) {
-                   int styleId = ((SpreadsheetCellStyle) node).cell.style;
-                   SpreadsheetStyle style = getStyle(styleId);
-                   if (style == null) {
-                       style = SpreadsheetStyle.empty();
-                       if (styleId != style.getStyleId())
-                           new Exception("different style ids!" + styleId + "  " + style.getStyleId()).printStackTrace();
-                       addStyle(style);
-                   }
-                   return style;
-               } else if (node instanceof SpreadsheetCellEditable) {
-                   boolean editable = ((SpreadsheetCellEditable) node).editable();
-                   return editable;
-               }
-               return null;
-       }
-
-       @Override
-       public void setEngineValue(SheetNode node, Object value) {
-       }
-
-       @Override
-       public String getName(SheetNode node) {
-               return node.getName();
-       }
-
-       @Override
-       public Map<String, SheetNode> getChildren(SheetNode node) {
-               return node.getChildren();
-       }
-
-       @Override
-       public Map<String, SheetNode> getProperties(SheetNode node) {
-               return node.getProperties();
-       }
-
-       @Override
-       public String getName() {
-               return "";
-       }
-
-       @Override
-       public Map<String, SpreadsheetEngine> getChildren() {
-               Map<String,SpreadsheetEngine> result = new HashMap<String,SpreadsheetEngine>();
-               for(SpreadsheetEngine engine : sheets)
-                       result.put(engine.getName(), engine);
-               return result;
-       }
-
-       @Override
-       public Map<String, SheetNode> getProperties() {
-               return Collections.emptyMap();
-       }
-       
-       public SpreadsheetCell get(String sheet, int row, int column) {
-               SpreadsheetEngine engine = getEngine(sheet);
-               if(engine == null) return null;
-               SpreadsheetLine line = engine.getLine(row);
-               if(line == null) return null;
-               if(line.cells.size() <= column) return null;
-               return line.cells.get(column);
-       }
-
-       public SpreadsheetCell get(SpreadsheetEngine engine, int row, int column) {
-               SpreadsheetLine line = engine.getLine(row);
-               if(line == null) return null;
-               if(line.cells.size() <= column) return null;
-               return line.cells.get(column);
-       }
-
-       public SpreadsheetEngine getEngine(String sheet) {
-               for(SpreadsheetEngine engine : sheets)
-                       if(sheet.equals(engine.getName())) return engine;
-               return null;
-       }
-
-       @Override
-       public ModuleUpdaterBase<SheetLineComponent> createUpdater(String id) throws DatabaseException {
-               if("http://www.simantics.org/Spreadsheet-1.2/Line".equals(id))
-                       return new LineUpdater(id);
-               else if("http://www.simantics.org/Spreadsheet-1.2/LineNode".equals(id))
-                       return new LineNodeUpdater(id);
-               else if ("http://www.simantics.org/Spreadsheet-1.2/Style".equals(id))
-                   return new StyleUpdater(id);
-               else if("http://www.simantics.org/Spreadsheet-1.2/Lines".equals(id))
-                       return new NullUpdater(id);
-               else if("http://www.simantics.org/Spreadsheet-1.2/Spreadsheet".equals(id))
-                       return new NullUpdater(id);
-               else if("http://www.simantics.org/Spreadsheet-1.2/Book".equals(id))
-                       return new NullUpdater(id);
-               else
-                       throw new IllegalStateException("createUpdater " + id);
-       }
-
-       @Override
-       public SheetLineComponent create(String uid) {
-               return new SheetLineComponent(uid);
-       }
-
-       @Override
-       public String getFreshName(String parentName, String name) {
-               return parentName + "/" + name;
-       }
-
-       @Override
-       public String ensureNameIsVariationOf(String parentName, int id, String name) {
-           if (parentName.isEmpty())
-               return name;
-               return parentName + "/" + name;
-       }
-
-       final static int COMP_ROOT_POS = "COMP_ROOT/".length();
-       
-       @Override
-       public int getId(String name) {
-               
-               if("COMP_ROOT".equals(name)) return 1;
-
-               String path = name.substring(COMP_ROOT_POS);
-               String[] parts = path.split("/");
-               Object o = resolve(parts, 0);
-               if(o instanceof SpreadsheetLines) {
-                       return ((SpreadsheetLines)o).getId();
-               } else if(o instanceof SpreadsheetLine) {
-                       return ((SpreadsheetLine)o).getId();
-               } else if(o instanceof SpreadsheetEngine) {
-                       return ((SpreadsheetEngine)o).getId();
-               } else if (o instanceof SpreadsheetStyle) {
-                   return ((SpreadsheetStyle) o).getId();
-               }
-               
-               throw new IllegalStateException("Resolved object for parts " + Arrays.toString(parts) + " is not the right type! It is " + o);
-               
-       }
-       
-       Object resolve(String[] parts, int index) {
-               String part = parts[index];
-               if (part.startsWith("Style")) {
-                   for (SpreadsheetStyle style : styles.values()) {
-                       if (style.name.equals(part)) {
-                           return style;
-                       }
-                   }
-               }
-               SpreadsheetEngine engine = getEngine(part);
-               if(engine == null) return 0;
-               if(index == parts.length-1) return engine;
-               else return engine.resolve(parts, index+1);
-       }
-
-       @Override
-       public String getName(int id) {
-               if(id == -2) return "http://www.simantics.org/Spreadsheet-1.2/Book";
-               else if(id == -3) return "http://www.simantics.org/Spreadsheet-1.2/Spreadsheet";
-               else if(id == -4) return "http://www.simantics.org/Spreadsheet-1.2/Lines";
-               else if(id == -5)
-                   return "http://www.simantics.org/Spreadsheet-1.2/LineNode";
-               else if (id == -6)
-                   return "http://www.simantics.org/Spreadsheet-1.2/Line";
-               else if(id == -7)
-                   return "http://www.simantics.org/Spreadsheet-1.2/Style";
-               else return "" + id;
-       }
-
-       @Override
-       public int getModuleType(int id) {
-               Serializable s = children.get(id);
-               if(s instanceof SpreadsheetBook) return -2;
-               else if(s instanceof SpreadsheetEngine) return -3;
-               else if(s instanceof SpreadsheetLines) {
-                       if("Lines".equals(((SpreadsheetLines) s).getName()))
-                               return -4;
-                       else
-                               return -5;
-               }
-               else if(s instanceof SpreadsheetLine)
-                   return -6;
-               else if (s instanceof SpreadsheetStyle)
-                   return -7;
-               else throw new IllegalStateException();
-       }
-
-       @Override
-       public void remove(int id) {
-           
-           SpreadsheetElement child = children.get(id);
-           Optional<SpreadsheetElement> parent = child.getParent();
-           
-           if (parent.isPresent()) {
-               parent.get().remove(child);
-               children.remove(id);
-           }
-       }
-
-       @Override
-       public void addSubprocess(String name, String subprocessType) {
-               ensureSubprocess(name);
-       }
-       
-       public <T> T ensureSubprocess(String name) {
-               String[] parts = name.split("/");
-               if(parts.length == 2) {
-                       SpreadsheetEngine engine = getEngine(parts[1]);
-                       if(engine == null) {
-                               engine = new SpreadsheetEngine(this, parts[1]);
-                               sheets.add(engine);
-                       }
-                       return (T)engine;
-               } else if (parts.length > 2) {
-                       SpreadsheetEngine engine = getEngine(parts[1]);
-                       return (T)engine.ensureSubprocess(parts, 2);
-               }
-               throw new IllegalStateException();
-       }
-       
-
-       @Override
-       public void includeSubprocess(String parentName, String subprocessName) {
-               // Nop
-       }
-
-       @Override
-       public <T> T getConcreteSolver() {
-               return (T)this;
-       }
-       
-       @Override
-       public void accept(SpreadsheetVisitor v) {
-               v.visit(this);
-       }
-       
-       //Recursively find all SpreadsheetCells, invalidate them and return them all as a set
-       public Set<SpreadsheetCell> invalidate(SpreadsheetCell cell) {
-               Set<SpreadsheetCell> result = new HashSet<>();
-               result.add(cell);
-               cell.invalidate();
-               long refKey = cell.makeReferenceKey();
-               AbstractLongSet refs = referenceMap.remove(refKey);
-               if(refs == null) return result;
-               for(long ref : refs) {
-                       long sheet = ref >> 40;
-                       long row = (ref >> 20) & 0xFFFFF;
-                       long col = (ref) & 0xFFFFF;
-                       SpreadsheetCell referer = get(sheets.get((int)sheet), (int)row, (int)col);
-                       result.addAll(invalidate(referer));
-               }
-               return result;
-       }
-       
-       @Deprecated
-       public List<SpreadsheetCell> invalidateShallow(SpreadsheetCell cell) {
-               ArrayList<SpreadsheetCell> result = new ArrayList<>();
-               result.add(cell);
-               cell.invalidate();
-               long refKey = cell.makeReferenceKey();
-               AbstractLongSet refs = referenceMap.remove(refKey);
-               if(refs == null) return result;
-               for(long ref : refs) {
-                       long sheet = ref >> 40;
-                       long row = (ref >> 20) & 0xFFFFF;
-                       long col = (ref) & 0xFFFFF;
-                       SpreadsheetCell referer = get(sheets.get((int)sheet), (int)row, (int)col);
-                       invalidate(referer);
-                       result.add(referer);
-               }
-               return result;
-       }
-
-    public void addStyle(SpreadsheetStyle style) {
-        if (style.name == null) {
-            new Exception("Trying to add style to book without name!!").printStackTrace();
-            return;
-        }
-        style.setSynchronizationId(getNewId(style));
-        styles.put(style.getStyleId(), style);
-    }
-
-    public SpreadsheetStyle getStyle(int styleId) {
-        return styles.get(styleId);
-    }
-
-    public MappingBase<SheetLineComponent> getMapping() {
-        return mapping;
-    }
-
-    @Override
-    public Optional<SpreadsheetElement> getParent() {
-        return Optional.empty();
-    }
-
-    @Override
-    public Collection<SpreadsheetElement> getSpreadsheetChildren() {
-        return children.values();
-    }
-
-    @Override
-    public void remove(SpreadsheetElement child) {
-        // TODO Auto-generated method stub
-        
-    }
-
-       public void setIterationEnabled(boolean value) {
-               this.iterationEnabled = value;
-       }
-       
-       public boolean isIterationEnabled() {
-               return iterationEnabled;
-       }
-
-}
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetCell.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetCell.java
deleted file mode 100644 (file)
index 0ee66cf..0000000
+++ /dev/null
@@ -1,224 +0,0 @@
-package org.simantics.spreadsheet.graph;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-
-import org.simantics.spreadsheet.graph.formula.FormulaError2;
-import org.simantics.spreadsheet.graph.formula.SpreadsheetEvaluationEnvironment;
-import org.simantics.spreadsheet.graph.parser.ast.AstValue;
-import org.simantics.spreadsheet.resource.SpreadsheetResource;
-import org.simantics.spreadsheet.util.SpreadsheetUtils;
-
-public class SpreadsheetCell implements SpreadsheetElement, SheetNode {
-
-       private static final long serialVersionUID = 6616793596542239339L;
-
-       public static SpreadsheetCell EMPTY;
-       
-       static {
-           EMPTY = new SpreadsheetCell(null, -1);
-           EMPTY.setContent("");
-           EMPTY.setStyle(SpreadsheetStyle.empty().getStyleId());
-       }
-       
-       private boolean inProgress = false;
-       private int iterations = 0;
-       
-       final private SpreadsheetLine line;
-       final private int column;
-       int style;
-       Object content;
-       final private Map<String, SheetNode> properties;
-       
-       public SpreadsheetCell(SpreadsheetLine line, int column) {
-               this.properties = createProperties();
-               this.line = line;
-               this.column = column;
-       }
-
-       //All SpreadsheetCells have these properties - create them when object is created
-       private Map<String, SheetNode> createProperties() {
-           Map<String, SheetNode> p = new HashMap<>();     
-           p.put("typeURI", new SpreadsheetTypeNode(SpreadsheetResource.URIs.Cell));
-           p.put("content", new SpreadsheetCellContent(this));
-        p.put("style", new SpreadsheetCellStyle(this));
-        p.put("editable", new SpreadsheetCellEditable(this));
-        return p;
-       }
-       
-    public boolean hasExpression() {
-               return content instanceof SpreadsheetFormula || content instanceof SpreadsheetSCLConstant; 
-       }
-       
-       public void setContent(Object newContent) {
-//       if(newContent != null) {
-//            if (!(newContent instanceof Serializable)) {
-//                throw new AssertionError("content not instanceof Serializable but it is " + newContent.getClass().getSimpleName());
-//            }
-//        }
-           if (GraphUI.DEBUG)
-               System.out.println("SpreadsheetCell.setContent "+ this + " " + newContent);
-               this.content = newContent;
-       }
-
-       @Override
-       public String getName() {
-               return SpreadsheetUtils.cellName(line.row, column);
-       }
-
-       @Override
-       public Map<?, ?> getChildren() {
-               return Collections.emptyMap();
-       }
-       
-       private static String[] keys = { "typeURI", "content" };
-       
-       @Override
-       public Map<String, SheetNode> getProperties() {
-           if (GraphUI.DEBUG)
-               System.out.println("SpreadsheetCell.getProperties: " + this + " " + content + " " + style);
-           return properties; //Return this SpreadsheetCells's properties, rather than a new HashMap
-       }
-       
-       public SpreadsheetBook getBook() {
-               return line.getEngine().getBook();
-       }
-
-       public SpreadsheetEngine getEngine() {
-               return line.getEngine();
-       }
-
-       public <T> T evaluate(SpreadsheetEvaluationEnvironment env) {
-               return evaluate(env, null);
-       }
-
-       public <T> T evaluate(SpreadsheetEvaluationEnvironment env, CellValueVisitor caller) {
-//         System.err.println(getEngine().getName() + ":" + getName() + ": evaluate");
-               if(caller != null)
-                       caller.addReference(makeReferenceKey());
-               if(content instanceof SpreadsheetFormula) {
-                       SpreadsheetFormula f = (SpreadsheetFormula)content;
-                       if(f.result == null) {
-                               CellValueVisitor visitor = new CellValueVisitor(env, this);
-                               AstValue value = ((SpreadsheetFormula)content).value;
-                               if(this.inProgress == true) this.iterations++;
-                               
-                               if(!env.getBook().isIterationEnabled()){
-                                       if(this.inProgress == false){
-                                               this.inProgress = true;
-                                               f.result = value.accept(visitor);
-                                       }
-                                       else f.result = FormulaError2.CIRCULAR_REF.getString();
-                               }
-                               else if(this.iterations<env.iterationLimit){
-                                       this.inProgress = true;
-                                       f.result = value.accept(visitor);
-                               }
-                               else {
-                                       if(f.result==null)
-                                               f.result = 0.0;
-                               }
-                               
-                               env.getBook().registerReferences(makeReferenceKey(), visitor.getReferences());
-                       }
-                       this.inProgress = false;
-                       this.iterations = 0;
-                       return (T)f.result;
-               } else if (content instanceof SpreadsheetSCLConstant) {
-                   SpreadsheetSCLConstant sclConstant = (SpreadsheetSCLConstant) content;
-                   return (T) sclConstant.content;
-               } else {
-                       this.inProgress = false;
-                       return (T)content;
-               }
-       }
-       
-       public long makeReferenceKey() {
-               SpreadsheetBook book = getBook();
-               SpreadsheetEngine engine = getEngine();
-               long engineIndex = book.getEngineIndex(engine);
-               long row = line.row;
-               long col = column;
-               return (engineIndex << 40) + (row << 20) + col; 
-       }
-       
-       public void invalidate() {
-               getEngine().rangeCache = null;
-               if(content instanceof SpreadsheetFormula) {
-                       SpreadsheetFormula f = (SpreadsheetFormula)content;
-                       f.result = null;
-               }
-       }
-
-       @Override
-       public void accept(SpreadsheetVisitor v) {
-               v.visit(this);
-       }
-
-    @Override
-    public Optional<SpreadsheetElement> getParent() {
-        return Optional.of(line);
-    }
-
-    @Override
-    public List<SpreadsheetElement> getSpreadsheetChildren() {
-        return Collections.emptyList();
-    }
-
-    @Override
-    public void remove(SpreadsheetElement child) {
-        // TODO Auto-generated method stub
-        
-    }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + column;
-        result = prime * result + ((line == null) ? 0 : line.hashCode());
-        return result;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj)
-            return true;
-        if (obj == null)
-            return false;
-        if (getClass() != obj.getClass())
-            return false;
-        SpreadsheetCell other = (SpreadsheetCell) obj;
-        if (column != other.column)
-            return false;
-        if (line == null) {
-            if (other.line != null)
-                return false;
-        } else if (!line.equals(other.line))
-            return false;
-        return true;
-    }
-
-    public void setStyle(int styleId) {
-        this.style = styleId;
-    }
-
-    public int getStyle() {
-        return style;
-    }
-
-    public Object getContent() {
-        return content;
-    }
-    
-    public static SpreadsheetCell empty(SpreadsheetLine line, int column) {
-        SpreadsheetCell cell =  new SpreadsheetCell(line, column);
-        cell.setContent("");
-        cell.setStyle(SpreadsheetStyle.empty().getStyleId());
-        return cell;
-    }
-
-}
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetEngine.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetEngine.java
deleted file mode 100644 (file)
index 364e926..0000000
+++ /dev/null
@@ -1,162 +0,0 @@
-package org.simantics.spreadsheet.graph;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-
-import org.simantics.spreadsheet.Range;
-import org.simantics.spreadsheet.graph.parser.ast.AstRange;
-
-@SuppressWarnings("rawtypes")
-public class SpreadsheetEngine implements SpreadsheetElement, SheetNode {
-
-       private static final long serialVersionUID = -5246063647558595642L;
-       
-       private static final String LINES = "Lines";
-       
-       private final SpreadsheetBook book;
-       private final String name;
-       private final int id;
-
-       public SpreadsheetLines lines;
-       
-       transient public Map<String,Object> rangeCache;
-
-       public Map<String,Object> getRangeCache() {
-               if(rangeCache == null) rangeCache = new HashMap<String,Object>();
-               return rangeCache;
-       }
-       
-       public Object getCachedRange(AstRange range) {
-               if(range.sheetName != null) return null;
-               return getRangeCache().get(range.first + ":" + range.second); 
-       }
-       
-       public void cacheRange(AstRange range, Object value) {
-               if(range.sheetName != null) return;
-               getRangeCache().put(range.first + ":" + range.second, value);
-       }
-
-       public SpreadsheetEngine(SpreadsheetBook book, String name) {
-               this.book = book;
-               this.name = name;
-               this.id = book.getNewId(this);
-               this.lines = new SpreadsheetLines(this, LINES);
-       }
-       
-       public SpreadsheetBook getBook() {
-               return book;
-       }
-       
-       public int getId() {
-               return id;
-       }
-       
-       Object resolve(String[] parts, int index) {
-               
-               String part = parts[index];
-               if(!part.equals(LINES)) return null;
-               
-               if(index == parts.length-1) return lines;
-               
-               return lines.resolve(parts, index+1);
-
-       }
-       
-       @Override
-       public String getName() {
-               return name;
-       }
-       
-       @Override
-       public Map<String, SheetNode> getChildren() {
-               return Collections.singletonMap(LINES, lines);
-       }
-       
-       @Override
-       public Map<String, SheetNode> getProperties() {
-               return Collections.emptyMap();
-       } 
-       
-       public Object ensureSubprocess(String[] path, int index) {
-               
-               String name = path[index];
-               if(!LINES.equals(name)) throw new IllegalStateException();
-               if(index == path.length - 1) return lines;
-               return lines.ensureSubprocess(path, index+1);
-               
-       }
-       
-       public SpreadsheetLine getLine(int row) {
-               assert(lines.nodes.size() == 1);
-               SpreadsheetLines root = lines.nodes.values().iterator().next();
-               return root.getLine(row);
-       }
-
-       @Override
-       public void accept(SpreadsheetVisitor v) {
-               v.visit(this);
-       }
-       
-       public Range actualRange(Range r) {
-               if(r.isFullRows()) {
-                       SpreadsheetLines root = lines.nodes.values().iterator().next();
-                       Range result = new Range(r);
-                       result.startRow = 0;
-                       result.endRow = root.getMaxRow(); 
-                       return result;
-               } else {
-                       return r;
-               }
-       }
-
-    @Override
-    public Optional<SpreadsheetElement> getParent() {
-        return Optional.of(book);
-    }
-
-    @Override
-    public List<SpreadsheetElement> getSpreadsheetChildren() {
-        return Collections.singletonList(lines);
-    }
-
-    @Override
-    public void remove(SpreadsheetElement child) {
-        
-    }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((book == null) ? 0 : book.hashCode());
-        result = prime * result + ((name == null) ? 0 : name.hashCode());
-        return result;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj)
-            return true;
-        if (obj == null)
-            return false;
-        if (getClass() != obj.getClass())
-            return false;
-        SpreadsheetEngine other = (SpreadsheetEngine) obj;
-        if (book == null) {
-            if (other.book != null)
-                return false;
-        } else if (!book.equals(other.book))
-            return false;
-        if (name == null) {
-            if (other.name != null)
-                return false;
-        } else if (!name.equals(other.name))
-            return false;
-        return true;
-    }
-       
-       
-}
\ No newline at end of file
index 032acfcfce722809848b8fceeeac10bb9bd19800..35a05d7aa59c7d45980f0a781a8fdd726ea621e3 100644 (file)
@@ -23,28 +23,52 @@ import org.simantics.datatypes.utils.BTree;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.BinaryRead;
 import org.simantics.db.common.request.ObjectsWithType;
+import org.simantics.db.common.request.UnaryRead;
+import org.simantics.db.common.request.WriteRequest;
 import org.simantics.db.common.utils.LiteralFileUtil;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.exception.ServiceException;
 import org.simantics.db.layer0.util.Layer0Utils;
+import org.simantics.db.layer0.variable.StandardGraphChildVariable;
 import org.simantics.db.layer0.variable.Variable;
 import org.simantics.db.layer0.variable.Variables;
+import org.simantics.db.procedure.Listener;
 import org.simantics.db.service.ClusteringSupport;
 import org.simantics.layer0.Layer0;
+import org.simantics.scl.compiler.commands.CommandSession;
+import org.simantics.scl.runtime.SCLContext;
+import org.simantics.scl.runtime.function.Function;
+import org.simantics.scl.runtime.tuple.Tuple0;
 import org.simantics.scl.runtime.tuple.Tuple2;
 import org.simantics.simulator.toolkit.StandardRealm;
+import org.simantics.spreadsheet.CellEditor;
+import org.simantics.spreadsheet.ExternalRef;
+import org.simantics.spreadsheet.OperationMode;
 import org.simantics.spreadsheet.Range;
+import org.simantics.spreadsheet.Spreadsheets;
+import org.simantics.spreadsheet.Transaction;
 import org.simantics.spreadsheet.graph.synchronization.SpreadsheetSynchronizationEventHandler;
 import org.simantics.spreadsheet.resource.SpreadsheetResource;
+import org.simantics.spreadsheet.solver.SheetNode;
+import org.simantics.spreadsheet.solver.SpreadsheetBook;
+import org.simantics.spreadsheet.solver.SpreadsheetCell;
+import org.simantics.spreadsheet.solver.SpreadsheetEngine;
+import org.simantics.spreadsheet.solver.SpreadsheetLine;
+import org.simantics.spreadsheet.solver.SpreadsheetStyle;
 import org.simantics.spreadsheet.util.SpreadsheetUtils;
 import org.simantics.structural.synchronization.client.Synchronizer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import gnu.trove.iterator.TObjectIntIterator;
 import gnu.trove.map.hash.TObjectIntHashMap;
 
 public class SpreadsheetGraphUtils {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(SpreadsheetGraphUtils.class);
+
     public static File extractInitialCondition(ReadGraph graph, Resource ic) throws DatabaseException, IOException {
 
        SpreadsheetResource SR = SpreadsheetResource.getInstance(graph);
@@ -168,12 +192,6 @@ public class SpreadsheetGraphUtils {
                        
         SpreadsheetSynchronizationEventHandler handler = new SpreadsheetSynchronizationEventHandler(graph, book);
         
-//        System.err.println("sessionName : " + sessionName);
-//        System.err.println("bookResource : " + graph.getURI(bookResource));
-//        System.err.println("configuration : " + configuration.getURI(graph));
-//        System.err.println("realm : " + realm);
-//        System.err.println("book : " + book);
-        
         if (changeFlags == null) {
             synchronizer.fullSynchronization(configuration, handler);
         } else {
@@ -193,14 +211,6 @@ public class SpreadsheetGraphUtils {
             synchronizer.partialSynchronization(configuration, handler, changeFlags);
         }
         
-//        book.accept(new InvalidateAll());
-//        realm.getNodeManager().refreshVariables();
-//        mapping.currentRevision = synchronizer.getHeadRevisionId();
-//        mapping.setTrustUids(true);
-        // Clean up queries
-//        QueryControl qc = g.getService(QueryControl.class);
-//        qc.flush(g);
-//        TimeLogger.log("Finished full synchronization");
         realm.getNodeManager().fireNodeListeners();
         return handler.getDidChanges();
         
@@ -218,7 +228,7 @@ public class SpreadsheetGraphUtils {
        SpreadsheetEngine engine = book.getEngine(sheetName);
        if(engine == null) return null;
        
-       Range r = SpreadsheetUtils.decodeCellAbsolute(cellName);
+       Range r = Spreadsheets.decodeCellAbsolute(cellName);
        SpreadsheetLine line = engine.getLine(r.startRow);
        if(line == null) return null;
        
@@ -233,200 +243,6 @@ public class SpreadsheetGraphUtils {
     }
 
     
-    public static boolean asBoolean(Object object) {
-       if(object instanceof Boolean) return (Boolean)object;
-       else if(object instanceof Number) return ((Number)object).doubleValue() != 0;
-       else if(object instanceof Variant) return asBoolean(((Variant)object).getValue());
-       else if(object instanceof String) {
-               Double d = asDoubleWhereEmptyStringIsZero((String)object);
-               if(d==null) return false;
-               else return d != 0;
-       }
-       return false;
-    }
-    
-    public static String asString(Object object) {
-       if(object == null) return "";
-       if(object instanceof String) return (String)object;
-       if(object instanceof Number) {
-               double dVal = ((Number)object).doubleValue();
-               if(dVal == Math.floor(dVal)){
-                       return ""+((Number)object).intValue();
-               } else {
-                       return object.toString();
-               }
-       }
-       else if(object instanceof Variant) {
-               Object o = ((Variant) object).getValue();
-               if(o instanceof String) return (String)o;
-               else if(o instanceof Number) asString((Number)o);
-               else return o.toString();
-       }
-       return object.toString();
-    }
-    
-    public static Double asDoubleWhereEmptyStringIsZero(Object object){
-       if(object instanceof Number)
-               return ((Number)object).doubleValue();
-       else if(object instanceof String) {
-               try {
-                       if(((String)object).isEmpty())
-                               return 0.0;
-                       return Double.parseDouble((String)object);
-                       } catch (NumberFormatException e) {
-                               return null;
-                       }
-       } else if(object instanceof Variant) {
-               Object o = ((Variant) object).getValue();
-               return asDoubleWhereEmptyStringIsZero(o);
-       } else if (SpreadsheetCell.EMPTY == object) {
-               return null;
-       }
-       return null;
-    }
-    
-    public static double asNumber(Object object) {
-       if(object instanceof Number) {
-               return ((Number)object).doubleValue();
-       } else if(object instanceof String) {
-               try {
-                       String str = (String)object;
-                       if(str.isEmpty()) return 0;
-                       return Double.parseDouble((String)object);
-                       } catch (NumberFormatException e) {
-                       return 0;
-                       }
-       } else if(object instanceof Variant) {
-               Object o = ((Variant) object).getValue();
-               return asNumber(o);
-       } else if (SpreadsheetCell.EMPTY == object) {
-               return 0.0;
-       }
-               
-       return 0.0;
-       
-    }
-    
-    public static Number asValidNumber(Object object) {
-       if(object instanceof Number) {
-               return (Number)object;
-       } else if(object instanceof String) {
-               try {
-                       return Double.parseDouble((String)object);
-                       } catch (NumberFormatException e) {
-                       return null;
-                       }
-       } else if(object instanceof Variant) {
-               Object o = ((Variant) object).getValue();
-               return asNumber(o);
-       } else if (SpreadsheetCell.EMPTY == object) {
-               return null;
-       }
-               
-       return null;
-       
-    }
-    
-    public static boolean matchCriteria(Object value, Object criteria) {
-       if(value==null || criteria==null) return false;
-       
-       if(value instanceof Variant){
-               Double dVal = asDoubleWhereEmptyStringIsZero(value);
-               if(dVal==null) value = ((Variant)value).getValue();
-               else value = dVal;
-       }
-       if(criteria instanceof Variant){
-               Double dVal = asDoubleWhereEmptyStringIsZero(criteria);
-               if(dVal==null) criteria = ((Variant)criteria).getValue();
-               else criteria = dVal;
-       }
-       
-       if(criteria instanceof Number && value instanceof Number) {
-               Number nc = (asNumber(criteria));
-               Number nv = (asNumber(value));
-               return nc.equals(nv);
-       }
-       if(criteria instanceof String){
-               boolean nums = false;
-               Object valueObj = null;
-                       if(value instanceof Number){
-                               valueObj = ((Number)value).doubleValue();
-                               nums = true;
-                       }
-                       else valueObj = value.toString();
-                       
-               String sc = criteria.toString();
-                       if(sc.length() >= 3){
-                               String oper = sc.substring(0, 2);
-                               String criteriaStr = sc.substring(2);
-                               Double criteriaNum = null;
-                               try {
-                                       criteriaNum = Double.parseDouble(criteriaStr);
-                                       if(oper.equals("<>")){
-                                               if(!nums) return true;
-                                       }
-                                       else if(!nums) return false;
-                                       nums = true;
-                               } catch (NumberFormatException e){
-                                       if(oper.equals("<>")){
-                                               if(nums) return true;
-                                       }
-                                       else if(nums) return false;
-                                       nums = false;
-                               }
-                               
-                               if(oper.equals(">=")){
-                                       if(!nums) return (valueObj.toString().toLowerCase()).compareTo(criteriaStr.toLowerCase()) >= 0 ;
-                                       else return ((Number)valueObj).doubleValue() >= criteriaNum;
-                               } else if(oper.equals("<=")){
-                                       if(!nums) return (valueObj.toString().toLowerCase()).compareTo(criteriaStr.toLowerCase()) <= 0 ;
-                                       else return ((Number)valueObj).doubleValue() <= criteriaNum;
-                               } else if(oper.equals("<>")){
-                                       if(!nums) return (valueObj.toString().toLowerCase()).compareTo(criteriaStr.toLowerCase()) != 0 ;
-                                       else return ((Number)valueObj).doubleValue() != criteriaNum;
-                               }
-                       }
-               if(sc.length() >= 2){
-                       String oper = sc.substring(0, 1);
-                       String criteriaStr = sc.substring(1);
-                       Double criteriaNum = null;
-                       
-                       try {
-                                       criteriaNum = Double.parseDouble(criteriaStr);
-                                       if(!nums) return false;
-                                       nums = true;
-                               } catch (NumberFormatException e){
-                                       if(nums) return false;
-                                       nums = false;
-                               }
-                       if(oper.equals("<")){
-                               if(!nums) return (valueObj.toString().toLowerCase()).compareTo(criteriaStr.toLowerCase()) < 0;
-                               else return ((Number)valueObj).doubleValue() < criteriaNum;
-                       } else if(oper.equals(">")){
-                               if(!nums) return (valueObj.toString().toLowerCase()).compareTo(criteriaStr.toLowerCase()) > 0;
-                               else return ((Number)valueObj).doubleValue() > criteriaNum;
-                       } else if(oper.equals("=")){
-                               if(!nums) return (valueObj.toString().toLowerCase()).compareTo(criteriaStr.toLowerCase()) == 0;
-                               else return ((Number)valueObj).doubleValue() == criteriaNum;
-                       }
-               }
-               return sc.equals(valueObj);
-       }
-       else if (criteria instanceof Number){
-               return false;
-       }
-       throw new IllegalStateException();
-    }
-
-    public static boolean excelEquals(Object left, Object right) {
-       if(left instanceof String) {
-               if(right instanceof String) {
-                       return ((String) left).toLowerCase().equals(((String) right).toLowerCase());
-               }
-       }
-       return left.equals(right);
-    }
-    
 
     public static List<Variable> possibleConfigurationCellVariables(ReadGraph graph, Variable sheet, Range range) throws DatabaseException {
         List<Variable> rowVariables = possibleConfigurationLineVariables(graph, sheet, range);
@@ -521,7 +337,7 @@ public class SpreadsheetGraphUtils {
     
     private static boolean variableInRange(ReadGraph graph, Variable child, Range range) throws DatabaseException {
         String name = child.getName(graph);
-        Range childRange = SpreadsheetUtils.decodeCellAbsolute(name);
+        Range childRange = Spreadsheets.decodeCellAbsolute(name);
 //        System.out.print(" and range " + childRange);
         if (childRange != null && range.contains(childRange)) {
 //             System.out.println(" => range.contains(childRange) = true");
@@ -566,7 +382,7 @@ public class SpreadsheetGraphUtils {
             for (int rowNumber = range.startRow; rowNumber <= range.endRow; rowNumber++) {
                 Variable row = rowIterator.next();
                 for (int colNumber = range.startColumn; colNumber <= range.endColumn; colNumber++) {
-                    String location = SpreadsheetUtils.cellName(rowNumber, colNumber);
+                    String location = Spreadsheets.cellName(rowNumber, colNumber);
                     defaultCreateCell(graph, row, location, new Variant(Bindings.STRING, ""));
                 }
             }
@@ -670,5 +486,169 @@ public class SpreadsheetGraphUtils {
         SpreadsheetGraphUtils.saveInitialCondition(graph, run, root, "Initial");
         return run;
     }
+    
+    public static Variant extRefVariable(ReadGraph graph, Variable var) throws DatabaseException {
+        return new Variant(Bindings.VOID, new ExternalRefVariable(graph, var));
+    }
+    
+    static class ExternalRefVariable implements ExternalRef {
+
+        final private String uri;
+        
+        public ExternalRefVariable(ReadGraph graph, Variable variable) throws DatabaseException {
+            this.uri = variable.getURI(graph);
+        }
+        
+        @Override
+        public void listen(Object context, ExternalRefListener listener) {
+            Simantics.getSession().asyncRequest(new UnaryRead<String, Variant>(uri) {
+
+                @Override
+                public Variant perform(ReadGraph graph) throws DatabaseException {
+                    Variable variable = Variables.getVariable(graph, parameter);
+                    return variable.getVariantValue(graph);
+                }
+                
+            }, new Listener<Variant>() {
+
+                @Override
+                public void execute(Variant result) {
+                    listener.newValue(result);
+                }
+
+                @Override
+                public void exception(Throwable t) {
+                    LOGGER.error("Error while evaluating variable value", t);
+                }
+
+                @Override
+                public boolean isDisposed() {
+                    return listener.isDisposed();
+                }
+                
+            });
+        }
+        
+        @Override
+        public void modify(Object context, Variant newValue) {
+            
+            Simantics.getSession().asyncRequest(new WriteRequest() {
 
+                @Override
+                public void perform(WriteGraph graph) throws DatabaseException {
+                    Variable variable = Variables.getVariable(graph, uri);
+                    variable.setValue(graph, newValue);
+                }
+            });
+            
+        }
+        
+    }
+
+    public static Variant extRefActiveVariable(ReadGraph graph, Variable var) throws DatabaseException {
+        return new Variant(Bindings.VOID, new ExternalRefActiveVariable(graph, var));
+    }
+    
+    static class ExternalRefActiveVariable implements ExternalRef {
+
+        final private String uri;
+        
+        public ExternalRefActiveVariable(ReadGraph graph, Variable variable) throws DatabaseException {
+            this.uri = variable.getURI(graph);
+        }
+        
+        @Override
+        public void listen(Object context, ExternalRefListener listener) {
+            Simantics.getSession().asyncRequest(new BinaryRead<String, String, Variant>((String)context, uri) {
+
+                @Override
+                public Variant perform(ReadGraph graph) throws DatabaseException {
+                    Variable contextVariable = Variables.getVariable(graph, parameter);
+                    Variable configVariable = Variables.getVariable(graph, parameter2);
+                    Variable activeVariable = Variables.switchPossibleContext(graph, configVariable, contextVariable.getRepresents(graph));
+                    if(activeVariable == null) return Variant.ofInstance("Could not resolve " + configVariable.getURI(graph) + " for " + contextVariable.getURI(graph));
+                    return activeVariable.getVariantValue(graph);
+                }
+            }, new Listener<Variant>() {
+
+                @Override
+                public void execute(Variant result) {
+                    listener.newValue(result);
+                }
+
+                @Override
+                public void exception(Throwable t) {
+                    LOGGER.error("Error while evaluating variable value, context = " + context + " uri=" + uri, t);
+                }
+
+                @Override
+                public boolean isDisposed() {
+                    return listener.isDisposed();
+                }
+                
+            });
+        }
+        
+        @Override
+        public void modify(Object context, Variant newValue) {
+            
+            Simantics.getSession().asyncRequest(new WriteRequest() {
+
+                @Override
+                public void perform(WriteGraph graph) throws DatabaseException {
+                    Variable contextVariable = Variables.getVariable(graph, (String)context);
+                    Variable configVariable = Variables.getVariable(graph,uri);
+                    Variable activeVariable = Variables.switchPossibleContext(graph, configVariable, contextVariable.getRepresents(graph));
+                    if(activeVariable == null) return;
+                    activeVariable.setValue(graph, newValue.getValue(), newValue.getBinding());
+                }
+            });
+            
+        }
+        
+    }
+    
+    public static CellEditor cellEditor(ReadGraph graph, Resource sheet) throws DatabaseException {
+        SpreadsheetResource SHEET = SpreadsheetResource.getInstance(graph);
+        Variable sheetVariable = Variables.getVariable(graph, sheet);
+        return sheetVariable.getPropertyValue(graph, SHEET.cellEditor);
+    }
+    
+    public static final String SPREADSHEET_TRANSACTION = "spreadsheetTransaction";
+
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    public static Object syncExec(CellEditor editor, OperationMode mode, Function fun) throws InterruptedException {
+        
+        Transaction tr = editor.startTransaction(mode);
+        
+        SCLContext context = SCLContext.getCurrent();
+        Transaction oldTransaction = (Transaction)context.put(SPREADSHEET_TRANSACTION, tr);
+        
+        Object result = null;
+        
+        try {
+
+            result = fun.apply(Tuple0.INSTANCE);
+            
+        } finally {
+            
+            tr.commit();
+            
+            context.put(SPREADSHEET_TRANSACTION, oldTransaction);
+            
+        }
+        
+        return result;
+        
+    }
+    
+    public static int cellColumn(ReadGraph graph, Variable cell) {
+        if(cell instanceof StandardGraphChildVariable) {
+            StandardGraphChildVariable sgcv = (StandardGraphChildVariable)cell;
+            SpreadsheetCell sc = (SpreadsheetCell)sgcv.node.node;
+            return sc.getColumn();
+        }
+        throw new IllegalStateException("Expected StandardGraphChildVariable, got " + cell.getClass().getName());
+    }
+    
 }
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetLine.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetLine.java
deleted file mode 100644 (file)
index ef6937f..0000000
+++ /dev/null
@@ -1,125 +0,0 @@
-package org.simantics.spreadsheet.graph;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-
-import org.simantics.spreadsheet.Range;
-import org.simantics.spreadsheet.resource.SpreadsheetResource;
-import org.simantics.spreadsheet.util.SpreadsheetUtils;
-
-import it.unimi.dsi.fastutil.objects.ObjectArrayList;
-
-public class SpreadsheetLine implements SpreadsheetElement<SpreadsheetCell, SpreadsheetLines>, SheetNode {
-
-       private static final long serialVersionUID = -304574098117404663L;
-       
-       final private SpreadsheetLines parent;
-       final public int row;
-       int id;
-       
-       public ObjectArrayList<SpreadsheetCell> cells = new ObjectArrayList<>();
-       
-       public SpreadsheetLine(SpreadsheetLines parent, int row) {
-               this.parent = parent;
-               this.row = row;
-               this.id = getEngine().getBook().getNewId(this);
-//             getEngine().registerRow(row, this);
-       }
-       
-       public int getId() {
-               return id;
-       }
-       
-       public SpreadsheetEngine getEngine() {
-//             if(parent instanceof SpreadsheetEngine)
-//                 return (SpreadsheetEngine)parent;
-               return ((SpreadsheetLines)parent).getEngine();
-       }
-
-       @Override
-       public String getName() {
-               return "Row"+row;
-       }
-
-       @Override
-       public Map getChildren() {
-               String rowName = ""+row;
-               Map<String,SpreadsheetCell> result = new HashMap<>();
-               for(int i=0;i<cells.size();i++) {
-                       SpreadsheetCell cell = cells.get(i);
-                       if(SpreadsheetCell.EMPTY == cell) continue;
-                       String name = "Row"+SpreadsheetUtils.columnName(i) + rowName;
-                       result.put(name, cell);
-               }
-               return result;
-       }
-
-       @Override
-       public Map getProperties() {
-               return Collections.singletonMap("typeURI", new SpreadsheetTypeNode(SpreadsheetResource.URIs.Line));
-       }
-       
-       Object resolve(String[] parts, int index) {
-               
-               if(index == parts.length) return this;
-               
-               Range r = SpreadsheetUtils.decodeCellAbsolute(parts[index]);
-               return cells.get(r.startColumn);
-               
-       }
-
-       public void accept(SpreadsheetVisitor v) {
-               v.visit(this);
-       }
-       
-       public String getPath() {
-               return ((SpreadsheetLines)parent).getPath() + "/" + getName();
-       }
-
-    @Override
-    public Optional<SpreadsheetLines> getParent() {
-        return Optional.of(parent);
-    }
-
-    @Override
-    public List<SpreadsheetCell> getSpreadsheetChildren() {
-        return cells;
-    }
-
-    @Override
-    public void remove(SpreadsheetCell child) {
-        
-    }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((parent == null) ? 0 : parent.hashCode());
-        result = prime * result + row;
-        return result;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj)
-            return true;
-        if (obj == null)
-            return false;
-        if (getClass() != obj.getClass())
-            return false;
-        SpreadsheetLine other = (SpreadsheetLine) obj;
-        if (parent == null) {
-            if (other.parent != null)
-                return false;
-        } else if (!parent.equals(other.parent))
-            return false;
-        if (row != other.row)
-            return false;
-        return true;
-    }
-
-}
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetLines.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetLines.java
deleted file mode 100644 (file)
index b3d6f09..0000000
+++ /dev/null
@@ -1,206 +0,0 @@
-package org.simantics.spreadsheet.graph;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Map;
-import java.util.Optional;
-
-import org.simantics.spreadsheet.resource.SpreadsheetResource;
-
-import it.unimi.dsi.fastutil.ints.Int2ObjectAVLTreeMap;
-
-public class SpreadsheetLines implements SpreadsheetElement<SpreadsheetLine, SpreadsheetEngine>, SheetNode {
-
-       private static final long serialVersionUID = -3615335969248723486L;
-       
-       private final int id;
-       private SpreadsheetEngine parent;
-       private String name;
-       public Int2ObjectAVLTreeMap<SpreadsheetLines> nodes = new Int2ObjectAVLTreeMap<SpreadsheetLines>();
-       public Int2ObjectAVLTreeMap<SpreadsheetLine> lines = new Int2ObjectAVLTreeMap<SpreadsheetLine>();
-       public int[] keys;
-
-       public SpreadsheetLines(SpreadsheetEngine parent, String name) {
-               this.parent = parent;
-               this.name = name;
-               id = getEngine().getBook().getNewId(this);
-       }
-
-       public SpreadsheetEngine getEngine() {
-               return parent;
-       }
-
-       public int getId() {
-               return id;
-       }
-       
-       @Override
-       public String getName() {
-               return name;
-       }
-
-       @Override
-       public Map getChildren() {
-               Int2ObjectAVLTreeMap result = new Int2ObjectAVLTreeMap();
-               result.putAll(nodes);
-               result.putAll(lines);
-               return result;
-       }
-
-       @Override
-       public Map getProperties() {
-               return Collections.singletonMap("typeURI", new SpreadsheetTypeNode(SpreadsheetResource.URIs.Lines));
-       } 
-       
-       Object resolve(String[] parts, int index) {
-               
-               String part = parts[index];
-               if(part.charAt(0) == 'R') {
-                       int indx = Integer.parseInt(part.substring(3));
-                       SpreadsheetLine line = lines.get(-indx);
-                       if(line != null) {
-                               if(index == parts.length-1) return line;
-                               else return line.resolve(parts, index+1);
-                       }
-               } else {
-                       int indx = Integer.parseInt(part);
-                       SpreadsheetLines node = nodes.get(indx);
-                       if(node != null) {
-                               if(index == parts.length-1) return node;
-                               else return node.resolve(parts, index+1);
-                       }
-               }
-               
-               return null;
-
-       }
-
-       public Object ensureSubprocess(String[] path, int index) {
-               
-               String name = path[index];
-
-               int i = Integer.parseInt(name);
-               SpreadsheetLines line = nodes.get(i);
-               if(line == null) {
-                       line = new SpreadsheetLines(parent, "" + i);
-                       nodes.put(i, line);
-               }
-
-               if(index == path.length - 1) {
-                       return line;
-               } else {
-                       return line.ensureSubprocess(path, index+1);
-               }
-               
-       }
-       
-       public void setKeys(int[] keys) {
-               this.keys = keys;
-       }
-       
-       @Override
-       public void accept(SpreadsheetVisitor v) {
-               v.visit(this);
-       }
-
-       public String getPath() {
-                       return "/" + parent.getName() + "/" + parent.lines.getName() + "/" + getName();
-       }
-
-       private int getKey(int index) {
-               return keys[2*index+1];
-       }
-
-       private int getChild(int index) {
-               return keys[2*index];
-       }
-
-       /*
-        *  [(child,key),...,key)
-        * 
-        */
-       public SpreadsheetLine getLine(int k) {
-               
-               int i=1;
-               int n = (keys.length - 1) / 2;
-               
-               while(i <= n && k > getKey(i-1)) i++;
-               
-               if(i <= n && k == getKey(i-1)) {
-                       return lines.get(-k);
-               }
-
-               int nodeName = getChild(i-1);
-               SpreadsheetLines node = nodes.get(nodeName);
-               if(node == null) return null;
-               return node.getLine(k);
-               
-       }
-       
-       public int getMaxRow() {
-               // if keys == null then this is the root of BTree which has only one child 
-               if (keys == null) {
-                       int maxRow = 0;
-                       for (SpreadsheetLines node : nodes.values()) {
-                               int row = node.getMaxRow();
-                               if (row > maxRow)
-                                       maxRow = row;
-                       }
-                       return maxRow;
-               }
-               int largestChild = keys[keys.length-1]; 
-               if(largestChild > 0) {
-                       SpreadsheetLines child = nodes.get(largestChild);
-                       return child.getMaxRow();
-               } else {
-                       return keys[keys.length-2];
-               }
-       }
-
-    @Override
-    public Optional<SpreadsheetEngine> getParent() {
-        return Optional.of(parent);
-    }
-
-    @Override
-    public Collection<SpreadsheetLine> getSpreadsheetChildren() {
-        return lines.values();
-    }
-
-    @Override
-    public void remove(SpreadsheetLine child) {
-        lines.remove(-child.row);
-    }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((name == null) ? 0 : name.hashCode());
-        result = prime * result + ((parent == null) ? 0 : parent.hashCode());
-        return result;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj)
-            return true;
-        if (obj == null)
-            return false;
-        if (getClass() != obj.getClass())
-            return false;
-        SpreadsheetLines other = (SpreadsheetLines) obj;
-        if (name == null) {
-            if (other.name != null)
-                return false;
-        } else if (!name.equals(other.name))
-            return false;
-        if (parent == null) {
-            if (other.parent != null)
-                return false;
-        } else if (!parent.equals(other.parent))
-            return false;
-        return true;
-    }
-       
-}
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetMapping.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetMapping.java
deleted file mode 100644 (file)
index 64079d2..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-package org.simantics.spreadsheet.graph;
-
-import java.io.Serializable;
-
-import org.simantics.spreadsheet.graph.synchronization.SheetLineComponent;
-import org.simantics.structural.synchronization.utils.ComponentFactory;
-import org.simantics.structural.synchronization.utils.MappingBase;
-import org.simantics.structural.synchronization.utils.Solver;
-import org.simantics.structural.synchronization.utils.StateUndoContextBase;
-
-public class SpreadsheetMapping extends MappingBase<SheetLineComponent> implements Serializable {
-       
-    private static final long serialVersionUID = -7556699663877911393L;
-    
-    final SheetLineComponent configuration;
-       
-       public SpreadsheetMapping(SheetLineComponent configuration) {
-           super(configuration, true);
-               this.configuration = configuration;
-       }
-
-       @Override
-       public SheetLineComponent getConfiguration() {
-               return configuration;
-       }
-
-       @Override
-       public StateUndoContextBase createUndoContext() {
-               return new StateUndoContextBase() {
-                       
-                       @Override
-                       public void saveState(Solver solver, int componentId, String uid) {
-                       }
-                       
-                       @Override
-                       public boolean loadState(Solver solver, int componentId, String uid) {
-                               return false;
-                       }
-               };
-       }
-
-       @Override
-       public ComponentFactory<SheetLineComponent> createComponentFactory() {
-               return new ComponentFactory<SheetLineComponent>() {
-
-                       @Override
-                       public SheetLineComponent create(String uid) {
-                               return new SheetLineComponent(uid);
-                       }
-                       
-               };
-       }
-
-}
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetMatrix.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetMatrix.java
deleted file mode 100644 (file)
index b9a4f95..0000000
+++ /dev/null
@@ -1,129 +0,0 @@
-package org.simantics.spreadsheet.graph;
-
-import java.io.Serializable;
-
-import org.simantics.databoard.binding.mutable.Variant;
-import org.simantics.spreadsheet.graph.formula.FormulaError2;
-
-public class SpreadsheetMatrix implements Serializable {
-
-       private static final long serialVersionUID = 5729700370527844640L;
-       
-       private int w;
-       private int h;
-       public Object[] values;
-       
-       public SpreadsheetMatrix(int w, int h) {
-               this.w = w;
-               this.h = h;
-               this.values = new Object[w*h];
-       }
-       
-       public Object get(int row, int column) {
-               return values[w*row+column];
-       }
-       
-       public void set(int row, int column, Object value) {
-               values[w*row+column] = value;
-       }
-
-       public int getWidth() {
-               return w;
-       }
-
-       public int getHeight() {
-               return h;
-       }
-       
-       public double sum() {
-               double result = 0;
-               for(int i=0;i<values.length;i++) {
-                       Number n = SpreadsheetGraphUtils.asValidNumber(values[i]);
-                       if(n != null) result += n.doubleValue();
-               }
-               return result;
-       }
-       
-       public Object sumWithFormulaError(){
-               Double result = 0.0;
-               for(int i = 0; i < values.length; i++){
-                       Object obj = values[i];
-                       if(obj != null){
-                               FormulaError2 error = FormulaError2.forObject(obj);
-                if(error!=null) return error.getString();
-                    
-                Number n = SpreadsheetGraphUtils.asValidNumber(obj);
-                               if(n != null) result += n.doubleValue();
-                       }
-               }
-               return result;
-       }
-
-       public double average() {
-               double result = 0;
-               double count = 0;
-               for(int i=0;i<values.length;i++) {
-                       Number n = SpreadsheetGraphUtils.asValidNumber(values[i]);
-                       if(n != null) {
-                               result += n.doubleValue();
-                               count++;
-                       }
-               }
-               if(count == 0) return result;
-               return result / count;
-       }
-       
-       public double countOfActualDoubleValues(){
-               double count = 0.0;
-               for(int i = 0; i < values.length; i++){
-                       Number n = SpreadsheetGraphUtils.asValidNumber(values[i]);
-                       if(n!=null) count++;
-               }
-               return count;
-       }
-       
-       public Object productWithFormulaError(){
-               Double result = 1.0;
-               boolean atLeastOne = false;
-               for(int i = 0; i < values.length; i++){
-                       Object obj = values[i];
-                       if(obj != null){
-                               FormulaError2 error = FormulaError2.forObject(obj);
-                       if(error!=null) return error.getString();
-                       
-                               Number n = SpreadsheetGraphUtils.asValidNumber(values[i]);
-                               if(n != null) {
-                                       double dval = n.doubleValue();
-                                       if(dval<=0) return FormulaError2.NUM.getString();
-                                       result = result*dval;
-                                       atLeastOne = true;
-                               }
-                       }
-               }
-               if(atLeastOne) return result;
-               else return 0.0;
-       }
-       
-       public SpreadsheetMatrix pow(Object exponent_) {
-               if(exponent_ instanceof SpreadsheetMatrix) {
-                       SpreadsheetMatrix exponent = (SpreadsheetMatrix)exponent_;
-                       SpreadsheetMatrix result = new SpreadsheetMatrix(exponent.w, h);
-                       for(int i=0;i<h;i++) {
-                               for(int j=0;j<exponent.w;j++) {
-                                       result.set(i,j, Math.pow(SpreadsheetGraphUtils.asNumber(get(i, 0)),
-                                                       SpreadsheetGraphUtils.asNumber(exponent.get(0, j))));
-                               }
-                       }
-                       return result;
-               } else {
-                       double n = SpreadsheetGraphUtils.asNumber(exponent_);
-                       SpreadsheetMatrix result = new SpreadsheetMatrix(w, h);
-                       for(int i=0;i<result.values.length;i++) {
-                               result.values[i] = Math.pow(SpreadsheetGraphUtils.asNumber(values[i]), n);
-                       }
-                       return result;
-               }
-       }
-       
-       
-}
\ No newline at end of file
index caa6dc23f4602d10589187018c99f66a9f1f9a24..64d002f831d81c7198406b877ef21b7cb46cd3e9 100644 (file)
@@ -1,22 +1,52 @@
 package org.simantics.spreadsheet.graph;
 
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
 import org.simantics.databoard.binding.Binding;
+import org.simantics.databoard.binding.mutable.Variant;
 import org.simantics.layer0.Layer0;
-import org.simantics.simulator.toolkit.StandardNodeManager;
+import org.simantics.simulator.toolkit.db.StandardVariableNodeManager;
 import org.simantics.simulator.variable.exceptions.NodeManagerException;
+import org.simantics.spreadsheet.SpreadsheetCellStyle;
 import org.simantics.spreadsheet.resource.SpreadsheetResource;
+import org.simantics.spreadsheet.solver.SheetNode;
+import org.simantics.spreadsheet.solver.SpreadsheetBook;
+import org.simantics.spreadsheet.solver.SpreadsheetBook.SpreadsheetBookListener;
+import org.simantics.spreadsheet.solver.SpreadsheetCell;
+import org.simantics.spreadsheet.solver.SpreadsheetCellContent;
+import org.simantics.spreadsheet.solver.SpreadsheetCellContentExpression;
+import org.simantics.spreadsheet.solver.SpreadsheetCellEditable;
+import org.simantics.spreadsheet.solver.SpreadsheetFormula;
+import org.simantics.spreadsheet.solver.SpreadsheetSCLConstant;
+import org.simantics.spreadsheet.solver.SpreadsheetTypeNode;
 import org.simantics.structural.stubs.StructuralResource2;
 
 @SuppressWarnings("rawtypes")
-public class SpreadsheetNodeManager extends StandardNodeManager<SheetNode, SpreadsheetBook> {
+public class SpreadsheetNodeManager extends StandardVariableNodeManager<SheetNode, SpreadsheetBook> {
 
     public SpreadsheetNodeManager(SpreadsheetRealm realm) {
         super(realm, realm.getEngine());
+        realm.getEngine().registerListener(new SpreadsheetBookListener() {
+            
+            @Override
+            public void cellsChanged(Collection<SpreadsheetCell> cells) {
+                realm.asyncExec(new Runnable() {
+                    @Override
+                    public void run() {
+                        for(SpreadsheetCell cell : cells) {
+                            refreshVariable(new SpreadsheetCellContent(cell));
+                            Object content = cell.getContent();
+                            if(content instanceof SpreadsheetFormula || content instanceof SpreadsheetSCLConstant)
+                                refreshVariable(new SpreadsheetCellContentExpression(cell));
+                        }
+                    }
+                });
+            }
+        });
     }
 
     static final Set<String> COMPONENT_CLASS = Collections.singleton(StructuralResource2.URIs.Component);
@@ -52,6 +82,12 @@ public class SpreadsheetNodeManager extends StandardNodeManager<SheetNode, Sprea
     public void setValue(SheetNode node, Object value, Binding binding) throws NodeManagerException {
        Set<SheetNode> dirtyNodeContents = findDirtyNodeContents(node);
        super.setValueAndFireSelectedListeners(node, value, binding, dirtyNodeContents);
+       if(value instanceof SpreadsheetFormula) {
+           SpreadsheetCellContent scc = (SpreadsheetCellContent)node;
+           SpreadsheetCellContentExpression scce = new SpreadsheetCellContentExpression(scc.cell);
+           // We need to also refresh the expression variable in this case
+           refreshVariable(scce);
+       }
     }
     
     //Find the cells that are used by this cell and their SpreadsheetContents, so that they can be marked as dirty later
@@ -78,4 +114,18 @@ public class SpreadsheetNodeManager extends StandardNodeManager<SheetNode, Sprea
        
        return dirtyNodeContents;
     }
+    
+    
+    @Override
+    protected Variant getEngineVariantOrCached(SheetNode node) throws NodeManagerException {
+        Variant variant = valueCache.get(node);
+        if(variant == null) {
+            Object value = realm.getEngine().getEngineValue(node);
+            Binding binding = realm.getEngine().getEngineBinding(node);
+            variant = new Variant(binding, value);
+            valueCache.put(node, variant);
+        }
+        return variant;
+    }
+    
 }
index 5ec73b1e5729ddea5eaa870c59c052a9a929308e..8812c847de0dc26130d66c76d7301fa0118d5114 100644 (file)
@@ -2,6 +2,8 @@ package org.simantics.spreadsheet.graph;
 
 import org.simantics.simulator.toolkit.StandardNodeManager;
 import org.simantics.simulator.toolkit.StandardRealm;
+import org.simantics.spreadsheet.solver.SheetNode;
+import org.simantics.spreadsheet.solver.SpreadsheetBook;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
index 6c3c0b17ca9c648f5401f48d181ef6da0b5166c7..371540a3827672e0ad6bcb8f5bc447dc6e551e8f 100644 (file)
@@ -1,6 +1,6 @@
 package org.simantics.spreadsheet.graph;
 
-import org.simantics.spreadsheet.graph.synchronization.SheetLineComponent;
+import org.simantics.spreadsheet.solver.SheetLineComponent;
 import org.simantics.structural.synchronization.base.ReferenceResolverBase;
 import org.simantics.structural.synchronization.utils.Solver;
 import org.slf4j.Logger;
index ec8935f285ced8713f9614c9fca87f6ecdce9329..936bee76e55db2033edbdb60336d6d89ba3a88f3 100644 (file)
@@ -20,9 +20,11 @@ import org.simantics.db.layer0.variable.Variable;
 import org.simantics.db.layer0.variable.Variables;
 import org.simantics.simulator.toolkit.StandardRealm;
 import org.simantics.simulator.toolkit.db.StandardVariableSessionManager;
-import org.simantics.spreadsheet.graph.formula.SpreadsheetEvaluationEnvironment;
 import org.simantics.spreadsheet.graph.synchronization.SpreadsheetSynchronizationEventHandler;
 import org.simantics.spreadsheet.resource.SpreadsheetResource;
+import org.simantics.spreadsheet.solver.SheetNode;
+import org.simantics.spreadsheet.solver.SpreadsheetBook;
+import org.simantics.spreadsheet.solver.formula.SpreadsheetEvaluationEnvironment;
 import org.simantics.structural.synchronization.client.Synchronizer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -136,7 +138,7 @@ public class SpreadsheetSessionManager extends StandardVariableSessionManager<Sh
                 return ic;
         }
 
-        SpreadsheetBook book = new SpreadsheetBook();
+        SpreadsheetBook book = new SpreadsheetBook(context.getURI(graph));
         
         Variable base = ProxyVariables.proxyVariableBase(graph, run);
         Resource bookResource = base.getRepresents(graph);
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetTypeNode.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetTypeNode.java
deleted file mode 100644 (file)
index b982f19..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-package org.simantics.spreadsheet.graph;
-
-import java.util.Collections;
-import java.util.Map;
-
-public class SpreadsheetTypeNode implements SheetNode {
-
-       public final String uri;
-       
-       public SpreadsheetTypeNode(String uri) {
-               this.uri = uri;
-       }
-       
-       @Override
-       public String getName() {
-               return "typeURI";
-       }
-
-       @Override
-       public Map getChildren() {
-               return Collections.emptyMap();
-       }
-
-       @Override
-       public Map getProperties() {
-               return Collections.emptyMap();
-       }
-
-}
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetVisitable.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetVisitable.java
deleted file mode 100644 (file)
index 192c7e2..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-package org.simantics.spreadsheet.graph;
-
-public interface SpreadsheetVisitable {
-       void accept(SpreadsheetVisitor v);
-}
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetVisitor.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetVisitor.java
deleted file mode 100644 (file)
index ff11703..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-package org.simantics.spreadsheet.graph;
-
-public interface SpreadsheetVisitor {
-
-       void visit(SpreadsheetBook book);
-       void visit(SpreadsheetEngine engine);
-       void visit(SpreadsheetLines node);
-       void visit(SpreadsheetLine line);
-       void visit(SpreadsheetCell cell);
-
-}
index 22695e52d7f4781c2ac88c1628209707b450808c..8650fc8f91fdc8e87dd205f1dd34e6fa10a7183e 100644 (file)
@@ -10,9 +10,9 @@ import org.simantics.db.layer0.variable.ConstantChildVariable;
 import org.simantics.db.layer0.variable.Variable;
 import org.simantics.db.layer0.variable.Variables;
 import org.simantics.spreadsheet.Range;
+import org.simantics.spreadsheet.Spreadsheets;
 import org.simantics.spreadsheet.common.cell.VariableCellEditor;
 import org.simantics.spreadsheet.resource.SpreadsheetResource;
-import org.simantics.spreadsheet.util.SpreadsheetUtils;
 
 public class DoubleArrayCellVariable extends ConstantChildVariable {
 
@@ -38,8 +38,8 @@ public class DoubleArrayCellVariable extends ConstantChildVariable {
                                        if(baseLocation == null) return;
                                        String editLocation = cell.getPossiblePropertyValue(graph, Variables.NAME);
                                        
-                                       Range baseRange = SpreadsheetUtils.decodeCellAbsolute(baseLocation);
-                                       Range editRange = SpreadsheetUtils.decodeCellAbsolute(editLocation);
+                                       Range baseRange = Spreadsheets.decodeCellAbsolute(baseLocation);
+                                       Range editRange = Spreadsheets.decodeCellAbsolute(editLocation);
                                        
                                        int x = editRange.startColumn - baseRange.startColumn;
                                        int y = editRange.startRow - baseRange.startRow;
index 896fd6602cdaa39ff7721639b9a39d7765555d29..a6db85a5e45db34cfe8f9b74a4bf64460ded52e0 100644 (file)
@@ -5,7 +5,6 @@ import java.util.Collection;
 import java.util.Collections;
 
 import org.simantics.databoard.Bindings;
-import org.simantics.databoard.Datatypes;
 import org.simantics.databoard.binding.Binding;
 import org.simantics.databoard.binding.mutable.Variant;
 import org.simantics.db.ReadGraph;
@@ -16,8 +15,8 @@ import org.simantics.db.layer0.variable.Variable;
 import org.simantics.db.layer0.variable.VariableFactory;
 import org.simantics.db.layer0.variable.Variables;
 import org.simantics.spreadsheet.SheetVariables;
+import org.simantics.spreadsheet.Spreadsheets;
 import org.simantics.spreadsheet.resource.SpreadsheetResource;
-import org.simantics.spreadsheet.util.SpreadsheetUtils;
 import org.simantics.utils.datastructures.datatype.RGBInt8;
 
 public class DoubleArrayCells implements VariableFactory {
@@ -49,7 +48,7 @@ public class DoubleArrayCells implements VariableFactory {
                for(int offset=0,i=0;i<rows;i++) {
                        for(int j=0;j<width;j++) {
                                double value = data[offset++];
-                               String valueLocation = SpreadsheetUtils.offset(location, i, j);
+                               String valueLocation = Spreadsheets.offset(location, i, j);
                                result.add(new DoubleArrayCellVariable(variable, valueLocation, propertyNames, bindings, new Object[] { Variant.ofInstance(value), fore, back, configuration, String.valueOf(value), false }));
                        }
                }
index 0244d5c07949fc897b01f9fc37f7ddf3dbe675a1..f3d8c1c2bbe961e7c774e04b24d5b64dfc40e544 100644 (file)
@@ -15,8 +15,8 @@ import org.simantics.db.layer0.variable.Variables;
 import org.simantics.layer0.Layer0;
 import org.simantics.spreadsheet.Range;
 import org.simantics.spreadsheet.SheetVariables;
+import org.simantics.spreadsheet.Spreadsheets;
 import org.simantics.spreadsheet.common.matrix.VariantMatrix;
-import org.simantics.spreadsheet.util.SpreadsheetUtils;
 
 public class SpreadsheetVariable extends ExtendedGraphChildVariable {
 
@@ -90,13 +90,13 @@ public class SpreadsheetVariable extends ExtendedGraphChildVariable {
        @Override
        public Variable getPossibleSpecialChild(ReadGraph graph, String name) throws DatabaseException {
                if(name.contains(":")) {
-                       Range range = SpreadsheetUtils.decodeRange(name, 0, 0);
+                       Range range = Spreadsheets.decodeRange(name, 0, 0);
                        
                        VariantMatrix matrix = new VariantMatrix(range.height(),range.width());
                        
                        for(int x=range.startColumn;x<=range.endColumn;x++) {
                                for(int y=range.startRow;y<=range.endRow;y++) {
-                                       String location = SpreadsheetUtils.cellName(y,x);
+                                       String location = Spreadsheets.cellName(y,x);
                                        Variable child = getPossibleChild(graph, location);
                                        Variant value = null;
                                        if(child != null)
index b75142b3462c262ed5bd0f884ee06f7794b158f2..041332451a5624a9097e5aa253882ee165f50d27 100644 (file)
@@ -13,8 +13,8 @@ import org.simantics.db.layer0.variable.ConstantChildVariable;
 import org.simantics.db.layer0.variable.Variable;
 import org.simantics.db.layer0.variable.VariableFactory;
 import org.simantics.db.layer0.variable.Variables;
+import org.simantics.spreadsheet.Spreadsheets;
 import org.simantics.spreadsheet.resource.SpreadsheetResource;
-import org.simantics.spreadsheet.util.SpreadsheetUtils;
 
 public class StringArrayCells implements VariableFactory {
 
@@ -39,7 +39,7 @@ public class StringArrayCells implements VariableFactory {
                for(int offset=0,i=0;i<rows;i++) {
                        for(int j=0;j<width;j++) {
                                String value = data[offset++];
-                               String valueLocation = SpreadsheetUtils.offset(location, i, j);
+                               String valueLocation = Spreadsheets.offset(location, i, j);
                                result.add(new ConstantChildVariable(variable, valueLocation, propertyNames, bindings, new Object[] { value, true }));
                        }
                }
index ae22581a2d3076769268dc33d078790e74d8980f..9cabb6c3249beb96098974f0327ff7738687a2d5 100644 (file)
@@ -12,7 +12,8 @@ import org.simantics.db.layer0.util.Layer0Utils;
 import org.simantics.db.layer0.variable.Variable;
 import org.simantics.db.request.Write;
 import org.simantics.spreadsheet.CellEditor;
-import org.simantics.spreadsheet.ClientModel.OperationMode;
+import org.simantics.spreadsheet.OperationMode;
+import org.simantics.spreadsheet.Transaction;
 import org.simantics.spreadsheet.util.SpreadsheetUtils;
 
 public class GraphCellEditorAdapter implements CellEditor<Write> {
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/AndFormulaFunction.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/AndFormulaFunction.java
deleted file mode 100644 (file)
index 4152188..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-package org.simantics.spreadsheet.graph.formula;
-
-import org.simantics.spreadsheet.graph.CellFormulaFunction;
-import org.simantics.spreadsheet.graph.CellValueVisitor;
-import org.simantics.spreadsheet.graph.SpreadsheetGraphUtils;
-import org.simantics.spreadsheet.graph.parser.ast.AstArgList;
-
-public class AndFormulaFunction implements CellFormulaFunction<Object> {
-
-    @Override
-    public Object evaluate(CellValueVisitor visitor, AstArgList args) {
-        if (args.values.size() == 0)
-            throw new IllegalStateException();
-        Boolean finalResult = Boolean.TRUE;
-        for (int i = 0; i < args.values.size(); i++) {
-               Object res = (args.values.get(i).accept(visitor));
-               FormulaError2 err = FormulaError2.forObject(res);
-               if(err!=null) return err.getString();
-               
-            if ((res instanceof Boolean && !((Boolean)res)) || !SpreadsheetGraphUtils.asBoolean(res))
-                finalResult = Boolean.FALSE;
-        }
-        return finalResult;
-    }
-}
\ No newline at end of file
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/AverageFormulaFunction.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/AverageFormulaFunction.java
deleted file mode 100644 (file)
index b8ca32e..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-package org.simantics.spreadsheet.graph.formula;
-
-import org.simantics.databoard.binding.mutable.Variant;
-import org.simantics.spreadsheet.graph.CellFormulaFunction;
-import org.simantics.spreadsheet.graph.CellValueVisitor;
-import org.simantics.spreadsheet.graph.SpreadsheetGraphUtils;
-import org.simantics.spreadsheet.graph.SpreadsheetMatrix;
-import org.simantics.spreadsheet.graph.parser.ast.AstArgList;
-import org.simantics.spreadsheet.graph.parser.ast.AstValue;
-
-public class AverageFormulaFunction implements CellFormulaFunction<Object> {
-
-    @Override
-    public Object evaluate(CellValueVisitor visitor, AstArgList args) {
-        if (args.values.size() == 0)
-            throw new IllegalStateException();
-        Double sum = 0.0;
-        double count = 0.0;
-        for(AstValue value : args.values){
-               Object res = value.accept(visitor);
-               if (res instanceof SpreadsheetMatrix) {
-              Object value2 = ((SpreadsheetMatrix) res).sumWithFormulaError();
-              if(value2 instanceof String) return value2;
-              
-              sum += ((Number)value2).doubleValue();
-              count += ((SpreadsheetMatrix) res).countOfActualDoubleValues();
-               } else {
-                       FormulaError2 err = FormulaError2.forObject(res);
-                       if(err!=null) return err.getString();
-                       
-                       if(res instanceof Variant){
-                               Double dVal = SpreadsheetGraphUtils.asDoubleWhereEmptyStringIsZero(res);
-                               if(dVal==null) res = ((Variant)res).toString();
-                               else res = dVal;
-                       }
-                       
-                       Double v = null;
-               if(res instanceof String && !res.equals("")){
-                       v = SpreadsheetGraphUtils.asDoubleWhereEmptyStringIsZero(res);
-               }
-               else if(res instanceof Number)
-                       v = SpreadsheetGraphUtils.asDoubleWhereEmptyStringIsZero(res);
-               
-                       if(v!=null){
-                               sum += v;
-                               count++;
-                       }
-               }
-        }
-        if(count==0.0) return FormulaError2.DIV0.getString();
-        return sum/count;
-    }
-}
\ No newline at end of file
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/CountifFormulaFunction.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/CountifFormulaFunction.java
deleted file mode 100644 (file)
index f34b89f..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-package org.simantics.spreadsheet.graph.formula;
-
-import org.simantics.spreadsheet.graph.CellFormulaFunction;
-import org.simantics.spreadsheet.graph.CellValueVisitor;
-import org.simantics.spreadsheet.graph.SpreadsheetGraphUtils;
-import org.simantics.spreadsheet.graph.SpreadsheetMatrix;
-import org.simantics.spreadsheet.graph.parser.ast.AstArgList;
-import org.simantics.spreadsheet.graph.parser.ast.AstRange;
-
-public class CountifFormulaFunction implements CellFormulaFunction<Integer> {
-
-    @Override
-    public Integer evaluate(CellValueVisitor visitor, AstArgList args) {
-        if (args.values.size() != 2) throw new IllegalStateException();
-        
-        AstRange range = (AstRange) args.values.get(0);
-        SpreadsheetMatrix matrix = (SpreadsheetMatrix) range.accept(visitor);
-        Object crit = null;
-        try {
-               crit = args.values.get(1).accept(visitor);
-        } catch (IllegalStateException e){
-               return 0;
-        }
-        
-        String criteria = SpreadsheetGraphUtils.asString(crit);
-        int result = 0;
-        for (Object value : matrix.values) {
-            if (SpreadsheetGraphUtils.matchCriteria(value, criteria))
-                result++;
-        }
-        return Integer.valueOf(result);
-    }
-}
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/FormulaError2.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/FormulaError2.java
deleted file mode 100644 (file)
index e47cbe8..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-package org.simantics.spreadsheet.graph.formula;
-
-import java.util.HashMap;
-import java.util.Map;
-import org.apache.poi.util.Internal;
-import org.simantics.databoard.binding.mutable.Variant;
-
-public enum FormulaError2{
-       @Internal
-       _NO_ERROR(-1, "(no error)"),NULL(0x00, "#NULL"),DIV0(0x07,"#DIV/0!"),VALUE(0x0F,
-       "#VALUE!"),REF(0x17,"#REF!"),NAME(0x1D,"#NAME?"),NUM(0x24,"#NUM!"),NA(0x2A, "#N/A"),
-       CIRCULAR_REF(0xFFFFFFC4, "~CIRCULAR~REF~"),FUNCTION_NOT_IMPLEMENTED(0xFFFFFFE2,"~FUNCTION~NOT~IMPLEMENTED~");
-       
-       private final String text;
-       //private final Integer longType;
-       //private final byte shortType;
-       
-       private static Map<String, FormulaError2> smap = new HashMap<String, FormulaError2>();
-       
-       private FormulaError2(int type, String text){
-               //this.longType = type;
-               //this.shortType = (byte)type;
-               this.text = text;
-       }
-       
-       static {
-               for(FormulaError2 error : values()) {
-                       smap.put(error.getString(), error);
-               }
-       }
-       
-       public String getString(){
-               return this.text;
-       }
-       
-       public static FormulaError2 forString(String errorName){
-        FormulaError2 err = smap.get(errorName);
-        return err;
-    }
-       
-       public static FormulaError2 forObject(Object errorObj){
-               if(errorObj instanceof Variant)
-                       return forString(((Variant)errorObj).getValue().toString());
-               else
-                       return forString(errorObj.toString());
-       }
-       
-       public static String handleErrorCall(Object value){
-               if(value==null) return VALUE.getString();
-               FormulaError2 error = FormulaError2.forObject(value);
-               if(error!=null) return error.getString();
-               return VALUE.getString();
-       }
-}
\ No newline at end of file
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/GeomeanFormulaFunction.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/GeomeanFormulaFunction.java
deleted file mode 100644 (file)
index 8868985..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-package org.simantics.spreadsheet.graph.formula;
-
-import org.simantics.spreadsheet.graph.CellFormulaFunction;
-import org.simantics.spreadsheet.graph.CellValueVisitor;
-import org.simantics.spreadsheet.graph.SpreadsheetGraphUtils;
-import org.simantics.spreadsheet.graph.SpreadsheetMatrix;
-import org.simantics.spreadsheet.graph.parser.ast.AstArgList;
-import org.simantics.spreadsheet.graph.parser.ast.AstValue;
-
-public class GeomeanFormulaFunction implements CellFormulaFunction<Object> {
-
-    @Override
-    public Object evaluate(CellValueVisitor visitor, AstArgList args) {
-        if (args.values.size() == 0)
-            throw new IllegalStateException();
-        double result = 1.0;
-        double count = 0.0;
-        for (AstValue value : args.values){
-               Object r = value.accept(visitor);
-               if (r instanceof SpreadsheetMatrix) {
-              Object v = ((SpreadsheetMatrix) r).productWithFormulaError();
-              if(v instanceof String) return v;
-              double dval = ((Number)v).doubleValue();
-              if(dval!=0.0){
-                  result = result*dval;
-                  count += ((SpreadsheetMatrix) r).countOfActualDoubleValues();
-              }
-               } else {
-                               FormulaError2 error = FormulaError2.forObject(r);
-                               if(error!=null) return error.getString();
-                       
-                               Number vNum = SpreadsheetGraphUtils.asValidNumber(r);
-                               Double v = null;
-                               if(vNum!=null) v = vNum.doubleValue();
-                               
-                       if(v!=null){
-                               if(v<=0) return FormulaError2.NUM.getString();
-                               result = result*v;
-                               count++;
-                       }
-               }
-        }
-        if(result==0.0 || count==0.0) return FormulaError2.NUM.getString();
-        return Double.valueOf(Math.pow(result, (1.0/count)));
-    }
-
-}
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/HlookupFormulaFunction.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/HlookupFormulaFunction.java
deleted file mode 100644 (file)
index 409ae8b..0000000
+++ /dev/null
@@ -1,139 +0,0 @@
-package org.simantics.spreadsheet.graph.formula;
-
-import org.simantics.databoard.binding.mutable.Variant;
-import org.simantics.spreadsheet.graph.CellFormulaFunction;
-import org.simantics.spreadsheet.graph.CellValueVisitor;
-import org.simantics.spreadsheet.graph.SpreadsheetGraphUtils;
-import org.simantics.spreadsheet.graph.SpreadsheetMatrix;
-import org.simantics.spreadsheet.graph.parser.ast.AstArgList;
-
-public class HlookupFormulaFunction implements CellFormulaFunction<Object> {
-
-    @Override
-    public Object evaluate(CellValueVisitor visitor, AstArgList args) {
-        if (args.values.size() < 3 || args.values.size() > 4) throw new IllegalStateException();
-
-        Object lookupValue = args.values.get(0).accept(visitor);
-        boolean lookupIsString = lookupValue instanceof String;
-
-        FormulaError2 error = FormulaError2.forObject(lookupValue);
-        if(error!=null) return error.getString();
-        
-        if(lookupValue instanceof Variant){
-               Object varVal = ((Variant)lookupValue).getValue();
-               Double dVal = SpreadsheetGraphUtils.asDoubleWhereEmptyStringIsZero(varVal);
-               if(dVal==null) {
-                       lookupValue = varVal.toString();
-                       lookupIsString = true;
-               }
-               else lookupValue = dVal;
-        }
-        
-        SpreadsheetMatrix array = (SpreadsheetMatrix) args.values.get(1).accept(visitor);
-        
-        boolean approximateMatch = args.values.size() == 4 ? (Boolean) args.values.get(3).accept(visitor) : true;
-
-               if(array.values.length != 0){
-                       if(lookupIsString){
-                               Object obj = array.values[0];
-                               if(obj instanceof Variant)
-                                       obj = ((Variant)obj).getValue();
-                               if(SpreadsheetGraphUtils.asValidNumber(obj)!=null)
-                                       return FormulaError2.NA.getString();
-                               obj = obj.toString();
-                               String valStr = ((String)obj).toLowerCase();
-                               if((lookupValue.toString().toLowerCase()).compareTo(valStr)<0 )
-                                       return FormulaError2.NA.getString();
-                       }
-                       else if(lookupValue instanceof Number){
-                               Double d = ((Number)lookupValue).doubleValue();
-                               Number d2 = SpreadsheetGraphUtils.asValidNumber(array.values[0]);
-                               if(d2==null || d<(d2.doubleValue()))
-                                       return FormulaError2.NA.getString();
-                       }
-               }
-
-        Number rowIndexN = (Number) SpreadsheetGraphUtils.asValidNumber(args.values.get(2).accept(visitor));
-        if(rowIndexN==null) return FormulaError2.REF.getString();
-        int rowIndexNum = rowIndexN.intValue();
-               if(rowIndexNum>array.getHeight()) return FormulaError2.REF.getString();
-               
-        if (approximateMatch) {
-               Integer colPosOfLargestValSmallerThanLookUp = null;
-               if(lookupIsString){
-                       String largestValSmallerThanLookUp = null;
-                       String ref = lookupValue.toString();
-                       String previousValue = null;
-                       for(int i = 0; i < array.getWidth(); i++){
-                               Object val = array.get(0, i);
-                               if(val instanceof Variant)
-                                       val = ((Variant)val).getValue();
-                               String currValue = val.toString();
-                               int currCompedToRef = currValue.compareTo(ref);
-                               if(currCompedToRef>=0){
-                                       if(i==0)
-                                               return array.get(rowIndexNum-1, i);
-                                       else if(previousValue.compareTo(ref) > currCompedToRef )
-                                               return array.get(rowIndexNum-1, i);
-                                       else 
-                                               return array.get(rowIndexNum - 1, i - 1);
-                               }
-                               if(colPosOfLargestValSmallerThanLookUp==null){
-                                       colPosOfLargestValSmallerThanLookUp = i;
-                                       largestValSmallerThanLookUp = currValue;
-                               } else if(largestValSmallerThanLookUp.compareTo(currValue)<0){
-                                       colPosOfLargestValSmallerThanLookUp = i;
-                                       largestValSmallerThanLookUp = currValue;
-                               }
-                               previousValue = currValue;
-                       }
-                       
-               } else {
-                       double ref = SpreadsheetGraphUtils.asNumber(lookupValue);
-                       double lastDiff = Double.MIN_VALUE;
-                       Double largestValSmallerThanLookUp = null;
-               for (int i = 0; i < array.getWidth(); i++) {
-                       Object value = array.get(0, i);
-                       double n = SpreadsheetGraphUtils.asNumber(value);
-                       double diff = n - ref;
-                       if (diff >= 0) {
-                       if (i == 0)
-                               return array.get(rowIndexNum - 1, i);
-                       else if (diff < -lastDiff)
-                               return array.get(rowIndexNum - 1, i);
-                       else
-                               return array.get(rowIndexNum - 1, i - 1);
-                       }
-                               if(colPosOfLargestValSmallerThanLookUp==null){
-                                       colPosOfLargestValSmallerThanLookUp = i;
-                                       largestValSmallerThanLookUp = n;
-                               } else if(largestValSmallerThanLookUp < n){
-                                       colPosOfLargestValSmallerThanLookUp = i;
-                                       largestValSmallerThanLookUp = n;
-                               }
-                       lastDiff = diff;
-               }
-               }
-               if(colPosOfLargestValSmallerThanLookUp!=null) return array.get(rowIndexNum - 1, colPosOfLargestValSmallerThanLookUp);
-               
-        } else {
-
-            for (int i = 0; i < array.getWidth(); i++) {
-                Object value = array.get(0, i);
-                if(value instanceof Variant){
-                       if(lookupIsString)
-                               value = ((Variant)value).getValue().toString();
-                       else 
-                               value = SpreadsheetGraphUtils.asNumber(value);
-                }
-                if (SpreadsheetGraphUtils.excelEquals(lookupValue, value)) {
-                    return array.get(rowIndexNum - 1, i);
-                }
-            }
-
-        }
-
-        return FormulaError2.NA.getString();
-    }
-
-}
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/MatchFormulaFunction.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/MatchFormulaFunction.java
deleted file mode 100644 (file)
index e9b7c7b..0000000
+++ /dev/null
@@ -1,202 +0,0 @@
-package org.simantics.spreadsheet.graph.formula;
-
-import org.simantics.databoard.binding.mutable.Variant;
-import org.simantics.spreadsheet.graph.CellFormulaFunction;
-import org.simantics.spreadsheet.graph.CellValueVisitor;
-import org.simantics.spreadsheet.graph.SpreadsheetGraphUtils;
-import org.simantics.spreadsheet.graph.SpreadsheetMatrix;
-import org.simantics.spreadsheet.graph.parser.ast.AstArgList;
-
-public class MatchFormulaFunction implements CellFormulaFunction<Object>{
-       
-       @Override
-    public Object evaluate(CellValueVisitor visitor, AstArgList args) {
-        if (args.values.size() < 2 || args.values.size() > 3) throw new IllegalStateException();
-        
-        SpreadsheetMatrix lookup_array = (SpreadsheetMatrix) args.values.get(1).accept(visitor);
-        if(lookup_array.getWidth()!=1 && lookup_array.getHeight()!=1) return FormulaError2.NA.getString();
-        
-        Object lookup_value = args.values.get(0).accept(visitor);
-        
-        int match_type = 1;
-        try{
-               if(args.values.size()==3){
-                       int matchArg = ((Number)args.values.get(2).accept(visitor)).intValue();
-                       if(matchArg<0)
-                               match_type = -1;
-                       else if(matchArg>0)
-                               match_type = 1;
-                       else
-                               match_type = 0;
-               }
-        } catch(Exception e) {
-               return FormulaError2.NA.getString();
-        }
-
-        boolean useHeight = false;
-        if(lookup_array.getWidth()==1) useHeight = true;
-        
-        int max = 0;
-        if(useHeight) max = lookup_array.getHeight();
-        else max = lookup_array.getWidth();
-
-        Integer pos = null;
-        if(lookup_value instanceof Variant){
-               Object obj = ((Variant)lookup_value).getValue();
-               Number nVal = SpreadsheetGraphUtils.asValidNumber(obj);
-               if(nVal!=null) obj = nVal;
-               else obj = obj.toString();
-        }
-        
-        if(lookup_value instanceof Number){
-               Double previousValue = null;
-               Double closestMatch = null;
-            Double lookup = ((Number)lookup_value).doubleValue();
-            int indexWhereCorrectOrderStartsAt = 0;
-            
-            if(match_type!=0) {
-               for(int i = 0; i < max;i++){
-                       Double currValue = null;
-                       Number currNum;
-                               if(useHeight){
-                                       currNum = SpreadsheetGraphUtils.asValidNumber(lookup_array.get(i,0));
-                               } else {
-                                       currNum = SpreadsheetGraphUtils.asValidNumber(lookup_array.get(0,i));
-                               }
-                               if(currNum!=null){
-                                       currValue = currNum.doubleValue();
-                               if(currValue != null){
-                                       if(previousValue!=null){
-                                               if((match_type==-1 && currValue>previousValue) || (match_type==1 && currValue<previousValue))
-                                                       indexWhereCorrectOrderStartsAt = i;
-                                               else
-                                                       break;
-                                       }
-                                       previousValue = currValue;
-                               }
-                       }
-               }
-            }
-            int begin = indexWhereCorrectOrderStartsAt;
-            
-            for(int i = begin; i < max;i++){
-                Double currValue = null;
-                Number currNum;
-                       if(useHeight){
-                               currNum = SpreadsheetGraphUtils.asValidNumber(lookup_array.get(i,0));
-                       } else {
-                               currNum = SpreadsheetGraphUtils.asValidNumber(lookup_array.get(0,i));
-                       }
-                       if(currNum!=null){
-                               currValue = currNum.doubleValue();
-                       if(currValue != null){
-                               if(previousValue==null) previousValue = currValue;
-                               if((match_type==-1 && currValue>previousValue) || (match_type==1 && currValue<previousValue)){
-                                       if(pos!=null)
-                                               return pos+1;
-                               previousValue = currValue;
-                               }
-                                       int comp = lookup.compareTo(currValue);
-                                       if(comp == 0){
-                                               closestMatch = currValue;
-                                               pos = i;
-                                       }
-                                       else if((comp > 0 && match_type==1) || (comp<0 && match_type==-1)){
-                                               if(closestMatch==null && pos==null){
-                                                       closestMatch = currValue;
-                                                       pos = i;
-                                               }
-                                               else if((currValue.compareTo(closestMatch)>=0 && match_type==1) || (currValue.compareTo(closestMatch)<=0 && match_type==-1)){
-                                                       closestMatch = currValue;
-                                                       pos = i;
-                                               }
-                                       }
-                               previousValue = currValue;
-                       }
-                }
-            }
-        }
-            
-        else if(lookup_value instanceof String){
-               String previousValue = null;
-               String closestMatch = null;
-            String lookup = (String)lookup_value;
-            int indexWhereCorrectOrderStartsAt = 0;
-            
-            if(match_type!=0) {
-               for(int i = 0; i < max;i++){
-                       String currValue = null;
-                       Object obj;
-                       if(useHeight){
-                               obj = lookup_array.get(i,0);
-                       } else {
-                               obj = lookup_array.get(0,i);
-                       }
-                       if(obj instanceof Variant){
-                               obj = ((Variant)obj).getValue();
-                       }
-                       if(obj!=null && !(obj instanceof Number)){
-                               currValue = obj.toString();
-                               currValue = currValue.toLowerCase();
-                       }
-                       if(currValue != null && !currValue.equals("")){
-                               if(previousValue!=null){
-                                       if((match_type==-1 && currValue.compareTo(previousValue)>0) || (match_type==1 && currValue.compareTo(previousValue)<0))
-                                               indexWhereCorrectOrderStartsAt = i;
-                                       else
-                                               break;
-                               }
-                               previousValue = currValue;
-                       }
-               }
-            }
-            
-            int begin = indexWhereCorrectOrderStartsAt;
-
-            for(int i = begin; i < max;i++){
-               String currValue = null;
-                       Object obj;
-                       if(useHeight){
-                               obj = lookup_array.get(i,0);
-                       } else {
-                               obj = lookup_array.get(0,i);
-                       }
-                       if(obj instanceof Variant){
-                               obj = ((Variant)obj).getValue();
-                       }
-                       if(obj!=null && !(obj instanceof Number)){
-                               currValue = obj.toString();
-                               currValue = currValue.toLowerCase();
-                       }
-
-                if(currValue != null && !currValue.equals("")){
-                       if(previousValue==null) previousValue = currValue;
-                       if((match_type==-1 && currValue.compareTo(previousValue)>0) || (match_type==1 && currValue.compareTo(previousValue)<0)){
-                               if(pos!=null)
-                                       return pos+1;
-                           previousValue = currValue;
-                       }
-                       int comp = lookup.compareTo(currValue);
-                       if(comp == 0){
-                               closestMatch = currValue;
-                               pos = i;
-                       }
-                               else if((comp > 0 && match_type==1) || (comp<0 && match_type==-1)){
-                                       if(closestMatch==null && pos==null){
-                                               closestMatch = currValue;
-                                               pos = i;
-                                       }
-                                       else if((currValue.compareTo(closestMatch)>=0 && match_type==1) || (currValue.compareTo(closestMatch)<=0 && match_type==-1)){
-                                               closestMatch = currValue;
-                                               pos = i;
-                                       }
-                               }
-                       previousValue = currValue;
-                }
-            }
-        }
-
-        if(pos==null)return FormulaError2.NA.getString();
-        return pos+1;
-    }
-}
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/OrFormulaFunction.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/OrFormulaFunction.java
deleted file mode 100644 (file)
index 9422211..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-package org.simantics.spreadsheet.graph.formula;
-
-import org.simantics.spreadsheet.graph.CellFormulaFunction;
-import org.simantics.spreadsheet.graph.CellValueVisitor;
-import org.simantics.spreadsheet.graph.SpreadsheetGraphUtils;
-import org.simantics.spreadsheet.graph.parser.ast.AstArgList;
-
-public class OrFormulaFunction implements CellFormulaFunction<Object> {
-
-    @Override
-    public Object evaluate(CellValueVisitor visitor, AstArgList args) {
-        if (args.values.size() == 0) throw new IllegalStateException();
-        
-        for (int i = 0; i < args.values.size(); i++) {
-               Object obj = null;
-               try {
-                       obj = args.values.get(i).accept(visitor);
-               } catch (IllegalStateException e){
-                       return FormulaError2.NAME.getString();
-               }
-               FormulaError2 error = FormulaError2.forObject(obj);
-               if(error!=null) return error.getString();
-               
-            if (SpreadsheetGraphUtils.asBoolean(obj))
-                return Boolean.TRUE;
-        }
-        return Boolean.FALSE;
-    }
-
-}
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/VlookupFormulaFunction.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/VlookupFormulaFunction.java
deleted file mode 100644 (file)
index 5f99cfc..0000000
+++ /dev/null
@@ -1,163 +0,0 @@
-package org.simantics.spreadsheet.graph.formula;
-
-import org.simantics.databoard.binding.mutable.Variant;
-import org.simantics.spreadsheet.graph.CellFormulaFunction;
-import org.simantics.spreadsheet.graph.CellValueVisitor;
-import org.simantics.spreadsheet.graph.SpreadsheetGraphUtils;
-import org.simantics.spreadsheet.graph.SpreadsheetMatrix;
-import org.simantics.spreadsheet.graph.parser.ast.AstArgList;
-
-public class VlookupFormulaFunction implements CellFormulaFunction<Object> {
-
-    @Override
-    public Object evaluate(CellValueVisitor visitor, AstArgList args) {
-        if (args.values.size() < 3 || args.values.size() > 4) throw new IllegalStateException();
-
-        Object lookupValue = args.values.get(0).accept(visitor);
-        boolean lookupIsString = lookupValue instanceof String;
-
-        FormulaError2 error = FormulaError2.forObject(lookupValue);
-        if(error!=null) return error.getString();
-        
-        if(lookupValue instanceof Variant){
-               Object varVal = ((Variant)lookupValue).getValue();
-               Double dVal = SpreadsheetGraphUtils.asDoubleWhereEmptyStringIsZero(varVal);
-               if(dVal==null) {
-                       lookupValue = varVal.toString();
-                       lookupIsString = true;
-               }
-               else lookupValue = dVal;
-        }
-
-        
-        SpreadsheetMatrix array = (SpreadsheetMatrix) args.values.get(1).accept(visitor);
-
-        boolean approximateMatch = args.values.size() == 4 ? (Boolean) args.values.get(3).accept(visitor) : true;
-
-        boolean valueExists = false;
-               if(array.values.length != 0){
-                       for(int i = 0; i < array.getHeight(); i++){
-                               if(lookupIsString){
-                                       Object obj = array.get(i,0);
-                                       if(obj instanceof Variant)
-                                               obj = ((Variant)obj).getValue();
-                                       if(obj!=null && SpreadsheetGraphUtils.asValidNumber(obj)==null){
-                                               obj = obj.toString();
-                                               String valStr = ((String)obj).toLowerCase();
-                                               if((lookupValue.toString().toLowerCase()).compareTo(valStr)>=0 ){
-                                                       valueExists = true;
-                                                       break;
-                                               }
-                                       }
-                               }
-                               else if(lookupValue instanceof Number){
-                                       Double d = ((Number)lookupValue).doubleValue();
-                                       Number d2 = SpreadsheetGraphUtils.asValidNumber(array.get(i,0));
-                                       if(d2!=null && d>=(d2.doubleValue())){
-                                               valueExists = true;
-                                               break;
-                                       }
-                               }
-                       }
-//                     if(lookupIsString){
-//                             Object obj = array.values[0];
-//                             if(obj instanceof Variant)
-//                                     obj = ((Variant)obj).getValue();
-//                             if(SpreadsheetGraphUtils.asValidNumber(obj)!=null)
-//                                     return FormulaError2.NA.getString();
-//                             obj = obj.toString();
-//                             String valStr = ((String)obj).toLowerCase();
-//                             if((lookupValue.toString().toLowerCase()).compareTo(valStr)<0 )
-//                                     return FormulaError2.NA.getString();
-//                     }
-//                     else if(lookupValue instanceof Number){
-//                             Double d = ((Number)lookupValue).doubleValue();
-//                             Number d2 = SpreadsheetGraphUtils.asValidNumber(array.values[0]);
-//                             if(d2==null || d<(d2.doubleValue()))
-//                                     return FormulaError2.NA.getString();
-//                     }
-               }
-               if(!valueExists) return FormulaError2.NA.getString();
-               
-               Number colIndexN = SpreadsheetGraphUtils.asValidNumber(args.values.get(2).accept(visitor));
-               if(colIndexN==null) return FormulaError2.REF.getString();
-               int colIndexNum = colIndexN.intValue();
-        if(colIndexNum>array.getWidth()) return FormulaError2.REF.getString();
-        
-        if (approximateMatch) {
-               Integer rowPosOfLargestValSmallerThanLookUp = null;
-               if(lookupIsString){
-                       String ref = lookupValue.toString().toLowerCase();
-                       String previousValue = null;
-                       String largestValSmallerThanLookUp = null;
-                       for(int i = 0; i < array.getHeight(); i++){
-                               Object val = array.get(i, 0);
-                               if(val instanceof Variant)
-                                       val = ((Variant)val).getValue();
-                               String currValue = val.toString().toLowerCase();
-                               if(currValue.compareTo(ref)>0){
-                                       if(i==0)
-                                               return array.get(i, colIndexNum-1);
-                                       else if(previousValue.compareTo(ref) > currValue.compareTo(ref))
-                                               return array.get(i, colIndexNum-1);
-                                       else 
-                                               return array.get(i - 1, colIndexNum - 1);
-                               }
-                               if(rowPosOfLargestValSmallerThanLookUp==null){
-                                       rowPosOfLargestValSmallerThanLookUp = i;
-                                       largestValSmallerThanLookUp = currValue;
-                               } else if(largestValSmallerThanLookUp.compareTo(currValue)<0){
-                                       rowPosOfLargestValSmallerThanLookUp = i;
-                                       largestValSmallerThanLookUp = currValue;
-                               }
-                               previousValue = currValue;
-                       }
-                       
-               } else {
-                       double ref = SpreadsheetGraphUtils.asNumber(lookupValue);
-               double lastDiff = Double.MIN_VALUE;
-               Double largestValSmallerThanLookUp = null;
-               for (int i = 0; i < array.getHeight(); i++) {
-                       Object value = array.get(i, 0);
-                       double n = SpreadsheetGraphUtils.asNumber(value);
-                       double diff = n - ref;
-                       if (diff > 0) {
-                       if (i == 0)
-                               return array.get(i, colIndexNum - 1);
-                       else if (diff < -lastDiff)
-                               return array.get(i, colIndexNum - 1);
-                       else
-                               return array.get(i - 1, colIndexNum - 1);
-                       }
-                               if(rowPosOfLargestValSmallerThanLookUp==null){
-                                       rowPosOfLargestValSmallerThanLookUp = i;
-                                       largestValSmallerThanLookUp = n;
-                               } else if(largestValSmallerThanLookUp < n){
-                                       rowPosOfLargestValSmallerThanLookUp = i;
-                                       largestValSmallerThanLookUp = n;
-                               }
-                       lastDiff = diff;
-               }
-               }
-               
-               if(rowPosOfLargestValSmallerThanLookUp!=null) return array.get(rowPosOfLargestValSmallerThanLookUp, colIndexNum - 1);
-        
-        } else {
-            for (int i = 0; i < array.getHeight(); i++) {
-                Object value = array.get(i, 0);
-                if(value instanceof Variant){
-                       if(lookupIsString)
-                               value = ((Variant)value).getValue().toString();
-                       else 
-                               value = SpreadsheetGraphUtils.asNumber(value);
-                }
-                if (SpreadsheetGraphUtils.excelEquals(lookupValue, value)) {
-                    return array.get(i, colIndexNum - 1);
-                }
-            }
-        }
-
-        return FormulaError2.NA.getString();
-    }
-
-}
index 98ef90231fc6be36999667b377ad46fe1cd5b516..49099344135daab31bc72218b881568e278298dd 100644 (file)
@@ -54,22 +54,25 @@ import org.simantics.simulator.variable.exceptions.NodeManagerException;
 import org.simantics.spreadsheet.CellEditor;
 import org.simantics.spreadsheet.ClientModel;
 import org.simantics.spreadsheet.Range;
-import org.simantics.spreadsheet.graph.ExcelFormula;
-import org.simantics.spreadsheet.graph.SheetNode;
-import org.simantics.spreadsheet.graph.SpreadsheetBook;
-import org.simantics.spreadsheet.graph.SpreadsheetCell;
-import org.simantics.spreadsheet.graph.SpreadsheetCellContent;
-import org.simantics.spreadsheet.graph.SpreadsheetFormula;
+import org.simantics.spreadsheet.Transaction;
 import org.simantics.spreadsheet.graph.SpreadsheetGraphUtils;
-import org.simantics.spreadsheet.graph.SpreadsheetSCLConstant;
 import org.simantics.spreadsheet.graph.SpreadsheetSessionManager;
-import org.simantics.spreadsheet.graph.SpreadsheetStyle;
-import org.simantics.spreadsheet.graph.SpreadsheetStyle.SpreadsheetStyleBuilder;
 import org.simantics.spreadsheet.graph.celleditor.GraphCellEditorAdapter;
-import org.simantics.spreadsheet.graph.parser.ParseException;
-import org.simantics.spreadsheet.graph.parser.SheetFormulaParser;
-import org.simantics.spreadsheet.graph.parser.ast.AstValue;
 import org.simantics.spreadsheet.resource.SpreadsheetResource;
+import org.simantics.spreadsheet.solver.SheetNode;
+import org.simantics.spreadsheet.solver.SpreadsheetBook;
+import org.simantics.spreadsheet.solver.SpreadsheetCell;
+import org.simantics.spreadsheet.solver.SpreadsheetCellContent;
+import org.simantics.spreadsheet.solver.SpreadsheetFormula;
+import org.simantics.spreadsheet.solver.SpreadsheetSCLConstant;
+import org.simantics.spreadsheet.solver.SpreadsheetStyle;
+import org.simantics.spreadsheet.solver.SpreadsheetStyle.SpreadsheetStyleBuilder;
+import org.simantics.spreadsheet.solver.formula.parser.ParseException;
+import org.simantics.spreadsheet.solver.formula.parser.SheetFormulaParser;
+import org.simantics.spreadsheet.solver.formula.parser.ast.AstValue;
+import org.simantics.spreadsheet.synchronization.ExcelFormula;
+import org.simantics.spreadsheet.synchronization.LineContentBean;
+import org.simantics.spreadsheet.synchronization.LineContentBeanCell;
 import org.simantics.spreadsheet.util.SpreadsheetUtils;
 
 import gnu.trove.map.TMap;
index 5327d9b7cb389363fa9d88cc6e79963f04921657..aad988fb94cbe10c9f6926730ebc04bf7d0ffa75 100644 (file)
@@ -20,6 +20,7 @@ import org.simantics.db.layer0.variable.VariableNode;
 import org.simantics.db.layer0.variable.Variables;
 import org.simantics.spreadsheet.Range;
 import org.simantics.spreadsheet.SheetVariables;
+import org.simantics.spreadsheet.Spreadsheets;
 import org.simantics.spreadsheet.common.matrix.VariantMatrix;
 import org.simantics.spreadsheet.graph.Ranges;
 import org.simantics.spreadsheet.resource.SpreadsheetResource;
@@ -77,7 +78,7 @@ public class SpreadsheetRootVariable extends StandardGraphChildVariable {
         
         if(name.contains(":")) {
                
-            Range range = SpreadsheetUtils.decodeRange(name, 0, 0);
+            Range range = Spreadsheets.decodeRange(name, 0, 0);
             
             VariantMatrix matrix = new VariantMatrix(range.height(),range.width());
             String rangeNames[][] = new String[range.height()][range.width()];
@@ -85,7 +86,7 @@ public class SpreadsheetRootVariable extends StandardGraphChildVariable {
             
             for(int x=range.startColumn;x<=range.endColumn;x++) {
                 for(int y=range.startRow;y<=range.endRow;y++) {
-                    String location = SpreadsheetUtils.cellName(y,x);
+                    String location = Spreadsheets.cellName(y,x);
                     Variable child = context.getPossibleChild(graph, location);
                     Variant value = null;
                     if(child != null)
index be73a741cdb633532055ff67ccd6878b13dece54..71466070ef099d03bbfc947570d43980b98f117a 100644 (file)
@@ -29,7 +29,7 @@ import org.simantics.db.layer0.variable.Variable;
 import org.simantics.db.layer0.variable.Variables;
 import org.simantics.layer0.Layer0;
 import org.simantics.spreadsheet.Range;
-import org.simantics.spreadsheet.util.SpreadsheetUtils;
+import org.simantics.spreadsheet.Spreadsheets;
 
 public class SpreadsheetExpressionVisitor extends DepthFirstAdapter {
 
@@ -220,13 +220,13 @@ public class SpreadsheetExpressionVisitor extends DepthFirstAdapter {
                
                String identifier = node.toString().trim();
 
-               Range range = SpreadsheetUtils.decodeRange(identifier, row, column);
+               Range range = Spreadsheets.decodeRange(identifier, row, column);
                if (range.size() != 1) {
                        ArrayList<Object> value = new ArrayList<Object>();
                        for (int c = range.startColumn; c <= range.endColumn; c++) {
                                for (int r = range.startRow; r <= range.endRow; r++) {
                                        try {
-                                               String location = SpreadsheetUtils.cellName(r, c);
+                                               String location = Spreadsheets.cellName(r, c);
                                                Variable cell = cellVariable.getChild(graph, location);
                                                System.out.println("cell=" + cell.getURI(graph));
                                                String label = cell.getPossiblePropertyValue(graph, "Label");
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/synchronization/LineCommandBuilder.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/synchronization/LineCommandBuilder.java
deleted file mode 100644 (file)
index 90c96cc..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
-package org.simantics.spreadsheet.graph.synchronization;
-
-import java.io.StringReader;
-
-import org.simantics.databoard.adapter.AdaptException;
-import org.simantics.databoard.binding.mutable.Variant;
-import org.simantics.spreadsheet.graph.ExcelArrayFormula;
-import org.simantics.spreadsheet.graph.ExcelFormula;
-import org.simantics.spreadsheet.graph.SpreadsheetBook;
-import org.simantics.spreadsheet.graph.SpreadsheetCell;
-import org.simantics.spreadsheet.graph.SpreadsheetFormula;
-import org.simantics.spreadsheet.graph.SpreadsheetLine;
-import org.simantics.spreadsheet.graph.SpreadsheetLines;
-import org.simantics.spreadsheet.graph.SpreadsheetSCLConstant;
-import org.simantics.spreadsheet.graph.function.LineContentBean;
-import org.simantics.spreadsheet.graph.function.LineContentBeanCell;
-import org.simantics.spreadsheet.graph.parser.SheetFormulaParser;
-import org.simantics.spreadsheet.graph.parser.ast.AstArrayFormulaReference;
-import org.simantics.spreadsheet.graph.parser.ast.AstValue;
-import org.simantics.structural.synchronization.base.CommandBuilder;
-import org.simantics.structural.synchronization.utils.Solver;
-
-public class LineCommandBuilder implements CommandBuilder {
-       
-       private String name;
-//     private boolean update;
-       LineContentBean bean;
-       
-       public LineCommandBuilder(String name, boolean update) {
-               this.name = name;
-//             this.update = update;
-       }
-
-       @Override
-       public void apply(Solver solver) {
-               
-               SpreadsheetBook book = solver.getConcreteSolver();
-               
-               String path = name.substring(0, name.lastIndexOf("/"));
-               String lineName = name.substring(name.lastIndexOf("/")+1);
-               int row = Integer.parseInt(lineName.substring(3));
-               
-               SpreadsheetLines node = book.ensureSubprocess(path);
-               SpreadsheetLine line = node.lines.get(-row);
-               if(line == null) {
-                       line = new SpreadsheetLine(node, row);
-                       node.lines.put(-row, line);
-               }
-               
-//             line.cells.clear();
-               for(int i=0;i<bean.cells.length;i++) {
-                       
-                   SpreadsheetCell currentCell;
-                   if (line.cells.size() > i) {
-                       currentCell = line.cells.get(i);
-                   } else {
-                       currentCell = new SpreadsheetCell(line, i);
-                       line.cells.add(currentCell);
-                   }
-                   
-                       LineContentBeanCell cell = bean.cells[i];
-                       
-                       try {
-                               Object content = cell.getContent();
-                               if (content instanceof Variant) {
-                                   Variant cellVariant = (Variant) content;
-                                   if (cellVariant == LineContentBeanCell.EMPTY) {
-                                       currentCell.setStyle(cell.getStyleId());
-                                       // Empty content
-                                       currentCell.setContent("");
-//                                     if (currentCell != SpreadsheetCell.EMPTY) {
-//                                         line.cells.remove(i);
-//                                         line.cells.add(i, SpreadsheetCell.EMPTY);
-//                                     }
-                                   } else if(ExcelFormula.BINDING.type().equals(cellVariant.getBinding().type())) {
-                           ExcelFormula formula = (ExcelFormula)cellVariant.getValue(ExcelFormula.BINDING);
-                           SheetFormulaParser p = new SheetFormulaParser(new StringReader(formula.expression));
-                           AstValue v = p.relation();
-                        currentCell.setStyle(cell.getStyleId());
-                        SpreadsheetFormula sformula = new SpreadsheetFormula(v, formula.expression);
-                        currentCell.setContent(sformula);
-                       } else if (ExcelArrayFormula.BINDING.type().equals(cellVariant.getBinding().type())) {
-                           ExcelArrayFormula formula = (ExcelArrayFormula)cellVariant.getValue(ExcelArrayFormula.BINDING);
-                           SheetFormulaParser p = new SheetFormulaParser(new StringReader(formula.expression));
-                           AstArrayFormulaReference v = new AstArrayFormulaReference(formula.range, p.relation());
-                        currentCell.setStyle(cell.getStyleId());
-                        SpreadsheetFormula sformula = new SpreadsheetFormula(v, formula.expression);
-                        currentCell.setContent(sformula);
-                       } else {
-                        currentCell.setStyle(cell.getStyleId());
-                        // DO not update constant values during update
-                        currentCell.setContent(cellVariant.getValue());
-                       }
-                               } else if (content instanceof SpreadsheetSCLConstant){
-                    currentCell.setStyle(cell.getStyleId());
-                    currentCell.setContent(content);
-                               }
-                       } catch (Throwable e) {
-                           Object content = cell.getContent();
-                if (content instanceof Variant) {
-                    Variant cellVariant = (Variant) content;
-                    currentCell.setStyle(cell.getStyleId());
-                    currentCell.setContent(content);
-                    try {
-                        new Exception("failed: " + ((ExcelFormula)(cellVariant.getValue(ExcelFormula.BINDING))).expression, e).printStackTrace();
-                    } catch (AdaptException e1) {
-                        e1.printStackTrace();
-                    }
-                } else {
-                    currentCell.setStyle(cell.getStyleId());
-                    currentCell.setContent("LCB error happened");
-                }
-                       }
-               }
-       }
-
-       @SuppressWarnings("unchecked")
-       @Override
-       public <T> T getConcrete() {
-               return (T)this;
-       }
-       
-}
\ No newline at end of file
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/synchronization/LineNodeUpdater.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/synchronization/LineNodeUpdater.java
deleted file mode 100644 (file)
index 811a35c..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-package org.simantics.spreadsheet.graph.synchronization;
-
-import java.util.Collection;
-import java.util.Map;
-
-import org.simantics.databoard.binding.mutable.Variant;
-import org.simantics.structural.synchronization.base.CommandBuilder;
-import org.simantics.structural.synchronization.base.ModuleUpdateContext;
-import org.simantics.structural.synchronization.base.ModuleUpdaterBase;
-import org.simantics.structural.synchronization.base.PropertyUpdateRule;
-
-public class LineNodeUpdater extends ModuleUpdaterBase<SheetLineComponent> {
-       
-       public LineNodeUpdater(String id) {
-               
-               super(id);
-               
-               isComposite = true;
-               
-               addPropertyUpdateRule(new PropertyUpdateRule<SheetLineComponent>() {
-                       
-                       @Override
-                       public String getPropertyName() {
-                               return "keys";
-                       }
-                       
-                       @Override
-                       public void apply(ModuleUpdateContext<SheetLineComponent> context, boolean isCreating,
-                                       Map<String, Variant> propertyMap, Map<String, Collection<String>> connectionMap, Variant value) {
-                               
-                               LinesCommandBuilder builder = context.<LinesCommandBuilder>getConcreteCommand();
-                               Variant v = propertyMap.get("keys");
-                               if (v != null & v.getValue() != null)
-                                   builder.keys = (int[])v.getValue();
-                               
-                       }
-                       
-               });
-               
-       }
-
-       @Override
-       public CommandBuilder createAddCommandBuilder(String name) {
-               return new LinesCommandBuilder(name, false);
-       }
-
-       @Override
-       public CommandBuilder createUpdateCommandBuilder(String name) {
-               return new LinesCommandBuilder(name, true);
-       }
-       
-}
\ No newline at end of file
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/synchronization/LineUpdater.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/synchronization/LineUpdater.java
deleted file mode 100644 (file)
index 18f0bfb..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-package org.simantics.spreadsheet.graph.synchronization;
-
-import java.util.Collection;
-import java.util.Map;
-
-import org.simantics.databoard.adapter.AdaptException;
-import org.simantics.databoard.binding.mutable.Variant;
-import org.simantics.spreadsheet.graph.function.LineContentBean;
-import org.simantics.structural.synchronization.base.CommandBuilder;
-import org.simantics.structural.synchronization.base.ModuleUpdateContext;
-import org.simantics.structural.synchronization.base.ModuleUpdaterBase;
-import org.simantics.structural.synchronization.base.PropertyUpdateRule;
-
-public class LineUpdater extends ModuleUpdaterBase<SheetLineComponent> {
-       
-       public LineUpdater(String id) {
-               super(id);
-               addPropertyUpdateRule(new PropertyUpdateRule<SheetLineComponent>() {
-                       
-                       @Override
-                       public String getPropertyName() {
-                               return "content";
-                       }
-                       
-                       @Override
-                       public void apply(ModuleUpdateContext<SheetLineComponent> context, boolean isCreating,
-                                       Map<String, Variant> propertyMap, Map<String, Collection<String>> connectionMap, Variant value) {
-                               
-                               LineCommandBuilder builder = context.<LineCommandBuilder>getConcreteCommand();
-                try {
-                    LineContentBean valuee = (LineContentBean) value.getValue(LineContentBean.BINDING);
-                    builder.bean = valuee;
-                } catch (AdaptException e) {
-                    e.printStackTrace();
-                } catch (ClassCastException e) {
-                    e.printStackTrace();
-                }
-//                             if (valuee instanceof LineContentBean)
-//                         
-//                     else
-//                         System.err.println("valuee is instanceof " + valuee.getClass().getSimpleName() + " " + valuee);
-                       
-                       }
-                       
-               });
-       }
-
-       @Override
-       public CommandBuilder createAddCommandBuilder(String name) {
-               return new LineCommandBuilder(name, false);
-       }
-
-       @Override
-       public CommandBuilder createUpdateCommandBuilder(String name) {
-               return new LineCommandBuilder(name, true);
-       }
-       
-}
\ No newline at end of file
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/synchronization/LinesCommandBuilder.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/synchronization/LinesCommandBuilder.java
deleted file mode 100644 (file)
index 4cf804c..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-package org.simantics.spreadsheet.graph.synchronization;
-
-import org.simantics.spreadsheet.graph.SpreadsheetBook;
-import org.simantics.spreadsheet.graph.SpreadsheetLines;
-import org.simantics.structural.synchronization.base.CommandBuilder;
-import org.simantics.structural.synchronization.utils.Solver;
-
-public class LinesCommandBuilder implements CommandBuilder {
-       
-       private final boolean update;
-    private String name;
-       int[] keys;
-       
-       public LinesCommandBuilder(String name, boolean update) {
-               this.name = name;
-               this.update = update;
-       }
-
-       @Override
-       public void apply(Solver solver) {
-//         if (update)
-//             return;
-               
-               SpreadsheetBook book = solver.getConcreteSolver();
-               SpreadsheetLines node = book.ensureSubprocess(name);
-               node.setKeys(keys);
-               
-//             String path = name.substring(0, name.lastIndexOf("/"));
-//             String lineName = name.substring(name.lastIndexOf("/")+1);
-//             int row = Integer.parseInt(lineName.substring(3));
-//             
-               
-//             SpreadsheetLine line = node.lines.get(-row);
-//             if(line == null) {
-//                     line = new SpreadsheetLine(node, row);
-//                     node.lines.put(-row, line);
-//             }
-//             
-//             for(int i=0;i<bean.cells.length;i++) {
-//                     
-//                     LineContentBeanCell cell = bean.cells[i];
-//                     
-//                     try {
-//                             
-//                             if(ExcelFormula.BINDING.type().equals(cell.content.getBinding().type())) {
-//                                     ExcelFormula formula = (ExcelFormula)cell.content.getValue(ExcelFormula.BINDING);
-//                                     SheetFormulaParser p = new SheetFormulaParser(new StringReader(formula.expression));
-//                                     AstValue v = p.relation();
-//                                     line.cells.add(new SpreadsheetCell(line, i, new SpreadsheetFormula(v, formula.expression), 0));
-//                             } else {
-//                                     line.cells.add(new SpreadsheetCell(line, i, cell.content.getValue(), 0));
-//                             }
-//                     } catch (Throwable e) {
-//                             line.cells.add(new SpreadsheetCell(line, i, cell.content.getValue(), 0));
-//                             try {
-//                                     new Exception("failed: " + ((ExcelFormula)(cell.content.getValue(ExcelFormula.BINDING))).expression, e).printStackTrace();
-//                             } catch (AdaptException e1) {
-//                                     e1.printStackTrace();
-//                             }
-//                     }
-//                     
-//             }
-               
-       }
-
-       @SuppressWarnings("unchecked")
-       @Override
-       public <T> T getConcrete() {
-               return (T)this;
-       }
-       
-}
\ No newline at end of file
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/synchronization/NullCommandBuilder.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/synchronization/NullCommandBuilder.java
deleted file mode 100644 (file)
index 80ed1ca..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-package org.simantics.spreadsheet.graph.synchronization;
-
-import org.simantics.structural.synchronization.base.CommandBuilder;
-import org.simantics.structural.synchronization.utils.Solver;
-
-public class NullCommandBuilder implements CommandBuilder {
-       
-       @Override
-       public void apply(Solver solver) {
-       }
-
-       @SuppressWarnings("unchecked")
-       @Override
-       public <T> T getConcrete() {
-               return (T)this;
-       }
-       
-}
\ No newline at end of file
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/synchronization/NullUpdater.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/synchronization/NullUpdater.java
deleted file mode 100644 (file)
index e03169f..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-package org.simantics.spreadsheet.graph.synchronization;
-
-import org.simantics.structural.synchronization.base.CommandBuilder;
-import org.simantics.structural.synchronization.base.ModuleUpdaterBase;
-
-public class NullUpdater extends ModuleUpdaterBase<SheetLineComponent> {
-       
-       public NullUpdater(String typeId) {
-               super(typeId);
-               isComposite = true;
-       }
-
-       @Override
-       public CommandBuilder createAddCommandBuilder(String name) {
-               return new NullCommandBuilder();
-       }
-
-       @Override
-       public CommandBuilder createUpdateCommandBuilder(String name) {
-               return new NullCommandBuilder();
-       }
-       
-}
\ No newline at end of file
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/synchronization/SheetLineComponent.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/synchronization/SheetLineComponent.java
deleted file mode 100644 (file)
index 5edea56..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-package org.simantics.spreadsheet.graph.synchronization;
-
-import java.io.Serializable;
-
-import org.simantics.structural.synchronization.utils.ComponentBase;
-
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.procedure.TObjectProcedure;
-
-public class SheetLineComponent extends ComponentBase<SheetLineComponent> implements Serializable {
-
-    private static final long serialVersionUID = 1777515716175831266L;
-    
-       private THashMap<String, SheetLineComponent> childMap = new THashMap<>();
-       
-       public SheetLineComponent(String uid) {
-           super(uid, 0);
-       }
-       
-//     public SheetLineComponent(String uid, String solverComponentName, int componentId) {
-//             this.uid = uid;
-//             this.solverComponentName = solverComponentName;
-//             this.componentId = componentId;
-//     }
-       
-       @Override
-       public THashMap<String, SheetLineComponent> getChildMap() {
-               return childMap;
-       }
-
-       @Override
-       public void setChildMap(THashMap<String, SheetLineComponent> newChildMap) {
-               childMap = newChildMap;
-               if(childMap != null) {
-                       childMap.forEachValue(new TObjectProcedure<SheetLineComponent>() {
-                               @Override
-                               public boolean execute(SheetLineComponent component) {
-                                       component.parent = SheetLineComponent.this;
-                                       return true;
-                               }
-                       });
-               }
-       }
-       
-       @Override
-       public String toString() {
-           return solverComponentName + " (" + super.toString() + ")";
-       }
-
-}
index 716086b63b76635a654b787a1079a6d46242b735..1d6d19de8ac7db981b2c2dac5de3bb2e4d7a8b9c 100644 (file)
@@ -1,8 +1,9 @@
 package org.simantics.spreadsheet.graph.synchronization;
 
 import org.simantics.db.ReadGraph;
-import org.simantics.spreadsheet.graph.SpreadsheetBook;
 import org.simantics.spreadsheet.graph.SpreadsheetReferenceResolver;
+import org.simantics.spreadsheet.solver.SheetLineComponent;
+import org.simantics.spreadsheet.solver.SpreadsheetBook;
 import org.simantics.structural.synchronization.base.SynchronizationEventHandlerBase;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
index 86fda3d5a7634933efff640a2690ba99de19773b..98335a529126d1e3c784dec6ea4665a5d2a3d617 100644 (file)
@@ -10,8 +10,6 @@
  *******************************************************************************/
 package org.simantics.spreadsheet.ui;
 
-import gnu.trove.map.hash.THashMap;
-
 import java.awt.Rectangle;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -23,10 +21,12 @@ import java.util.Set;
 import java.util.concurrent.CopyOnWriteArrayList;
 
 import org.simantics.spreadsheet.ClientModel;
-import org.simantics.spreadsheet.util.SpreadsheetUtils;
+import org.simantics.spreadsheet.Spreadsheets;
 import org.simantics.utils.datastructures.Pair;
 import org.simantics.utils.datastructures.collections.CollectionUtils;
 
+import gnu.trove.map.hash.THashMap;
+
 public class ClientModelImpl implements ClientModel {
        
        final private Map<String, Map<String, Object>> properties = new THashMap<String, Map<String, Object>>();
@@ -226,7 +226,7 @@ public class ClientModelImpl implements ClientModel {
                        Map<String, Object> cls = cells.remove(location);
                        if(cls == null) return;
                        
-                       long l = SpreadsheetUtils.decodeCellCoded(location);
+                       long l = Spreadsheets.decodeCellCoded(location);
                        int row = (int)(l & 0xffffffff) - 1;
                        int column = (int)((l>>32) & 0xffffffff);
                        
@@ -280,7 +280,7 @@ public class ClientModelImpl implements ClientModel {
 
                                cls.put(property, value);
 
-                               long l = SpreadsheetUtils.decodeCellCoded(location);
+                               long l = Spreadsheets.decodeCellCoded(location);
                                int row = (int)(l & 0xffffffff) - 1;
                                int column = (int)((l>>32) & 0xffffffff);
 
index 395fcbdd73e536555cd6336b8f02b52e4e35afe0..b77350a0cce6f37c755e8c46b79af712032d4cbc 100644 (file)
@@ -18,8 +18,9 @@ import javax.swing.table.DefaultTableModel;
 
 import org.simantics.spreadsheet.ClientModel;
 import org.simantics.spreadsheet.ClientModel.ClientModelListener;
-import org.simantics.spreadsheet.ClientModel.OperationMode;
-import org.simantics.spreadsheet.graph.SpreadsheetStyle;
+import org.simantics.spreadsheet.OperationMode;
+import org.simantics.spreadsheet.Spreadsheets;
+import org.simantics.spreadsheet.solver.SpreadsheetStyle;
 import org.simantics.spreadsheet.util.SpreadsheetUtils;
 import org.simantics.ui.colors.Colors;
 import org.simantics.ui.fonts.Fonts;
@@ -142,7 +143,7 @@ final public class ClientTableModel extends DefaultTableModel {
        
        @Override
        public Object getValueAt(int row, int column) {
-               String location = SpreadsheetUtils.cellName(row, column);
+               String location = Spreadsheets.cellName(row, column);
                
 //             System.out.println("CellValue for location " + location);
                
index 44c2b219a756bc00645cf9cf644b722cce5b887d..6ac032259799ea294e077aa0cdd80976adb6309a 100644 (file)
@@ -16,8 +16,8 @@ import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.ui.handlers.HandlerUtil;
 import org.simantics.spreadsheet.CellEditor;
+import org.simantics.spreadsheet.Spreadsheets;
 import org.simantics.spreadsheet.graph.GraphUI;
-import org.simantics.spreadsheet.util.SpreadsheetUtils;
 
 
 public class DeleteHandler extends AbstractHandler {
@@ -39,7 +39,7 @@ public class DeleteHandler extends AbstractHandler {
        
        for(int row : rows) {
                for(int col : cols) {
-                       ce.edit(null, SpreadsheetUtils.cellName(row, col), null, null);
+                       ce.edit(null, Spreadsheets.cellName(row, col), null, null);
                }
        }
        
index b21a22500eddf2898fdee4febf1f6ecb6f22b559..f39e92c7a42613d555ae13445bfafe0066b8c6e8 100644 (file)
@@ -24,10 +24,11 @@ import org.simantics.databoard.binding.mutable.MutableVariant;
 import org.simantics.databoard.binding.mutable.Variant;
 import org.simantics.spreadsheet.Adaptable;
 import org.simantics.spreadsheet.CellEditor;
-import org.simantics.spreadsheet.CellEditor.Transaction;
-import org.simantics.spreadsheet.ClientModel.OperationMode;
 import org.simantics.spreadsheet.ClientModel;
+import org.simantics.spreadsheet.OperationMode;
 import org.simantics.spreadsheet.Range;
+import org.simantics.spreadsheet.Spreadsheets;
+import org.simantics.spreadsheet.Transaction;
 import org.simantics.spreadsheet.common.cell.StringCellParser;
 import org.simantics.spreadsheet.util.SpreadsheetUtils;
 import org.simantics.utils.threads.logger.ITask;
@@ -196,7 +197,7 @@ public class ExcelAdapter implements ActionListener {
 
                                                        CellValue cell = (CellValue)table.getValueAt(startRow+i, startCol+j);
                                                        if(cell.label != null) {
-                                                               String location = SpreadsheetUtils.cellName(startRow+i, startCol+j);
+                                                               String location = Spreadsheets.cellName(startRow+i, startCol+j);
                                                                Boolean computed = model.getPropertyAt(location, ClientModel.COMPUTED);
                                                                if(computed != null && computed) return;
                                                                removals.add(location);
@@ -221,9 +222,9 @@ public class ExcelAdapter implements ActionListener {
                                                                startCol+j< table.getColumnCount()) {
 
                                                        if (value.startsWith("=")) {
-                                                               editor.edit(tr, SpreadsheetUtils.cellName(startRow+i, startCol+j), ClientModel.CONTENT_EXPRESSION, value, Bindings.STRING, null);
+                                                               editor.edit(tr, Spreadsheets.cellName(startRow+i, startCol+j), ClientModel.CONTENT_EXPRESSION, value, Bindings.STRING, null);
                                                        } else {
-                                                               editor.edit(tr, SpreadsheetUtils.cellName(startRow+i, startCol+j), Variant.ofInstance(value), null);
+                                                               editor.edit(tr, Spreadsheets.cellName(startRow+i, startCol+j), Variant.ofInstance(value), null);
                                                        }
 
                                                }
@@ -243,8 +244,8 @@ public class ExcelAdapter implements ActionListener {
 
                                for(int i=0;i<from.height();i++) {
                                        for(int j=0;j<from.width();j++) {
-                                               String fromCell = SpreadsheetUtils.cellName(from.startRow+i, from.startColumn+j);
-         &n