X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.spreadsheet%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fsolver%2FExternalRefData.java;fp=bundles%2Forg.simantics.spreadsheet%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fsolver%2FExternalRefData.java;h=f561f4b1b9e5b248b5747c6b0c2036493774950e;hb=e5871be84f8ba53a1c80be728bcfb67231c29279;hp=0000000000000000000000000000000000000000;hpb=fb89ec6bace6b3eef93a4c437171bb173fc861b6;p=simantics%2Fplatform.git 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 index 000000000..f561f4b1b --- /dev/null +++ b/bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/ExternalRefData.java @@ -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