]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/SpreadsheetCell.java
SCL API for direct access to SpreadsheetBooks
[simantics/platform.git] / bundles / org.simantics.spreadsheet / src / org / simantics / spreadsheet / solver / SpreadsheetCell.java
index 5b732cf864b9f768fd90435ca641fcb3e1e204c8..71566482f1f8e2752ac652a7bd7c22f38f61c781 100644 (file)
@@ -17,7 +17,7 @@ import org.simantics.spreadsheet.solver.formula.SpreadsheetEvaluationEnvironment
 import org.simantics.spreadsheet.solver.formula.parser.ast.AstValue;
 
 @SuppressWarnings("rawtypes")
-public class SpreadsheetCell implements SpreadsheetElement, SheetNode {
+public class SpreadsheetCell extends BinarySearch implements SpreadsheetElement, SheetNode {
 
     private static final long serialVersionUID = 6616793596542239339L;
 
@@ -33,15 +33,14 @@ public class SpreadsheetCell implements SpreadsheetElement, SheetNode {
     private int iterations = 0;
 
     final private SpreadsheetLine line;
-    final private int column;
     int style;
-    private Object content;
+    Object content;
     final private Map<String, SheetNode> properties;
 
     public SpreadsheetCell(SpreadsheetLine line, int column) {
+        super(column);
         this.properties = createProperties();
         this.line = line;
-        this.column = column;
     }
 
     //All SpreadsheetCells have these properties - create them when object is created
@@ -219,6 +218,24 @@ public class SpreadsheetCell implements SpreadsheetElement, SheetNode {
     public Object getContent() {
         return content;
     }
+    
+    public Variant getContentVariant(SpreadsheetBook book) {
+        
+        try {
+            Object content = evaluate(SpreadsheetEvaluationEnvironment.getInstance(book));
+            if(content == null) return Variant.ofInstance("");
+            if(content instanceof Variant) return (Variant)content;
+            if(content instanceof ExternalRefData) return ((ExternalRefData)content).getContent();
+            else return Variant.ofInstance(content);
+        } catch (Throwable t) {
+            t.printStackTrace();
+            return Variant.ofInstance(t.toString());
+        }
+    }
+    
+    public SpreadsheetLine getLine() {
+        return line;
+    }
 
     public static SpreadsheetCell empty(SpreadsheetLine line, int column) {
         SpreadsheetCell cell =  new SpreadsheetCell(line, column);