+ 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;
+ }
+