X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.spreadsheet.graph%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fgraph%2FSpreadsheetGraphUtils.java;fp=bundles%2Forg.simantics.spreadsheet.graph%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fgraph%2FSpreadsheetGraphUtils.java;h=ee57745ae857bf6bdf4cfd46ce6b0bba87364c2a;hb=cb9643ae2fed519f02b4e95126836722d97105bc;hp=52b7cab5cea0e542218d1a4ec666a0dbf7232f09;hpb=eef8022b52cb287487d543cb64a71a367e2ee251;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetGraphUtils.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetGraphUtils.java index 52b7cab5c..ee57745ae 100644 --- a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetGraphUtils.java +++ b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetGraphUtils.java @@ -30,20 +30,29 @@ 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; @@ -566,4 +575,47 @@ public class SpreadsheetGraphUtils { } + 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()); + } + }