X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.spreadsheet.graph%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fgraph%2Fsynchronization%2FLineCommandBuilder.java;h=6e191436142b82b0bb148e209c63bff343da5d78;hp=bdfc97468b960893e8ad145c16dde184132724d0;hb=refs%2Fchanges%2F38%2F238%2F2;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 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 index bdfc97468..6e1914361 100644 --- 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 @@ -1,123 +1,123 @@ -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.base.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 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 getConcrete() { - return (T)this; - } - +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.base.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 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 getConcrete() { + return (T)this; + } + } \ No newline at end of file