import java.util.List;
import java.util.Map;
+import javax.xml.soap.Node;
+
import org.simantics.Simantics;
import org.simantics.databoard.Bindings;
import org.simantics.databoard.binding.mutable.Variant;
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.VariableNode;
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.function.Function1;
+import org.simantics.scl.runtime.tuple.Tuple;
import org.simantics.scl.runtime.tuple.Tuple0;
import org.simantics.scl.runtime.tuple.Tuple2;
import org.simantics.simulator.toolkit.StandardRealm;
}
-
+ public static void forRows(ReadGraph graph, Variable run, String sheetName, int min, int max, Function1<Variable, Tuple> fn) throws DatabaseException {
+
+ String sessionName = run.getParent(graph).getURI(graph);
+ StandardRealm<SheetNode, SpreadsheetBook> realm = SpreadsheetSessionManager.getInstance().getOrCreateRealm(graph, sessionName);
+ SpreadsheetBook book = realm.getEngine();
+ SpreadsheetEngine engine = book.getEngine(sheetName);
+ if(engine == null) return;
+
+ engine.forLines(line -> {
+
+ String path = line.getPath();
+ if(path == null) return;
+ try {
+ Variable lineVariable = run.browse(graph, path);
+ if(lineVariable != null)
+ fn.apply(lineVariable);
+ } catch (DatabaseException e) {
+ // This is not reported here
+ }
+
+ } , min, max);
+
+ }
+
public static List<Variable> possibleConfigurationCellVariables(ReadGraph graph, Variable sheet, Range range) throws DatabaseException {
List<Variable> rowVariables = possibleConfigurationLineVariables(graph, sheet, range);
List<Variable> result = new ArrayList<>();
throw new IllegalStateException("Expected StandardGraphChildVariable, got " + cell.getClass().getName());
}
+ private static SpreadsheetCell getCellFromVariable(Variable cell) {
+ StandardGraphChildVariable std = (StandardGraphChildVariable)cell;
+ return (SpreadsheetCell)std.node.node;
+ }
+
+ private static SpreadsheetLine getLineFromVariable(Variable cell) {
+ StandardGraphChildVariable std = (StandardGraphChildVariable)cell;
+ return (SpreadsheetLine)std.node.node;
+ }
+
+ public static Variable linesVariable(ReadGraph graph, Variable sheetVariable) throws DatabaseException {
+ while(!"Lines".equals(sheetVariable.getName(graph)))
+ sheetVariable = sheetVariable.getParent(graph);
+ return sheetVariable;
+ }
+
+ public static Variable offsetCell(ReadGraph graph, Variable cellVariable, int x, int y) throws DatabaseException {
+
+ Variable lineVariable = cellVariable.getParent(graph);
+ Variable offsetLine = offsetRow(graph, lineVariable, y);
+ if(offsetLine == null) return null;
+ SpreadsheetCell cell = getCellFromVariable(cellVariable);
+ return rowCell(graph, offsetLine, cell.column + x);
+
+ }
+
+ public static Variable offsetRow(ReadGraph graph, Variable lineVariable, int offset) throws DatabaseException {
+
+ if(offset == 0) return lineVariable;
+
+ SpreadsheetLine line = getLineFromVariable(lineVariable);
+ SpreadsheetLine offsetLine = line.possibleOffset(offset);
+ if(offsetLine == null) return null;
+
+ Variable linesVariable = linesVariable(graph, lineVariable);
+ String path = offsetLine.getLinesPath();
+ return linesVariable.browsePossible(graph, path);
+
+ }
+
+ public static Variable rowCell(ReadGraph graph, Variable lineVariable, int column) throws DatabaseException {
+
+ SpreadsheetLine line = getLineFromVariable(lineVariable);
+
+ return lineVariable.getPossibleChild(graph, Spreadsheets.cellName(line.row, column));
+
+ }
+
+ public static SpreadsheetBook spreadsheetBook(Variable variable) {
+ if(variable instanceof StandardGraphChildVariable) {
+ VariableNode<Node> node = ((StandardGraphChildVariable)variable).node;
+ if(node != null) {
+ if(node.node instanceof SpreadsheetBook)
+ return (SpreadsheetBook) node.node;
+ }
+ }
+ return null;
+ }
+
}