]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/ExternalRefData.java
Adopt spreadsheet changes made in Balas development
[simantics/platform.git] / bundles / org.simantics.spreadsheet / src / org / simantics / spreadsheet / solver / ExternalRefData.java
diff --git a/bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/ExternalRefData.java b/bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/ExternalRefData.java
new file mode 100644 (file)
index 0000000..f561f4b
--- /dev/null
@@ -0,0 +1,52 @@
+package org.simantics.spreadsheet.solver;
+
+import org.simantics.databoard.binding.mutable.Variant;
+import org.simantics.spreadsheet.ExternalRef;
+import org.simantics.spreadsheet.ExternalRef.ExternalRefListener;
+
+class ExternalRefData implements ExternalRefListener {
+    
+    final private SpreadsheetBook book;
+    final private long referenceKey;
+    final private ExternalRef ref;
+    private boolean isDisposed = false;
+    private Variant value = SpreadsheetBook.DEFAULT_VALUE;
+    
+    public ExternalRefData(SpreadsheetBook book, long referenceKey, ExternalRef ref) {
+        this.book = book;
+        this.referenceKey = referenceKey;
+        this.ref = ref;
+        ref.listen(book.context, this);
+    }
+    
+    public Variant getContent() {
+        return value;
+    }
+    
+    public ExternalRef getRef() {
+        return ref;
+    }
+
+    @Override
+    public void newValue(Variant newVariant) {
+        SpreadsheetCell cell = book.cellByReferenceKey(referenceKey);
+        if(cell.getContent() instanceof SpreadsheetSCLConstant) {
+            SpreadsheetSCLConstant ssc = (SpreadsheetSCLConstant)cell.getContent();
+            Object content = ssc.getContent();
+            if(content.equals(ref)) {
+                value = newVariant;
+                book.fireChanges(book.invalidate(cell));
+                return;
+            }
+        }
+        isDisposed = true;
+    }
+
+    @Override
+    public boolean isDisposed() {
+        if(isDisposed)
+            return true;
+        return book.isDisposed();
+    }
+    
+}
\ No newline at end of file